Search in sources :

Example 26 with PublicApiException

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

the class ProcessDefinitionWorkflowApiTest method testAuthenticationAndAuthorization.

@Test
public void testAuthenticationAndAuthorization() throws Exception {
    // Fetching process definitions as admin should be possible
    RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    ListResponse<ProcessDefinition> processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
    Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
    assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
    assertTrue(processDefinitionMap.containsKey("activitiReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(5, processDefinitionMap.size());
    // Fetching process definitions as admin from another tenant shouldn't be possible
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    publicApiClient.setRequestContext(otherContext);
    processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
    processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
    // the response should contain process definitions from the new tenant
    assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
    assertTrue(processDefinitionMap.containsKey("activitiReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(5, processDefinitionMap.size());
    // Fetching a specific process definitions as admin should be possible
    publicApiClient.setRequestContext(requestContext);
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    // Get a single process definitions
    ProcessDefinition adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
    assertNotNull(adhocDefinition);
    // Check fields of a resulting process-definition
    assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
    assertEquals("activitiAdhoc", adhocDefinition.getKey());
    assertEquals(activitiDefinition.getDeploymentId(), adhocDefinition.getDeploymentId());
    assertEquals(activitiDefinition.getCategory(), adhocDefinition.getCategory());
    assertEquals(activitiDefinition.getName(), adhocDefinition.getName());
    assertEquals(activitiDefinition.getVersion(), adhocDefinition.getVersion());
    assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinition.isGraphicNotationDefined());
    assertEquals("wf:submitAdhocTask", adhocDefinition.getStartFormResourceKey());
    // Fetching a specific process definitions as admin from another tenant should not be possible
    publicApiClient.setRequestContext(otherContext);
    try {
        adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
        fail("not found expected");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
    }
    // Fetching the start form model of a process definition as admin should be possible
    publicApiClient.setRequestContext(requestContext);
    JSONObject model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
    assertNotNull(model);
    JSONArray entries = (JSONArray) model.get("entries");
    assertNotNull(entries);
    // Add all entries to a map, to make lookup easier
    Map<String, JSONObject> modelFieldsByName = new HashMap<String, JSONObject>();
    JSONObject entry = null;
    for (int i = 0; i < entries.size(); i++) {
        entry = (JSONObject) entries.get(i);
        assertNotNull(entry);
        entry = (JSONObject) entry.get("entry");
        assertNotNull(entry);
        modelFieldsByName.put((String) entry.get("name"), entry);
    }
    // Check well-known properties and their types
    // Validate bpm:description
    JSONObject modelEntry = modelFieldsByName.get("bpm_workflowDescription");
    assertNotNull(modelEntry);
    assertEquals("Description", modelEntry.get("title"));
    assertEquals("{http://www.alfresco.org/model/bpm/1.0}workflowDescription", modelEntry.get("qualifiedName"));
    assertEquals("d:text", modelEntry.get("dataType"));
    assertFalse((Boolean) modelEntry.get("required"));
    // Fetching a specific process definitions as admin from another tenant should not be possible
    publicApiClient.setRequestContext(otherContext);
    try {
        model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
        fail("not found expected");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
    }
}
Also used : HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) 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) 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 27 with PublicApiException

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsImage.

@Test
public void testGetProcessDefinitionsImage() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    try {
        HttpResponse response = processDefinitionsClient.findImageById(activitiDefinition.getId());
        fail("Exception expected");
    } catch (PublicApiException expected) {
        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), expected.getHttpResponse().getStatusCode());
        assertTrue(expected.getMessage().contains("No image available"));
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 28 with PublicApiException

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionByIdUnexisting.

