Search in sources :

Example 56 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletDeleteTest method testDeleteAllChildrenByPath.

/**
     * Test for SLING-2415 Ability to delete child nodes, without deleting the parent node
     * Using :applyTo value of "/*"
     */
public void testDeleteAllChildrenByPath() throws IOException {
    final String urlA = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    final String urlB = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    final String urlC = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    final String urlD = testClient.createNode(postUrl + "/specific-location/for-delete", null);
    // initially all nodes must be found
    assertHttpStatus(urlA + DEFAULT_EXT, HttpServletResponse.SC_OK, "A must initially exist");
    assertHttpStatus(urlB + DEFAULT_EXT, HttpServletResponse.SC_OK, "B must initially exist");
    assertHttpStatus(urlC + DEFAULT_EXT, HttpServletResponse.SC_OK, "C must initially exist");
    assertHttpStatus(urlD + DEFAULT_EXT, HttpServletResponse.SC_OK, "D must initially exist");
    // delete and check
    final List<NameValuePair> params = new LinkedList<NameValuePair>();
    params.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_DELETE));
    params.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, "/*"));
    assertPostStatus(postUrl, HttpServletResponse.SC_OK, params, "Delete must return expected status");
    assertHttpStatus(urlA + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "A must be deleted");
    assertHttpStatus(urlB + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "B must be deleted");
    assertHttpStatus(urlC + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "C must be deleted");
    assertHttpStatus(urlD + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "D must be deleted");
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) LinkedList(java.util.LinkedList)

Example 57 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletDeleteTest method testDelete.

public void testDelete() throws IOException {
    final String urlA = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    final String urlB = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    final String urlC = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
    final String urlD = testClient.createNode(postUrl + "/specific-location/for-delete", null);
    // initially all nodes must be found
    assertHttpStatus(urlA + DEFAULT_EXT, HttpServletResponse.SC_OK, "A must initially exist");
    assertHttpStatus(urlB + DEFAULT_EXT, HttpServletResponse.SC_OK, "B must initially exist");
    assertHttpStatus(urlC + DEFAULT_EXT, HttpServletResponse.SC_OK, "C must initially exist");
    assertHttpStatus(urlD + DEFAULT_EXT, HttpServletResponse.SC_OK, "D must initially exist");
    // delete one and check
    final List<NameValuePair> params = new LinkedList<NameValuePair>();
    params.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_DELETE));
    assertPostStatus(urlA, HttpServletResponse.SC_OK, params, "Delete must return expected status (3)");
    assertHttpStatus(urlA + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "A must be deleted (1)");
    assertHttpStatus(urlB + DEFAULT_EXT, HttpServletResponse.SC_OK, "B must still exist");
    assertHttpStatus(urlC + DEFAULT_EXT, HttpServletResponse.SC_OK, "C must still exist");
    assertHttpStatus(urlD + DEFAULT_EXT, HttpServletResponse.SC_OK, "D must still exist");
    // delete the others with successive requests
    assertPostStatus(urlB, HttpServletResponse.SC_OK, params, "Delete must return expected status (2)");
    assertPostStatus(urlC, HttpServletResponse.SC_OK, params, "Delete must return expected status (2)");
    assertPostStatus(urlD, HttpServletResponse.SC_OK, params, "Delete must return expected status (2)");
    assertHttpStatus(urlA + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "A must be deleted (2)");
    assertHttpStatus(urlB + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "B must be deleted (2)");
    assertHttpStatus(urlC + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "C must be deleted (2)");
    assertHttpStatus(urlD + DEFAULT_EXT, HttpServletResponse.SC_NOT_FOUND, "D must be deleted (2)");
    // attempting to delete non-existing nodes is ok
    assertPostStatus(postUrl, HttpServletResponse.SC_OK, params, "Delete must return expected status (2)");
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) LinkedList(java.util.LinkedList)

Example 58 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletImportTest method testImportNodeWithAlreadyUsedExactName.

/**
     * SLING-1091: test error reporting when attempting to import a node with an
     * already used node name.
     */
public void testImportNodeWithAlreadyUsedExactName() throws IOException, JsonException {
    String testNodeName = "alreadyUsedExactNodeName";
    String location = importNodeWithExactName(testNodeName);
    //try to create the same node again, since same name siblings are not allowed an error should be
    // thrown
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(SlingPostConstants.RP_NODE_NAME, testNodeName));
    //expect a 500 status since the name is not unique
    String postUrl = location.substring(0, location.lastIndexOf('/'));
    assertPostStatus(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList)

Example 59 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletCopyTest method testCopyAllChildrenByPath.

/**
     * Test for SLING-2415 Ability to move all child nodes, without the parent node
     * Using :applyTo value of "/*"
     */
public void testCopyAllChildrenByPath() throws IOException {
    final String testPath = TEST_BASE_PATH + "/cpmultwc/" + 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 + "/test/src1", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src2", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src3", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src4", props);
    // create destination parent
    testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
    // copy the src? nodes
    List<NameValuePair> nvPairs = new ArrayList<NameValuePair>();
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_COPY));
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_DEST, testPath + "/dest/"));
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, "/*"));
    // we expect success
    assertPostStatus(testRoot + "/test", HttpServletResponse.SC_OK, nvPairs, "Expecting Copy Success");
    // assert 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_OK);
    assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src4/text", HttpServletResponse.SC_OK);
    testClient.delete(testRoot);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 60 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletCopyTest method testCopyAllChildrenOfSubNode.

/**
     * Test for SLING-2415 Ability to copy all child nodes of a subnode, without the parent node
     * Using :applyTo value of "subnode_path/*"
     */
public void testCopyAllChildrenOfSubNode() throws IOException {
    final String testPath = TEST_BASE_PATH + "/cpmultwc/" + 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 + "/test/src1", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src2", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src3", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src4", props);
    // create destination parent
    testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
    // copy the src? nodes
    List<NameValuePair> nvPairs = new ArrayList<NameValuePair>();
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_COPY));
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_DEST, testPath + "/dest/"));
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, "test/*"));
    // we expect success
    assertPostStatus(testRoot, HttpServletResponse.SC_OK, nvPairs, "Expecting Copy Success");
    // assert 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_OK);
    assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src4/text", HttpServletResponse.SC_OK);
    testClient.delete(testRoot);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)217 ArrayList (java.util.ArrayList)114 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)61 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 PostMethod (org.apache.commons.httpclient.methods.PostMethod)41 HashMap (java.util.HashMap)28 IOException (java.io.IOException)23 Header (org.apache.commons.httpclient.Header)21 JsonArray (javax.json.JsonArray)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 HashSet (java.util.HashSet)17 HttpMethod (org.apache.commons.httpclient.HttpMethod)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)16 Cookie (org.apache.commons.httpclient.Cookie)13 GetRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8