use of javax.json.JsonObject in project sling by apache.
the class PostServletImportTest method testImportXMLFromRequestParamWithoutOptionalName.
public void testImportXMLFromRequestParamWithoutOptionalName() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
urlsToDelete.add(testNode);
props.clear();
props.put(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT);
String xmlContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport2.xml"));
props.put(SlingPostConstants.RP_CONTENT, xmlContent);
props.put(SlingPostConstants.RP_CONTENT_TYPE, "xml");
props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, props);
//make sure the name is what was inside the file.
assertTrue(importedNodeUrl.endsWith("/nodeName"));
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
use of javax.json.JsonObject in project sling by apache.
the class PostServletImportTest method testImportCheckinNodes.
/**
* Test import operation which checks in versionable nodes.
*/
public void testImportCheckinNodes() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
urlsToDelete.add(testNode);
props.clear();
props.put(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT);
String testNodeName = "testNode_" + String.valueOf(random.nextInt());
props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName);
testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport3.json"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
props.put(SlingPostConstants.RP_CHECKIN, "true");
String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, testFile, SlingPostConstants.RP_CONTENT_FILE, null);
// assert content at new location
String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert that the versionable node is checked in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));
//now try with the checkin value set to false
testFile.delete();
props.clear();
props.put(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT);
String testNodeName2 = "testNode_" + String.valueOf(random.nextInt());
props.put(SlingPostConstants.RP_NODE_NAME_HINT, testNodeName2);
testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport3.json"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
props.put(SlingPostConstants.RP_CHECKIN, "false");
String importedNodeUrl2 = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, testFile, SlingPostConstants.RP_CONTENT_FILE, null);
// assert content at new location
String content2 = getContent(importedNodeUrl2 + ".json", CONTENT_TYPE_JSON);
JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);
//assert that the versionable node is checked in.
assertTrue(jsonObj2.getBoolean("jcr:isCheckedOut"));
}
use of javax.json.JsonObject in project sling by apache.
the class PostServletMoveTest method testMoveNodeMultipleSourceReplace.
public void testMoveNodeMultipleSourceReplace() throws Exception {
final String testPath = TEST_BASE_PATH + "/mvmult/" + System.currentTimeMillis();
final String testRoot = testClient.createNode(HTTP_BASE_URL + testPath, null);
// create multiple source nodes
Map<String, String> props = new HashMap<String, String>();
props.put("text", "Hello");
testClient.createNode(HTTP_BASE_URL + testPath + "/src1", props);
testClient.createNode(HTTP_BASE_URL + testPath + "/src2", props);
// move the src? nodes
List<NameValuePair> nvPairs = new ArrayList<NameValuePair>();
nvPairs.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_MOVE));
nvPairs.add(new NameValuePair(SlingPostConstants.RP_DEST, testPath + "/dest/"));
nvPairs.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, testPath + "/src1"));
nvPairs.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, testPath + "/src2"));
assertPostStatus(testRoot, HttpServletResponse.SC_PRECONDITION_FAILED, nvPairs, "Expecting Move Failure: dest parent does not exist");
// create destination parent
testClient.createNode(HTTP_BASE_URL + testPath + "/dest", null);
// now dest exists, so we expect success
assertPostStatus(testRoot, HttpServletResponse.SC_OK, nvPairs, "Expecting Move Success");
// assert partial existence of the src?/text properties
assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src1/text", HttpServletResponse.SC_OK);
assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src2/text", HttpServletResponse.SC_OK);
assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src3/text", HttpServletResponse.SC_NOT_FOUND);
assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src4/text", HttpServletResponse.SC_NOT_FOUND);
// assert content test
String content = getContent(HTTP_BASE_URL + testPath + "/dest/src1.json", CONTENT_TYPE_JSON);
JsonObject json = JsonUtil.parseObject(content);
assertEquals("Hello", json.getString("text"));
// modify src1 content
nvPairs.clear();
nvPairs.add(new NameValuePair("text", "Modified Hello"));
assertPostStatus(HTTP_BASE_URL + testPath + "/src1", HttpServletResponse.SC_CREATED, nvPairs, "Expect Content Create Success");
// move the src? nodes
nvPairs.clear();
nvPairs.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_MOVE));
nvPairs.add(new NameValuePair(SlingPostConstants.RP_DEST, testPath + "/dest/"));
nvPairs.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, testPath + "/src1"));
nvPairs.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, testPath + "/src2"));
assertPostStatus(testRoot, HttpServletResponse.SC_OK, nvPairs, "Expecting Move Success");
// assert content test
String content2 = getContent(HTTP_BASE_URL + testPath + "/dest/src1.json", CONTENT_TYPE_JSON);
JsonObject json2 = JsonUtil.parseObject(content2);
assertEquals("Modified Hello", json2.getString("text"));
// clean up
testClient.delete(testRoot);
}
use of javax.json.JsonObject in project sling by apache.
the class ModifyAceTest method testAddAceOrderByNumeric.
/**
* Test to verify adding an ACE at a specific index inside
* the ACL
*/
@Test
public void testAddAceOrderByNumeric() throws IOException, JsonException {
createAceOrderTestFolderWithOneAce();
testGroupId = H.createTestGroup();
addOrUpdateAce(testFolderUrl, testGroupId, true, "0");
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(2, jsonObject.size());
JsonObject group = jsonObject.getJsonObject(testGroupId);
assertNotNull(group);
assertEquals(testGroupId, group.getString("principal"));
assertEquals(0, group.getInt("order"));
JsonObject user = jsonObject.getJsonObject(testUserId);
assertNotNull(user);
assertEquals(testUserId, user.getString("principal"));
assertEquals(1, user.getInt("order"));
//add another principal between the testGroupId and testUserId
testUserId2 = H.createTestUser();
addOrUpdateAce(testFolderUrl, testUserId2, true, "1");
String json2 = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json2);
JsonObject jsonObject2 = JsonUtil.parseObject(json2);
assertEquals(3, jsonObject2.size());
JsonObject group2 = jsonObject2.getJsonObject(testGroupId);
assertNotNull(group2);
assertEquals(testGroupId, group2.getString("principal"));
assertEquals(0, group2.getInt("order"));
JsonObject user3 = jsonObject2.getJsonObject(testUserId2);
assertNotNull(user3);
assertEquals(testUserId2, user3.getString("principal"));
assertEquals(1, user3.getInt("order"));
JsonObject user2 = jsonObject2.getJsonObject(testUserId);
assertNotNull(user2);
assertEquals(testUserId, user2.getString("principal"));
assertEquals(2, user2.getInt("order"));
}
use of javax.json.JsonObject in project sling by apache.
the class ModifyAceTest method testUpdateAcePreservePosition.
/**
* Test to make sure modifying an existing ace without changing the order
* leaves the ACE in the same position in the ACL
*/
@Test
public void testUpdateAcePreservePosition() throws IOException, JsonException {
createAceOrderTestFolderWithOneAce();
testGroupId = H.createTestGroup();
addOrUpdateAce(testFolderUrl, testGroupId, true, "first");
//update the ace to make sure the update does not change the ACE order
addOrUpdateAce(testFolderUrl, testGroupId, false, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(2, jsonObject.size());
JsonObject group = jsonObject.getJsonObject(testGroupId);
assertNotNull(group);
assertEquals(testGroupId, group.getString("principal"));
assertEquals(0, group.getInt("order"));
JsonObject user = jsonObject.getJsonObject(testUserId);
assertNotNull(user);
assertEquals(testUserId, user.getString("principal"));
assertEquals(1, user.getInt("order"));
}
Aggregations