@Test
public void testGetProcessDefinitionByIdUnexisting() throws Exception {
    initApiClientWithTestUser();
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    try {
        processDefinitionsClient.findProcessDefinitionById("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) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) Test(org.junit.Test)

Example 29 with PublicApiException

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

the class ProcessWorkflowApiTest method testGetProcessInstances.

@Test
public void testGetProcessInstances() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    final ProcessInfo process1 = startAdhocProcess(requestContext, null);
    final ProcessInfo process2 = startAdhocProcess(requestContext, null);
    final ProcessInfo process3 = startAdhocProcess(requestContext, null);
    try {
        ProcessesClient processesClient = publicApiClient.processesClient();
        Map<String, String> paramMap = new HashMap<String, String>();
        ListResponse<ProcessInfo> processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        Map<String, ProcessInfo> processMap = new HashMap<String, ProcessInfo>();
        for (ProcessInfo processRest : processList.getList()) {
            processMap.put(processRest.getId(), processRest);
        }
        assertTrue(processMap.containsKey(process1.getId()));
        assertTrue(processMap.containsKey(process2.getId()));
        assertTrue(processMap.containsKey(process3.getId()));
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        assertNull(processList.getList().get(0).getProcessVariables());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc2')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "2");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(2, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "3");
        paramMap.put("skipCount", "1");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(2, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "5");
        paramMap.put("skipCount", "2");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
        paramMap.put("maxItems", "5");
        paramMap.put("skipCount", "5");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'completed')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'any')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'active')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(status = 'active2')");
        try {
            processList = processesClient.getProcesses(paramMap);
            fail();
        } catch (PublicApiException e) {
        // expected exception
        }
        // Test the variable where-clause
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority = 'd_int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority = 'd:int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority > 'd:int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority >= 'd:int 1')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority < 'd:int 5')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority <= 'd:int 4')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(3, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/bpm_priority = 'd_int 5')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
        // test with date variable
        Calendar dateCal = Calendar.getInstance();
        Map<String, Object> variablesToSet = new HashMap<String, Object>();
        variablesToSet.put("testVarDate", dateCal.getTime());
        activitiProcessEngine.getRuntimeService().setVariables(process1.getId(), variablesToSet);
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(variables/testVarDate = 'd_datetime " + ISO8601DateFormat.format(dateCal.getTime()) + "')");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        // include process variables as well
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(includeVariables=true)");
        paramMap.put("maxItems", "1");
        paramMap.put("skipCount", "0");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
        paramMap.put("maxItems", "1");
        paramMap.put("skipCount", "0");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(1, processList.getList().size());
        ProcessInfo processInfo = processList.getList().get(0);
        assertNotNull(processInfo.getProcessVariables());
        boolean foundDescription = false;
        boolean foundAssignee = false;
        for (Variable variable : processInfo.getProcessVariables()) {
            if ("bpm_description".equals(variable.getName())) {
                assertEquals("d:text", variable.getType());
                assertNull(variable.getValue());
                foundDescription = true;
            } else if ("bpm_assignee".equals(variable.getName())) {
                assertEquals("cm:person", variable.getType());
                assertEquals(requestContext.getRunAsUser(), variable.getValue());
                foundAssignee = true;
            }
        }
        assertTrue(foundDescription);
        assertTrue(foundAssignee);
        // include process variables with paging
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
        paramMap.put("maxItems", "3");
        paramMap.put("skipCount", "1");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(2, processList.getList().size());
        processInfo = processList.getList().get(0);
        assertNotNull(processInfo.getProcessVariables());
        foundDescription = false;
        foundAssignee = false;
        for (Variable variable : processInfo.getProcessVariables()) {
            if ("bpm_description".equals(variable.getName())) {
                assertEquals("d:text", variable.getType());
                assertNull(variable.getValue());
                foundDescription = true;
            } else if ("bpm_assignee".equals(variable.getName())) {
                assertEquals("cm:person", variable.getType());
                assertEquals(requestContext.getRunAsUser(), variable.getValue());
                foundAssignee = true;
            }
        }
        assertTrue(foundDescription);
        assertTrue(foundAssignee);
        // include process variables with paging outside boundaries
        paramMap = new HashMap<String, String>();
        paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc' AND includeVariables = true)");
        paramMap.put("maxItems", "4");
        paramMap.put("skipCount", "5");
        processList = processesClient.getProcesses(paramMap);
        assertNotNull(processList);
        assertEquals(0, processList.getList().size());
    } finally {
        cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Variable(org.alfresco.rest.workflow.api.model.Variable) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 30 with PublicApiException

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

the class ProcessWorkflowApiTest method testDeleteProcessInstanceByIdUnexisting.

@Test
public void testDeleteProcessInstanceByIdUnexisting() throws Exception {
    initApiClientWithTestUser();
    ProcessesClient processesClient = publicApiClient.processesClient();
    try {
        processesClient.deleteProcessById("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)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