Skip to content

Instantly share code, notes, and snippets.

@yasassri
Created June 4, 2018 08:43
Show Gist options
  • Save yasassri/55ff03c4f06de1c4becd87cb6fd5d3aa to your computer and use it in GitHub Desktop.
Save yasassri/55ff03c4f06de1c4becd87cb6fd5d3aa to your computer and use it in GitHub Desktop.
import ballerina/http;
import ballerina/test;
import ballerina/config;
string uri = "http://0.0.0.0:9095/v1";
boolean isServiceSkeletonStarted;
function init() {
// Starting the swagger based service
isServiceSkeletonStarted = test:startServiceSkeleton("mockservice",
"<PATH_TO_SWAGGER_DEFINITION>/petstore.yaml");
}
function clean() {
// Stopping the swager based service
test:stopServiceSkeleton("mockservice");
}
@test:Config{
before: "init",
after: "clean"
}
function testService () {
endpoint http:Client httpEndpoint {
url:uri
};
test:assertTrue(isServiceSkeletonStarted, msg = "Service skeleton failed to start");
// Send a GET request to the specified endpoint
var response = httpEndpoint -> get("/pets");
match response {
http:Response resp => {
var strRes = resp.getTextPayload();
string expected = "Sample listPets Response";
test:assertEquals(strRes, expected);
}
error err => test:assertFail(msg = "Failed to call the endpoint: "+uri);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment