Search in sources :

Example 66 with PublicApiException

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsWhereClause.

@Test
public void testGetProcessDefinitionsWhereClause() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    // Filter on category equals
    Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')");
    assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
    assertTrue(processDefinitionMap.containsKey("activitiReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(5, processDefinitionMap.size());
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'unexisting')");
    assertEquals(0, processDefinitionMap.size());
    // Filter on name equals
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name = 'Adhoc Activiti Process')");
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(1, processDefinitionMap.size());
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name = 'unexisting')");
    assertEquals(0, processDefinitionMap.size());
    // Filter on key equals
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key='activitiAdhoc')");
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(1, processDefinitionMap.size());
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key='unexisting')");
    assertEquals(0, processDefinitionMap.size());
    // Filter on version equals
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(version='1')");
    assertEquals(5, processDefinitionMap.size());
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(version='2')");
    assertEquals(0, processDefinitionMap.size());
    // Filter on deploymentId equals
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(deploymentId='" + activitiDefinition.getDeploymentId() + "')");
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(1, processDefinitionMap.size());
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(deploymentId='unexisting')");
    assertEquals(0, processDefinitionMap.size());
    // Filter on category matches
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category matches('%alfresco.o%'))");
    assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
    assertTrue(processDefinitionMap.containsKey("activitiReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(5, processDefinitionMap.size());
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category matches('unexisting'))");
    assertEquals(0, processDefinitionMap.size());
    // Filter on name matches
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name matches('Adhoc Activiti %'))");
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(1, processDefinitionMap.size());
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name matches('unexisting'))");
    assertEquals(0, processDefinitionMap.size());
    // Filter on key matches
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key matches('activitiAd%'))");
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(1, processDefinitionMap.size());
    // Use AND operator
    processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org' AND name = 'Adhoc Activiti Process')");
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(1, processDefinitionMap.size());
    // Use OR operator
    try {
        processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org' OR name = 'Adhoc Activiti Process')");
        fail("Expected exception");
    } catch (PublicApiException e) {
        assertEquals(400, e.getHttpResponse().getStatusCode());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) ProcessDefinition(org.alfresco.rest.workflow.api.model.ProcessDefinition) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 67 with PublicApiException

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsSorting.

@Test
public void testGetProcessDefinitionsSorting() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    List<ProcessDefinition> processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "name");
    assertEquals(5, processDefinitions.size());
    List<String> expectedNames = Arrays.asList("Adhoc Activiti Process", "Parallel Group Review And Approve Activiti Process", "Parallel Review And Approve Activiti Process", "Pooled Review And Approve Activiti Process", "Review And Approve Activiti Process");
    List<String> names = collect(processDefinitions, new Collector() {

        @Override
        public String collect(ProcessDefinition definition) {
            return definition.getName();
        }
    });
    assertEquals(expectedNames, names);
    processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "name DESC");
    assertEquals(5, processDefinitions.size());
    names = collect(processDefinitions, new Collector() {

        @Override
        public String collect(ProcessDefinition definition) {
            return definition.getName();
        }
    });
    Collections.reverse(expectedNames);
    assertEquals(expectedNames, names);
    processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "version DESC");
    // all the same version so no sorting
    assertEquals(5, processDefinitions.size());
    processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "id ASC");
    assertEquals(5, processDefinitions.size());
    List<String> ids = collect(processDefinitions, new Collector() {

        @Override
        public String collect(ProcessDefinition definition) {
            return definition.getId();
        }
    });
    List<String> sortedIds = new ArrayList<>(ids);
    Collections.sort(sortedIds);
    assertEquals(sortedIds, ids);
    processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "category ASC");
    // all the same
    assertEquals(5, processDefinitions.size());
    processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "key DESC");
    assertEquals(5, processDefinitions.size());
    List<String> keys = collect(processDefinitions, new Collector() {

        @Override
        public String collect(ProcessDefinition definition) {
            return definition.getKey();
        }
    });
    List<String> sortedKeys = new ArrayList<>(keys);
    // order
    Collections.sort(sortedKeys);
    // reverse order
    Collections.reverse(sortedKeys);
    assertEquals(sortedKeys, keys);
    processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "deploymentId ASC");
    assertEquals(5, processDefinitions.size());
    List<String> deploymentIds = collect(processDefinitions, new Collector() {

        @Override
        public String collect(ProcessDefinition definition) {
            return definition.getDeploymentId();
        }
    });
    List<String> sortedDeploymentIds = new ArrayList<>(deploymentIds);
    Collections.sort(sortedDeploymentIds);
    assertEquals(sortedDeploymentIds, deploymentIds);
    try {
        processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "sausage ASC");
        fail("Expected exception");
    } catch (PublicApiException e) {
        assertEquals(400, e.getHttpResponse().getStatusCode());
        assertTrue(e.getMessage().contains("OrderBy sausage is not supported, supported items are"));
    }
    try {
        processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "deploymentId ASC, key");
        fail("Expected exception");
    } catch (PublicApiException e) {
        assertEquals(400, e.getHttpResponse().getStatusCode());
        assertTrue(e.getHttpResponse().getResponse().contains("Only one orderBy parameter is supported"));
    }
}
Also used : ArrayList(java.util.ArrayList) ProcessDefinition(org.alfresco.rest.workflow.api.model.ProcessDefinition) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 68 with PublicApiException

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

