Search in sources :

Example 86 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class HistoricProcessInstanceCommentResourceTest method testCreateComment.

/**
   * Test creating a comment for a process instance.
   * POST history/historic-process-instances/{processInstanceId}/comments
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testCreateComment() throws Exception {
    ProcessInstance pi = null;
    try {
        pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT_COLLECTION, pi.getId()));
        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("message", "This is a comment...");
        httpPost.setEntity(new StringEntity(requestNode.toString()));
        CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
        assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode());
        List<Comment> commentsOnProcess = taskService.getProcessInstanceComments(pi.getId());
        assertNotNull(commentsOnProcess);
        assertEquals(1, commentsOnProcess.size());
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseNode);
        assertEquals("kermit", responseNode.get("author").textValue());
        assertEquals("This is a comment...", responseNode.get("message").textValue());
        assertEquals(commentsOnProcess.get(0).getId(), responseNode.get("id").textValue());
        assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), commentsOnProcess.get(0).getId())));
        assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
        assertTrue(responseNode.get("taskUrl").isNull());
        assertTrue(responseNode.get("taskId").isNull());
    } finally {
        if (pi != null) {
            List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
            for (Comment c : comments) {
                taskService.deleteComment(c.getId());
            }
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Comment(org.activiti.engine.task.Comment) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 87 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class HistoricProcessInstanceQueryResourceTest method testQueryProcessInstancesWithVariables.

/**
   * Test querying historic process instance based on variables. 
   * POST query/historic-process-instances
   */
@Deployment
public void testQueryProcessInstancesWithVariables() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_QUERY);
    // Process variables
    ObjectNode requestNode = objectMapper.createObjectNode();
    ArrayNode variableArray = objectMapper.createArrayNode();
    ObjectNode variableNode = objectMapper.createObjectNode();
    variableArray.add(variableNode);
    requestNode.put("variables", variableArray);
    // String equals
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // Integer equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67890);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // Boolean equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", false);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // String not equals
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "ghijkl");
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // Integer not equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 45678);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // Boolean not equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", true);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // String equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "azeRTY");
    variableNode.put("operation", "equalsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // String not equals ignore case (not supported)
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "HIJKLm");
    variableNode.put("operation", "notEqualsIgnoreCase");
    assertErrorResult(url, requestNode, HttpStatus.SC_BAD_REQUEST);
    // String equals without value
    variableNode.removeAll();
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    // String equals with non existing value
    variableNode.removeAll();
    variableNode.put("value", "Azerty2");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode);
    // String like ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "azerty");
    variableNode.put("operation", "likeIgnoreCase");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "azerty2");
    variableNode.put("operation", "likeIgnoreCase");
    assertResultsPresentInPostDataResponse(url, requestNode);
    requestNode = objectMapper.createObjectNode();
    requestNode.put("finished", true);
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());
    requestNode = objectMapper.createObjectNode();
    requestNode.put("finished", false);
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance2.getId());
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", processInstance.getProcessDefinitionId());
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionKey", "oneTaskProcess");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionKey", "oneTaskProcess");
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url + "?sort=startTime");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);
    assertEquals(2, dataNode.size());
    assertEquals(processInstance.getId(), dataNode.get(0).get("id").asText());
    assertEquals(processInstance2.getId(), dataNode.get(1).get("id").asText());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Task(org.activiti.engine.task.Task) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Deployment(org.activiti.engine.test.Deployment)

Example 88 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class HistoricProcessInstanceResourceTest method testGetProcessInstance.

/**
   * Test retrieval of historic process instance. 
   * GET history/historic-process-instances/{processInstanceId}
   */
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetProcessInstance() throws Exception {
    ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess").processInstanceName("processName").start();
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_OK);
    assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertEquals("processName", responseNode.get("name").textValue());
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());
    response = executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_NO_CONTENT);
    assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
    closeResponse(response);
}
Also used : Task(org.activiti.engine.task.Task) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 89 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class HistoricTaskInstanceCollectionResourceTest method testQueryTaskInstances.

/**
   * Test querying historic task instance. 
   * GET history/historic-task-instances
   */
