Search in sources :

Example 16 with NameValuePairList

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])");
}
Also used : NameValuePairList(org.apache.sling.commons.testing.integration.NameValuePairList)

Example 17 with NameValuePairList

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);
}
Also used : HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject) NameValuePairList(org.apache.sling.commons.testing.integration.NameValuePairList)

Example 18 with NameValuePairList

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);
}
Also used : HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject) NameValuePairList(org.apache.sling.commons.testing.integration.NameValuePairList)

Example 19 with NameValuePairList

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);
}
Also used : HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject) NameValuePairList(org.apache.sling.commons.testing.integration.NameValuePairList)

Example 20 with NameValuePairList

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);
}
Also used : HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject) NameValuePairList(org.apache.sling.commons.testing.integration.NameValuePairList)

Aggregations

NameValuePairList (org.apache.sling.commons.testing.integration.NameValuePairList)21 HashMap (java.util.HashMap)13 JsonObject (javax.json.JsonObject)11 ArrayList (java.util.ArrayList)2 JsonArray (javax.json.JsonArray)2 NameValuePair (org.apache.commons.httpclient.NameValuePair)2 Repository (javax.jcr.Repository)1 Session (javax.jcr.Session)1 SimpleCredentials (javax.jcr.SimpleCredentials)1 ObservationManager (javax.jcr.observation.ObservationManager)1 JsonString (javax.json.JsonString)1 Credentials (org.apache.commons.httpclient.Credentials)1 HttpMethod (org.apache.commons.httpclient.HttpMethod)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)1 NamespaceContext (org.custommonkey.xmlunit.NamespaceContext)1 SimpleNamespaceContext (org.custommonkey.xmlunit.SimpleNamespaceContext)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1