Skip to content

Commit

Permalink
Add negative test case for invalid abandon
Browse files Browse the repository at this point in the history
  • Loading branch information
RDPerera committed Sep 26, 2023
1 parent 54fdc3b commit cae2e53
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions ballerina/tests/asb_sender_receiver_negative_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ballerina/test;
import ballerina/regex;

string invalidCompleteError = "^Failed to complete message with ID:.*$";

string invalidAbandonError = "^Failed to abandon message with ID:.*$";
@test:Config {
groups: ["asb_sender_receiver_negative"],
dependsOn: [testCreateQueue, testCreateTopicOperation, testCreateSubscription]
Expand Down Expand Up @@ -88,13 +88,53 @@ function testInvalidComplete() returns error? {
check messageSender->close();

log:printInfo("Closing Asb receiver client.");
check messageSender->close();
check messageReceiver->close();
}

@test:Config {
groups: ["asb_sender_receiver_negative"],
dependsOn: [testInvalidComplete]
}
function testInvalidAbandon() returns error? {
log:printInfo("[[testInvalidAbandon]");

log:printInfo("Initializing Asb sender client.");
MessageSender messageSender = check new (senderConfig);

log:printInfo("Initializing Asb receiver client.");
receiverConfig.receiveMode = RECEIVE_AND_DELETE;

MessageReceiver messageReceiver = check new (receiverConfig);

log:printInfo("Sending via Asb sender.");
check messageSender->send(message1);

log:printInfo("Receiving from Asb receiver client.");
Message|error? receivedMessage = messageReceiver->receive(serverWaitTime);

if receivedMessage is Message {
log:printInfo("messgae" + receivedMessage.toString());
Error? result = messageReceiver->abandon(receivedMessage);
test:assertTrue(result is error, msg = "Unexpected Abandon for Messages in Receive and Delete Mode");
test:assertTrue(regex:matches((<Error>result).message(),invalidAbandonError), msg = "Invalid Abandon for " +
" Messages in Receive and Delete Mode");
} else if receivedMessage is () {
test:assertFail("No message in the queue.");
} else {
test:assertFail("Receiving message via Asb receiver connection failed.");
}

log:printInfo("Closing Asb sender client.");
check messageSender->close();

log:printInfo("Closing Asb receiver client.");
check messageReceiver->close();
}

@test:Config {
groups: ["asb_sender_receiver_negative"],
dependsOn: [testInvalidAbandon]
}
function testReceivePayloadWithUnsupportedUnionExpectedType() returns error? {
log:printInfo("[[testReceivePayloadWithUnsupportedUnionExpectedType]]");
log:printInfo("Creating Asb message sender.");
Expand Down

0 comments on commit cae2e53

Please sign in to comment.