use of com.axway.ats.action.rest.RestClient in project ats-framework by Axway.
the class RestOperationTests 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";
RestClient client = new RestClient(BASE_URI + "peoplepage/delete");
client.addResourcePath("Chuck");
// the above 2 lines are equivalent to:
// new RestClient(BASE_URI + "peoplepage/delete/Chuck");
RestResponse response = client.delete();
assertEquals(response.getStatusCode(), 200);
assertTrue(response.getBodyAsString().startsWith("Deleted person with first name " + firstNameParam));
}
use of com.axway.ats.action.rest.RestClient in project ats-framework by Axway.
the class RestOperationTests 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();
RestClient client = new RestClient(BASE_URI + "peoplepage/get_xmlBean");
client.addResourcePath("Chuck");
client.addResourcePath("Norris");
client.setResponseMediaType(RestMediaType.APPLICATION_XML);
RestResponse response = client.get();
// get the body as XmlText
XmlText xmlResponse = response.getBodyAsXml();
// 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());
}
use of com.axway.ats.action.rest.RestClient in project ats-framework by Axway.
the class RestOperationTests method get_json.
/**
* A GET which returns some JSON body.
*
* We read the response body as JsonText and use its common methods to retrieve the needed data
*/
@Test
public void get_json() {
createPersonToManipulateInTheTest();
RestClient client = new RestClient(BASE_URI + "peoplepage/get_jsonPojo");
client.addResourcePath("Chuck");
client.setResponseMediaType(RestMediaType.APPLICATION_JSON);
RestResponse response = client.get();
// get the body as JsonText
JsonText jsonResponse = response.getBodyAsJson();
// now call the different getter methods to retrieve the needed data
String firstName = jsonResponse.getString("firstName");
String lastName = jsonResponse.getString("lastName");
int age = jsonResponse.getInt("age");
log.info("Got back a JSON body saying that " + firstName + " " + lastName + " is " + age + " old");
log.info("A JSON body looks like that:\n" + jsonResponse.toString());
log.info("A well formatter JSON body looks like that:\n" + jsonResponse.toFormattedString());
}
use of com.axway.ats.action.rest.RestClient in project ats-framework by Axway.
the class RestOperationTests method get_xmlToJavaObject.
/**
* A GET which returns some XML body.
*
* We serialize the response body to a java instance and use its particular class methods to retrieve the needed data
*/
@Test
public void get_xmlToJavaObject() {
createPersonToManipulateInTheTest();
RestClient client = new RestClient(BASE_URI + "peoplepage/get_xmlBean");
client.addResourcePath("Chuck");
client.addResourcePath("Norris");
client.setResponseMediaType(RestMediaType.APPLICATION_XML);
RestResponse response = client.get();
// get the body as a java object
PersonXmlBean person = response.getBodyAsObject(PersonXmlBean.class);
// now call the different java methods to retrieve the needed data
assertEquals(person.getFirstName(), "Chuck");
assertEquals(person.getLastName(), "Norris");
assertEquals(person.getAge(), 70);
log.info("Got back a java object which is: " + person.toString());
}
use of com.axway.ats.action.rest.RestClient in project ats-framework by Axway.
the class RestOperationTests method get_usingPathParams.
/**
* A GET using some resource path parameters.
*
* The application we work with returns a body with the path parameters we have sent
*/
@Test
public void get_usingPathParams() {
final String pathParam1 = "value1";
final String pathParam2 = "value2";
RestClient client = new RestClient(BASE_URI + "simplepage/");
// add as many as needed path parameters
client.addResourcePath(pathParam1);
client.addResourcePath(pathParam2);
RestResponse response = client.get();
assertEquals(response.getBodyAsString(), "You passed " + pathParam1 + " and " + pathParam2 + " path params");
}
Aggregations