@@ -712,3 +712,117 @@ func TestIntProperty(t *testing.T) {
712712 assert .True (t , propExists ) // exists, even though it is set to zero
713713
714714}
715+
716+ /*
717+ * Test the creation of a text message with an int property.
718+ */
719+ func TestDoubleProperty (t * testing.T ) {
720+
721+ // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
722+ cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
723+ assert .Nil (t , cfErr )
724+
725+ // Creates a connection to the queue manager, using defer to close it automatically
726+ // at the end of the function (if it was created successfully)
727+ context , ctxErr := cf .CreateContext ()
728+ assert .Nil (t , ctxErr )
729+ if context != nil {
730+ defer context .Close ()
731+ }
732+
733+ // Create a TextMessage and check that we can populate it
734+ msgBody := "DoublePropertyRequestMsg"
735+ txtMsg := context .CreateTextMessage ()
736+ txtMsg .SetText (msgBody )
737+
738+ propName := "myProperty"
739+ propValue := float64 (15867494.43857438 )
740+
741+ // Test the empty value before the property is set.
742+ gotPropValue , propErr := txtMsg .GetDoubleProperty (propName )
743+ assert .Nil (t , propErr )
744+ assert .Equal (t , float64 (0 ), gotPropValue )
745+ propExists , propErr := txtMsg .PropertyExists (propName )
746+ assert .Nil (t , propErr )
747+ assert .False (t , propExists )
748+
749+ // Test the ability to set properties before the message is sent.
750+ retErr := txtMsg .SetDoubleProperty (propName , propValue )
751+ assert .Nil (t , retErr )
752+ gotPropValue , propErr = txtMsg .GetDoubleProperty (propName )
753+ assert .Nil (t , propErr )
754+ assert .Equal (t , propValue , gotPropValue )
755+ assert .Equal (t , msgBody , * txtMsg .GetText ())
756+ propExists , propErr = txtMsg .PropertyExists (propName )
757+ assert .Nil (t , propErr )
758+ assert .True (t , propExists ) // now exists
759+
760+ propName2 := "myProperty2"
761+ propValue2 := float64 (- 246810.2255343676 )
762+ retErr = txtMsg .SetDoubleProperty (propName2 , propValue2 )
763+ assert .Nil (t , retErr )
764+ gotPropValue , propErr = txtMsg .GetDoubleProperty (propName2 )
765+ assert .Nil (t , propErr )
766+ assert .Equal (t , propValue2 , gotPropValue )
767+
768+ // Set a property then try to "unset" it by setting to 0
769+ unsetPropName := "mySendThenRemovedString"
770+ unsetPropValue := float64 (12345.123456 )
771+ retErr = txtMsg .SetDoubleProperty (unsetPropName , unsetPropValue )
772+ assert .Nil (t , retErr )
773+ gotPropValue , propErr = txtMsg .GetDoubleProperty (unsetPropName )
774+ assert .Nil (t , propErr )
775+ assert .Equal (t , unsetPropValue , gotPropValue )
776+ retErr = txtMsg .SetDoubleProperty (unsetPropName , 0 )
777+ assert .Nil (t , retErr )
778+ gotPropValue , propErr = txtMsg .GetDoubleProperty (unsetPropName )
779+ assert .Nil (t , propErr )
780+ assert .Equal (t , float64 (0 ), gotPropValue )
781+
782+ // Set up objects for send/receive
783+ queue := context .CreateQueue ("DEV.QUEUE.1" )
784+ consumer , errCons := context .CreateConsumer (queue )
785+ if consumer != nil {
786+ defer consumer .Close ()
787+ }
788+ assert .Nil (t , errCons )
789+
790+ // Now send the message and get it back again, to check that it roundtripped.
791+ errSend := context .CreateProducer ().SetTimeToLive (10000 ).Send (queue , txtMsg )
792+ assert .Nil (t , errSend )
793+
794+ rcvMsg , errRvc := consumer .ReceiveNoWait ()
795+ assert .Nil (t , errRvc )
796+ assert .NotNil (t , rcvMsg )
797+
798+ switch msg := rcvMsg .(type ) {
799+ case jms20subset.TextMessage :
800+ assert .Equal (t , msgBody , * msg .GetText ())
801+ default :
802+ assert .Fail (t , "Got something other than a text message" )
803+ }
804+
805+ // Check property is available on received message.
806+ gotPropValue , propErr = rcvMsg .GetDoubleProperty (propName )
807+ assert .Nil (t , propErr )
808+ assert .Equal (t , propValue , gotPropValue )
809+ propExists , propErr = txtMsg .PropertyExists (propName )
810+ assert .Nil (t , propErr )
811+ assert .True (t , propExists ) // now exists
812+
813+ gotPropValue , propErr = rcvMsg .GetDoubleProperty (propName2 )
814+ assert .Nil (t , propErr )
815+ assert .Equal (t , propValue2 , gotPropValue )
816+
817+ // Properties that are not set should return nil
818+ gotPropValue , propErr = rcvMsg .GetDoubleProperty ("nonExistentProperty" )
819+ assert .Nil (t , propErr )
820+ assert .Equal (t , float64 (0 ), gotPropValue )
821+ gotPropValue , propErr = rcvMsg .GetDoubleProperty (unsetPropName )
822+ assert .Nil (t , propErr )
823+ assert .Equal (t , float64 (0 ), gotPropValue )
824+ propExists , propErr = txtMsg .PropertyExists (unsetPropName )
825+ assert .Nil (t , propErr )
826+ assert .True (t , propExists ) // exists, even though it is set to zero
827+
828+ }
0 commit comments