use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class CrudTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
final String slingResourceType = getClass().getName();
this.scriptPath = "/apps/" + slingResourceType;
this.testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
// create the test node, under a path that's specific to this class to allow collisions
final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + SlingPostConstants.DEFAULT_CREATE_SUFFIX;
final NameValuePairList list = new NameValuePairList();
list.add("sling:resourceType", slingResourceType);
this.displayUrl = testClient.createNode(url, list, null, true);
}
use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class PostServletImportTest method testImportAutoCheckoutNodes.
/**
* SLING-2108 Test import operation which auto checks out versionable nodes.
*/
public void testImportAutoCheckoutNodes() 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);
//1. first create some content to update.
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"));
//2. try an update with the :autoCheckout value set to false
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "false"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
assertPostStatus(importedNodeUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, "Expected error from VersionException");
//3. now try an update with the :autoCheckout value set to true
postParams.clear();
postParams.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT_TYPE, "json"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "true"));
postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
postParams.add(new NameValuePair(":http-equiv-accept", "application/json,*/*;q=0.9"));
HttpMethod post = assertPostStatus(importedNodeUrl, HttpServletResponse.SC_CREATED, postParams, "Expected 201 status");
String responseBodyAsString = post.getResponseBodyAsString();
JsonObject responseJSON = JsonUtil.parseObject(responseBodyAsString);
JsonArray changes = responseJSON.getJsonArray("changes");
JsonObject checkoutChange = changes.getJsonObject(0);
assertEquals("checkout", checkoutChange.getString("type"));
// assert content at new location
String content2 = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);
//make sure it was really updated
assertEquals("def2", jsonObj2.getString("abc"));
//assert that the versionable node is checked back in.
assertFalse(jsonObj.getBoolean("jcr:isCheckedOut"));
}
use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class PostServletImportTest method testImportJCRXMLFromFile.
public void testImportJCRXMLFromFile() 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_1287021810";
props.put(SlingPostConstants.RP_NODE_NAME, testNodeName);
testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport.jcr.xml"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "jcr.xml");
props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
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 + ".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 org.apache.sling.commons.testing.integration.NameValuePairList 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 org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class PostServletImportTest method testImportReplace.
/**
* Test import operation which replaces existing content
*/
public void testImportReplace() 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);
//add node that will get replaced
props.put("propTest", "propTestValue");
String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath + "/nodeName", props);
//import with the replace option to replace the existing node.
props.clear();
props.put(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_IMPORT);
testFile = getTestFile(getClass().getResourceAsStream("/integration-test/servlets/post/testimport2.json"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
props.put(SlingPostConstants.RP_REDIRECT_TO, SERVLET_CONTEXT + testPath + "/*");
props.put(SlingPostConstants.RP_REPLACE, "true");
String importedNodeUrl2 = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, testFile, SlingPostConstants.RP_CONTENT_FILE, null);
//the new node should have the same path as the replaced node
assertEquals(importedNodeUrl, importedNodeUrl2);
// assert content at new location
String content = getContent(importedNodeUrl2 + ".3.json", CONTENT_TYPE_JSON);
JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//test property should be gone.
assertNull(jsonObj.get("propTest"));
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
Aggregations