use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class InviteServiceTest method deleteInvitation.
/**
* Adapted from similar method in org.alfresco.repo.web.scripts.invitation.InvitationWebScriptTest
*/
JSONObject deleteInvitation(String invitationID, String siteShortName, int expectedStatus) throws Exception {
assertNotNull(invitationID);
assertNotNull(siteShortName);
assertFalse(invitationID.isEmpty());
assertFalse(siteShortName.isEmpty());
Response response = sendRequest(new DeleteRequest(URL_SITES + "/" + siteShortName + "/invitations/" + invitationID), expectedStatus);
JSONObject jsonResponse = new JSONObject(response.getContentAsString());
assertNotNull(jsonResponse);
return jsonResponse;
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class PersonServiceTest method deletePerson.
private JSONObject deletePerson(String userName, int expectedStatus) throws Exception {
// switch to admin user to delete a person
String currentUser = this.authenticationComponent.getCurrentUserName();
String adminUser = this.authenticationComponent.getSystemUserName();
this.authenticationComponent.setCurrentUser(adminUser);
Response response = sendRequest(new DeleteRequest(URL_PEOPLE + "/" + userName), expectedStatus);
this.createdPeople.remove(userName);
// switch back to non-admin user
this.authenticationComponent.setCurrentUser(currentUser);
return new JSONObject(response.getContentAsString());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class QuickShareRestApiTest method testSanityCheckUrls.
public void testSanityCheckUrls() throws Exception {
checkTransformer();
final int expectedStatusOK = 200;
final int expectedStatusNotFound = 404;
// currently mapped from AccessDenied (should it be 403, 404 or does it depend on use-case)
final int expectedStatusServerError = 500;
final int expectedStatusForbidden = 403;
String testNodeRef_3 = testNode.toString().replace("://", "/");
// As user one ...
// get metadata for node (authenticated)
Response rsp = sendRequest(new GetRequest(AUTH_METADATA_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE);
JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
String name = jsonRsp.getString("name");
assertEquals(TEST_NAME, name);
String mimetype = jsonRsp.getString("mimetype");
assertEquals(TEST_MIMETYPE_JPEG, mimetype);
// get content for node (authenticated)
// Commented out when removing original CMIS impl
// rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE);
// byte[] content = rsp.getContentAsByteArray();
// checkBytes(TEST_CONTENT, content);
// get content thumbnail for node (authenticated)
rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_ONE);
String type = rsp.getContentType();
assertEquals(TEST_MIMETYPE_PNG, type);
// As user two ...
rsp = sendRequest(new GetRequest(AUTH_METADATA_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusServerError, USER_TWO);
// Commented out when removing original CMIS impl
// rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusForbidden, USER_TWO);
rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusServerError, USER_TWO);
// As user one ...
// share
rsp = sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", testNodeRef_3), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
String sharedId = jsonRsp.getString("sharedId");
assertNotNull(sharedId);
// note: we may have to adjust/remove this check if we change length of id (or it becomes variable length)
assertEquals(22, sharedId.length());
// As user two ...
// get metadata for share (note: can be unauthenticated)
rsp = sendRequest(new GetRequest(SHARE_METADATA_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_TWO);
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
name = jsonRsp.getString("name");
assertEquals(TEST_NAME, name);
mimetype = jsonRsp.getString("mimetype");
assertEquals(TEST_MIMETYPE_JPEG, mimetype);
// get content for share (note: can be unauthenticated)
rsp = sendRequest(new GetRequest(SHARE_CONTENT_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_TWO);
byte[] content = rsp.getContentAsByteArray();
checkBytes(TEST_CONTENT, content);
// get content thumbnail for share (note: can be unauthenticated)
rsp = sendRequest(new GetRequest(SHARE_CONTENT_THUMBNAIL_URL.replace("{shared_id}", sharedId).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_TWO);
type = rsp.getContentType();
assertEquals(TEST_MIMETYPE_PNG, type);
// As user one ...
// unshare
rsp = sendRequest(new DeleteRequest(UNSHARE_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_ONE);
// As user two ...
// -ve test (should not be able to get metadata or content via sharedId) - whether authenticated or not
rsp = sendRequest(new GetRequest(SHARE_METADATA_URL.replace("{shared_id}", sharedId)), expectedStatusNotFound, USER_TWO);
rsp = sendRequest(new GetRequest(SHARE_CONTENT_URL.replace("{shared_id}", sharedId)), expectedStatusNotFound, USER_TWO);
rsp = sendRequest(new GetRequest(SHARE_CONTENT_THUMBNAIL_URL.replace("{shared_id}", sharedId).replace("{thumbnailname}", "doclib")), expectedStatusNotFound, USER_TWO);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testInvitationSanityCheck.
/**
* End to end sanity check of web site invitation.
*
* Nominated and Moderated invitations.
*
* @throws Exception
*/
public void testInvitationSanityCheck() throws Exception {
String shortName = GUID.generate();
String secondShortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
createSite("myPreset", secondShortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
String inviteComments = "Please sir, let me in";
String userName = USER_TWO;
String roleName = SiteModel.SITE_CONSUMER;
String inviteeFirstName = "Buffy";
String inviteeLastName = "Summers";
String inviteeEmail = "buffy@sunnydale";
String inviteeUserName = userName;
String serverPath = "http://localhost:8081/share/";
String acceptURL = "page/accept-invite";
String rejectURL = "page/reject-invite";
// Create a new moderated invitation
String moderatedId = createModeratedInvitation(secondShortName, inviteComments, userName, roleName);
// Get the moderated invitation
sendRequest(new GetRequest(URL_SITES + "/" + secondShortName + "/invitations/" + moderatedId), 200);
// search for the moderated invitation
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=" + userName), 200);
// Create a nominated invitation
String nominatedId = createNominatedInvitation(shortName, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL, 201);
// Search for all invitations on this site
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations"), 200);
// cancel the moderated invitation
sendRequest(new DeleteRequest(URL_SITES + "/" + secondShortName + "/invitations/" + moderatedId), 200);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.
the class SiteServiceTest method testDeleteSite.
public void testDeleteSite() throws Exception {
// Delete non-existent site
sendRequest(new DeleteRequest(URL_SITES + "/" + "somerandomshortname"), 404);
// Create a site
String shortName = GUID.generate();
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
// Get the site
sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
// Delete the site
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 200);
// Get the site
sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404);
}
Aggregations