Skip to content

Commit

Permalink
Merge pull request #18 from ayeshLK/master
Browse files Browse the repository at this point in the history
Refactor test cases
  • Loading branch information
ayeshLK authored Oct 31, 2023
2 parents 4b35b49 + 4b4106d commit 8ef89f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
22 changes: 11 additions & 11 deletions ballerina/tests/pub_sub_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ballerina/test;
groups: ["ibmmqTopic"]
}
function basicPublisherSubscriberTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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({
Expand All @@ -40,7 +40,7 @@ function basicPublisherSubscriberTest() returns error? {
groups: ["ibmmqTopic"]
}
function pubSubMultipleMessagesInOrderTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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 {
Expand All @@ -65,7 +65,7 @@ function pubSubMultipleMessagesInOrderTest() returns error? {
groups: ["ibmmqTopic"]
}
function subscribeWithFiniteTimeoutTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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({
Expand All @@ -86,7 +86,7 @@ function subscribeWithFiniteTimeoutTest() returns error? {
groups: ["ibmmqTopic"]
}
function subscribeWithoutPublishTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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 ());
Expand All @@ -98,7 +98,7 @@ function subscribeWithoutPublishTest() returns error? {
groups: ["ibmmqTopic"]
}
function publishToNonExistingTopicTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand All @@ -114,7 +114,7 @@ function publishToNonExistingTopicTest() returns error? {
groups: ["ibmmqTopic"]
}
function subscribeToNonExistingTopicTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand All @@ -130,7 +130,7 @@ function subscribeToNonExistingTopicTest() returns error? {
groups: ["ibmmqTopic"]
}
function subscribeWithInvalidTopicNameTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand All @@ -146,7 +146,7 @@ function subscribeWithInvalidTopicNameTest() returns error? {
groups: ["ibmmqTopic"]
}
function publishWithInvalidTopicNameTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand All @@ -162,7 +162,7 @@ function publishWithInvalidTopicNameTest() returns error? {
groups: ["ibmmqTopic"]
}
function accessTopicAfterQMDisconnectTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
check queueManager.disconnect();
Topic|Error result = queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT);
if result is Error {
Expand All @@ -179,7 +179,7 @@ function accessTopicAfterQMDisconnectTest() returns error? {
groups: ["ibmmqTopic"]
}
function putToTopicAfterTopicCloseTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT);
check publisher->close();
Error? result = publisher->put({
Expand All @@ -200,7 +200,7 @@ function putToTopicAfterTopicCloseTest() returns error? {
groups: ["ibmmqTopic"]
}
function putToTopicAfterQMDisconnectTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
Topic publisher = check queueManager.accessTopic("dev", "DEV.BASE.TOPIC", OPEN_AS_PUBLICATION, MQOO_OUTPUT);
check queueManager.disconnect();
Error? result = publisher->put({
Expand Down
15 changes: 7 additions & 8 deletions ballerina/tests/queue_producer_consumer_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/test;

@test:Config {
groups: ["ibmmqQueue"]
}
function basicQueueProducerConsumerTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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({
Expand All @@ -41,7 +40,7 @@ function basicQueueProducerConsumerTest() returns error? {
groups: ["ibmmqQueue"]
}
function pubSubMultipleMessagesQueueProducerConsumerTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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 {
Expand All @@ -66,7 +65,7 @@ function pubSubMultipleMessagesQueueProducerConsumerTest() returns error? {
groups: ["ibmmqQueue"]
}
function consumerWithoutProducingMessageTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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 ());
Expand All @@ -78,7 +77,7 @@ function consumerWithoutProducingMessageTest() returns error? {
groups: ["ibmmqQueue"]
}
function produceToNonExistingQueueTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand All @@ -94,7 +93,7 @@ function produceToNonExistingQueueTest() returns error? {
groups: ["ibmmqQueue"]
}
function consumerConnectToNonExistingQueueTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand All @@ -110,7 +109,7 @@ function consumerConnectToNonExistingQueueTest() returns error? {
groups: ["ibmmqQueue"]
}
function produceWithInvalidQueueNameTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand All @@ -126,7 +125,7 @@ function produceWithInvalidQueueNameTest() returns error? {
groups: ["ibmmqQueue"]
}
function consumeFromAnInvalidQueueNameTest() returns error? {
QueueManager queueManager = check new QueueManager(name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
QueueManager queueManager = check new (name = "QM1", host = "localhost", channel = "DEV.APP.SVRCONN");
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'.");
Expand Down

0 comments on commit 8ef89f1

Please sign in to comment.