@@ -199,7 +199,7 @@ func TestCorrelIDParsing(t *testing.T) {
199
199
200
200
testCorrel = "ThisIsAVeryLongCorrelationIDWhichIsMoreThanTwentyFourCharacters"
201
201
msg .SetJMSCorrelationID (testCorrel )
202
- assert .Equal (t , testCorrel [0 :24 ], msg .GetJMSCorrelationID ())
202
+ assert .Equal (t , testCorrel [0 :12 ], msg .GetJMSCorrelationID ())
203
203
204
204
// MessageID format
205
205
testCorrel = "414d5120514d312020202020202020201017155c0255b621"
@@ -212,3 +212,79 @@ func TestCorrelIDParsing(t *testing.T) {
212
212
assert .Equal (t , "" , msg .GetJMSCorrelationID ())
213
213
214
214
}
215
+
216
+ // Do a round-trip send and receive of a message in order to check the correlation ID
217
+ func checkCorrelIDOnSendReceive (t * testing.T , context jms20subset.JMSContext , queue jms20subset.Queue ,
218
+ producer jms20subset.JMSProducer , consumer jms20subset.JMSConsumer ,
219
+ inputCorrelID string , expectedCorrelID string ) {
220
+
221
+ msg := context .CreateTextMessage ()
222
+ msg .SetJMSCorrelationID (inputCorrelID )
223
+ assert .Equal (t , expectedCorrelID , msg .GetJMSCorrelationID ())
224
+ sendErr := producer .Send (queue , msg )
225
+ assert .Nil (t , sendErr )
226
+
227
+ rcvMsg , rcvErr := consumer .ReceiveNoWait ()
228
+ assert .Nil (t , rcvErr )
229
+ assert .NotNil (t , rcvMsg )
230
+ assert .Equal (t , expectedCorrelID , rcvMsg .GetJMSCorrelationID ())
231
+
232
+ }
233
+
234
+ /*
235
+ * Test that we can round trip various correlation IDs via messages sent
236
+ * and received, since there is some checking on send.
237
+ */
238
+ func TestCorrelIDParsingOnSend (t * testing.T ) {
239
+
240
+ // Loads CF parameters from connection_info.json and applicationApiKey.json in the Downloads directory
241
+ cf , cfErr := mqjms .CreateConnectionFactoryFromDefaultJSONFiles ()
242
+ assert .Nil (t , cfErr )
243
+
244
+ // Creates a connection to the queue manager, using defer to close it automatically
245
+ // at the end of the function (if it was created successfully)
246
+ context , ctxErr := cf .CreateContext ()
247
+ assert .Nil (t , ctxErr )
248
+ if context != nil {
249
+ defer context .Close ()
250
+ }
251
+
252
+ // First, check the Send queue is initially empty
253
+ queue := context .CreateQueue ("DEV.QUEUE.1" )
254
+ consumer , rConErr := context .CreateConsumer (queue )
255
+ assert .Nil (t , rConErr )
256
+ if consumer != nil {
257
+ defer consumer .Close ()
258
+ }
259
+ reqMsgTest , rcvErr := consumer .ReceiveNoWait ()
260
+ assert .Nil (t , rcvErr )
261
+ assert .Nil (t , reqMsgTest )
262
+
263
+ producer := context .CreateProducer ().SetTimeToLive (1000 )
264
+ assert .NotNil (t , producer )
265
+
266
+ // Try out the various combinations of correlation ID
267
+ testCorrel := ""
268
+ checkCorrelIDOnSendReceive (t , context , queue , producer , consumer , testCorrel , "" )
269
+
270
+ // MessageID format
271
+ testCorrel = "414d5120514d312020202020202020201017155c0255b621"
272
+ checkCorrelIDOnSendReceive (t , context , queue , producer , consumer , testCorrel , testCorrel )
273
+
274
+ // Empty correlationID
275
+ testCorrel = "000000000000000000000000000000000000000000000000"
276
+ checkCorrelIDOnSendReceive (t , context , queue , producer , consumer , testCorrel , "" )
277
+
278
+ testCorrel = "ThisIsAVeryLongCorrelationIDWhichIsMoreThanTwentyFourCharacters"
279
+ checkCorrelIDOnSendReceive (t , context , queue , producer , consumer , testCorrel , testCorrel [0 :12 ])
280
+
281
+ testCorrel = "Hello World"
282
+ checkCorrelIDOnSendReceive (t , context , queue , producer , consumer , testCorrel , testCorrel )
283
+
284
+ testCorrel = " "
285
+ checkCorrelIDOnSendReceive (t , context , queue , producer , consumer , testCorrel , testCorrel )
286
+
287
+ testCorrel = "010203040506"
288
+ checkCorrelIDOnSendReceive (t , context , queue , producer , consumer , testCorrel , testCorrel )
289
+
290
+ }
0 commit comments