@Deployment
public void testQueryTaskInstances() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    Calendar created = Calendar.getInstance();
    created.set(Calendar.YEAR, 2001);
    created.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(created.getTime());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", "testBusinessKey", processVariables);
    processEngineConfiguration.getClock().reset();
    Task task1 = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task1.getId());
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "local", "test");
    taskService.setOwner(task.getId(), "test");
    taskService.setDueDate(task.getId(), new GregorianCalendar(2013, 0, 1).getTime());
    // Set tenant on deployment
    managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", processVariables, "myTenant");
    Task task2 = taskService.createTaskQuery().processInstanceId(processInstance2.getId()).singleResult();
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_TASK_INSTANCES);
    assertResultsPresentInDataResponse(url, 3, task.getId(), task2.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionName=" + "The%20One%20Task%20Process", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionNameLike=" + "The%25", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionKey=" + "oneTaskProcess", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processDefinitionKeyLike=" + "oneTask%25", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?taskMinPriority=" + "0", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?taskMaxPriority=" + "60", 3, task.getId());
    assertResultsPresentInDataResponse(url + "?processBusinessKey=" + "testBusinessKey", 2, task.getId());
    assertResultsPresentInDataResponse(url + "?processBusinessKeyLike=" + "testBusin%25", 2, task.getId());
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId(), 2, task.getId());
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId(), 1, task2.getId());
    assertResultsPresentInDataResponse(url + "?taskAssignee=kermit", 2, task2.getId());
    assertResultsPresentInDataResponse(url + "?taskAssigneeLike=" + encode("%mit"), 2, task2.getId());
    assertResultsPresentInDataResponse(url + "?taskAssignee=fozzie", 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskOwner=test", 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskOwnerLike=" + encode("t%"), 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskInvolvedUser=test", 1, task.getId());
    assertResultsPresentInDataResponse(url + "?dueDateAfter=" + dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime()), 1, task.getId());
    assertResultsPresentInDataResponse(url + "?dueDateAfter=" + dateFormat.format(new GregorianCalendar(2013, 4, 1).getTime()), 0);
    assertResultsPresentInDataResponse(url + "?dueDateBefore=" + dateFormat.format(new GregorianCalendar(2010, 0, 1).getTime()), 0);
    assertResultsPresentInDataResponse(url + "?dueDateBefore=" + dateFormat.format(new GregorianCalendar(2013, 4, 1).getTime()), 1, task.getId());
    assertResultsPresentInDataResponse(url + "?taskCreatedOn=" + dateFormat.format(created.getTime()), 1, task1.getId());
    created.set(Calendar.YEAR, 2002);
    assertResultsPresentInDataResponse(url + "?taskCreatedBefore=" + dateFormat.format(created.getTime()), 1, task1.getId());
    created.set(Calendar.YEAR, 2000);
    assertResultsPresentInDataResponse(url + "?taskCreatedAfter=" + dateFormat.format(created.getTime()), 3, task1.getId(), task2.getId());
    // Without tenant id
    assertResultsPresentInDataResponse(url + "?withoutTenantId=true", 2, task.getId(), task1.getId());
    // Tenant id
    assertResultsPresentInDataResponse(url + "?tenantId=myTenant", 1, task2.getId());
    assertResultsPresentInDataResponse(url + "?tenantId=anotherTenant", 0);
    // Tenant id like
    assertResultsPresentInDataResponse(url + "?tenantIdLike=" + encode("%enant"), 1, task2.getId());
    assertResultsPresentInDataResponse(url + "?tenantIdLike=anotherTenant", 0);
}
Also used : Task(org.activiti.engine.task.Task) ChangeDeploymentTenantIdCmd(org.activiti.engine.impl.cmd.ChangeDeploymentTenantIdCmd) HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 90 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class HistoricVariableInstanceCollectionResourceTest method testQueryVariableInstances.

/**
   * Test querying historic variable instance. 
   * GET history/historic-variable-instances
   */
@Deployment
public void testQueryVariableInstances() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "test");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_VARIABLE_INSTANCES);
    assertResultsPresentInDataResponse(url + "?variableName=stringVar", 2, "stringVar", "Azerty");
    assertResultsPresentInDataResponse(url + "?variableName=booleanVar", 2, "booleanVar", false);
    assertResultsPresentInDataResponse(url + "?variableName=booleanVar2", 0, null, null);
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId(), 4, "taskVariable", "test");
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId() + "&excludeTaskVariables=true", 3, "intVar", 67890);
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId(), 3, "stringVar", "Azerty");
    assertResultsPresentInDataResponse(url + "?taskId=" + task.getId(), 1, "taskVariable", "test");
    assertResultsPresentInDataResponse(url + "?taskId=" + task.getId() + "&variableName=booleanVar", 0, null, null);
    assertResultsPresentInDataResponse(url + "?variableNameLike=" + encode("%Var"), 6, "stringVar", "Azerty");
    assertResultsPresentInDataResponse(url + "?variableNameLike=" + encode("%Var2"), 0, null, null);
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Deployment (org.activiti.engine.test.Deployment)1178 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)846 Task (org.activiti.engine.task.Task)549 HashMap (java.util.HashMap)277 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)218 Execution (org.activiti.engine.runtime.Execution)151 Date (java.util.Date)94 Job (org.activiti.engine.runtime.Job)91 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)87 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)85 JsonNode (com.fasterxml.jackson.databind.JsonNode)66 Calendar (java.util.Calendar)63 DelegateTask (org.activiti.engine.delegate.DelegateTask)52 StringEntity (org.apache.http.entity.StringEntity)50 ArrayList (java.util.ArrayList)49 HttpGet (org.apache.http.client.methods.HttpGet)49 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)41 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)34 ActivitiException (org.activiti.engine.ActivitiException)31