Search in sources :

Example 86 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryIntegerVariable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryIntegerVariable() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("integerVar", 12345);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("integerVar", 12345);
    vars.put("integerVar2", 67890);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("integerVar", 55555);
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Query on single integer variable, should result in 2 matches
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345);
    List<Execution> executions = query.list();
    assertNotNull(executions);
    assertEquals(2, executions.size());
    // Query on two integer variables, should result in single value
    query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345).variableValueEquals("integerVar2", 67890);
    Execution execution = query.singleResult();
    assertNotNull(execution);
    assertEquals(processInstance2.getId(), execution.getId());
    // Query with unexisting variable value
    execution = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 9999).singleResult();
    assertNull(execution);
    // Test NOT_EQUALS
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("integerVar", 12345).singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    // Test GREATER_THAN
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 44444).singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 55555).count());
    assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 1).count());
    // Test GREATER_THAN_OR_EQUAL
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 1).count());
    // Test LESS_THAN
    executions = runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 55555).list();
    assertEquals(2, executions.size());
    List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
    List<String> ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expecedIds);
    assertTrue(ids.isEmpty());
    assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 12345).count());
    assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 66666).count());
    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("integerVar", 55555).list();
    assertEquals(3, executions.size());
    assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("integerVar", 12344).count());
    // Test value-only matching
    execution = runtimeService.createExecutionQuery().variableValueEquals(55555).singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    executions = runtimeService.createExecutionQuery().variableValueEquals(12345).list();
    assertEquals(2, executions.size());
    expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
    ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expecedIds);
    assertTrue(ids.isEmpty());
    execution = runtimeService.createExecutionQuery().variableValueEquals(99999).singleResult();
    assertNull(execution);
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Deployment(org.activiti.engine.test.Deployment)

Example 87 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryExecutionId.

public void testQueryExecutionId() {
    Execution execution = runtimeService.createExecutionQuery().processDefinitionKey(SEQUENTIAL_PROCESS_KEY).singleResult();
    assertNotNull(runtimeService.createExecutionQuery().executionId(execution.getId()));
}
Also used : Execution(org.activiti.engine.runtime.Execution)

Example 88 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryStringVariable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryStringVariable() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("stringVar", "abcdef");
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("stringVar", "abcdef");
    vars.put("stringVar2", "ghijkl");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("stringVar", "azerty");
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Test EQUAL on single string variable, should result in 2 matches
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("stringVar", "abcdef");
    List<Execution> executions = query.list();
    assertNotNull(executions);
    assertEquals(2, executions.size());
    // Test EQUAL on two string variables, should result in single match
    query = runtimeService.createExecutionQuery().variableValueEquals("stringVar", "abcdef").variableValueEquals("stringVar2", "ghijkl");
    Execution execution = query.singleResult();
    assertNotNull(execution);
    assertEquals(processInstance2.getId(), execution.getId());
    // Test NOT_EQUAL, should return only 1 execution
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("stringVar", "abcdef").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    // Test GREATER_THAN, should return only matching 'azerty'
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("stringVar", "abcdef").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("stringVar", "z").singleResult();
    assertNull(execution);
    // Test GREATER_THAN_OR_EQUAL, should return 3 results
    assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("stringVar", "abcdef").count());
    assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("stringVar", "z").count());
    // Test LESS_THAN, should return 2 results
    executions = runtimeService.createExecutionQuery().variableValueLessThan("stringVar", "abcdeg").list();
    assertEquals(2, executions.size());
    List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
    List<String> ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expecedIds);
    assertTrue(ids.isEmpty());
    assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("stringVar", "abcdef").count());
    assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "z").count());
    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "abcdef").list();
    assertEquals(2, executions.size());
    expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
    ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expecedIds);
    assertTrue(ids.isEmpty());
    assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "z").count());
    assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("stringVar", "aa").count());
    // Test LIKE
    execution = runtimeService.createExecutionQuery().variableValueLike("stringVar", "azert%").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueLike("stringVar", "%y").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueLike("stringVar", "%zer%").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    assertEquals(3, runtimeService.createExecutionQuery().variableValueLike("stringVar", "a%").count());
    assertEquals(0, runtimeService.createExecutionQuery().variableValueLike("stringVar", "%x%").count());
    // Test value-only matching
    execution = runtimeService.createExecutionQuery().variableValueEquals("azerty").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance3.getId(), execution.getId());
    executions = runtimeService.createExecutionQuery().variableValueEquals("abcdef").list();
    assertEquals(2, executions.size());
    expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
    ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expecedIds);
    assertTrue(ids.isEmpty());
    execution = runtimeService.createExecutionQuery().variableValueEquals("notmatchinganyvalues").singleResult();
    assertNull(execution);
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Deployment(org.activiti.engine.test.Deployment)

