Search in sources :

Example 76 with GetRequest

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

the class ActionDefinitionsRestApiTest method testRmGetActionDefinitions.

/**
 * Test the REST API to retrieve the list of rm action definitions
 *
 * @throws IOException
 * @throws JSONException
 */
public void testRmGetActionDefinitions() throws IOException, JSONException {
    // Send request
    Response response = sendRequest(new GetRequest(RM_ACTIONDEFINITIONS_URL), Status.STATUS_OK);
    // Check the content from the response
    String contentAsString = response.getContentAsString();
    assertNotNull(contentAsString);
    // Convert the response to json and check the data
    JSONObject contentAsJson = new JSONObject(contentAsString);
    JSONArray data = contentAsJson.getJSONArray("data");
    assertNotNull(data);
    // Get a (sub)list of available dm action definitions
    List<String> dmActionDefinitions = getDmActionDefinitions();
    // Get the list of rm action definitions from the response and check it
    List<String> rmActionDefinitions = new ArrayList<String>();
    for (int i = 0; i < data.length(); i++) {
        String name = data.getJSONObject(i).getString("name");
        assertNotNull(name);
        rmActionDefinitions.add(name);
        assertFalse(dmActionDefinitions.contains(name));
    }
    assertTrue(rmActionDefinitions.containsAll(getRmActionDefinitions()));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList)

Example 77 with GetRequest

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

the class CapabilitiesRestApiTest method testGetCapabilitiesAction.

/**
 * Tests the REST API to get the list of capabilities
 *
 * @throws IOException
 * @throws JSONException
 */
