Search in sources :

Example 1 with DeleteRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project records-management by Alfresco.

the class RMCaveatConfigScriptTest method testDeleteRMConstraint.

/**
 * Delete the entire constraint
 *
 * @throws Exception
 */
public void testDeleteRMConstraint() throws Exception {
    /**
     * Delete the list to remove any junk then recreate it.
     */
    if (caveatConfigService.getRMConstraint(RM_LIST) != null) {
        caveatConfigService.deleteRMConstraint(RM_LIST);
    }
    caveatConfigService.addRMConstraint(RM_LIST, "my title", new String[0]);
    /**
     * Now do a delete
     */
    Response response = sendRequest(new DeleteRequest(URL_RM_CONSTRAINTS + "/" + RM_LIST), Status.STATUS_OK);
    /**
     * Now delete the list that should have been deleted
     */
    // TODO NEED TO THINK ABOUT THIS BEHAVIOUR
    // {
    // sendRequest(new DeleteRequest(URL_RM_CONSTRAINTS + "/" + RM_LIST), Status.STATUS_NOT_FOUND);
    // }
    /**
     * Negative test - delete list that does not exist
     */
    {
        sendRequest(new DeleteRequest(URL_RM_CONSTRAINTS + "/" + "rmc_wibble"), Status.STATUS_NOT_FOUND);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 2 with DeleteRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project records-management by Alfresco.

the class EventRestApiTest method testDeleteRole.

public void testDeleteRole() throws Exception {
    String eventName = GUID.generate();
    assertFalse(eventService.existsEvent(eventName));
    eventService.addEvent(EVENT_TYPE, eventName, DISPLAY_LABEL);
    assertTrue(eventService.existsEvent(eventName));
    sendRequest(new DeleteRequest(GET_EVENTS_URL + "/" + eventName), 200);
    assertFalse(eventService.existsEvent(eventName));
    // Bad request
    sendRequest(new DeleteRequest(GET_EVENTS_URL + "/cheese"), 404);
}
Also used : DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 3 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 4 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)

Example 5 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)

Aggregations

DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)44 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)32 JSONObject (org.json.JSONObject)29 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)22 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