Search in sources :

Example 11 with HttpResponse

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

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