Search in sources :

Example 11 with HttpClient

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

Example 12 with HttpClient

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

the class HttpOperationTests method post_usingFormParameters.

/**
 * A POST which sends form parameters.
 *
 * In the particular case on the server side a new person will be added to the list
 * of known persons.
 * It returns info about the newly added person.
 */
@Test
public void post_usingFormParameters() {
    HttpClient client = new HttpClient(BASE_URI + "peoplepage/post");
    client.setRequestMediaType("application/x-www-form-urlencoded");
    // add parameters' info
    client.addRequestParameter("firstName", "Chuck");
    client.addRequestParameter("lastName", "Norris");
    client.addRequestParameter("age", "70");
    // send the data
    HttpResponse response = client.post();
    // check the status code is "201 CREATED"
    response.verifyStatusCode(201);
    // check the returned result to make sure the server accepted the data we sent
    assertTrue(response.getBodyAsString().startsWith("Saved Person with name Chuck Norris at 70 years"));
}
Also used : HttpClient(com.axway.ats.action.http.HttpClient) HttpResponse(com.axway.ats.action.http.HttpResponse) Test(org.testng.annotations.Test)

Example 13 with HttpClient

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

the class FileTransferTests 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.put();
    httpClient.close();
}
Also used : HttpClient(com.axway.ats.action.http.HttpClient) BeforeClass(org.testng.annotations.BeforeClass)

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