@@ -27,6 +27,11 @@ import (
27
27
* JMS: SetStringProperty, GetStringProperty,
28
28
* https://github.com/eclipse-ee4j/messaging/blob/master/api/src/main/java/jakarta/jms/Message.java#L1119
29
29
*
30
+ * Double
31
+ * Boolean
32
+ *
33
+ * BytesMessage
34
+ *
30
35
*/
31
36
32
37
/*
@@ -337,19 +342,19 @@ func TestPropertyClearProperties(t *testing.T) {
337
342
assert .Equal (t , 0 , len (allPropNames ))
338
343
339
344
propName2 := "myPropertyTwo"
340
- propValue2 := "myValueTwo"
345
+ propValue2 := 246811
341
346
342
347
// Set multiple properties
343
348
retErr = txtMsg .SetStringProperty (propName , & propValue )
344
349
assert .Nil (t , retErr )
345
350
gotPropValue , propErr = txtMsg .GetStringProperty (propName )
346
351
assert .Nil (t , propErr )
347
352
assert .Equal (t , propValue , * gotPropValue )
348
- retErr = txtMsg .SetStringProperty (propName2 , & propValue2 )
353
+ retErr = txtMsg .SetIntProperty (propName2 , propValue2 )
349
354
assert .Nil (t , retErr )
350
- gotPropValue , propErr = txtMsg .GetStringProperty (propName2 )
355
+ gotPropValue2 , propErr : = txtMsg .GetIntProperty (propName2 )
351
356
assert .Nil (t , propErr )
352
- assert .Equal (t , propValue2 , * gotPropValue )
357
+ assert .Equal (t , propValue2 , gotPropValue2 )
353
358
propExists , propErr = txtMsg .PropertyExists (propName2 )
354
359
assert .Nil (t , propErr )
355
360
assert .True (t , propExists ) // now exists
@@ -593,3 +598,117 @@ func TestStringPropertyTextMessageEmptyBody(t *testing.T) {
593
598
assert .Equal (t , propBValue , * gotPropValue )
594
599
595
600
}
601
+
602
+ /*
603
+ * Test the creation of a text message with an int property.
604
+ */
605
+ func TestIntProperty (t * testing.T ) {
606
+
607
+ // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
608
+ cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
609
+ assert .Nil (t , cfErr )
610
+
611
+ // Creates a connection to the queue manager, using defer to close it automatically
612
+ // at the end of the function (if it was created successfully)
613
+ context , ctxErr := cf .CreateContext ()
614
+ assert .Nil (t , ctxErr )
615
+ if context != nil {
616
+ defer context .Close ()
617
+ }
618
+
619
+ // Create a TextMessage and check that we can populate it
620
+ msgBody := "IntPropertyRequestMsg"
621
+ txtMsg := context .CreateTextMessage ()
622
+ txtMsg .SetText (msgBody )
623
+
624
+ propName := "myProperty"
625
+ propValue := 6
626
+
627
+ // Test the empty value before the property is set.
628
+ gotPropValue , propErr := txtMsg .GetIntProperty (propName )
629
+ assert .Nil (t , propErr )
630
+ assert .Equal (t , 0 , gotPropValue )
631
+ propExists , propErr := txtMsg .PropertyExists (propName )
632
+ assert .Nil (t , propErr )
633
+ assert .False (t , propExists )
634
+
635
+ // Test the ability to set properties before the message is sent.
636
+ retErr := txtMsg .SetIntProperty (propName , propValue )
637
+ assert .Nil (t , retErr )
638
+ gotPropValue , propErr = txtMsg .GetIntProperty (propName )
639
+ assert .Nil (t , propErr )
640
+ assert .Equal (t , propValue , gotPropValue )
641
+ assert .Equal (t , msgBody , * txtMsg .GetText ())
642
+ propExists , propErr = txtMsg .PropertyExists (propName )
643
+ assert .Nil (t , propErr )
644
+ assert .True (t , propExists ) // now exists
645
+
646
+ propName2 := "myProperty2"
647
+ propValue2 := 246810
648
+ retErr = txtMsg .SetIntProperty (propName2 , propValue2 )
649
+ assert .Nil (t , retErr )
650
+ gotPropValue , propErr = txtMsg .GetIntProperty (propName2 )
651
+ assert .Nil (t , propErr )
652
+ assert .Equal (t , propValue2 , gotPropValue )
653
+
654
+ // Set a property then try to "unset" it by setting to 0
655
+ unsetPropName := "mySendThenRemovedString"
656
+ unsetPropValue := 12345
657
+ retErr = txtMsg .SetIntProperty (unsetPropName , unsetPropValue )
658
+ assert .Nil (t , retErr )
659
+ gotPropValue , propErr = txtMsg .GetIntProperty (unsetPropName )
660
+ assert .Nil (t , propErr )
661
+ assert .Equal (t , unsetPropValue , gotPropValue )
662
+ retErr = txtMsg .SetIntProperty (unsetPropName , 0 )
663
+ assert .Nil (t , retErr )
664
+ gotPropValue , propErr = txtMsg .GetIntProperty (unsetPropName )
665
+ assert .Nil (t , propErr )
666
+ assert .Equal (t , 0 , gotPropValue )
667
+
668
+ // Set up objects for send/receive
669
+ queue := context .CreateQueue ("DEV.QUEUE.1" )
670
+ consumer , errCons := context .CreateConsumer (queue )
671
+ if consumer != nil {
672
+ defer consumer .Close ()
673
+ }
674
+ assert .Nil (t , errCons )
675
+
676
+ // Now send the message and get it back again, to check that it roundtripped.
677
+ errSend := context .CreateProducer ().SetTimeToLive (10000 ).Send (queue , txtMsg )
678
+ assert .Nil (t , errSend )
679
+
680
+ rcvMsg , errRvc := consumer .ReceiveNoWait ()
681
+ assert .Nil (t , errRvc )
682
+ assert .NotNil (t , rcvMsg )
683
+
684
+ switch msg := rcvMsg .(type ) {
685
+ case jms20subset.TextMessage :
686
+ assert .Equal (t , msgBody , * msg .GetText ())
687
+ default :
688
+ assert .Fail (t , "Got something other than a text message" )
689
+ }
690
+
691
+ // Check property is available on received message.
692
+ gotPropValue , propErr = rcvMsg .GetIntProperty (propName )
693
+ assert .Nil (t , propErr )
694
+ assert .Equal (t , propValue , gotPropValue )
695
+ propExists , propErr = txtMsg .PropertyExists (propName )
696
+ assert .Nil (t , propErr )
697
+ assert .True (t , propExists ) // now exists
698
+
699
+ gotPropValue , propErr = rcvMsg .GetIntProperty (propName2 )
700
+ assert .Nil (t , propErr )
701
+ assert .Equal (t , propValue2 , gotPropValue )
702
+
703
+ // Properties that are not set should return nil
704
+ gotPropValue , propErr = rcvMsg .GetIntProperty ("nonExistentProperty" )
705
+ assert .Nil (t , propErr )
706
+ assert .Equal (t , 0 , gotPropValue )
707
+ gotPropValue , propErr = rcvMsg .GetIntProperty (unsetPropName )
708
+ assert .Nil (t , propErr )
709
+ assert .Equal (t , 0 , gotPropValue )
710
+ propExists , propErr = txtMsg .PropertyExists (unsetPropName )
711
+ assert .Nil (t , propErr )
712
+ assert .True (t , propExists ) // exists, even though it is set to zero
713
+
714
+ }
0 commit comments