use of javax.json.JsonArray in project sling by apache.
the class ModifyAceTest method testModifyAceForUser.
@Test
public void testModifyAceForUser() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:write", "denied"));
//invalid value should be ignored.
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "bogus"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(1, jsonObject.size());
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
String principalString = aceObject.getString("principal");
assertEquals(testUserId, principalString);
int order = aceObject.getInt("order");
assertEquals(0, order);
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals(1, grantedArray.size());
assertEquals("jcr:read", grantedArray.getString(0));
JsonArray deniedArray = aceObject.getJsonArray("denied");
assertNotNull(deniedArray);
assertEquals(1, deniedArray.size());
assertEquals("jcr:write", deniedArray.getString(0));
}
use of javax.json.JsonArray in project sling by apache.
the class RemoveAcesTest method createFolderWithAces.
private String createFolderWithAces(boolean addGroupAce) throws IOException, JsonException {
testUserId = createTestUser();
testFolderUrl = createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:write", "denied"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
if (addGroupAce) {
testGroupId = createTestGroup();
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testGroupId));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
if (addGroupAce) {
assertEquals(2, jsonObject.size());
} else {
assertEquals(1, jsonObject.size());
}
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
assertEquals(0, aceObject.getInt("order"));
String principalString = aceObject.getString("principal");
assertEquals(testUserId, principalString);
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals("jcr:read", grantedArray.getString(0));
JsonArray deniedArray = aceObject.getJsonArray("denied");
assertNotNull(deniedArray);
assertEquals("jcr:write", deniedArray.getString(0));
if (addGroupAce) {
aceObject = jsonObject.getJsonObject(testGroupId);
assertNotNull(aceObject);
principalString = aceObject.getString("principal");
assertEquals(testGroupId, principalString);
assertEquals(1, aceObject.getInt("order"));
grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals("jcr:read", grantedArray.getString(0));
}
return testFolderUrl;
}
use of javax.json.JsonArray in project sling by apache.
the class JsonObjectCreatorTest method testCreateArray.
@Test
public void testCreateArray() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("emptyArray", new Object[] {});
properties.put("stringArray", new String[] { "10", "100" });
properties.put("intArray", new int[] { 10, 100 });
properties.put("doubleArray", new double[] { 10d, 100d });
properties.put("byteArray", new byte[] { 0x0A, 0x64 });
properties.put("floatArray", new float[] { 10.0f, 100.0f });
properties.put("shortArray", new short[] { 10, 100 });
properties.put("longArray", new long[] { 10, 100 });
properties.put("booleanArray", new boolean[] { true, false });
properties.put("charArray", new char[] { 'a', 'b' });
Resource resource = new MockResource("/some/path", properties, resolver);
JsonObject json = JsonObjectCreator.create(resource).build();
assertEquals(0, json.getJsonArray("emptyArray").size());
JsonArray array;
array = json.getJsonArray("stringArray");
assertEquals("10", array.getString(0));
array = json.getJsonArray("intArray");
assertEquals(10, array.getInt(0));
array = json.getJsonArray("doubleArray");
assertEquals("10.0", array.getString(0));
array = json.getJsonArray("byteArray");
assertEquals("10", array.getString(0));
array = json.getJsonArray("floatArray");
assertEquals("10.0", array.getString(0));
array = json.getJsonArray("shortArray");
assertEquals("10", array.getString(0));
array = json.getJsonArray("longArray");
assertEquals(10L, array.getJsonNumber(0).longValue());
array = json.getJsonArray("booleanArray");
assertEquals(true, array.getBoolean(0));
array = json.getJsonArray("charArray");
assertEquals("a", array.getString(0));
}
use of javax.json.JsonArray in project sling by apache.
the class SlingRemoteTestRunner method maybeExecuteTests.
private void maybeExecuteTests() throws Exception {
if (testHttpClient != null) {
// Tests already ran
return;
}
testHttpClient = new RemoteTestHttpClient(testParameters.getJunitServletUrl(), this.username, this.password, true);
// Let the parameters class customize the request if desired
if (testParameters instanceof RequestCustomizer) {
testHttpClient.setRequestCustomizer((RequestCustomizer) testParameters);
}
// Run tests remotely and get response
final RequestExecutor executor = testHttpClient.runTests(testParameters.getTestClassesSelector(), testParameters.getTestMethodSelector(), "json");
executor.assertContentType("application/json");
final JsonArray json = Json.createReader(new StringReader(JsonTicksConverter.tickToDoubleQuote(executor.getContent()))).readArray();
// based on this vlaue
for (int i = 0; i < json.size(); i++) {
final JsonObject obj = json.getJsonObject(i);
if (obj.containsKey("INFO_TYPE") && "test".equals(obj.getString("INFO_TYPE"))) {
children.add(new SlingRemoteTest(testClass, obj));
}
}
log.info("Server-side tests executed as {} at {} with path {}", new Object[] { this.username, testParameters.getJunitServletUrl(), testHttpClient.getTestExecutionPath() });
// Optionally check that number of tests is as expected
if (testParameters instanceof SlingTestsCountChecker) {
((SlingTestsCountChecker) testParameters).checkNumberOfTests(children.size());
}
}
use of javax.json.JsonArray in project drill by apache.
the class ProfileParser method parseFragProfiles.
private void parseFragProfiles() {
JsonArray frags = getFragmentProfile();
for (JsonObject fragProfile : frags.getValuesAs(JsonObject.class)) {
int mId = fragProfile.getInt("majorFragmentId");
FragInfo major = fragments.get(mId);
major.parse(fragProfile);
}
}
Aggregations