@@ -137,3 +137,68 @@ func TestTextMessageEmptyBody(t *testing.T) {
137137 }
138138
139139}
140+
141+ /*
142+ * Test the behaviour for send/receive of a text message with a body that starts
143+ * and ends with spaces. Reported issue that the trailing spaces are trimmed from
144+ * the returned message.
145+ */
146+ func TestTextMessageWithSpaces (t * testing.T ) {
147+
148+ // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
149+ cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
150+ assert .Nil (t , cfErr )
151+
152+ // Creates a connection to the queue manager, using defer to close it automatically
153+ // at the end of the function (if it was created successfully)
154+ context , ctxErr := cf .CreateContext ()
155+ assert .Nil (t , ctxErr )
156+ if context != nil {
157+ defer context .Close ()
158+ }
159+
160+ // Create a TextMessage
161+ msgText := " This is some text with spaces before and after "
162+ msg := context .CreateTextMessageWithString (msgText )
163+
164+ // Now send the message and get it back again.
165+ queue := context .CreateQueue ("DEV.QUEUE.1" )
166+ producer := context .CreateProducer ().SetTimeToLive (5000 )
167+ errSend := producer .Send (queue , msg )
168+ assert .Nil (t , errSend )
169+
170+ consumer , errCons := context .CreateConsumer (queue )
171+ assert .Nil (t , errCons )
172+ if consumer != nil {
173+ defer consumer .Close ()
174+ }
175+
176+ rcvMsg , errRvc := consumer .ReceiveNoWait ()
177+ assert .Nil (t , errRvc )
178+ assert .NotNil (t , rcvMsg )
179+
180+ switch msg := rcvMsg .(type ) {
181+ case jms20subset.TextMessage :
182+ assert .Equal (t , msgText , * msg .GetText ())
183+ default :
184+ assert .Fail (t , "Got something other than a text message" )
185+ }
186+
187+ // Create a TextMessage consisting of all spaces.
188+ msgText2 := " "
189+ msg2 := context .CreateTextMessageWithString (msgText2 )
190+ errSend = producer .Send (queue , msg2 )
191+ assert .Nil (t , errSend )
192+
193+ rcvMsg2 , errRvc2 := consumer .ReceiveNoWait ()
194+ assert .Nil (t , errRvc2 )
195+ assert .NotNil (t , rcvMsg2 )
196+
197+ switch msg := rcvMsg2 .(type ) {
198+ case jms20subset.TextMessage :
199+ assert .Equal (t , msgText2 , * msg .GetText ())
200+ default :
201+ assert .Fail (t , "Got something other than a text message" )
202+ }
203+
204+ }
0 commit comments