Search in sources :

Example 36 with NameValuePair

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

the class UpdateUserTest method testUpdateUserResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
@Test
public void testUpdateUserResponseAsJSON() throws IOException, JsonException {
    testUserId = H.createTestUser();
    String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.json";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("displayName", "My Updated Test User"));
    postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
    Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
    String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
    //make sure the json response can be parsed as a JSON object
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 37 with NameValuePair

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

the class UpdateUserTest method testChangeUserPasswordAsAdministratorWithoutOldPwd.

/**
	 * Test for SLING-2069
	 * @throws IOException
	 */
@Test
public void testChangeUserPasswordAsAdministratorWithoutOldPwd() throws IOException {
    testUserId = H.createTestUser();
    String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".changePassword.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("newPwd", "testNewPwd"));
    postParams.add(new NameValuePair("newPwdConfirm", "testNewPwd"));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 38 with NameValuePair

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

the class CreateGroupTest method testCreateGroupAlreadyExists.

public void testCreateGroupAlreadyExists() throws IOException {
    String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";
    testGroupId = "testGroup" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));
    assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
    //post the same info again, should fail
    assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList)

Example 39 with NameValuePair

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

the class CreateGroupTest method testCreateGroupResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
public void testCreateGroupResponseAsJSON() throws IOException, JsonException {
    String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.json";
    testGroupId = "testGroup" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));
    postParams.add(new NameValuePair("marker", testGroupId));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
    //make sure the json response can be parsed as a JSON object
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
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 40 with NameValuePair

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

the class PostServletVersionableTest method testDeletingAPropertyOfACheckedInNodeFailsWithoutAutoCheckout.

public void testDeletingAPropertyOfACheckedInNodeFailsWithoutAutoCheckout() throws IOException {
    params.put(":checkinNewVersionableNodes", "true");
    params.put("testprop", "testvalue");
    final String location = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, params);
    assertHttpStatus(location + DEFAULT_EXT, HttpServletResponse.SC_OK, "POST must redirect to created resource (" + location + ")");
    assertTrue("Node (" + location + ") must have generated name", !location.endsWith("/*"));
    assertTrue("Node (" + location + ") must created be under POST URL (" + postUrl + ")", location.contains(postUrl + "/"));
    String content = getContent(location + ".txt", CONTENT_TYPE_PLAIN);
    assertTrue("Node (" + location + ") should be checked in.", content.contains("jcr:isCheckedOut: false"));
    assertTrue("Node (" + location + ") has a test property.", content.contains("testprop: testvalue"));
    List<NameValuePair> testParams = Arrays.asList(new NameValuePair(":autoCheckout", "false"), new NameValuePair("testprop@Delete", ""));
    assertPostStatus(location, 500, testParams, "Attempted modification with :autoCheckout=false should fail.");
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)162 ArrayList (java.util.ArrayList)109 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)55 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 HashMap (java.util.HashMap)24 PostMethod (org.apache.commons.httpclient.methods.PostMethod)24 JsonArray (javax.json.JsonArray)20 Header (org.apache.commons.httpclient.Header)16 HashSet (java.util.HashSet)14 HttpClient (org.apache.commons.httpclient.HttpClient)13 HttpMethod (org.apache.commons.httpclient.HttpMethod)13 GetMethod (org.apache.commons.httpclient.methods.GetMethod)12 IOException (java.io.IOException)8 LinkedList (java.util.LinkedList)8 InputStream (java.io.InputStream)7 URL (java.net.URL)6 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)5