use of com.axway.ats.action.rest.RestClient in project ats-framework by Axway.
the class RestOperationTests method get_jsonToJavaObject.
/**
* A GET which returns some JSON body.
*
* We serialize the response body to a java instance and use its particular class methods to retrieve the needed data
*/
@Test
public void get_jsonToJavaObject() {
createPersonToManipulateInTheTest();
RestClient client = new RestClient(BASE_URI + "peoplepage/get_jsonPojo");
client.addResourcePath("Chuck");
client.setResponseMediaType(RestMediaType.APPLICATION_JSON);
RestResponse response = client.get();
// get the body as a java object
PersonPojo person = response.getBodyAsObject(PersonPojo.class);
// now call the different java methods to retrieve the needed data
assertEquals(person.getFirstName(), "Chuck");
assertEquals(person.getLastName(), "Norris");
assertEquals(person.getAge(), 70);
log.info("Got back a java object which is: " + person.toString());
}
use of com.axway.ats.action.rest.RestClient in project ats-framework by Axway.
the class RestOperationTests method post_usingFormParameters.
/**
* A POST which sends form parameters.
*
* In the particular case on the server side a new person will be added to the list
* of known persons.
* It returns info about the newly added person.
*/
@Test
public void post_usingFormParameters() {
RestClient client = new RestClient(BASE_URI + "peoplepage/post");
// create a RestForm and add parameters' info
RestForm formParameters = new RestForm().addParameter("firstName", "Chuck").addParameter("lastName", "Norris").addParameter("age", "70");
// send the form data
RestResponse response = client.postForm(formParameters);
// check the status code is "201 CREATED"
response.verifyStatusCode(201);
// check the returned result to make sure the server accepted the data we sent
assertTrue(response.getBodyAsString().startsWith("Saved Person with name Chuck Norris at 70 years"));
}
Aggregations