use of javax.json.JsonObject in project sling by apache.
the class JsonResponseTest method testSetError.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public void testSetError() throws IOException {
String errMsg = "Dummy error";
res.setError(new Error(errMsg));
MockSlingHttpServletResponse resp = new MockSlingHttpServletResponse();
res.send(resp, true);
JsonObject json = res.getJson();
JsonValue error = assertProperty(json, "error");
assertProperty((JsonObject) error, "class", Error.class.getName());
assertProperty((JsonObject) error, "message", errMsg);
}
use of javax.json.JsonObject in project sling by apache.
the class JSONGroovyBuilderTest method testRichObject.
public void testRichObject() throws IOException, JsonException {
final String toDelete = uploadTestScript("builder_rich_object.groovy", "json.groovy");
try {
final String content = getContent(displayUrl + ".json", CONTENT_TYPE_JSON);
log.debug("{} content: {}", displayUrl, content);
JsonObject jo = Json.createReader(new StringReader(content)).readObject();
assertEquals("Content contained wrong number of items", 2, jo.size());
assertEquals("Content contained wrong data", testText, jo.getString("text"));
assertEquals("Content contained wrong data", "bar", ((JsonObject) jo.getJsonObject("obj")).getString("foo"));
} finally {
testClient.delete(toDelete);
}
}
use of javax.json.JsonObject in project sling by apache.
the class JSONGroovyBuilderTest method testObject.
public void testObject() throws IOException, JsonException {
final String toDelete = uploadTestScript("builder_object.groovy", "json.groovy");
try {
final String content = getContent(displayUrl + ".json", CONTENT_TYPE_JSON);
JsonObject jo = Json.createReader(new StringReader(content)).readObject();
assertEquals("Content contained wrong number of items", 1, jo.size());
assertEquals("Content contained wrong key", "text", jo.keySet().iterator().next());
assertEquals("Content contained wrong data", testText, jo.getString("text"));
} finally {
testClient.delete(toDelete);
}
}
use of javax.json.JsonObject in project sling by apache.
the class AccessPrivilegesInfoTest method testSLING_1090.
/**
* Test the fix for SLING-1090
*/
@Test
public void testSLING_1090() throws Exception {
testUserId = H.createTestUser();
//grant jcr: removeChildNodes to the root node
ArrayList<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:removeChildNodes", "granted"));
Credentials adminCreds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(adminCreds, HttpTest.HTTP_BASE_URL + "/.modifyAce.html", HttpServletResponse.SC_OK, postParams, null);
//create a node as a child of the root folder
testFolderUrl = H.getTestClient().createNode(HttpTest.HTTP_BASE_URL + "/testFolder" + random.nextInt() + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
String postUrl = testFolderUrl + ".modifyAce.html";
//grant jcr:removeNode to the test node
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:removeNode", "granted"));
H.assertAuthenticatedPostStatus(adminCreds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the test page to verify the settings.
String getUrl = testFolderUrl + ".privileges-info.json";
Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(true, jsonObj.getBoolean("canDelete"));
}
use of javax.json.JsonObject in project sling by apache.
the class GetAclTest method testEffectiveAclForUser.
/**
* Test for SLING-2600, Effective ACL servlet returns incorrect information
*/
@Test
public void testEffectiveAclForUser() throws IOException, JsonException {
testUserId = H.createTestUser();
testUserId2 = H.createTestUser();
String testFolderUrl = H.createTestFolder("{ \"jcr:primaryType\": \"nt:unstructured\", \"propOne\" : \"propOneValue\", \"child\" : { \"childPropOne\" : true } }");
String postUrl = testFolderUrl + ".modifyAce.html";
//1. create an initial set of privileges
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId2));
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId2));
postParams.add(new NameValuePair("privilege@jcr:lockManagement", "granted"));
postUrl = testFolderUrl + "/child.modifyAce.html";
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the eacl to verify the settings.
String getUrl = testFolderUrl + "/child.eacl.json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
String principalString = aceObject.getString("principal");
assertEquals(testUserId, principalString);
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals(1, grantedArray.size());
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:write");
Object deniedArray = aceObject.get("denied");
assertNull(deniedArray);
JsonObject aceObject2 = jsonObject.getJsonObject(testUserId2);
assertNotNull(aceObject2);
String principalString2 = aceObject2.getString("principal");
assertEquals(testUserId2, principalString2);
JsonArray grantedArray2 = aceObject2.getJsonArray("granted");
assertNotNull(grantedArray2);
assertEquals(2, grantedArray2.size());
Set<String> grantedPrivilegeNames2 = new HashSet<String>();
for (int i = 0; i < grantedArray2.size(); i++) {
grantedPrivilegeNames2.add(grantedArray2.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:write");
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:lockManagement");
Object deniedArray2 = aceObject2.get("denied");
assertNull(deniedArray2);
}
Aggregations