Example 89 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testLocalizeExecution.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/executionLocalization.bpmn20.xml" })
public void testLocalizeExecution() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("executionLocalization");
    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
    assertEquals(2, executions.size());
    for (Execution execution : executions) {
        if (execution.getParentId() == null) {
            assertNull(execution.getName());
            assertNull(execution.getDescription());
        } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
            assertNull(execution.getName());
            assertNull(execution.getDescription());
        }
    }
    ObjectNode infoNode = dynamicBpmnService.getProcessDefinitionInfo(processInstance.getProcessDefinitionId());
    dynamicBpmnService.changeLocalizationName("en-GB", "executionLocalization", "Process Name 'en-GB'", infoNode);
    dynamicBpmnService.changeLocalizationDescription("en-GB", "executionLocalization", "Process Description 'en-GB'", infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
    dynamicBpmnService.changeLocalizationName("en", "executionLocalization", "Process Name 'en'", infoNode);
    dynamicBpmnService.changeLocalizationDescription("en", "executionLocalization", "Process Description 'en'", infoNode);
    dynamicBpmnService.changeLocalizationName("en-GB", "subTask", "Sub task Name 'en-GB'", infoNode);
    dynamicBpmnService.changeLocalizationDescription("en-GB", "subTask", "Sub task Description 'en-GB'", infoNode);
    dynamicBpmnService.changeLocalizationName("en", "subTask", "Sub task Name 'en'", infoNode);
    dynamicBpmnService.changeLocalizationDescription("en", "subTask", "Sub task Description 'en'", infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
    executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
    String subProcessId = null;
    assertEquals(2, executions.size());
    for (Execution execution : executions) {
        if (execution.getParentId() == null) {
            assertNull(execution.getName());
            assertNull(execution.getDescription());
        } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
            assertNull(execution.getName());
            assertNull(execution.getDescription());
            subProcessId = execution.getId();
        }
    }
    executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).locale("es").list();
    assertEquals(2, executions.size());
    for (Execution execution : executions) {
        if (execution.getParentId() == null) {
            assertEquals("Nombre del proceso", execution.getName());
            assertEquals("Descripción del proceso", execution.getDescription());
        } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
            assertEquals("Nombre Subproceso", execution.getName());
            assertEquals("Subproceso Descripción", execution.getDescription());
        }
    }
    executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).locale("en-GB").list();
    assertEquals(2, executions.size());
    for (Execution execution : executions) {
        if (execution.getParentId() == null) {
            assertEquals("Process Name 'en-GB'", execution.getName());
            assertEquals("Process Description 'en-GB'", execution.getDescription());
        } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
            assertEquals("Sub task Name 'en-GB'", execution.getName());
            assertEquals("Sub task Description 'en-GB'", execution.getDescription());
        }
    }
    executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).listPage(0, 10);
    assertEquals(2, executions.size());
    for (Execution execution : executions) {
        if (execution.getParentId() == null) {
            assertNull(execution.getName());
            assertNull(execution.getDescription());
        } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
            assertNull(execution.getName());
            assertNull(execution.getDescription());
        }
    }
    executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).locale("es").listPage(0, 10);
    assertEquals(2, executions.size());
    for (Execution execution : executions) {
        if (execution.getParentId() == null) {
            assertEquals("Nombre del proceso", execution.getName());
            assertEquals("Descripción del proceso", execution.getDescription());
        } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
            assertEquals("Nombre Subproceso", execution.getName());
            assertEquals("Subproceso Descripción", execution.getDescription());
        }
    }
    executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).locale("en-GB").listPage(0, 10);
    assertEquals(2, executions.size());
    for (Execution execution : executions) {
        if (execution.getParentId() == null) {
            assertEquals("Process Name 'en-GB'", execution.getName());
            assertEquals("Process Description 'en-GB'", execution.getDescription());
        } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
            assertEquals("Sub task Name 'en-GB'", execution.getName());
            assertEquals("Sub task Description 'en-GB'", execution.getDescription());
        }
    }
    Execution execution = runtimeService.createExecutionQuery().executionId(processInstance.getId()).singleResult();
    assertNull(execution.getName());
    assertNull(execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(subProcessId).singleResult();
    assertNull(execution.getName());
    assertNull(execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(processInstance.getId()).locale("es").singleResult();
    assertEquals("Nombre del proceso", execution.getName());
    assertEquals("Descripción del proceso", execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(subProcessId).locale("es").singleResult();
    assertEquals("Nombre Subproceso", execution.getName());
    assertEquals("Subproceso Descripción", execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(processInstance.getId()).locale("en-GB").singleResult();
    assertEquals("Process Name 'en-GB'", execution.getName());
    assertEquals("Process Description 'en-GB'", execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(subProcessId).locale("en-GB").singleResult();
    assertEquals("Sub task Name 'en-GB'", execution.getName());
    assertEquals("Sub task Description 'en-GB'", execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(processInstance.getId()).locale("en-AU").withLocalizationFallback().singleResult();
    assertEquals("Process Name 'en'", execution.getName());
    assertEquals("Process Description 'en'", execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(subProcessId).locale("en-AU").withLocalizationFallback().singleResult();
    assertEquals("Sub task Name 'en'", execution.getName());
    assertEquals("Sub task Description 'en'", execution.getDescription());
    infoNode = dynamicBpmnService.changeLocalizationName("en-US", "executionLocalization", "Process Name 'en-US'");
    dynamicBpmnService.changeLocalizationDescription("en-US", "executionLocalization", "Process Description 'en-US'", infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
    dynamicBpmnService.changeLocalizationName("en-US", "subTask", "Sub task Name 'en-US'", infoNode);
    dynamicBpmnService.changeLocalizationDescription("en-US", "subTask", "Sub task Description 'en-US'", infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
    execution = runtimeService.createExecutionQuery().executionId(processInstance.getId()).locale("en-US").singleResult();
    assertEquals("Process Name 'en-US'", execution.getName());
    assertEquals("Process Description 'en-US'", execution.getDescription());
    execution = runtimeService.createExecutionQuery().executionId(subProcessId).locale("en-US").singleResult();
    assertEquals("Sub task Name 'en-US'", execution.getName());
    assertEquals("Sub task Description 'en-US'", execution.getDescription());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 90 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class JavaServiceTaskTest method testFieldInjection.

@Deployment
public void testFieldInjection() {
    // Process contains 2 service-tasks using field-injection. One should use the exposed setter,
    // the other is using the private field.
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("fieldInjection");
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).activityId("waitState").singleResult();
    assertEquals("HELLO WORLD", runtimeService.getVariable(execution.getId(), "var"));
    assertEquals("HELLO SETTER", runtimeService.getVariable(execution.getId(), "setterVar"));
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5