Search in sources :

Example 76 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testDeleteProcessVariable.

@Test
public void testDeleteProcessVariable() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInfo processRest = startAdhocProcess(requestContext, null);
    try {
        assertNotNull(processRest);
        String processId = processRest.getId();
        // Create a variable to be deleted
        activitiProcessEngine.getRuntimeService().setVariable(processId, "deleteMe", "This is a string");
        // Delete variable
        publicApiClient.processesClient().deleteVariable(processId, "deleteMe");
        assertFalse(activitiProcessEngine.getRuntimeService().hasVariable(processId, "deleteMe"));
        // Deleting again should fail with 404, as variable doesn't exist anymore
        try {
            publicApiClient.processesClient().deleteVariable(processId, "deleteMe");
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("The entity with id: deleteMe was not found", expected.getHttpResponse());
        }
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 77 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testGetProcessActivities.

@Test
public void testGetProcessActivities() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    final ProcessInfo process1 = startAdhocProcess(requestContext, null);
    try {
        ProcessesClient processesClient = publicApiClient.processesClient();
        Map<String, String> paramMap = new HashMap<String, String>();
        JSONObject activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        JSONArray entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
        Map<String, JSONObject> activitiesMap = new HashMap<String, JSONObject>();
        for (Object entry : entriesJSON) {
            JSONObject jsonEntry = (JSONObject) entry;
            JSONObject activityJSONObject = (JSONObject) jsonEntry.get("entry");
            activitiesMap.put((String) activityJSONObject.get("activityDefinitionId"), activityJSONObject);
        }
        JSONObject activityJSONObject = activitiesMap.get("start");
        assertNotNull(activityJSONObject);
        assertNotNull(activityJSONObject.get("id"));
        assertEquals("start", activityJSONObject.get("activityDefinitionId"));
        assertNull(activityJSONObject.get("activityDefinitionName"));
        assertEquals("startEvent", activityJSONObject.get("activityDefinitionType"));
        assertNotNull(activityJSONObject.get("startedAt"));
        assertNotNull(activityJSONObject.get("endedAt"));
        assertNotNull(activityJSONObject.get("durationInMs"));
        activityJSONObject = activitiesMap.get("adhocTask");
        assertNotNull(activityJSONObject);
        assertNotNull(activityJSONObject.get("id"));
        assertEquals("adhocTask", activityJSONObject.get("activityDefinitionId"));
        assertEquals("Adhoc Task", activityJSONObject.get("activityDefinitionName"));
        assertEquals("userTask", activityJSONObject.get("activityDefinitionType"));
        assertNotNull(activityJSONObject.get("startedAt"));
        assertNull(activityJSONObject.get("endedAt"));
        assertNull(activityJSONObject.get("durationInMs"));
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "active");
        activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "completed");
        activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        paramMap = new HashMap<String, String>();
        try {
            processesClient.getActivities("fakeid", paramMap);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("The entity with id: fakeid was not found", expected.getHttpResponse());
        }
        // get activities with admin from the same tenant as the process initiator
        publicApiClient.setRequestContext(adminContext);
        paramMap = new HashMap<String, String>();
        activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
        // get tasks with admin from another tenant as the process initiator
        publicApiClient.setRequestContext(otherContext);
        paramMap = new HashMap<String, String>();
        try {
            processesClient.getActivities(process1.getId(), paramMap);
            fail("forbidden expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(process1.getId());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 78 with PublicApiException

use of org.alfresco.rest.api.tests.client.PublicApiException in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testCreateProcessInstanceWithNoParams.

@Test
public void testCreateProcessInstanceWithNoParams() throws Exception {
    initApiClientWithTestUser();
    ProcessesClient processesClient = publicApiClient.processesClient();
    JSONObject createProcessObject = new JSONObject();
    try {
        processesClient.createProcess(createProcessObject.toJSONString());
        fail("Exception excpected");
    } catch (PublicApiException e) {
        assertEquals(400, e.getHttpResponse().getStatusCode());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) JSONObject(org.json.simple.JSONObject) Test(org.junit.Test)

Aggregations

PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)78 Test (org.junit.Test)73 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)67 JSONObject (org.json.simple.JSONObject)40 ArrayList (java.util.ArrayList)24 Task (org.activiti.engine.task.Task)23 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)23 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)21 ProcessesClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient)19 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)18 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)16 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)16 NodeRef (org.alfresco.service.cmr.repository.NodeRef)15 HashMap (java.util.HashMap)13 List (java.util.List)13 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)13 JSONArray (org.json.simple.JSONArray)13 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)12 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)11 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)9