use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class PostServletPatchTest method testPatch.
public void testPatch() throws Exception {
final NameValuePairList props = new NameValuePairList();
// 1. create multi-value property
props.add("prop@TypeHint", "String[]");
props.add("prop", "alpha");
props.add("prop", "beta");
props.add("prop", "beta");
props.add("prop", "gamma");
// make sure both epsilons are kept, as they are not touched
props.add("prop", "epsilon");
// by the patch operations below
props.add("prop", "epsilon");
String location = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props, null, false);
props.clear();
// 2. update mv prop through Patch method
props.add("prop@Patch", "true");
//props.add("prop@TypeHint", "String[]");
// remove all betas
props.add("prop", "-beta");
// add one delta
props.add("prop", "+delta");
// already exists, do not add a second alpha
props.add("prop", "+alpha");
testClient.createNode(location, props, null, false);
String content = getContent(location + ".json", CONTENT_TYPE_JSON);
assertJavascript("true", content, "out.println(data.prop.length == 5)");
assertJavascript("alpha", content, "out.println(data.prop[0])");
assertJavascript("gamma", content, "out.println(data.prop[1])");
assertJavascript("epsilon", content, "out.println(data.prop[2])");
assertJavascript("epsilon", content, "out.println(data.prop[3])");
assertJavascript("delta", content, "out.println(data.prop[4])");
}
use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class PostServletImportTest method testImportJSONFromFile.
/**
* Test import operation for a posted json file
*/
public void testImportJSONFromFile() 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/testimport.json"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "json");
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 testImportJSONFromFileWithoutOptionalName.
/**
* Test import operation for a posted json file without the optional name
*/
public void testImportJSONFromFileWithoutOptionalName() 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);
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 + "/*");
String importedNodeUrl = testClient.createNode(HTTP_BASE_URL + testPath, new NameValuePairList(props), null, true, testFile, SlingPostConstants.RP_CONTENT_FILE, null);
//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 org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class PostServletImportTest method testImportJarFromFile.
public void testImportJarFromFile() 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/testimport.jar"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "jar");
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/testimportzip.json"));
assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class PostServletImportTest method testImportXMLFromFile.
public void testImportXMLFromFile() 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/testimport.xml"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "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);
}
Aggregations