Search in sources :

Example 1 with RestForm

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

the class HttpBaseClass method createPersonToManipulateInTheTest.

protected void createPersonToManipulateInTheTest() {
    // create a new person using POST
    RestClient client = new RestClient(BASE_URI + "peoplepage/post");
    RestResponse response = client.postForm(new RestForm().addParameter("firstName", "Chuck").addParameter("lastName", "Norris").addParameter("age", "70"));
    assertEquals(response.getStatusCode(), 201);
    assertTrue(response.getBodyAsString().startsWith("Saved Person with name Chuck Norris at 70 years"));
}
Also used : RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) RestForm(com.axway.ats.action.rest.RestForm)

Example 2 with RestForm

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

the class RestOperationTests method put_usingFormParameters.

/**
 * A PUT which sends form parameters.
 *
 * The PUT is usually used to modify an existing resource
 * Thus this test first issues a POST to create the resource which will
 * be modified(updated) by the following PUT
 */
@Test
public void put_usingFormParameters() {
    createPersonToManipulateInTheTest();
    // update the already existing person using PUT
    RestClient client = new RestClient(BASE_URI + "peoplepage/put");
    RestResponse response = client.putForm(new RestForm().addParameter("firstName", "Chuck").addParameter("lastName", "Norris").addParameter("age", "71"));
    assertEquals(response.getStatusCode(), 200);
    // verify Chuck Norris grows up as expected
    assertTrue(response.getBodyAsString().startsWith("Chuck Norris was 70 years old, but now is 71 years old"));
}
Also used : RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) RestForm(com.axway.ats.action.rest.RestForm) Test(org.testng.annotations.Test)

Example 3 with RestForm

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

the class RestOperationTests 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() {
    RestClient client = new RestClient(BASE_URI + "peoplepage/post");
    // create a RestForm and add parameters' info
    RestForm formParameters = new RestForm().addParameter("firstName", "Chuck").addParameter("lastName", "Norris").addParameter("age", "70");
    // send the form data
    RestResponse response = client.postForm(formParameters);
    // 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 : RestResponse(com.axway.ats.action.rest.RestResponse) RestClient(com.axway.ats.action.rest.RestClient) RestForm(com.axway.ats.action.rest.RestForm) Test(org.testng.annotations.Test)

Aggregations

RestClient (com.axway.ats.action.rest.RestClient)3 RestForm (com.axway.ats.action.rest.RestForm)3 RestResponse (com.axway.ats.action.rest.RestResponse)3 Test (org.testng.annotations.Test)2