Skip to content

Instantly share code, notes, and snippets.

@garyjoy
Created January 29, 2018 14:56
Show Gist options
  • Save garyjoy/86be8ab9dedc723a9a5aa4f466c29b32 to your computer and use it in GitHub Desktop.
Save garyjoy/86be8ab9dedc723a9a5aa4f466c29b32 to your computer and use it in GitHub Desktop.
Service Testing Glue Code
@When("^I call \"([^\"]*)\" with \"([^\"]*)\" the \"([^\"]*)\" is \"([^\"]*)\"$")
public void i_call_with_the_is(String serviceName, String input, String property, String expectedValue) throws Throwable {
String userName = configuration.getProperty("bpm.user.name");
String password = configuration.getProperty("bpm.user.password");
String requestURL = configuration.getProperty("rest.url") + configuration.getProperty("rest.unitTest") + serviceName;
Response response = given().auth().
form(userName, password, formAuthConfig).
headers("Accept", "application/json", "Content-Type", "application/x-www-form-urlencoded", "X-Method-Override", "POST").
queryParam("action", "start").
queryParam("params", input).
queryParam("createTask", "false").
queryParam("parts", "all").
post(requestURL);
// System.out.println(response.prettyPrint());
String responseBody = response.getBody().asString();
JsonPath responseJson = new JsonPath(responseBody);
String actualValue = String.valueOf(responseJson.getString(property));
String contentsError = String.format("Expected %s but found %s", expectedValue, actualValue);
Assert.assertTrue(expectedValue.equals(actualValue), contentsError);
// System.out.println(response.prettyPrint());
checkResponseCode(response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment