@@ -518,3 +518,178 @@ function produceAndConsumerMessageWithMultipleHeaderTypesWithJsonPayloadTest() r
518
518
check queueManager .disconnect ();
519
519
}
520
520
521
+ @test :Config {
522
+ groups : [" ibmmqQueue" , " matchOptions" ]
523
+ }
524
+ function produceConsumeWithMsgId() returns error ? {
525
+ QueueManager queueManager = check new (
526
+ name = " QM1" , host = " localhost" , channel = " DEV.APP.SVRCONN" ,
527
+ userID = " app" , password = " password" );
528
+ Queue queue = check queueManager .accessQueue (" DEV.QUEUE.2" , MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF );
529
+
530
+ byte [] providedMsgId = " msg-id-1" .toBytes ();
531
+ string messageContent = " This is a sample message with a message-id." ;
532
+ check queue -> put ({
533
+ messageId : providedMsgId ,
534
+ payload : messageContent .toBytes ()
535
+ });
536
+
537
+ Message ? message = check queue -> get (matchOptions = { messageId : providedMsgId });
538
+ test : assertTrue (message is Message , " Could not retrieve a message for a valid message identifier" );
539
+
540
+ byte []? payload = message ?.payload ;
541
+ test : assertEquals (string : fromBytes (check payload .ensureType ()), messageContent );
542
+
543
+ check queue -> close ();
544
+ check queueManager .disconnect ();
545
+ }
546
+
547
+ @test :Config {
548
+ groups : [" ibmmqQueue" , " matchOptions" ]
549
+ }
550
+ function produceConsumeWithInvalidMsgId() returns error ? {
551
+ QueueManager queueManager = check new (
552
+ name = " QM1" , host = " localhost" , channel = " DEV.APP.SVRCONN" ,
553
+ userID = " app" , password = " password" );
554
+ Queue queue = check queueManager .accessQueue (" DEV.QUEUE.2" , MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF );
555
+
556
+ string messageContent = " This is a sample message with a message-id." ;
557
+ check queue -> put ({
558
+ payload : messageContent .toBytes ()
559
+ });
560
+
561
+ Message ? message = check queue -> get (matchOptions = { messageId : " test-msg-id-1" .toBytes () });
562
+ test : assertTrue (message is (), " Retrieved a message for an invalid message identifier" );
563
+
564
+ check queue -> close ();
565
+ check queueManager .disconnect ();
566
+ }
567
+
568
+ @test :Config {
569
+ groups : [" ibmmqQueue" , " matchOptions" ]
570
+ }
571
+ function produceConsumeWithCorrId() returns error ? {
572
+ QueueManager queueManager = check new (
573
+ name = " QM1" , host = " localhost" , channel = " DEV.APP.SVRCONN" ,
574
+ userID = " app" , password = " password" );
575
+ Queue queue = check queueManager .accessQueue (" DEV.QUEUE.2" , MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF );
576
+
577
+ byte [] providedCorrId = " corr-id-1" .toBytes ();
578
+ string messageContent = " This is a sample message with a correlation-id." ;
579
+ check queue -> put ({
580
+ correlationId : providedCorrId ,
581
+ payload : messageContent .toBytes ()
582
+ });
583
+
584
+ Message ? message = check queue -> get (matchOptions = { correlationId : providedCorrId });
585
+ test : assertTrue (message is Message , " Could not retrieve a message for a valid correlation identifier" );
586
+
587
+ byte []? correlationId = message ?.correlationId ;
588
+ test : assertTrue (correlationId is byte [], " Could not find the correlation identifier for the message" );
589
+
590
+ byte []? payload = message ?.payload ;
591
+ test : assertEquals (string : fromBytes (check payload .ensureType ()), messageContent );
592
+
593
+ check queue -> close ();
594
+ check queueManager .disconnect ();
595
+ }
596
+
597
+ @test :Config {
598
+ groups : [" ibmmqQueue" , " matchOptions" ]
599
+ }
600
+ function produceConsumeWithInvalidCorrId() returns error ? {
601
+ QueueManager queueManager = check new (
602
+ name = " QM1" , host = " localhost" , channel = " DEV.APP.SVRCONN" ,
603
+ userID = " app" , password = " password" );
604
+ Queue queue = check queueManager .accessQueue (" DEV.QUEUE.2" , MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF );
605
+
606
+ string messageContent = " This is a sample message with a message-id." ;
607
+ check queue -> put ({
608
+ payload : messageContent .toBytes ()
609
+ });
610
+
611
+ Message ? message = check queue -> get (matchOptions = { correlationId : " test-corr-id-1" .toBytes () });
612
+ test : assertTrue (message is (), " Retrieved a message for an invalid correlation identifier" );
613
+
614
+ check queue -> close ();
615
+ check queueManager .disconnect ();
616
+ }
617
+
618
+ @test :Config {
619
+ groups : [" ibmmqQueue" , " matchOptions" ]
620
+ }
621
+ function produceConsumeWithMsgIdAndCorrId() returns error ? {
622
+ QueueManager queueManager = check new (
623
+ name = " QM1" , host = " localhost" , channel = " DEV.APP.SVRCONN" ,
624
+ userID = " app" , password = " password" );
625
+ Queue queue = check queueManager .accessQueue (" DEV.QUEUE.2" , MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF );
626
+
627
+ byte [] providedMsgId = " msg-id-1" .toBytes ();
628
+ byte [] providedCorrId = " corr-id-1" .toBytes ();
629
+ string messageContent = " This is a sample message with a message-id and a correlation-id." ;
630
+ check queue -> put ({
631
+ messageId : providedMsgId ,
632
+ correlationId : providedCorrId ,
633
+ payload : messageContent .toBytes ()
634
+ });
635
+
636
+ Message ? message = check queue -> get (matchOptions = { messageId : providedMsgId , correlationId : providedCorrId });
637
+ test : assertTrue (message is Message , " Could not retrieve a message for a valid message identifier and correlation identifier" );
638
+
639
+ byte []? payload = message ?.payload ;
640
+ test : assertEquals (string : fromBytes (check payload .ensureType ()), messageContent );
641
+
642
+ check queue -> close ();
643
+ check queueManager .disconnect ();
644
+ }
645
+
646
+ @test :Config {
647
+ groups : [" ibmmqQueue" , " matchOptions" ],
648
+ dependsOn : [produceConsumeWithMsgIdAndCorrId ]
649
+ }
650
+ function produceConsumeWithInvalidMsgIdAndCorrId() returns error ? {
651
+ QueueManager queueManager = check new (
652
+ name = " QM1" , host = " localhost" , channel = " DEV.APP.SVRCONN" ,
653
+ userID = " app" , password = " password" );
654
+ Queue queue = check queueManager .accessQueue (" DEV.QUEUE.2" , MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF );
655
+
656
+ byte [] providedMsgId = " msg-id-1" .toBytes ();
657
+ byte [] providedCorrId = " corr-id-1" .toBytes ();
658
+ string messageContent = " This is a sample message with a message-id and a correlation-id." ;
659
+ check queue -> put ({
660
+ correlationId : providedCorrId ,
661
+ payload : messageContent .toBytes ()
662
+ });
663
+
664
+ Message ? message = check queue -> get (matchOptions = { messageId : providedMsgId , correlationId : providedCorrId });
665
+ test : assertTrue (message is (), " Retrieved a message for an invalid message-id and a correct correlation identifier" );
666
+
667
+ check queue -> close ();
668
+ check queueManager .disconnect ();
669
+ }
670
+
671
+ @test :Config {
672
+ groups : [" ibmmqQueue" , " matchOptions" ],
673
+ dependsOn : [produceConsumeWithInvalidMsgIdAndCorrId ]
674
+ }
675
+ function produceConsumeWithMsgIdAndInvalidCorrId() returns error ? {
676
+ QueueManager queueManager = check new (
677
+ name = " QM1" , host = " localhost" , channel = " DEV.APP.SVRCONN" ,
678
+ userID = " app" , password = " password" );
679
+ Queue queue = check queueManager .accessQueue (" DEV.QUEUE.2" , MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF );
680
+
681
+ byte [] providedMsgId = " msg-id-1" .toBytes ();
682
+ byte [] providedCorrId = " corr-id-1" .toBytes ();
683
+ string messageContent = " This is a sample message with a message-id and a correlation-id." ;
684
+ check queue -> put ({
685
+ messageId : providedMsgId ,
686
+ payload : messageContent .toBytes ()
687
+ });
688
+
689
+ Message ? message = check queue -> get (matchOptions = { messageId : providedMsgId , correlationId : providedCorrId });
690
+ test : assertTrue (message is (), " Retrieved a message for a correct message-id and an invalid correlation identifier" );
691
+
692
+ check queue -> close ();
693
+ check queueManager .disconnect ();
694
+ }
695
+
0 commit comments