Search in sources :

Example 6 with RestResponse

use of com.axway.ats.action.rest.RestResponse in project ats-framework by Axway.

the class RestOperationTests method delete_usingPathParam.

/**
 * A DELETE using path parameters.
 *
 * In this case all needed is to point to the resource to be deleted.
 *
 * Our server expects the the first name of the person to be deleted.
 */
@Test
public void delete_usingPathParam() {
    createPersonToManipulateInTheTest();
    final String firstNameParam = "Chuck";
    RestClient client = new RestClient(BASE_URI + "peoplepage/delete");
    client.addResourcePath("Chuck");
    // the above 2 lines are equivalent to:
    // new RestClient(BASE_URI + "peoplepage/delete/Chuck");
    RestResponse response = client.delete();
    assertEquals(response.getStatusCode(), 200);
    assertTrue(response.getBodyAsString().startsWith("Deleted person with first name " + firstNameParam));
}
Also used : RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) Test(org.testng.annotations.Test)

Example 7 with RestResponse

use of com.axway.ats.action.rest.RestResponse 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 8 with RestResponse

use of com.axway.ats.action.rest.RestResponse in project ats-framework by Axway.

the class RestOperationTests method get_json.

/**
 * A GET which returns some JSON body.
 *
 * We read the response body as JsonText and use its common methods to retrieve the needed data
 */
@Test
public void get_json() {
    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 JsonText
    JsonText jsonResponse = response.getBodyAsJson();
    // now call the different getter methods to retrieve the needed data
    String firstName = jsonResponse.getString("firstName");
    String lastName = jsonResponse.getString("lastName");
    int age = jsonResponse.getInt("age");
    log.info("Got back a JSON body saying that " + firstName + " " + lastName + " is " + age + " old");
    log.info("A JSON body looks like that:\n" + jsonResponse.toString());
    log.info("A well formatter JSON body looks like that:\n" + jsonResponse.toFormattedString());
}
Also used : RestResponse(com.axway.ats.action.rest.RestResponse) JsonText(com.axway.ats.action.json.JsonText) RestClient(com.axway.ats.action.rest.RestClient) Test(org.testng.annotations.Test)

Example 9 with RestResponse

use of com.axway.ats.action.rest.RestResponse in project ats-framework by Axway.

the class RestOperationTests method get_xmlToJavaObject.

/**
 * A GET which returns some XML 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_xmlToJavaObject() {
    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 a java object
    PersonXmlBean person = response.getBodyAsObject(PersonXmlBean.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 : PersonXmlBean(com.axway.ats.examples.basic.http.testbeans.PersonXmlBean) RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) Test(org.testng.annotations.Test)

Example 10 with RestResponse

use of com.axway.ats.action.rest.RestResponse in project ats-framework by Axway.

the class RestOperationTests method get_usingPathParams.

/**
 * A GET using some resource path parameters.
 *
 * The application we work with returns a body with the path parameters we have sent
 */
@Test
public void get_usingPathParams() {
    final String pathParam1 = "value1";
    final String pathParam2 = "value2";
    RestClient client = new RestClient(BASE_URI + "simplepage/");
    // add as many as needed path parameters
    client.addResourcePath(pathParam1);
    client.addResourcePath(pathParam2);
    RestResponse response = client.get();
    assertEquals(response.getBodyAsString(), "You passed " + pathParam1 + " and " + pathParam2 + " path params");
}
Also used : RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) Test(org.testng.annotations.Test)

Aggregations

RestResponse (com.axway.ats.action.rest.RestResponse)18 RestClient (com.axway.ats.action.rest.RestClient)16 Test (org.testng.annotations.Test)13 RestForm (com.axway.ats.action.rest.RestForm)3 RestHeader (com.axway.ats.action.rest.RestHeader)2 JsonText (com.axway.ats.action.json.JsonText)1 SystemOperations (com.axway.ats.action.system.SystemOperations)1 XmlText (com.axway.ats.action.xml.XmlText)1 FtpClient (com.axway.ats.core.filetransfer.FtpClient)1 MonitoringException (com.axway.ats.core.monitoring.MonitoringException)1 PersonPojo (com.axway.ats.examples.basic.http.testbeans.PersonPojo)1 PersonXmlBean (com.axway.ats.examples.basic.http.testbeans.PersonXmlBean)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 BeforeSuite (org.testng.annotations.BeforeSuite)1