Search in sources :

Example 81 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)

Aggregations

PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)81 Test (org.junit.Test)76 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 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)15 NodeRef (org.alfresco.service.cmr.repository.NodeRef)15 HashMap (java.util.HashMap)14 List (java.util.List)13 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)13 JSONArray (org.json.simple.JSONArray)13 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)11 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)9