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());
}
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;
}
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());
}
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");
}
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");
}
Aggregations