Search in sources :

Example 21 with Execution

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

the class ProcessInstanceSuspensionTest method testChildExecutionsSuspendedAfterProcessInstanceSuspend.

@Deployment
public void testChildExecutionsSuspendedAfterProcessInstanceSuspend() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testChildExecutionsSuspended");
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
    for (Execution execution : executions) {
        assertTrue(execution.isSuspended());
    }
    // Activate again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
    for (Execution execution : executions) {
        assertFalse(execution.isSuspended());
    }
    // Finish process
    while (taskService.createTaskQuery().count() > 0) {
        for (Task task : taskService.createTaskQuery().list()) {
            taskService.complete(task.getId());
        }
    }
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 22 with Execution

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

the class ExecutionQueryTest method testExecutionQueryWithProcessVariable.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/concurrentExecution.bpmn20.xml" })
public void testExecutionQueryWithProcessVariable() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("x", "parent");
    variables.put("xIgnoreCase", "PaReNt");
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("concurrent", variables);
    List<Execution> concurrentExecutions = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).list();
    assertEquals(3, concurrentExecutions.size());
    for (Execution execution : concurrentExecutions) {
        if (!((ExecutionEntity) execution).isProcessInstanceType()) {
            // only the concurrent executions, not the root one, would be cooler to query that directly, see https://activiti.atlassian.net/browse/ACT-1373
            runtimeService.setVariableLocal(execution.getId(), "x", "child");
            runtimeService.setVariableLocal(execution.getId(), "xIgnoreCase", "ChILD");
        }
    }
    assertEquals(2, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "child").count());
    assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "parent").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("x", "parent").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEquals("x", "xxx").count());
    // Test value-only query
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("child").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("parent").count());
    // Test ignore-case queries
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "CHILD").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "PARENT").count());
    // Test ignore-case queries
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "paRent").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "chilD").count());
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 23 with Execution

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

the class ExecutionQueryTest method testQueryEqualsIgnoreCase.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryEqualsIgnoreCase() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("mixed", "AbCdEfG");
    vars.put("lower", "ABCDEFG");
    vars.put("upper", "abcdefg");
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    Execution execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("mixed", "abcdefg").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("lower", "abcdefg").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("upper", "abcdefg").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    // Pass in non-lower-case string
    execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("upper", "ABCdefg").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    // Pass in null-value, should cause exception
    try {
        execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase("upper", null).singleResult();
        fail("Exception expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertEquals("value is null", ae.getMessage());
    }
    // Pass in null name, should cause exception
    try {
        execution = runtimeService.createExecutionQuery().variableValueEqualsIgnoreCase(null, "abcdefg").singleResult();
        fail("Exception expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertEquals("name is null", ae.getMessage());
    }
    // Test NOT equals 
    execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase("upper", "UIOP").singleResult();
    assertNotNull(execution);
    // Should return result when using "ABCdefg" case-insensitive while normal not-equals won't
    execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase("upper", "ABCdefg").singleResult();
    assertNull(execution);
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("upper", "ABCdefg").singleResult();
    assertNotNull(execution);
    // Pass in null-value, should cause exception
    try {
        execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase("upper", null).singleResult();
        fail("Exception expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertEquals("value is null", ae.getMessage());
    }
    // Pass in null name, should cause exception
    try {
        execution = runtimeService.createExecutionQuery().variableValueNotEqualsIgnoreCase(null, "abcdefg").singleResult();
        fail("Exception expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertEquals("name is null", ae.getMessage());
    }
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 24 with Execution

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

the class RuntimeServiceTest method testFindActiveActivityIdProcessWithErrorEventAndSubProcess.

/**
   * Testcase to reproduce ACT-950 (https://activiti.atlassian.net/browse/ACT-950)
   */
@Deployment
public void testFindActiveActivityIdProcessWithErrorEventAndSubProcess() {
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("errorEventSubprocess");
    List<String> activeActivities = runtimeService.getActiveActivityIds(processInstance.getId());
    assertEquals(3, activeActivities.size());
    List<Task> tasks = taskService.createTaskQuery().list();
    assertEquals(2, tasks.size());
    Task parallelUserTask = null;
    for (Task task : tasks) {
        if (!task.getName().equals("ParallelUserTask") && !task.getName().equals("MainUserTask")) {
            fail("Expected: <ParallelUserTask> or <MainUserTask> but was <" + task.getName() + ">.");
        }
        if (task.getName().equals("ParallelUserTask")) {
            parallelUserTask = task;
        }
    }
    assertNotNull(parallelUserTask);
    taskService.complete(parallelUserTask.getId());
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("subprocess1WaitBeforeError").singleResult();
    runtimeService.signal(execution.getId());
    activeActivities = runtimeService.getActiveActivityIds(processInstance.getId());
    assertEquals(2, activeActivities.size());
    tasks = taskService.createTaskQuery().list();
    assertEquals(2, tasks.size());
    Task beforeErrorUserTask = null;
    for (Task task : tasks) {
        if (!task.getName().equals("BeforeError") && !task.getName().equals("MainUserTask")) {
            fail("Expected: <BeforeError> or <MainUserTask> but was <" + task.getName() + ">.");
        }
        if (task.getName().equals("BeforeError")) {
            beforeErrorUserTask = task;
        }
    }
    assertNotNull(beforeErrorUserTask);
    taskService.complete(beforeErrorUserTask.getId());
    activeActivities = runtimeService.getActiveActivityIds(processInstance.getId());
    assertEquals(2, activeActivities.size());
    tasks = taskService.createTaskQuery().list();
    assertEquals(2, tasks.size());
    Task afterErrorUserTask = null;
    for (Task task : tasks) {
        if (!task.getName().equals("AfterError") && !task.getName().equals("MainUserTask")) {
            fail("Expected: <AfterError> or <MainUserTask> but was <" + task.getName() + ">.");
        }
        if (task.getName().equals("AfterError")) {
            afterErrorUserTask = task;
        }
    }
    assertNotNull(afterErrorUserTask);
    taskService.complete(afterErrorUserTask.getId());
    tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    assertEquals("MainUserTask", tasks.get(0).getName());
    activeActivities = runtimeService.getActiveActivityIds(processInstance.getId());
    assertEquals(1, activeActivities.size());
    assertEquals("MainUserTask", activeActivities.get(0));
    taskService.complete(tasks.get(0).getId());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 25 with Execution

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

the class ReceiveTaskTest method testWaitStateBehavior.

@Deployment
public void testWaitStateBehavior() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).activityId("waitState").singleResult();
    assertNotNull(execution);
    runtimeService.signal(execution.getId());
    assertProcessEnded(pi.getId());
}
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