Search in sources :

Example 6 with HttpClient

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

the class OtherOptionsTests method beforeClass.

@BeforeClass
public void beforeClass() {
    // This step is needed for the HTTP tests only.
    // We tell the remote HTTP server the folder to store to and read files from.
    // Of course, you can find a nicer way to do that.
    HttpClient httpClient = new HttpClient("http://" + configuration.getServerIp() + ":" + configuration.getHttpServerPort() + "/" + configuration.getHttpServerWebappWar() + "/transfers/");
    httpClient.addRequestHeader("repository", UPLOADS_DIR);
    httpClient.post();
    httpClient.close();
    // create some we will use for uploads
    new FileSystemOperations().createBinaryFile(LARGE_FILE, LARGE_FILE_SIZE, false);
}
Also used : HttpClient(com.axway.ats.action.http.HttpClient) FileSystemOperations(com.axway.ats.action.filesystem.FileSystemOperations) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with HttpClient

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

use of com.axway.ats.action.http.HttpClient 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 9 with HttpClient

use of com.axway.ats.action.http.HttpClient 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 10 with HttpClient

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

Aggregations

HttpClient (com.axway.ats.action.http.HttpClient)13 HttpResponse (com.axway.ats.action.http.HttpResponse)11 Test (org.testng.annotations.Test)11 HttpHeader (com.axway.ats.action.http.HttpHeader)2 BeforeClass (org.testng.annotations.BeforeClass)2 FileSystemOperations (com.axway.ats.action.filesystem.FileSystemOperations)1 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