use of javax.json.JsonObject in project sling by apache.
the class JsonSupportTest method testToJson.
@Test
public void testToJson() {
Map<String, Object> map = ImmutableMap.<String, Object>builder().put("prop1", "value1").put("prop2", ImmutableList.of("value2", "value3")).put("prop3", ImmutableMap.of("prop4", "value4")).build();
JsonObject obj = toJson(map);
assertEquals("value1", obj.getString("prop1"));
JsonArray array = obj.getJsonArray("prop2");
assertEquals(2, array.size());
assertEquals("value2", array.getString(0));
assertEquals("value3", array.getString(1));
JsonObject prop3 = obj.getJsonObject("prop3");
assertEquals("value4", prop3.getString("prop4"));
}
use of javax.json.JsonObject in project sling by apache.
the class BasicLauncherIT method testSpecificStartLevel.
@Test
@Retry(timeoutMsec = U.LONG_TIMEOUT_MSEC, intervalMsec = U.STD_INTERVAL)
public void testSpecificStartLevel() throws Exception {
// This bundle should only be installed, as it's set to start level 99
final String symbolicName = "org.apache.commons.collections";
assertEquals("Expecting bundle " + symbolicName + " to be installed", "Installed", osgiConsole.getBundleState(symbolicName));
// Start level is in the props array, with key="Start Level"
final JsonObject status = U.getBundleData(C, client, symbolicName);
final JsonArray props = status.getJsonArray("data").getJsonObject(0).getJsonArray("props");
final String KEY = "key";
final String SL = "Start Level";
boolean found = false;
for (int i = 0; i < props.size(); i++) {
final JsonObject o = props.getJsonObject(i);
if (o.containsKey(KEY) && SL.equals(o.getString(KEY))) {
found = true;
assertEquals("Expecting the start level that's set in provisioning model", 99, o.getInt("value"));
}
}
assertTrue("Expecting start level to be found in JSON output", found);
}
use of javax.json.JsonObject in project sling by apache.
the class PlumberServletTest method testAdditionalBindingsAndWriter.
@Test
public void testAdditionalBindingsAndWriter() throws Exception {
String testBinding = "testBinding";
String testBindingLength = testBinding + "Length";
String bindingValue = "testBindingValue";
String pathLengthParam = "pathLength";
String bindings = "{\"" + testBinding + "\":\"" + bindingValue + "\"}";
String respObject = "{\"" + pathLengthParam + "\":\"${path.get(\\\"dummyGrandChild\\\").length}\",\"" + testBindingLength + "\":\"${" + testBinding + ".length}\"}";
SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), dummyTreePath, null, bindings.toString(), respObject.toString(), null, null);
servlet.execute(request, response, false);
assertDummyTree();
JsonObject response = Json.createReader(new StringReader(stringResponse.toString())).readObject();
JsonArray array = response.getJsonArray(OutputWriter.KEY_ITEMS);
for (int i = 0; i < array.size(); i++) {
JsonObject object = array.getJsonObject(i);
assertNotNull("there should be an object returned at each time", object);
String path = object.getString(CustomWriter.PATH_KEY);
assertNotNull("the string path should be returned for each item, containing the path of the resource");
String pathLength = object.getString(pathLengthParam);
assertNotNull("there should be a pathLength param, as specified in the writer", pathLength);
assertEquals("Pathlength should be the string representation of the path length", path.length() + "", pathLength);
String testBindingLengthValue = object.getString(testBindingLength);
assertNotNull("testBindingLength should be there", testBindingLengthValue);
assertEquals("testBindingLength should be the string representation of the additional binding length", bindingValue.length() + "", testBindingLengthValue);
}
}
use of javax.json.JsonObject in project sling by apache.
the class PlumberServletTest method assertDummyTree.
private void assertDummyTree(int size) {
String finalResponse = stringResponse.toString();
assertFalse("There should be a response", StringUtils.isBlank(finalResponse));
JsonObject object = Json.createReader(new StringReader(finalResponse)).readObject();
assertEquals("response should be an obj with size value equals to " + DUMMYTREE_TEST_SIZE, object.getInt(OutputWriter.KEY_SIZE), DUMMYTREE_TEST_SIZE);
assertEquals("response should be an obj with items value equals to a " + size + " valued array", object.getJsonArray(OutputWriter.KEY_ITEMS).size(), size);
}
use of javax.json.JsonObject in project sling by apache.
the class PostServletOrderTest method verifyOrder.
/**
* Verify node order
*/
private void verifyOrder(String parentUrl, String[] names) throws IOException {
// check that nodes appear in creation order in their parent's list of children
final String content = getContent(parentUrl + ".1.json", CONTENT_TYPE_JSON);
String expected = "";
for (String n : names) {
expected += n + ",";
}
//assertJavascript(expected, content, TEST_SCRIPT);
try {
String actual = "";
JsonObject obj = JsonUtil.parseObject(content);
for (String name : obj.keySet()) {
Object o = obj.get(name);
if (o instanceof JsonObject) {
actual += name + ",";
}
}
assertEquals(expected, actual);
} catch (JsonException e) {
throw new IOException(e.toString());
}
}
Aggregations