Search in sources :

Example 1 with PersonPojo

use of com.axway.ats.examples.basic.http.testbeans.PersonPojo 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());
}
Also used : RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) PersonPojo(com.axway.ats.examples.basic.http.testbeans.PersonPojo) Test(org.testng.annotations.Test)

Aggregations

RestClient (com.axway.ats.action.rest.RestClient)1 RestResponse (com.axway.ats.action.rest.RestResponse)1 PersonPojo (com.axway.ats.examples.basic.http.testbeans.PersonPojo)1 Test (org.testng.annotations.Test)1