Search in sources :

Example 16 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 17 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 18 with DeleteRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.

the class FeedControlTest method deleteFeedControl.

protected void deleteFeedControl(String siteId, String appToolId) throws Exception {
    // Unset (delete) feed control
    int expectedStatus = 200;
    Response response = sendRequest(new DeleteRequest(URL_CONTROL + "?s=" + TEST_SITE_ID + "&a=" + TEST_APP_TOOL_ID), expectedStatus);
    if (logger.isDebugEnabled()) {
        logger.debug(response);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 19 with DeleteRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.

the class NodeArchiveServiceRestApiTest method testPurgeDeletedItemsAsNonAdminUser.

/**
 * This test method purges some deleted nodes from the archive store for the current user.
 */
public void testPurgeDeletedItemsAsNonAdminUser() throws Exception {
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
    String deleteUrl = getArchiveUrl(user2_DeletedTestNode.getStoreRef()) + "/" + user2_DeletedTestNode.getId();
    // User_One has the nodeRef of the node deleted by User_Two. User_One is
    // not an Admin, so he must not be allowed to purge a node which he doesn’t own.
    Response rsp = sendRequest(new DeleteRequest(deleteUrl), 403);
    assertEquals(403, rsp.getStatus());
    // Now User_One gets his own archived node and tries to purge it
    JSONObject jsonRsp = getArchivedNodes();
    JSONObject dataObj = (JSONObject) jsonRsp.get(DATA);
    JSONArray deletedNodesArray = (JSONArray) dataObj.get(AbstractArchivedNodeWebScript.DELETED_NODES);
    // User_One deleted only 1 node and he doesn't have permission to see other users' archived data.
    assertEquals("Unexpectedly found more than 1 item in the archive store.", 1, deletedNodesArray.length());
    JSONObject archivedNode = (JSONObject) deletedNodesArray.get(0);
    // So we have identified a specific Node in the archive that we want to delete permanently (purge).
    String nodeRefString = archivedNode.getString(AbstractArchivedNodeWebScript.NODEREF);
    assertTrue("nodeRef string is invalid", NodeRef.isNodeRef(nodeRefString));
    NodeRef nodeRef = new NodeRef(nodeRefString);
    // This is its current StoreRef i.e. archive://SpacesStore
    deleteUrl = getArchiveUrl(nodeRef.getStoreRef()) + "/" + nodeRef.getId();
    // Send the DELETE REST call.
    rsp = sendRequest(new DeleteRequest(deleteUrl), 200);
    jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    dataObj = jsonRsp.getJSONObject("data");
    JSONArray purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
    assertEquals("Only expected one NodeRef to have been purged.", 1, purgedNodesArray.length());
    // User_Two is authenticated
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
    // Now we'll purge all the nodes in the archive that User_Two owns.
    // This should only purge USER_TWO's archived nodes.
    String deleteAllUrl = getArchiveUrl(this.nodesOriginalStoreRef);
    rsp = sendRequest(new DeleteRequest(deleteAllUrl), 200);
    jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    dataObj = jsonRsp.getJSONObject("data");
    purgedNodesArray = dataObj.getJSONArray(ArchivedNodesDelete.PURGED_NODES);
    // User_Two deleted only 1 node.
    assertEquals("Only expected one NodeRef to have been purged.", 1, purgedNodesArray.length());
    // Test no other nodes have been deleted by User_Two 'Delete all archived nodes operation'.
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    jsonRsp = getArchivedNodes();
    dataObj = (JSONObject) jsonRsp.get(DATA);
    assertNotNull("JSON 'data' object was null", dataObj);
    deletedNodesArray = (JSONArray) dataObj.get(AbstractArchivedNodeWebScript.DELETED_NODES);
    assertNotNull("JSON 'deletedNodesArray' object was null", deletedNodesArray);
    assertEquals("There is 1 item in the archive store which was deleted by the Admin.", 1, deletedNodesArray.length());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 20 with DeleteRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method testWorkflowInstanceDeleteAsAdministrator.

public void testWorkflowInstanceDeleteAsAdministrator() throws Exception {
    // Start workflow as USER1
    personManager.setUser(USER1);
    WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
    Date dueDate = new Date();
    params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    params.put(WorkflowModel.PROP_CONTEXT, packageRef);
    WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
    WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
    startTask = workflowService.endTask(startTask.getId(), null);
    WorkflowInstance adhocInstance = startTask.getPath().getInstance();
    // Run next request as admin
    String admin = authenticationComponent.getDefaultAdministratorUserNames().iterator().next();
    AuthenticationUtil.setFullyAuthenticatedUser(admin);
    sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocInstance.getId()), Status.STATUS_OK);
    WorkflowInstance instance = workflowService.getWorkflowById(adhocInstance.getId());
    if (instance != null) {
        assertFalse("The deleted workflow is still active!", instance.isActive());
    }
    List<WorkflowInstance> instances = workflowService.getActiveWorkflows(adhocInstance.getDefinition().getId());
    for (WorkflowInstance activeInstance : instances) {
        assertFalse(adhocInstance.getId().equals(activeInstance.getId()));
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest) Date(java.util.Date)

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