Skip to content

Commit

Permalink
Add test case with to validate handling internal server errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuvindu committed Jul 29, 2024
1 parent 8c734f9 commit 30e4376
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
6 changes: 6 additions & 0 deletions ballerina/modules/soap12/tests/http_soap_service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ service / on new http:Listener(9090) {
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)</faultstring><detail/></soap:Fault></soap:Body></soap:Envelope>`;
}

resource function post getErrorPayload(http:Request request) returns xml|http:InternalServerError {
return {
body: "Error occurred in the server"
};
}

resource function post getSamePayload(http:Request request) returns xml|error {
return check request.getXmlPayload();
}
Expand Down
32 changes: 12 additions & 20 deletions ballerina/modules/soap12/tests/soap12_client_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ function testSendReceive12WithAction() returns error? {
test:assertEquals(response, expected);
}

@test:Config {
groups: ["soap12", "send_receive"]
}
function testSendReceive12WithServerError() returns error? {
Client soapClient = check new ("http://localhost:9090");
xml body = xml `<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding/"><soap:Body><quer:Add xmlns:quer="http://tempuri.org/"><quer:intA>2</quer:intA><quer:intB>3</quer:intB></quer:Add></soap:Body></soap:Envelope>`;

xml|Error response = soapClient->sendReceive(body, path = "/getErrorPayload");
test:assertTrue(response is Error);
test:assertEquals((<error>(<error>(<error>response).cause()).cause()).message(), "Internal Server Error");
}

@test:Config {
groups: ["soap12", "send_receive"]
}
Expand Down Expand Up @@ -347,26 +359,6 @@ function testSendReceiveError() returns error? {
test:assertEquals((<Error>response).message(), SOAP_ERROR);
}

@test:Config {
groups: ["soap12", "send_receive"]
}
function testSendReceiveWithInvalidAction() returns error? {
Client soapClient = check new ("http://www.dneonline.com/invalidcalculator.asmx?WSDL");
xml body = xml `<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<quer:Add xmlns:quer="http://tempuri.org/">
<quer:intA>2</quer:intA>
<quer:intB>3</quer:intB>
</quer:Add>
</soap:Body>
</soap:Envelope>`;
xml|Error response = soapClient->sendReceive(body, "http://tempuri.org/invalid_action");
test:assertTrue(response is Error);
test:assertEquals((<Error>response).message(), SOAP_ERROR);
}

@test:Config {
groups: ["soap12", "send_receive"]
}
Expand Down

0 comments on commit 30e4376

Please sign in to comment.