Search in sources :

Example 36 with ProcessInstance

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

the class MultiInstanceTest method testSequentialServiceTaskWithClassAndCollection.

@Deployment
public void testSequentialServiceTaskWithClassAndCollection() {
    Collection<Integer> items = Arrays.asList(1, 2, 3, 4, 5, 6);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("result", 1);
    vars.put("items", items);
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey("multiInstanceServiceTask", vars);
    Integer result = (Integer) runtimeService.getVariable(procInst.getId(), "result");
    assertEquals(720, result.intValue());
    runtimeService.signal(procInst.getId());
    assertProcessEnded(procInst.getId());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 37 with ProcessInstance

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

the class MultiInstanceTest method testEndTimeOnMiSubprocess.

@Deployment
public void testEndTimeOnMiSubprocess() {
    if (!processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        return;
    }
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("multiInstanceSubProcessParallelTasks");
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    assertEquals(2, tasks.size());
    assertEquals("User Task 1", tasks.get(0).getName());
    assertEquals("User Task 1", tasks.get(1).getName());
    // End time should not be set for the subprocess
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNotNull(historicActivityInstance.getStartTime());
        assertNull(historicActivityInstance.getEndTime());
    }
    // Complete one of the user tasks. This should not trigger setting of end time of the subprocess, but due to a bug it did exactly that
    taskService.complete(tasks.get(0).getId());
    historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNull(historicActivityInstance.getEndTime());
    }
    taskService.complete(tasks.get(1).getId());
    historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNull(historicActivityInstance.getEndTime());
    }
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskName("User Task 3").list();
    assertEquals(2, tasks.size());
    for (Task task : tasks) {
        taskService.complete(task.getId());
        historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
        assertEquals(2, historicActivityInstances.size());
        for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
            assertNull(historicActivityInstance.getEndTime());
        }
    }
    // Finishing the tasks should also set the end time
    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    assertEquals(2, tasks.size());
    for (Task task : tasks) {
        taskService.complete(task.getId());
    }
    historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("subprocess1").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNotNull(historicActivityInstance.getEndTime());
    }
}
Also used : Task(org.activiti.engine.task.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 38 with ProcessInstance

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

the class ConditionalSequenceFlowTest method testSkipExpression.

@Deployment
public void testSkipExpression() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("input", "right");
    variables.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);
    variables.put("skipLeft", true);
    variables.put("skipRight", false);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testSkipExpression", variables);
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("task left", task.getName());
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 39 with ProcessInstance

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

the class ConditionalSequenceFlowTest method testUelExpression.

@Deployment
public void testUelExpression() {
    Map<String, Object> variables = CollectionUtil.singletonMap("input", "right");
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("condSeqFlowUelExpr", variables);
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals("task right", task.getName());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 40 with ProcessInstance

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

the class CallServiceInServiceTaskTest method testStartProcessFromDelegate.

@Deployment
public void testStartProcessFromDelegate() {
    runtimeService.startProcessInstanceByKey("startProcessFromDelegate");
    // Starting the process should lead to two processes being started,
    // The other one started from the java delegate in the service task
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    assertEquals(2, processInstances.size());
    boolean startProcessFromDelegateFound = false;
    boolean oneTaskProcessFound = false;
    for (ProcessInstance processInstance : processInstances) {
        ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
        if (processDefinition.getKey().equals("startProcessFromDelegate")) {
            startProcessFromDelegateFound = true;
        } else if (processDefinition.getKey().equals("oneTaskProcess")) {
            oneTaskProcessFound = true;
        }
    }
    assertTrue(startProcessFromDelegateFound);
    assertTrue(oneTaskProcessFound);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ProcessInstance (org.activiti.engine.runtime.ProcessInstance)822 Deployment (org.activiti.engine.test.Deployment)708 Task (org.activiti.engine.task.Task)374 HashMap (java.util.HashMap)242 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)182 Execution (org.activiti.engine.runtime.Execution)76 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)64 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)57 Job (org.activiti.engine.runtime.Job)55 Date (java.util.Date)53 JsonNode (com.fasterxml.jackson.databind.JsonNode)49 Calendar (java.util.Calendar)48 ActivitiException (org.activiti.engine.ActivitiException)41 ArrayList (java.util.ArrayList)38 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)38 HttpGet (org.apache.http.client.methods.HttpGet)38 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)27 StringEntity (org.apache.http.entity.StringEntity)27 HttpPost (org.apache.http.client.methods.HttpPost)25 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)24