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 constructJsonText.
@Test
public void constructJsonText() {
JsonText json1 = new JsonText().add("name", "Acme 1006").add("description", "Acme Corporation is a fictional corporation in Road Runner/Wile E. Coyote cartoons").add("email", "support@acmecorp.com").add("phone", "+1 877-564-7700").add("integer", 100).add("float", 100.2).add("null_object", null).add("enabled", false);
assertEquals(new JsonText(body1).toString(), json1.toString());
}
use of com.axway.ats.action.json.JsonText in project ats-framework by Axway.
the class Test_JsonText method constructDeepJsonText.
@Test
public void constructDeepJsonText() {
JsonText json = new JsonText().add("lotto", new JsonText().add("lottoId", 5).addArray("winning-numbers", new int[] { 2, 45, 34, 23, 7, 5, 3 }).addArray("winners", new JsonText[] { new JsonText().add("winnerId", 23).addArray("numbers", new int[] { 2, 45, 34, 23, 3, 5 }), new JsonText().add("winnerId", 54).addArray("numbers", new int[] { 52, 3, 12, 11, 18, 22 }) }));
assertEquals(new JsonText(body2).toString(), json.toString());
}
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 iterateOverObjectElements.
@Test
public void iterateOverObjectElements() {
JsonText jsonText1 = new JsonText(body2);
assertTrue(jsonText1.isTopLevelObject());
assertEquals(1, jsonText1.getNumberOfElements(""));
for (String name1 : jsonText1.getElementNames()) {
assertEquals("lotto", name1);
JsonText jsonText2 = jsonText1.get(name1);
assertTrue(jsonText2.isTopLevelObject());
assertEquals(3, jsonText2.getNumberOfElements(""));
String[] names = jsonText2.getElementNames();
assertEquals("winners", names[0]);
assertEquals("lottoId", names[1]);
assertEquals("winning-numbers", names[2]);
}
}
Aggregations