@@ -1090,7 +1090,7 @@ func TestPropertyBytesMsg(t *testing.T) {
10901090}
10911091
10921092/*
1093- * Test the conversion between different message property data types.
1093+ * Test the conversion between string message properties and other data types.
10941094 */
10951095func TestPropertyTypesStringConversion (t * testing.T ) {
10961096
@@ -1140,24 +1140,6 @@ func TestPropertyTypesStringConversion(t *testing.T) {
11401140 msg .SetStringProperty (stringOfDoublePropName , & stringOfDoubleValue )
11411141 msg .SetStringProperty (stringOfDoublePropName2 , & stringOfDoubleValue2 )
11421142
1143- // Now an int property
1144- intPropName := "myIntProperty"
1145- intPropValue := 553786
1146- retErr := msg .SetIntProperty (intPropName , intPropValue )
1147- assert .Nil (t , retErr )
1148-
1149- // Now a double property
1150- doublePropName := "myDoubleProperty"
1151- doublePropValue := float64 (3.1415926535 )
1152- retErr = msg .SetDoubleProperty (doublePropName , doublePropValue )
1153- assert .Nil (t , retErr )
1154-
1155- // Now a bool property
1156- boolPropName := "myBoolProperty"
1157- boolPropValue := true
1158- retErr = msg .SetBooleanProperty (boolPropName , boolPropValue )
1159- assert .Nil (t , retErr )
1160-
11611143 // Set up objects for send/receive
11621144 queue := context .CreateQueue ("DEV.QUEUE.1" )
11631145 consumer , errCons := context .CreateConsumer (queue )
@@ -1297,3 +1279,141 @@ func TestPropertyTypesStringConversion(t *testing.T) {
12971279 assert .Equal (t , float64 (0 ), gotUnsetAsDoubleValue )
12981280
12991281}
1282+
1283+ /*
1284+ * Test the conversion between different int message properties and other data types.
1285+ */
1286+ func TestPropertyTypesIntConversion (t * testing.T ) {
1287+
1288+ // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
1289+ cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
1290+ assert .Nil (t , cfErr )
1291+
1292+ // Creates a connection to the queue manager, using defer to close it automatically
1293+ // at the end of the function (if it was created successfully)
1294+ context , ctxErr := cf .CreateContext ()
1295+ assert .Nil (t , ctxErr )
1296+ if context != nil {
1297+ defer context .Close ()
1298+ }
1299+
1300+ msg := context .CreateTextMessage ()
1301+
1302+ unsetPropName := "thisPropertyIsNotSet"
1303+
1304+ // Set up some different int properties
1305+ intOnePropName := "intOne"
1306+ intOneValue := 1
1307+ intZeroPropName := "intZero"
1308+ intZeroValue := 0
1309+ intMinusOnePropName := "intMinusOne"
1310+ intMinusOneValue := - 1
1311+
1312+ intLargePosPropName := "largePositive"
1313+ intLargePosValue := 48632675
1314+ intLargeNegPropName := "largeNegative"
1315+ intLargeNegValue := - 3789753467
1316+
1317+ msg .SetIntProperty (intOnePropName , intOneValue )
1318+ msg .SetIntProperty (intZeroPropName , intZeroValue )
1319+ msg .SetIntProperty (intMinusOnePropName , intMinusOneValue )
1320+ msg .SetIntProperty (intLargePosPropName , intLargePosValue )
1321+ msg .SetIntProperty (intLargeNegPropName , intLargeNegValue )
1322+
1323+ // Set up objects for send/receive
1324+ queue := context .CreateQueue ("DEV.QUEUE.1" )
1325+ consumer , errCons := context .CreateConsumer (queue )
1326+ if consumer != nil {
1327+ defer consumer .Close ()
1328+ }
1329+ assert .Nil (t , errCons )
1330+
1331+ // Now send the message and get it back again, to check that it roundtripped.
1332+ errSend := context .CreateProducer ().SetTimeToLive (10000 ).Send (queue , msg )
1333+ assert .Nil (t , errSend )
1334+
1335+ rcvMsg , errRvc := consumer .ReceiveNoWait ()
1336+ assert .Nil (t , errRvc )
1337+ assert .NotNil (t , rcvMsg )
1338+
1339+ // Check int properties were set correctly
1340+ gotOneValue , gotOneErr := rcvMsg .GetIntProperty (intOnePropName )
1341+ gotZeroValue , gotZeroErr := rcvMsg .GetIntProperty (intZeroPropName )
1342+ gotMinusOneValue , gotMinusOneErr := rcvMsg .GetIntProperty (intMinusOnePropName )
1343+ gotLargePosValue , gotLargePosErr := rcvMsg .GetIntProperty (intLargePosPropName )
1344+ gotLargeNegValue , gotLargeNegErr := rcvMsg .GetIntProperty (intLargeNegPropName )
1345+ gotUnsetPropValue , gotUnsetErr := rcvMsg .GetIntProperty (unsetPropName )
1346+ assert .Nil (t , gotOneErr )
1347+ assert .Nil (t , gotZeroErr )
1348+ assert .Nil (t , gotMinusOneErr )
1349+ assert .Nil (t , gotLargePosErr )
1350+ assert .Nil (t , gotLargeNegErr )
1351+ assert .Nil (t , gotUnsetErr )
1352+ assert .Equal (t , intOneValue , gotOneValue )
1353+ assert .Equal (t , intZeroValue , gotZeroValue )
1354+ assert .Equal (t , intMinusOneValue , gotMinusOneValue )
1355+ assert .Equal (t , intLargePosValue , gotLargePosValue )
1356+ assert .Equal (t , intLargeNegValue , gotLargeNegValue )
1357+ assert .Equal (t , 0 , gotUnsetPropValue )
1358+
1359+ // Convert back as string
1360+ gotStrOneValue , gotOneErr := rcvMsg .GetStringProperty (intOnePropName )
1361+ gotStrZeroValue , gotZeroErr := rcvMsg .GetStringProperty (intZeroPropName )
1362+ gotStrMinusOneValue , gotMinusOneErr := rcvMsg .GetStringProperty (intMinusOnePropName )
1363+ gotStrLargePosValue , gotLargePosErr := rcvMsg .GetStringProperty (intLargePosPropName )
1364+ gotStrLargeNegValue , gotLargeNegErr := rcvMsg .GetStringProperty (intLargeNegPropName )
1365+ gotStrUnsetPropValue , gotUnsetErr := rcvMsg .GetStringProperty (unsetPropName )
1366+ assert .Nil (t , gotOneErr )
1367+ assert .Nil (t , gotZeroErr )
1368+ assert .Nil (t , gotMinusOneErr )
1369+ assert .Nil (t , gotLargePosErr )
1370+ assert .Nil (t , gotLargeNegErr )
1371+ assert .Nil (t , gotUnsetErr )
1372+ assert .Equal (t , "1" , * gotStrOneValue )
1373+ assert .Equal (t , "0" , * gotStrZeroValue )
1374+ assert .Equal (t , "-1" , * gotStrMinusOneValue )
1375+ assert .Equal (t , "48632675" , * gotStrLargePosValue )
1376+ assert .Equal (t , "-3789753467" , * gotStrLargeNegValue )
1377+ assert .Nil (t , gotStrUnsetPropValue )
1378+
1379+ // Convert back as bool
1380+ gotBoolOneValue , gotOneErr := rcvMsg .GetBooleanProperty (intOnePropName )
1381+ gotBoolZeroValue , gotZeroErr := rcvMsg .GetBooleanProperty (intZeroPropName )
1382+ gotBoolMinusOneValue , gotMinusOneErr := rcvMsg .GetBooleanProperty (intMinusOnePropName )
1383+ gotBoolLargePosValue , gotLargePosErr := rcvMsg .GetBooleanProperty (intLargePosPropName )
1384+ gotBoolLargeNegValue , gotLargeNegErr := rcvMsg .GetBooleanProperty (intLargeNegPropName )
1385+ gotBoolUnsetPropValue , gotUnsetErr := rcvMsg .GetBooleanProperty (unsetPropName )
1386+ assert .Nil (t , gotOneErr )
1387+ assert .Nil (t , gotZeroErr )
1388+ assert .Nil (t , gotMinusOneErr )
1389+ assert .Nil (t , gotLargePosErr )
1390+ assert .Nil (t , gotLargeNegErr )
1391+ assert .Nil (t , gotUnsetErr )
1392+ assert .Equal (t , true , gotBoolOneValue )
1393+ assert .Equal (t , false , gotBoolZeroValue )
1394+ assert .Equal (t , false , gotBoolMinusOneValue )
1395+ assert .Equal (t , false , gotBoolLargePosValue )
1396+ assert .Equal (t , false , gotBoolLargeNegValue )
1397+ assert .Equal (t , false , gotBoolUnsetPropValue )
1398+
1399+ // Convert back as double
1400+ gotDoubleOneValue , gotOneErr := rcvMsg .GetDoubleProperty (intOnePropName )
1401+ gotDoubleZeroValue , gotZeroErr := rcvMsg .GetDoubleProperty (intZeroPropName )
1402+ gotDoubleMinusOneValue , gotMinusOneErr := rcvMsg .GetDoubleProperty (intMinusOnePropName )
1403+ gotDoubleLargePosValue , gotLargePosErr := rcvMsg .GetDoubleProperty (intLargePosPropName )
1404+ gotDoubleLargeNegValue , gotLargeNegErr := rcvMsg .GetDoubleProperty (intLargeNegPropName )
1405+ gotDoubleUnsetPropValue , gotUnsetErr := rcvMsg .GetDoubleProperty (unsetPropName )
1406+ assert .Nil (t , gotOneErr )
1407+ assert .Nil (t , gotZeroErr )
1408+ assert .Nil (t , gotMinusOneErr )
1409+ assert .Nil (t , gotLargePosErr )
1410+ assert .Nil (t , gotLargeNegErr )
1411+ assert .Nil (t , gotUnsetErr )
1412+ assert .Equal (t , float64 (1 ), gotDoubleOneValue )
1413+ assert .Equal (t , float64 (0 ), gotDoubleZeroValue )
1414+ assert .Equal (t , float64 (- 1 ), gotDoubleMinusOneValue )
1415+ assert .Equal (t , float64 (48632675 ), gotDoubleLargePosValue )
1416+ assert .Equal (t , float64 (- 3789753467 ), gotDoubleLargeNegValue )
1417+ assert .Equal (t , float64 (0 ), gotDoubleUnsetPropValue )
1418+
1419+ }
0 commit comments