public void testGetCapabilitiesAction() throws IOException, JSONException {
    String baseURL = MessageFormat.format(GET_CAPABILITIES_URL, filePlan.getStoreRef().getProtocol(), filePlan.getStoreRef().getIdentifier(), filePlan.getId());
    // Format url and send request
    String getUrl = String.format(baseURL + "includeAll=%s", true);
    Response getResponse = sendRequest(new GetRequest(getUrl), Status.STATUS_OK);
    // Check the content from the response
    String getContentAsString = getResponse.getContentAsString();
    assertNotNull(getContentAsString);
    System.out.println(getContentAsString);
    // Convert the response to json and check the data
    JSONObject getContentAsJson = new JSONObject(getContentAsString);
    JSONObject getData = getContentAsJson.getJSONObject("data");
    assertNotNull(getData);
    // Get the capabilities and check them
    JSONArray getDataSets = getData.getJSONArray("capabilities");
    assertNotNull(getDataSets);
    // Format url and send another request with different parameter
    getUrl = String.format(baseURL + "grouped=%s", true);
    getResponse = sendRequest(new GetRequest(getUrl), Status.STATUS_OK);
    // Check the content from the response
    getContentAsString = getResponse.getContentAsString();
    assertNotNull(getContentAsString);
    // If both parameters are specified the result should be the same with only specifying the "grouped" parameter
    getUrl = String.format(baseURL + "includeAll=%s&amp;grouped=%s", true, true);
    getResponse = sendRequest(new GetRequest(getUrl), Status.STATUS_OK);
    getContentAsString.equalsIgnoreCase(getResponse.getContentAsString());
    // Convert the response to json and check the data
    getContentAsJson = new JSONObject(getContentAsString);
    getData = getContentAsJson.getJSONObject("data");
    assertNotNull(getData);
    // Get the grouped capabilities and check them
    getDataSets = getData.getJSONArray("groupedCapabilities");
    assertNotNull(getDataSets);
    // Check the JSON structure
    int length = getDataSets.length();
    if (length > 0) {
        for (int i = 0; i < length; i++) {
            JSONObject jsonObject = getDataSets.getJSONObject(i);
            String key = (String) jsonObject.keys().next();
            JSONObject value = jsonObject.getJSONObject(key);
            assertNotNull(value.getString("groupTitle"));
            assertNotNull(value.getJSONObject("capabilities"));
        }
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 78 with GetRequest

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

the class DispositionRestApiTest method testGetDispositionSchedule.

public void testGetDispositionSchedule() throws Exception {
    // Test 404 status for non existent node
    int expectedStatus = 404;
    String nonExistentNode = "workspace/SpacesStore/09ca1e02-1c87-4a53-97e7-xxxxxxxxxxxx";
    String nonExistentUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, nonExistentNode);
    Response rsp = sendRequest(new GetRequest(nonExistentUrl), expectedStatus);
    // Test 404 status for node that doesn't have dispostion schedule i.e. a record series
    String seriesNodeUrl = recordSeries.toString().replace("://", "/");
    String wrongNodeUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, seriesNodeUrl);
    rsp = sendRequest(new GetRequest(wrongNodeUrl), expectedStatus);
    // Test data structure returned from "AIS Audit Records"
    expectedStatus = 200;
    String categoryNodeUrl = recordCategory.toString().replace("://", "/");
    String requestUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, categoryNodeUrl);
    rsp = sendRequest(new GetRequest(requestUrl), expectedStatus);
    assertEquals("application/json;charset=UTF-8", rsp.getContentType());
    // get response as JSON
    JSONObject jsonParsedObject = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    assertNotNull(jsonParsedObject);
    // check JSON data
    JSONObject dataObj = jsonParsedObject.getJSONObject("data");
    assertNotNull(dataObj);
    JSONObject rootDataObject = (JSONObject) dataObj;
    assertEquals(10, rootDataObject.length());
    // check individual data items
    String serviceUrl = SERVICE_URL_PREFIX + requestUrl;
    String url = rootDataObject.getString("url");
    assertEquals(serviceUrl, url);
    String authority = rootDataObject.getString("authority");
    assertEquals(CommonRMTestUtils.DEFAULT_DISPOSITION_AUTHORITY, authority);
    String instructions = rootDataObject.getString("instructions");
    assertEquals(CommonRMTestUtils.DEFAULT_DISPOSITION_INSTRUCTIONS, instructions);
    String actionsUrl = rootDataObject.getString("actionsUrl");
    assertEquals(serviceUrl + "/dispositionactiondefinitions", actionsUrl);
    boolean recordLevel = rootDataObject.getBoolean("recordLevelDisposition");
    assertFalse(recordLevel);
    assertFalse(rootDataObject.getBoolean("canStepsBeRemoved"));
    JSONArray actions = rootDataObject.getJSONArray("actions");
    assertNotNull(actions);
    assertEquals(2, actions.length());
    JSONObject action1 = (JSONObject) actions.get(0);
    assertEquals(9, action1.length());
    assertNotNull(action1.get("id"));
    assertNotNull(action1.get("url"));
    assertEquals(0, action1.getInt("index"));
    assertEquals("cutoff", action1.getString("name"));
    assertTrue(action1.getBoolean("eligibleOnFirstCompleteEvent"));
    JSONObject action2 = (JSONObject) actions.get(1);
    assertEquals(8, action2.length());
    // make sure the disposition schedule node ref is present and valid
    String scheduleNodeRefJSON = rootDataObject.getString("nodeRef");
    NodeRef scheduleNodeRef = new NodeRef(scheduleNodeRefJSON);
    assertTrue(this.nodeService.exists(scheduleNodeRef));
    // create a new recordCategory node in the recordSeries and then get
    // the disposition schedule
    NodeRef newRecordCategory = filePlanService.createRecordCategory(recordSeries, GUID.generate());
    dispositionService.createDispositionSchedule(newRecordCategory, null);
    categoryNodeUrl = newRecordCategory.toString().replace("://", "/");
    requestUrl = MessageFormat.format(GET_SCHEDULE_URL_FORMAT, categoryNodeUrl);
    // System.out.println("GET response: " + rsp.getContentAsString());
    rsp = sendRequest(new GetRequest(requestUrl), expectedStatus);
    // get response as JSON
    jsonParsedObject = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    System.out.println(rsp.getContentAsString());
    assertNotNull(jsonParsedObject);
    // check JSON data
    dataObj = jsonParsedObject.getJSONObject("data");
    assertNotNull(dataObj);
    rootDataObject = (JSONObject) dataObj;
    assertEquals(8, rootDataObject.length());
    actions = rootDataObject.getJSONArray("actions");
    assertNotNull(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) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 79 with GetRequest

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

the class RoleRestApiTest method testGetRoles.

