Search in sources :

Example 51 with NameValuePair

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

the class RemoveAcesTest method testRemoveAces.

//test removing multiple aces
public void testRemoveAces() throws IOException, JsonException {
    String folderUrl = createFolderWithAces(true);
    //remove the ace for the testUser principal
    String postUrl = folderUrl + ".deleteAce.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":applyTo", testUserId));
    postParams.add(new NameValuePair(":applyTo", testGroupId));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    //fetch the JSON for the acl to verify the settings.
    String getUrl = folderUrl + ".acl.json";
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObject = JsonUtil.parseObject(json);
    assertNotNull(jsonObject);
    assertEquals(0, jsonObject.size());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 52 with NameValuePair

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

the class RedirectOnLoginErrorTest method assertPostStatus.

/** Execute a POST request and check status
     * @return the HttpMethod executed
     * @throws IOException */
private HttpMethod assertPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage, String referer) throws IOException {
    final PostMethod post = new PostMethod(url);
    post.setFollowRedirects(false);
    post.setDoAuthentication(false);
    //set the referer to indicate where we came from
    post.setRequestHeader("Referer", referer);
    //set Accept header to trick sling into treating the request as from a browser
    post.setRequestHeader("User-Agent", "Mozilla/5.0 Sling Integration Test");
    if (postParams != null) {
        final NameValuePair[] nvp = {};
        post.setRequestBody(postParams.toArray(nvp));
    }
    if (postParams != null) {
        final NameValuePair[] nvp = {};
        post.setRequestBody(postParams.toArray(nvp));
    }
    final int status = httpClient.executeMethod(post);
    if (assertMessage == null) {
        assertEquals(expectedStatusCode, status);
    } else {
        assertEquals(assertMessage, expectedStatusCode, status);
    }
    return post;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod)

Example 53 with NameValuePair

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

the class RedirectOnLogoutTest method testRedirectToResourceAfterLogout.

/**
     * Test SLING-1847
     * @throws Exception
     */
@Test
public void testRedirectToResourceAfterLogout() throws Exception {
    //login
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_username", "admin"));
    params.add(new NameValuePair("j_password", "admin"));
    H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_MOVED_TEMPORARILY, params, null);
    //...and then...logout with a resource redirect
    String locationAfterLogout = HttpTest.SERVLET_CONTEXT + "/system/sling/info.sessionInfo.json";
    final GetMethod get = new GetMethod(HttpTest.HTTP_BASE_URL + "/system/sling/logout");
    NameValuePair[] logoutParams = new NameValuePair[1];
    logoutParams[0] = new NameValuePair("resource", locationAfterLogout);
    get.setQueryString(logoutParams);
    get.setFollowRedirects(false);
    final int status = H.getHttpClient().executeMethod(get);
    assertEquals("Expected redirect", HttpServletResponse.SC_MOVED_TEMPORARILY, status);
    Header location = get.getResponseHeader("Location");
    assertEquals(HttpTest.HTTP_BASE_URL + locationAfterLogout, location.getValue());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Header(org.apache.commons.httpclient.Header) ArrayList(java.util.ArrayList) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 54 with NameValuePair

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

the class PostServletDeleteTest method testDeleteAllChildrenOfSubNode.

/**
     * Test for SLING-2415 Ability to delete child nodes of a subnode, without deleting the parent node
     * Using :applyTo value of "subnode_path/*"
     */
public void testDeleteAllChildrenOfSubNode() 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");
    String testBaseUrl = HTTP_BASE_URL + TEST_BASE_PATH;
    String subPath = postUrl.substring(testBaseUrl.length() + 1);
    // 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, String.format("%s/*", subPath)));
    assertPostStatus(testBaseUrl, 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 55 with NameValuePair

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

the class PostServletDeleteTest method testDeleteAllChildren.

/**
     * Test for SLING-2415 Ability to delete child nodes, without deleting the parent node
     * Using :applyTo value of "*"
     */
public void testDeleteAllChildren() 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)

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