Search in sources :

Example 1 with XmlText

use of com.axway.ats.action.xml.XmlText in project ats-framework by Axway.

the class RestOperationTests method get_xml.

/**
 * A GET which returns some XML body.
 *
 * We read the response body as XmlText and use its common methods to retrieve the needed data
 */
@Test
public void get_xml() {
    createPersonToManipulateInTheTest();
    RestClient client = new RestClient(BASE_URI + "peoplepage/get_xmlBean");
    client.addResourcePath("Chuck");
    client.addResourcePath("Norris");
    client.setResponseMediaType(RestMediaType.APPLICATION_XML);
    RestResponse response = client.get();
    // get the body as XmlText
    XmlText xmlResponse = response.getBodyAsXml();
    // now call the different getter methods to retrieve the needed data
    String firstName = xmlResponse.getString("firstName");
    String lastName = xmlResponse.getString("lastName");
    int age = xmlResponse.getInt("age");
    log.info("Got back a XML body saying that " + firstName + " " + lastName + " is " + age + " old");
    log.info("A XML body looks like that:\n" + xmlResponse.toString());
    log.info("A well formatter XML body looks like that:\n" + xmlResponse.toFormattedString());
}
Also used : RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) XmlText(com.axway.ats.action.xml.XmlText) Test(org.testng.annotations.Test)

Example 2 with XmlText

use of com.axway.ats.action.xml.XmlText in project ats-framework by Axway.

the class HttpOperationTests method get_xml.

/**
 * A GET which returns some XML body.
 *
 * We read the response body as XmlText and use its common methods to retrieve the needed data
 */
@Test
public void get_xml() {
    createPersonToManipulateInTheTest();
    HttpClient client = new HttpClient(BASE_URI + "peoplepage/get_xmlBean");
    client.addResourcePath("Chuck");
    client.addResourcePath("Norris");
    HttpResponse response = client.get();
    // get the body as XmlText
    XmlText xmlResponse = response.getBodyAsXmlText();
    // now call the different getter methods to retrieve the needed data
    String firstName = xmlResponse.getString("firstName");
    String lastName = xmlResponse.getString("lastName");
    int age = xmlResponse.getInt("age");
    log.info("Got back a XML body saying that " + firstName + " " + lastName + " is " + age + " old");
    log.info("A XML body looks like that:\n" + xmlResponse.toString());
    log.info("A well formatter XML body looks like that:\n" + xmlResponse.toFormattedString());
}
Also used : HttpClient(com.axway.ats.action.http.HttpClient) HttpResponse(com.axway.ats.action.http.HttpResponse) XmlText(com.axway.ats.action.xml.XmlText) Test(org.testng.annotations.Test)

Aggregations

XmlText (com.axway.ats.action.xml.XmlText)2 Test (org.testng.annotations.Test)2 HttpClient (com.axway.ats.action.http.HttpClient)1 HttpResponse (com.axway.ats.action.http.HttpResponse)1 RestClient (com.axway.ats.action.rest.RestClient)1 RestResponse (com.axway.ats.action.rest.RestResponse)1