Search in sources :

Example 41 with PutRequest

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

the class RoleRestApiTest method testPutRole.

public void testPutRole() throws Exception {
    String role1 = GUID.generate();
    filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
    try {
        Set<Capability> caps = getListOfCapabilities(4, 8);
        JSONArray arrCaps = new JSONArray();
        for (Capability cap : caps) {
            System.out.println(cap.getName());
            arrCaps.put(cap.getName());
        }
        JSONObject obj = new JSONObject();
        obj.put("name", role1);
        obj.put("displayLabel", "Changed");
        obj.put("capabilities", arrCaps);
        // Get the roles
        Response rsp = sendRequest(new PutRequest(getRolesUrlBySite() + "/" + role1, obj.toString(), APPLICATION_JSON), 200);
        String rspContent = rsp.getContentAsString();
        JSONObject result = new JSONObject(rspContent);
        JSONObject roleObj = result.getJSONObject("data");
        assertNotNull(roleObj);
        assertNotNull(roleObj);
        assertEquals(role1, roleObj.get("name"));
        assertEquals("Changed", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 4);
        // Bad requests
        sendRequest(new PutRequest(getRolesUrlBySite() + "/cheese", obj.toString(), APPLICATION_JSON), 404);
    } finally {
        // Clean up
        filePlanRoleService.deleteRole(filePlan, role1);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) Capability(org.alfresco.module.org_alfresco_module_rm.capability.Capability) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Aggregations

PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)41 JSONObject (org.json.JSONObject)39 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)37 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)17 JSONArray (org.json.JSONArray)13 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)10 JSONTokener (org.json.JSONTokener)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 JSONStringer (org.json.JSONStringer)5 IOException (java.io.IOException)3 Serializable (java.io.Serializable)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)3 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)3 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)3 QName (org.alfresco.service.namespace.QName)3 JSONException (org.json.JSONException)3 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)3 ArrayList (java.util.ArrayList)1