use of com.axway.ats.action.exceptions.RestException in project ats-framework by Axway.
the class Test_JsonText method scoptToInternalPart_topElementIsJsonObject.
@Test
public void scoptToInternalPart_topElementIsJsonObject() {
// JSON Object
JsonText json = new JsonText(body2);
JsonText internalJson = json.get("lotto");
assertEquals(json.get("lotto").toString(), internalJson.toString());
// JSON Object -> JSON Array
internalJson = json.get("lotto/winners");
assertEquals("[{\"winnerId\":23,\"numbers\":[2,45,34,23,3,5]},{\"winnerId\":54,\"numbers\":[52,3,12,11,18,22]}]", internalJson.toString());
// JSON Object -> JSON Array -> JSON Object
internalJson = json.get("lotto/winners[1]");
assertEquals("{\"winnerId\":54,\"numbers\":[52,3,12,11,18,22]}", internalJson.toString());
// JSON Object -> JSON Array -> JSON Object -> JSON Array
internalJson = json.get("lotto/winners[1]/numbers");
assertEquals("[52,3,12,11,18,22]", internalJson.toString());
// Getting a Number as JsonText fails
try {
json.get("lotto/winners[1]/numbers[3]");
} catch (RestException e) {
assertEquals("java.lang.Integer cannot be cast to org.json.JSONObject", e.getCause().getMessage());
}
}
Aggregations