the class ProcessWorkflowApiTest method testDeleteProcessInstanceById.

@Test
public void testDeleteProcessInstanceById() 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);
    ProcessesClient processesClient = publicApiClient.processesClient();
    // delete with user starting the process instance
    ProcessInfo process = startAdhocProcess(requestContext, null);
    try {
        processesClient.deleteProcessById(process.getId());
        // Check if the process was actually deleted
        assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
        HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
        assertNotNull(deletedInstance);
        assertNotNull(deletedInstance.getEndTime());
        assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
        try {
            processesClient.deleteProcessById(process.getId());
            fail("expected exeception");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(process.getId());
    }
    // delete with admin in same network as the user starting the process instance
    process = startAdhocProcess(requestContext, null);
    try {
        publicApiClient.setRequestContext(adminContext);
        processesClient.deleteProcessById(process.getId());
        // Check if the process was actually deleted
        assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
        HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
        assertNotNull(deletedInstance);
        assertNotNull(deletedInstance.getEndTime());
        assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
    } finally {
        cleanupProcessInstance(process.getId());
    }
    // delete with admin from other network as the user starting the process instance
    process = startAdhocProcess(requestContext, null);
    try {
        publicApiClient.setRequestContext(otherContext);
        processesClient.deleteProcessById(process.getId());
        fail("Expect permission exception");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
    } finally {
        cleanupProcessInstance(process.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 69 with PublicApiException

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

the class ProcessWorkflowApiTest method testCreateProcessInstanceWithKey.

@Test
@SuppressWarnings("unchecked")
public void testCreateProcessInstanceWithKey() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    ProcessesClient processesClient = publicApiClient.processesClient();
    JSONObject createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionKey", "activitiAdhoc");
    final JSONObject variablesObject = new JSONObject();
    variablesObject.put("bpm_dueDate", "2013-09-30T00:00:00.000+0300");
    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);
    ProcessInfo processRest = processesClient.createProcess(createProcessObject.toJSONString());
    assertNotNull(processRest);
    Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
    assertEquals("test description", variables.get("bpm_description"));
    assertEquals(1, variables.get("bpm_priority"));
    cleanupProcessInstance(processRest.getId());
    // Test same create method with an admin user
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
    processRest = processesClient.createProcess(createProcessObject.toJSONString());
    assertNotNull(processRest);
    variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
    assertEquals("test description", variables.get("bpm_description"));
    assertEquals(1, variables.get("bpm_priority"));
    cleanupProcessInstance(processRest.getId());
    // Test create process with wrong key
    publicApiClient.setRequestContext(requestContext);
    createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionKey", "activitiAdhoc2");
    try {
        processRest = processesClient.createProcess(createProcessObject.toJSONString());
        fail();
    } catch (PublicApiException e) {
        // Exception expected because of wrong process definition key
        assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
        assertErrorSummary("No workflow definition could be found with key 'activitiAdhoc2'.", e.getHttpResponse());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Test(org.junit.Test)

Example 70 with PublicApiException

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

the class ProcessWorkflowApiTest method testGetProcessInstanceByIdUnexisting.

@Test
public void testGetProcessInstanceByIdUnexisting() throws Exception {
    initApiClientWithTestUser();
    ProcessesClient processesClient = publicApiClient.processesClient();
    try {
        processesClient.findProcessById("unexisting");
        fail("Exception expected");
    } catch (PublicApiException expected) {
        assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
        assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) 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