Search in sources :

Example 6 with DeleteRequest

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;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 7 with DeleteRequest

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());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 8 with DeleteRequest

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);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 9 with DeleteRequest

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);
}
Also used : GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 10 with DeleteRequest

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);
}
Also used : GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Aggregations

DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)43 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)32 JSONObject (org.json.JSONObject)29 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)21 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)14 JSONArray (org.json.JSONArray)9 JSONTokener (org.json.JSONTokener)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Serializable (java.io.Serializable)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 UserTransaction (javax.transaction.UserTransaction)3 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)3 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)3 QName (org.alfresco.service.namespace.QName)3 JSONStringer (org.json.JSONStringer)3 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)3 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)2