Search in sources :

Example 1 with ProcessDefinitionsClient

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionById.

@Test
public void testGetProcessDefinitionById() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    // Get a single process definitions
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    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());
    // get process definition with admin
    publicApiClient.setRequestContext(adminContext);
    adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
    assertNotNull(adhocDefinition);
    // Check fields of a resulting process-definition
    assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
    assertEquals("activitiAdhoc", adhocDefinition.getKey());
}
Also used : 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 2 with ProcessDefinitionsClient

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

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

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

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitions.

@Test
public void testGetProcessDefinitions() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    // Get all process definitions
    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());
    // Check fields of a resulting process-definition
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    ProcessDefinition adhocDefinitionRest = processDefinitionMap.get("activitiAdhoc");
    assertEquals(activitiDefinition.getId(), adhocDefinitionRest.getId());
    assertEquals("activitiAdhoc", adhocDefinitionRest.getKey());
    assertEquals(activitiDefinition.getDeploymentId(), adhocDefinitionRest.getDeploymentId());
    assertEquals(activitiDefinition.getCategory(), adhocDefinitionRest.getCategory());
    assertEquals(activitiDefinition.getName(), adhocDefinitionRest.getName());
    assertEquals(activitiDefinition.getVersion(), adhocDefinitionRest.getVersion());
    assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinitionRest.isGraphicNotationDefined());
    assertEquals("wf:submitAdhocTask", adhocDefinitionRest.getStartFormResourceKey());
    assertEquals("New Task", adhocDefinitionRest.getTitle());
    assertEquals("Assign a new task to yourself or a colleague", adhocDefinitionRest.getDescription());
    Map<String, String> params = new HashMap<String, String>();
    params.put("maxItems", "2");
    JSONObject definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    JSONObject paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(2l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(0l, paginationJSON.get("skipCount"));
    assertEquals(true, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(5l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(0l, paginationJSON.get("skipCount"));
    assertEquals(false, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    params.put("skipCount", "2");
    params.put("maxItems", "2");
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(2l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(2l, paginationJSON.get("skipCount"));
    assertEquals(true, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    params.put("skipCount", "2");
    params.put("maxItems", "5");
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(3l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(2l, paginationJSON.get("skipCount"));
    assertEquals(false, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    params.put("skipCount", "0");
    params.put("maxItems", "7");
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(5l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(0l, paginationJSON.get("skipCount"));
    assertEquals(false, paginationJSON.get("hasMoreItems"));
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.alfresco.rest.workflow.api.model.ProcessDefinition) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

ProcessDefinitionsClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient)9 Test (org.junit.Test)9 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)7 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)6 ProcessDefinition (org.alfresco.rest.workflow.api.model.ProcessDefinition)5 HashMap (java.util.HashMap)3 JSONObject (org.json.simple.JSONObject)3 JSONArray (org.json.simple.JSONArray)2 ArrayList (java.util.ArrayList)1 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)1 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)1