use of javax.json.JsonArray in project sling by apache.
the class WebconsoleClient method getBundleData.
private JsonObject getBundleData(String symbolicName) throws Exception {
// This returns a data structure like
// {"status":"Bundle information: 173 bundles in total - all 173 bundles active.","s":[173,171,2,0,0],"data":
// [
// {"id":0,"name":"System Bundle","fragment":false,"stateRaw":32,"state":"Active","version":"3.0.7","symbolicName":"org.apache.felix.framework","category":""},
// ]}
final String path = getBundlePath(symbolicName, ".json");
final String content = executor.execute(builder.buildGetRequest(path).withCredentials(username, password)).assertStatus(200).getContent();
final JsonObject root = Json.createReader(new StringReader(content)).readObject();
if (!root.containsKey(JSON_KEY_DATA)) {
fail(path + " does not provide '" + JSON_KEY_DATA + "' element, JSON content=" + content);
}
final JsonArray data = root.getJsonArray(JSON_KEY_DATA);
if (data.size() < 1) {
fail(path + "." + JSON_KEY_DATA + " is empty, JSON content=" + content);
}
final JsonObject bundle = data.getJsonObject(0);
if (!bundle.containsKey(JSON_KEY_STATE)) {
fail(path + ".data[0].state missing, JSON content=" + content);
}
return bundle;
}
use of javax.json.JsonArray in project sling by apache.
the class JSONGroovyBuilderTest method testArray.
public void testArray() throws IOException, JsonException {
final String toDelete = uploadTestScript("builder_array.groovy", "json.groovy");
try {
final String content = getContent(displayUrl + ".json", CONTENT_TYPE_JSON);
JsonArray jo = Json.createReader(new StringReader(content)).readArray();
assertEquals("Content contained wrong number of items", 1, jo.size());
assertEquals("Content contained wrong data", testText, jo.getString(0));
} finally {
testClient.delete(toDelete);
}
}
use of javax.json.JsonArray in project sling by apache.
the class ServerSideTestClient method runTests.
public TestResults runTests(String testPackageOrClassName) throws Exception {
final RemoteTestHttpClient testClient = new RemoteTestHttpClient(serverBaseUrl + "/system/sling/junit", serverUsername, serverPassword, true);
final TestResults r = new TestResults();
final Map<String, String> options = new HashMap<String, String>();
options.put("forceReload", "true");
final RequestExecutor executor = testClient.runTests(testPackageOrClassName, null, "json", options);
executor.assertContentType("application/json");
String content = executor.getContent();
if (!content.trim().isEmpty()) {
final JsonArray json = JsonUtil.parseArray(content);
for (int i = 0; i < json.size(); i++) {
final JsonObject obj = json.getJsonObject(i);
if ("test".equals(obj.getString("INFO_TYPE"))) {
r.testCount++;
if (obj.containsKey("failure")) {
r.failures.add(JsonUtil.toString(obj.get("failure")));
}
}
}
}
return r;
}
use of javax.json.JsonArray in project sling by apache.
the class UpdateGroupTest method getTestUserMemberships.
JsonArray getTestUserMemberships(Credentials creds) throws IOException, JsonException {
String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
//make sure the profile request returns some data
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
JsonArray memberships = jsonObj.getJsonArray("memberOf");
return memberships;
}
use of javax.json.JsonArray in project sling by apache.
the class UpdateGroupTest method testUpdateGroupMembers.
public void testUpdateGroupMembers() throws IOException, JsonException {
testGroupId = createTestGroup();
testUserId = createTestUser();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
// verify that the members array exists, but is empty
JsonArray members = getTestGroupMembers(creds);
assertEquals(0, members.size());
JsonArray memberships = getTestUserMemberships(creds);
assertEquals(0, memberships.size());
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
// add a group member
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":member", testUserId));
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
members = getTestGroupMembers(creds);
assertEquals(1, members.size());
assertEquals("/system/userManager/user/" + testUserId, members.getString(0));
memberships = getTestUserMemberships(creds);
assertEquals(1, memberships.size());
assertEquals("/system/userManager/group/" + testGroupId, memberships.getString(0));
// delete a group member
postParams.clear();
postParams.add(new NameValuePair(":member@Delete", testUserId));
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
members = getTestGroupMembers(creds);
assertEquals(0, members.size());
memberships = getTestUserMemberships(creds);
assertEquals(0, memberships.size());
}
Aggregations