Search in sources :

Example 21 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testCreateProcessInstanceFromOtherNetwork.

@Test
@SuppressWarnings("unchecked")
public void testCreateProcessInstanceFromOtherNetwork() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    publicApiClient.setRequestContext(otherContext);
    ProcessesClient processesClient = publicApiClient.processesClient();
    JSONObject createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionId", processDefinition.getId());
    final JSONObject variablesObject = new JSONObject();
    variablesObject.put("bpm_dueDate", ISO8601DateFormat.format(new Date()));
    variablesObject.put("bpm_priority", 1);
    variablesObject.put("bpm_description", "test description");
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
            return null;
        }
    }, requestContext.getRunAsUser(), requestContext.getNetworkId());
    createProcessObject.put("variables", variablesObject);
    try {
        processesClient.createProcess(createProcessObject.toJSONString());
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Date(java.util.Date) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 22 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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 23 with ProcessesClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient 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

ProcessesClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient)23 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)20 Test (org.junit.Test)20 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)17 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)16 JSONObject (org.json.simple.JSONObject)16 HashMap (java.util.HashMap)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 JSONArray (org.json.simple.JSONArray)6 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)4 Date (java.util.Date)3 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)3 Task (org.activiti.engine.task.Task)3 List (java.util.List)2 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)2 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 TaskService (org.activiti.engine.TaskService)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1