Search in sources :

Example 41 with DeleteRequest

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

the class DispositionRestApiTest method testDeleteDispositionAction.

public void testDeleteDispositionAction() throws Exception {
    NodeRef newRecordCategory = filePlanService.createRecordCategory(recordSeries, GUID.generate());
    dispositionService.createDispositionSchedule(newRecordCategory, null);
    // create an action definition to then delete
    String categoryNodeUrl = newRecordCategory.toString().replace("://", "/");
    String postRequestUrl = MessageFormat.format(POST_ACTIONDEF_URL_FORMAT, categoryNodeUrl);
    JSONObject jsonPostData = new JSONObject();
    jsonPostData.put("name", "cutoff");
    String jsonPostString = jsonPostData.toString();
    sendRequest(new PostRequest(postRequestUrl, jsonPostString, APPLICATION_JSON), 200);
    // verify the action definition is present and retrieve it's id
    String getRequestUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, categoryNodeUrl);
    Response rsp = sendRequest(new GetRequest(getRequestUrl), 200);
    JSONObject json = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    String actionDefId = json.getJSONObject("data").getJSONArray("actions").getJSONObject(0).getString("id");
    // try and delete a non existent action definition to check for 404
    String deleteRequestUrl = MessageFormat.format(DELETE_ACTIONDEF_URL_FORMAT, categoryNodeUrl, "xyz");
    rsp = sendRequest(new DeleteRequest(deleteRequestUrl), 404);
    // now delete the action defintion created above
    deleteRequestUrl = MessageFormat.format(DELETE_ACTIONDEF_URL_FORMAT, categoryNodeUrl, actionDefId);
    rsp = sendRequest(new DeleteRequest(deleteRequestUrl), 200);
    // verify it got deleted
    getRequestUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, categoryNodeUrl);
    rsp = sendRequest(new GetRequest(getRequestUrl), 200);
    json = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    JSONArray actions = json.getJSONObject("data").getJSONArray("actions");
    assertEquals(0, actions.length());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 42 with DeleteRequest

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

the class EmailMapScriptTest method testEmailMap.

/**
 * Tests the REST APIs for a custom mapping
 *
 * @throws IOException
 * @throws JSONException
 */
public void testEmailMap() throws IOException, JSONException {
    /**
     * Test GET
     */
    Response getResponse = sendRequest(new GetRequest(URL_RM_EMAILMAP), Status.STATUS_OK);
    JSONObject getResponseContent = new JSONObject(getResponse.getContentAsString());
    JSONObject getData = getResponseContent.getJSONObject("data");
    JSONArray getMappings = getData.getJSONArray("mappings");
    assertTrue(getMappings.length() == 20);
    /**
     * Test POST
     */
    JSONObject newMapping = new JSONObject();
    newMapping.put("from", "messageTo");
    newMapping.put("to", "rmc:Wibble");
    Response postResponse = sendRequest(new PostRequest(URL_RM_EMAILMAP, newMapping.toString(), APPLICATION_JSON), Status.STATUS_OK);
    JSONObject postResponseContent = new JSONObject(postResponse.getContentAsString());
    JSONObject postData = postResponseContent.getJSONObject("data");
    JSONArray postMappings = postData.getJSONArray("mappings");
    assertTrue(postMappings.length() == 21);
    assertTrue(existsMapping(postMappings));
    /**
     * Test DELETE
     */
    Response deleteResponse = sendRequest(new DeleteRequest(String.format(URL_RM_EMAILMAP_DELETE, "messageTo", "rmc:Wibble")), Status.STATUS_OK);
    JSONObject deleteResponseContent = new JSONObject(deleteResponse.getContentAsString());
    JSONObject deleteData = deleteResponseContent.getJSONObject("data");
    JSONArray deleteMappings = deleteData.getJSONArray("mappings");
    assertTrue(deleteMappings.length() == 20);
    assertFalse(existsMapping(deleteMappings));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 43 with DeleteRequest

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

the class RoleRestApiTest method testDeleteRole.

public void testDeleteRole() throws Exception {
    String role1 = GUID.generate();
    assertFalse(filePlanRoleService.existsRole(filePlan, role1));
    filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
    assertTrue(filePlanRoleService.existsRole(filePlan, role1));
    sendRequest(new DeleteRequest(getRolesUrlBySite() + "/" + role1), 200);
    assertFalse(filePlanRoleService.existsRole(filePlan, role1));
    // Bad request
    sendRequest(new DeleteRequest(getRolesUrlBySite() + "/cheese"), 404);
}
Also used : 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