use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class AnonymousAccessTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// create test node under a unique path
final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + SlingPostConstants.DEFAULT_CREATE_SUFFIX;
testText = "Test text " + System.currentTimeMillis();
final NameValuePairList list = new NameValuePairList();
list.add("text", testText);
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 testImportXMLFromFileWithoutOptionalName.
public void testImportXMLFromFileWithoutOptionalName() 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.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);
//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 testImportZipFromFile.
public void testImportZipFromFile() 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.zip"));
props.put(SlingPostConstants.RP_CONTENT_TYPE, "zip");
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 SlingDateValuesTest method doDateTest.
private void doDateTest(String expected, String input, String expected2, String input2) throws IOException {
final NameValuePairList props = new NameValuePairList();
props.add("someDate", input);
props.add("someDate@TypeHint", "Date");
props.add("manyDates", input);
props.add("manyDates", input2);
props.add("manyDates@TypeHint", "Date[]");
final String createdNodeUrl = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props, null, false);
String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
// default behaviour writes empty string
log.info("Expecting [{}] -> [{}] (single value)", input, expected);
assertJavascript(expected, content, "out.println(data.someDate)");
assertJavascript(expected, content, "out.println(data.manyDates[0])");
log.info("Expecting [{}] -> [{}] (multi-value)", input2, expected2);
assertJavascript(expected2, content, "out.println(data.manyDates[1])");
}
use of org.apache.sling.commons.testing.integration.NameValuePairList in project sling by apache.
the class SlingDefaultValuesTest method testDefaultBehaviour.
public void testDefaultBehaviour() throws IOException {
final Map<String, String> props = new HashMap<String, String>();
props.put("a", "");
final String createdNodeUrl = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
// default behaviour writes empty string
assertJavascript("undefined", content, "out.println(\"\" + data.a)");
// overwrite with "123"
props.put("a", "123");
testClient.createNode(createdNodeUrl, props);
content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
assertJavascript("123", content, "out.println(data.a)");
// and clear again
props.put("a", "");
testClient.createNode(createdNodeUrl, props);
content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
assertJavascript("undefined", content, "out.println(\"\" + data.a)");
// check array
NameValuePairList params = new NameValuePairList();
params.add("x", "1");
params.add("x", "2");
params.add("x", "3");
testClient.createNode(createdNodeUrl, params, null, false);
content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
assertJavascript("123", content, "out.println(data.x)");
// check array with empty value
params = new NameValuePairList();
params.add("x", "1");
params.add("x", "");
params.add("x", "3");
testClient.createNode(createdNodeUrl, params, null, false);
content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
assertJavascript("3.0", content, "out.println(data.x.length)");
assertJavascript("1", content, "out.println(data.x[0])");
assertJavascript("", content, "out.println(data.x[1])");
assertJavascript("3", content, "out.println(data.x[2])");
// check array with empty value and ignore blanks
params = new NameValuePairList();
params.add("x", "1");
params.add("x", "");
params.add("x", "3");
params.add("x@IgnoreBlanks", "true");
testClient.createNode(createdNodeUrl, params, null, false);
content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
assertJavascript("2.0", content, "out.println(data.x.length)");
assertJavascript("1", content, "out.println(data.x[0])");
assertJavascript("3", content, "out.println(data.x[1])");
}
Aggregations