@@ -22,7 +22,7 @@ import (
2222/*
2323 * Test the retrieval of special header properties
2424 */
25- func TestPropertySpecialGet (t * testing.T ) {
25+ func TestPropertySpecialStringGet (t * testing.T ) {
2626
2727 // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
2828 cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
@@ -302,3 +302,125 @@ func TestPropertyApplData(t *testing.T) {
302302 assert .Nil (t , gotPropValue )
303303
304304}
305+
306+ /*
307+ * Test the retrieval of special header properties that are Integers
308+ */
309+ func TestPropertySpecialIntGet (t * testing.T ) {
310+
311+ // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
312+ cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
313+ assert .Nil (t , cfErr )
314+
315+ // Creates a connection to the queue manager, using defer to close it automatically
316+ // at the end of the function (if it was created successfully)
317+ context , ctxErr := cf .CreateContext ()
318+ assert .Nil (t , ctxErr )
319+ if context != nil {
320+ defer context .Close ()
321+ }
322+
323+ // Create a BytesMessage and check that we can populate it
324+ sendMsg := context .CreateBytesMessage ()
325+
326+ // Set the special properties.
327+ putApplType := 6 // MQAT_DEFAULT. (seems to get written by queue manager, not application)
328+ sendMsg .SetIntProperty ("JMS_IBM_PutApplType" , putApplType )
329+ encoding := 273
330+ sendMsg .SetIntProperty ("JMS_IBM_Encoding" , encoding )
331+ ccsid := 1208
332+ sendMsg .SetIntProperty ("JMS_IBM_Character_Set" , ccsid )
333+ msgType := 8 // MQMT_DATAGRAM
334+ sendMsg .SetIntProperty ("JMS_IBM_MsgType" , msgType )
335+
336+ // Set up objects for send/receive
337+ queue := context .CreateQueue ("DEV.QUEUE.1" )
338+ consumer , errCons := context .CreateConsumer (queue )
339+ if consumer != nil {
340+ defer consumer .Close ()
341+ }
342+ assert .Nil (t , errCons )
343+
344+ // Now send the message and get it back again, to check that it roundtripped.
345+ ttlMillis := 20000
346+ errSend := context .CreateProducer ().SetTimeToLive (ttlMillis ).Send (queue , sendMsg )
347+ assert .Nil (t , errSend )
348+
349+ rcvMsg , errRvc := consumer .ReceiveNoWait ()
350+ assert .Nil (t , errRvc )
351+ assert .NotNil (t , rcvMsg )
352+
353+ switch msg := rcvMsg .(type ) {
354+ case jms20subset.BytesMessage :
355+ assert .Equal (t , 0 , msg .GetBodyLength ())
356+ default :
357+ assert .Fail (t , "Got something other than a bytes message" )
358+ }
359+
360+ // Check the properties came back as expected.
361+ gotPropValue , propErr := rcvMsg .GetIntProperty ("JMS_IBM_PutApplType" )
362+ assert .Nil (t , propErr )
363+ assert .Equal (t , putApplType , gotPropValue )
364+
365+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_Encoding" )
366+ assert .Nil (t , propErr )
367+ assert .Equal (t , encoding , gotPropValue )
368+
369+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_Character_Set" )
370+ assert .Nil (t , propErr )
371+ assert .Equal (t , ccsid , gotPropValue )
372+
373+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_MQMD_CodedCharSetId" )
374+ assert .Nil (t , propErr )
375+ assert .Equal (t , ccsid , gotPropValue )
376+
377+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_MsgType" )
378+ assert .Nil (t , propErr )
379+ assert .Equal (t , msgType , gotPropValue )
380+
381+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_MQMD_MsgType" )
382+ assert .Nil (t , propErr )
383+ assert .Equal (t , msgType , gotPropValue )
384+
385+ // Create a BytesMessage and check that we can populate it
386+ sendMsg2 := context .CreateBytesMessage ()
387+
388+ // Set the special properties, using the MQMD property name variants
389+ ccsid2 := 850
390+ sendMsg2 .SetIntProperty ("JMS_IBM_MQMD_CodedCharSetId" , ccsid2 )
391+ msgType2 := 2 // MQMT_REPLY
392+ sendMsg2 .SetIntProperty ("JMS_IBM_MQMD_MsgType" , msgType2 )
393+
394+ // Now send the message and get it back again, to check that it roundtripped.
395+ errSend = context .CreateProducer ().SetTimeToLive (ttlMillis ).Send (queue , sendMsg2 )
396+ assert .Nil (t , errSend )
397+
398+ rcvMsg , errRvc = consumer .ReceiveNoWait ()
399+ assert .Nil (t , errRvc )
400+ assert .NotNil (t , rcvMsg )
401+
402+ switch msg := rcvMsg .(type ) {
403+ case jms20subset.BytesMessage :
404+ assert .Equal (t , 0 , msg .GetBodyLength ())
405+ default :
406+ assert .Fail (t , "Got something other than a bytes message" )
407+ }
408+
409+ // Check the properties came back as expected.
410+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_Character_Set" )
411+ assert .Nil (t , propErr )
412+ assert .Equal (t , ccsid2 , gotPropValue )
413+
414+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_MQMD_CodedCharSetId" )
415+ assert .Nil (t , propErr )
416+ assert .Equal (t , ccsid2 , gotPropValue )
417+
418+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_MsgType" )
419+ assert .Nil (t , propErr )
420+ assert .Equal (t , msgType2 , gotPropValue )
421+
422+ gotPropValue , propErr = rcvMsg .GetIntProperty ("JMS_IBM_MQMD_MsgType" )
423+ assert .Nil (t , propErr )
424+ assert .Equal (t , msgType2 , gotPropValue )
425+
426+ }
0 commit comments