Search in sources :

Example 6 with HttpResponse

use of com.axway.ats.action.http.HttpResponse 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)

Example 7 with HttpResponse

use of com.axway.ats.action.http.HttpResponse in project ats-framework by Axway.

the class HttpOperationTests method get.

/**
 * A simple GET which returns some textual body
 */
@Test
public void get() {
    // create an instance of the HttpClient by providing the URI to work with
    HttpClient client = new HttpClient(BASE_URI + "simplepage/");
    // execute the HTTP method - in this case a GET
    // each HTTP method returns a response object
    HttpResponse response = client.get();
    // verify the response status in any of the following ways
    assertEquals(response.getStatusCode(), 200);
    response.verifyStatusCode(200);
    // this is how you can read the response headers
    log.info("We received the following response headers:");
    for (HttpHeader header : response.getHeaders()) {
        log.info(header.getKey() + ":" + header.getValue());
    }
    // there are different ways to get the body, here we get it as a simple text
    String responseBody = response.getBodyAsString();
    assertEquals(responseBody, "Some simple page response");
}
Also used : HttpHeader(com.axway.ats.action.http.HttpHeader) HttpClient(com.axway.ats.action.http.HttpClient) HttpResponse(com.axway.ats.action.http.HttpResponse) Test(org.testng.annotations.Test)

Example 8 with HttpResponse

use of com.axway.ats.action.http.HttpResponse in project ats-framework by Axway.

the class HttpOperationTests method delete_usingRequestParam.

/**
 * A DELETE using request parameters.
 *
 * Our server expects the the last name of the person to be deleted.
 */
@Test
public void delete_usingRequestParam() {
    createPersonToManipulateInTheTest();
    final String lastNameParam = "lastName";
    final String lastNameParamValue = "Norris";
    HttpClient client = new HttpClient(BASE_URI + "peoplepage/delete");
    // add the request parameter
    client.addRequestParameter(lastNameParam, lastNameParamValue);
    HttpResponse response = client.delete();
    assertEquals(response.getStatusCode(), 200);
    assertTrue(response.getBodyAsString().startsWith("Deleted person with last name " + lastNameParamValue));
}
Also used : HttpClient(com.axway.ats.action.http.HttpClient) HttpResponse(com.axway.ats.action.http.HttpResponse) Test(org.testng.annotations.Test)

Example 9 with HttpResponse

use of com.axway.ats.action.http.HttpResponse in project ats-framework by Axway.

the class HttpOperationTests method get_usingHeader.

/**
 * A GET using some request header.
 *
 * The application we work with returns a body with the header we have sent
 */
@Test
public void get_usingHeader() {
    final String header1 = "value1";
    HttpClient client = new HttpClient(BASE_URI + "simplepage/header");
    // add some important header(s)
    client.addRequestHeader("header1", header1);
    HttpResponse response = client.get();
    assertEquals(response.getBodyAsString(), "You passed header with name header1 and value " + header1);
}
Also used : HttpClient(com.axway.ats.action.http.HttpClient) HttpResponse(com.axway.ats.action.http.HttpResponse) Test(org.testng.annotations.Test)

Example 10 with HttpResponse

use of com.axway.ats.action.http.HttpResponse in project ats-framework by Axway.

the class HttpOperationTests 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";
    HttpClient client = new HttpClient(BASE_URI + "peoplepage/delete");
    client.addResourcePath("Chuck");
    HttpResponse response = client.delete();
    assertEquals(response.getStatusCode(), 200);
    assertTrue(response.getBodyAsString().startsWith("Deleted person with first name " + firstNameParam));
}
Also used : HttpClient(com.axway.ats.action.http.HttpClient) HttpResponse(com.axway.ats.action.http.HttpResponse) Test(org.testng.annotations.Test)

Aggregations

HttpClient (com.axway.ats.action.http.HttpClient)11 HttpResponse (com.axway.ats.action.http.HttpResponse)11 Test (org.testng.annotations.Test)11 HttpHeader (com.axway.ats.action.http.HttpHeader)2 JsonText (com.axway.ats.action.json.JsonText)1 XmlText (com.axway.ats.action.xml.XmlText)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1