From 2e3ed247faedd123bc447087eec6e8d9a7d73bca Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Mon, 29 Jan 2024 11:39:34 +0530 Subject: [PATCH] Update test cases with authentication --- .../tests/queue_producer_consumer_tests.bal | 52 +++++++++++---- ballerina/tests/secure_socket_tests.bal | 8 +++ .../topic_publisher_subscriber_tests.bal | 64 ++++++++++++++----- 3 files changed, 95 insertions(+), 29 deletions(-) diff --git a/ballerina/tests/queue_producer_consumer_tests.bal b/ballerina/tests/queue_producer_consumer_tests.bal index d228df0..1a15fd4 100644 --- a/ballerina/tests/queue_producer_consumer_tests.bal +++ b/ballerina/tests/queue_producer_consumer_tests.bal @@ -21,7 +21,9 @@ import ballerina/time; groups: ["ibmmqQueue"] } function basicQueueProducerConsumerTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); check producer->put({ @@ -42,7 +44,9 @@ function basicQueueProducerConsumerTest() returns error? { groups: ["ibmmqQueue"] } function basicQueueProducerConsumerWithOneQueueObjectTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue queue = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT | MQOO_INPUT_AS_Q_DEF); check queue->put({ payload: "Hello World with one queue".toBytes() @@ -61,7 +65,9 @@ function basicQueueProducerConsumerWithOneQueueObjectTest() returns error? { groups: ["ibmmqQueue"] } function basicQueueProducerConsumerWithJsonPayloadTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); json messageBody = { @@ -116,7 +122,9 @@ function basicQueueProducerConsumerWithJsonPayloadTest() returns error? { groups: ["ibmmqQueue"] } function pubSubMultipleMessagesQueueProducerConsumerTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); foreach int i in 0 ... 4 { @@ -141,7 +149,9 @@ function pubSubMultipleMessagesQueueProducerConsumerTest() returns error? { groups: ["ibmmqQueue"] } function consumerWithoutProducingMessageTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); Message|Error? result = consumer->get(options = MQGMO_WAIT, waitInterval = 5); test:assertTrue(result is ()); @@ -153,7 +163,9 @@ function consumerWithoutProducingMessageTest() returns error? { groups: ["ibmmqQueue"] } function produceToNonExistingQueueTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue|Error result = queueManager.accessQueue("NON.EXISTING.QUEUE", MQOO_OUTPUT); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing queue: MQJE001: Completion Code '2', Reason '2085'."); @@ -169,7 +181,9 @@ function produceToNonExistingQueueTest() returns error? { groups: ["ibmmqQueue"] } function consumerConnectToNonExistingQueueTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue|Error result = queueManager.accessQueue("NON.EXISTING.QUEUE", MQOO_INPUT_AS_Q_DEF); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing queue: MQJE001: Completion Code '2', Reason '2085'."); @@ -185,7 +199,9 @@ function consumerConnectToNonExistingQueueTest() returns error? { groups: ["ibmmqQueue"] } function produceWithInvalidQueueNameTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue|Error result = queueManager.accessQueue("INVALID QUEUE", MQOO_INPUT_AS_Q_DEF); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing queue: MQJE001: Completion Code '2', Reason '2085'."); @@ -201,7 +217,9 @@ function produceWithInvalidQueueNameTest() returns error? { groups: ["ibmmqQueue"] } function consumeFromAnInvalidQueueNameTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue|Error result = queueManager.accessQueue("INVALID QUEUE", MQOO_INPUT_AS_Q_DEF); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing queue: MQJE001: Completion Code '2', Reason '2085'."); @@ -217,7 +235,9 @@ function consumeFromAnInvalidQueueNameTest() returns error? { groups: ["ibmmqQueue"] } function produceAndConsumerMessageWithAdditionalPropertiesTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); time:Utc timeNow = time:utcNow(); @@ -257,7 +277,9 @@ function produceAndConsumerMessageWithAdditionalPropertiesTest() returns error? groups: ["ibmmqQueue"] } function produceAndConsumerMessageWithAdditionalPropertiesWithJsonPayloadTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); time:Utc timeNow = time:utcNow(); @@ -332,7 +354,9 @@ function produceAndConsumerMessageWithAdditionalPropertiesWithJsonPayloadTest() groups: ["ibmmqQueue"] } function produceAndConsumerMessageWithMultipleHeaderTypesTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); check producer->put({ @@ -397,7 +421,9 @@ function produceAndConsumerMessageWithMultipleHeaderTypesTest() returns error? { groups: ["ibmmqQueue"] } function produceAndConsumerMessageWithMultipleHeaderTypesWithJsonPayloadTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Queue producer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_OUTPUT); Queue consumer = check queueManager.accessQueue("DEV.QUEUE.1", MQOO_INPUT_AS_Q_DEF); json messageBody = { diff --git a/ballerina/tests/secure_socket_tests.bal b/ballerina/tests/secure_socket_tests.bal index 466e1df..9531b2c 100644 --- a/ballerina/tests/secure_socket_tests.bal +++ b/ballerina/tests/secure_socket_tests.bal @@ -25,6 +25,8 @@ function basicPublisherSubscriberSecureSocketTest() returns error? { host = "localhost", port = 1415, channel = "DEV.APP.SVRCONN", + userID = "app", + password = "password", sslCipherSuite = TLS12ORHIGHER, secureSocket = { cert: "./tests/resources/secrets/server.crt", @@ -59,6 +61,8 @@ function basicQueueProducerConsumerSecureSocketTest() returns error? { host = "localhost", port = 1415, channel = "DEV.APP.SVRCONN", + userID = "app", + password = "password", sslCipherSuite = TLS12ORHIGHER, secureSocket = { cert: "./tests/resources/secrets/server.crt", @@ -93,6 +97,8 @@ function basicPublisherSubscriberSecureSocketJksTest() returns error? { host = "localhost", port = 1415, channel = "DEV.APP.SVRCONN", + userID = "app", + password = "password", sslCipherSuite = TLS12ORHIGHER, secureSocket = { cert: { @@ -130,6 +136,8 @@ function basicQueueProducerConsumerSecureSocketJksTest() returns error? { host = "localhost", port = 1415, channel = "DEV.APP.SVRCONN", + userID = "app", + password = "password", sslCipherSuite = TLS12ORHIGHER, secureSocket = { cert: { diff --git a/ballerina/tests/topic_publisher_subscriber_tests.bal b/ballerina/tests/topic_publisher_subscriber_tests.bal index 74966de..6844bc8 100644 --- a/ballerina/tests/topic_publisher_subscriber_tests.bal +++ b/ballerina/tests/topic_publisher_subscriber_tests.bal @@ -20,7 +20,9 @@ import ballerina/test; groups: ["ibmmqTopic"] } function basicPublisherSubscriberTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->put({ @@ -41,7 +43,9 @@ function basicPublisherSubscriberTest() returns error? { groups: ["ibmmqTopic"] } function pubSubMultipleMessagesInOrderTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); foreach int i in 0 ... 4 { @@ -66,7 +70,9 @@ function pubSubMultipleMessagesInOrderTest() returns error? { groups: ["ibmmqTopic"] } function subscribeWithFiniteTimeoutTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->put({ @@ -87,7 +93,9 @@ function subscribeWithFiniteTimeoutTest() returns error? { groups: ["ibmmqTopic"] } function subscribeWithoutPublishTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Message|Error? result = subscriber->get(waitInterval = 5); test:assertTrue(result is ()); @@ -99,7 +107,9 @@ function subscribeWithoutPublishTest() returns error? { groups: ["ibmmqTopic"] } function publishToNonExistingTopicTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic|Error result = queueManager.accessTopic("dev", "NON.EXISTING.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing topic: MQJE001: Completion Code '2', Reason '2085'."); @@ -115,7 +125,9 @@ function publishToNonExistingTopicTest() returns error? { groups: ["ibmmqTopic"] } function subscribeToNonExistingTopicTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic|Error result = queueManager.accessTopic("dev", "NON.EXISTING.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing topic: MQJE001: Completion Code '2', Reason '2085'."); @@ -131,7 +143,9 @@ function subscribeToNonExistingTopicTest() returns error? { groups: ["ibmmqTopic"] } function subscribeWithInvalidTopicNameTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic|Error result = queueManager.accessTopic("dev", "INVALID TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing topic: MQJE001: Completion Code '2', Reason '2152'."); @@ -147,7 +161,9 @@ function subscribeWithInvalidTopicNameTest() returns error? { groups: ["ibmmqTopic"] } function publishWithInvalidTopicNameTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic|Error result = queueManager.accessTopic("dev", "INVALID TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); if result is Error { test:assertEquals(result.message(), "Error occurred while accessing topic: MQJE001: Completion Code '2', Reason '2085'."); @@ -163,7 +179,9 @@ function publishWithInvalidTopicNameTest() returns error? { groups: ["ibmmqTopic"] } function accessTopicAfterQMDisconnectTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); check queueManager.disconnect(); Topic|Error result = queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); if result is Error { @@ -180,7 +198,9 @@ function accessTopicAfterQMDisconnectTest() returns error? { groups: ["ibmmqTopic"] } function putToTopicAfterTopicCloseTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->close(); Error? result = publisher->put({ @@ -201,7 +221,9 @@ function putToTopicAfterTopicCloseTest() returns error? { groups: ["ibmmqTopic"] } function putToTopicAfterQMDisconnectTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check queueManager.disconnect(); Error? result = publisher->put({ @@ -222,7 +244,9 @@ function putToTopicAfterQMDisconnectTest() returns error? { groups: ["ibmmqTopic"] } function publishSubscribeWithMQRFH2HeadersTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->put({ @@ -299,7 +323,9 @@ function publishSubscribeWithMQRFH2HeadersTest() returns error? { groups: ["ibmmqTopic"] } function publishSubscribeWithMQRFHHeadersTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->put({ @@ -336,7 +362,9 @@ function publishSubscribeWithMQRFHHeadersTest() returns error? { groups: ["ibmmqTopic"] } function publishSubscribeWithMQCIHHeadersTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->put({ @@ -426,7 +454,9 @@ function publishSubscribeWithMQCIHHeadersTest() returns error? { groups: ["ibmmqTopic"] } function publishSubscribeWithMQIIHHeadersTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->put({ @@ -484,7 +514,9 @@ function publishSubscribeWithMQIIHHeadersTest() returns error? { groups: ["ibmmqTopic"] } function publishSubscribeWithMultipleHeaderTypesTest() returns error? { - QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN"); + QueueManager queueManager = check new ( + name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN", + userID = "app", password = "password"); Topic subscriber = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_SUBSCRIPTION, MQSO_CREATE); Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT); check publisher->put({