public void testGetRoles() throws Exception {
    String role1 = GUID.generate();
    String role2 = GUID.generate();
    String role3 = GUID.generate();
    // Create a couple or roles by hand
    filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
    filePlanRoleService.createRole(filePlan, role2, "My Test Role Too", getListOfCapabilities(5));
    // The user can either enter a plain text label or a key to look up in a property file.
    filePlanRoleService.createRole(filePlan, role3, "System Administrator", getListOfCapabilities(5));
    // create test group
    String groupName = GUID.generate();
    String group = authorityService.createAuthority(AuthorityType.GROUP, groupName, "monkey", null);
    // Add the admin user to one of the roles
    filePlanRoleService.assignRoleToAuthority(filePlan, role1, "admin");
    filePlanRoleService.assignRoleToAuthority(filePlan, role1, group);
    try {
        // Get the roles (for the default file plan)
        Response rsp = sendRequest(new GetRequest(getRolesUrlBySite()), 200);
        String rspContent = rsp.getContentAsString();
        JSONObject obj = new JSONObject(rspContent);
        JSONObject roles = obj.getJSONObject("data");
        assertNotNull(roles);
        JSONObject roleObj = roles.getJSONObject(role1);
        assertNotNull(roleObj);
        assertEquals(role1, roleObj.get("name"));
        assertEquals("My Test Role", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 5);
        roleObj = roles.getJSONObject(role2);
        assertNotNull(roleObj);
        assertEquals(role2, roleObj.get("name"));
        assertEquals("My Test Role Too", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 5);
        // Custom role with a user entered message key
        roleObj = roles.getJSONObject(role3);
        assertNotNull(roleObj);
        assertEquals(role3, roleObj.get("name"));
        assertEquals("System Administrator", roleObj.get("displayLabel"));
        // Get the roles, specifying the file plan
        rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan()), 200);
        rspContent = rsp.getContentAsString();
        obj = new JSONObject(rspContent);
        roles = obj.getJSONObject("data");
        assertNotNull(roles);
        roleObj = roles.getJSONObject(role1);
        assertNotNull(roleObj);
        assertEquals(role1, roleObj.get("name"));
        assertEquals("My Test Role", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 5);
        roleObj = roles.getJSONObject(role2);
        assertNotNull(roleObj);
        assertEquals(role2, roleObj.get("name"));
        assertEquals("My Test Role Too", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 5);
        // Get the roles for "admin"
        rsp = sendRequest(new GetRequest(getRolesUrlBySite() + "?user=admin"), 200);
        rspContent = rsp.getContentAsString();
        obj = new JSONObject(rspContent);
        roles = obj.getJSONObject("data");
        assertNotNull(roles);
        roleObj = roles.getJSONObject(role1);
        assertNotNull(roleObj);
        assertEquals(role1, roleObj.get("name"));
        assertEquals("My Test Role", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 5);
        assertFalse(roles.has(role2));
        // Get the roles including assigned authorities
        rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan() + "?auths=true"), 200);
        rspContent = rsp.getContentAsString();
        System.out.println(rspContent);
        obj = new JSONObject(rspContent);
        roles = obj.getJSONObject("data");
        assertNotNull(roles);
        roleObj = roles.getJSONObject(role1);
        assertNotNull(roleObj);
        assertEquals(role1, roleObj.get("name"));
        assertEquals("My Test Role", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 5);
        JSONArray users = roleObj.getJSONArray("assignedUsers");
        assertNotNull(users);
        assertEquals(1, users.length());
        JSONArray groups = roleObj.getJSONArray("assignedGroups");
        assertNotNull(groups);
        assertEquals(1, groups.length());
        roleObj = roles.getJSONObject(role2);
        assertNotNull(roleObj);
        assertEquals(role2, roleObj.get("name"));
        assertEquals("My Test Role Too", roleObj.get("displayLabel"));
        checkCapabilities(roleObj, 5);
        users = roleObj.getJSONArray("assignedUsers");
        assertNotNull(users);
        assertEquals(0, users.length());
        groups = roleObj.getJSONArray("assignedGroups");
        assertNotNull(groups);
        assertEquals(0, groups.length());
    } finally {
        // Clean up
        filePlanRoleService.deleteRole(filePlan, role1);
        filePlanRoleService.deleteRole(filePlan, role2);
    }
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) JSONArray(org.json.JSONArray)

Example 80 with GetRequest

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

the class AuditRestApiTest method testAuditAccessCapability.

public void testAuditAccessCapability() throws IOException {
    String recordAuditUrl = MessageFormat.format(GET_NODE_AUDITLOG_URL_FORMAT, record.toString().replace("://", "/"));
    sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_OK, AuthenticationUtil.getAdminUserName());
    sendRequest(new GetRequest(recordAuditUrl), Status.STATUS_FORBIDDEN, USER_WITHOUT_AUDIT_CAPABILITY);
}
Also used : GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Aggregations

GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)182 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)171 JSONObject (org.json.JSONObject)141 JSONArray (org.json.JSONArray)89 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)25 HashMap (java.util.HashMap)23 JSONTokener (org.json.JSONTokener)23 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)21 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Serializable (java.io.Serializable)13 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)13 QName (org.alfresco.service.namespace.QName)13 ArrayList (java.util.ArrayList)12 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)12 Date (java.util.Date)11 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)11 JSONStringer (org.json.JSONStringer)7 Calendar (java.util.Calendar)6 UserTransaction (javax.transaction.UserTransaction)6