use of com.axway.ats.action.json.JsonText 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.json.JsonText in project ats-framework by Axway.
the class HttpOperationTests 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();
HttpClient client = new HttpClient(BASE_URI + "peoplepage/get_jsonPojo");
client.addResourcePath("Chuck");
HttpResponse response = client.get();
// get the body as JsonText
JsonText jsonResponse = response.getBodyAsJsonText();
// 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.json.JsonText in project ats-framework by Axway.
the class Test_JsonText method addArray_intValues.
@Test
public void addArray_intValues() {
JsonText json = new JsonText().addArray("name", new int[] { 2, 45, 34, 23, 7, 5, 3 });
assertEquals("{\"name\":[2,45,34,23,7,5,3]}", json.toString());
}
use of com.axway.ats.action.json.JsonText in project ats-framework by Axway.
the class Test_JsonText method addArrayWhenNotAllowed.
@Test
public void addArrayWhenNotAllowed() {
try {
new JsonText().add("name", new int[] { 1, 2, 3 });
fail();
} catch (JsonException e) {
checkError(e, "Use the appropriate method to add.*");
}
}
use of com.axway.ats.action.json.JsonText in project ats-framework by Axway.
the class Test_JsonText method getAllValueTypes.
@Test
public void getAllValueTypes() {
JsonText json1 = new JsonText(body1);
assertEquals("Acme 1006", json1.getString("name"));
assertEquals(false, json1.getBoolean("enabled"));
assertEquals(100, json1.getInt("integer"));
assertEquals(100.2, json1.getFloat("float"), 0.1);
assertEquals(null, json1.get("null_object"));
JsonText json2 = new JsonText(body2);
assertEquals(5, json2.getInt("lotto/lottoId"));
assertEquals(54, json2.getInt("lotto/winners[1]/winnerId"));
assertEquals(11, json2.getInt("lotto/winners[1]/numbers[3]"));
assertEquals(45, json2.getInt("lotto/winning-numbers[1]"));
}
Aggregations