Search in sources :

Example 21 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class IntermediateConditionalEventTest method testEventBasedGatewayTrueCondition.

@Test
public void testEventBasedGatewayTrueCondition() {
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().userTask(TASK_BEFORE_CONDITION_ID).name(TASK_BEFORE_CONDITION).eventBasedGateway().id(EVENT_BASED_GATEWAY_ID).intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition(TRUE_CONDITION).conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION).endEvent().done();
    engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
    // given
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
    TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
    Task task = taskQuery.singleResult();
    // when task before condition is completed
    taskService.complete(task.getId());
    // then next wait state is on user task after conditional event, since condition was true
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(EVENT_BASED_GATEWAY_ID).singleResult();
    assertNull(execution);
    task = taskQuery.singleResult();
    assertNotNull(task);
    assertEquals(TASK_AFTER_CONDITION, task.getName());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 22 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class IntermediateConditionalEventTest method testTrueCondition.

@Test
@Deployment
public void testTrueCondition() {
    // given process with intermediate conditional event
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
    TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
    Task task = taskQuery.singleResult();
    assertNotNull(task);
    assertEquals(TASK_BEFORE_CONDITION, task.getName());
    // when task before condition is completed
    taskService.complete(task.getId());
    // then next wait state is on user task after conditional event, since condition was true
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
    assertNull(execution);
    task = taskQuery.singleResult();
    assertNotNull(task);
    assertEquals(TASK_AFTER_CONDITION, task.getName());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 23 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class IntermediateConditionalEventTest method testVariableConditionWithVariableNameAndEvent.

@Test
public void testVariableConditionWithVariableNameAndEvent() {
    // given process with boundary conditional event and defined variable name and event
    final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition(CONDITION_EXPR).camundaVariableName(VARIABLE_NAME).camundaVariableEvents(CONDITIONAL_VAR_EVENT_UPDATE).conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION).endEvent().done();
    engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
    TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
    assertNotNull(execution);
    assertEquals(1, conditionEventSubscriptionQuery.list().size());
    // when variable with name `variable` is set on execution
    runtimeService.setVariable(procInst.getId(), VARIABLE_NAME, 1);
    // then nothing happens
    execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
    assertNotNull(execution);
    assertEquals(1, conditionEventSubscriptionQuery.list().size());
    // when variable with name `variable` is updated
    runtimeService.setVariable(procInst.getId(), VARIABLE_NAME, 1);
    // then execution is at user task after conditional intermediate event
    Task task = taskQuery.singleResult();
    assertEquals(TASK_AFTER_CONDITION, task.getName());
    assertEquals(0, conditionEventSubscriptionQuery.list().size());
    // and task can be completed which ends process instance
    taskService.complete(task.getId());
    assertNull(taskService.createTaskQuery().singleResult());
    assertNull(runtimeService.createProcessInstanceQuery().singleResult());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 24 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class IntermediateConditionalEventTest method testEventBasedGatewayWith2VarConditions.

@Test
public void testEventBasedGatewayWith2VarConditions() {
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().eventBasedGateway().id(EVENT_BASED_GATEWAY_ID).intermediateCatchEvent().conditionalEventDefinition().condition(CONDITION_EXPR).conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION + 1).endEvent().moveToLastGateway().intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition("${var==2}").conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION + 2).endEvent().done();
    engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
    // given
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
    TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(EVENT_BASED_GATEWAY_ID).singleResult();
    assertNotNull(execution);
    // when wrong value of variable `var` is set
    runtimeService.setVariable(procInst.getId(), "var", 1);
    // then nothing happens
    execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(EVENT_BASED_GATEWAY_ID).singleResult();
    assertNotNull(execution);
    assertEquals(0, taskQuery.count());
    // when right value is set
    runtimeService.setVariable(procInst.getId(), "var", 2);
    // then next wait state is on user task after second conditional event
    Task task = taskQuery.singleResult();
    assertNotNull(task);
    assertEquals(TASK_AFTER_CONDITION + 2, task.getName());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 25 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class IntermediateConditionalEventTest method testSubProcessVariableValue.

@Test
@Deployment
public void testSubProcessVariableValue() {
    // given process with intermediate conditional event and variable with wrong value
    Map<String, Object> variables = Variables.createVariables();
    variables.put(VARIABLE_NAME, 0);
    ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY, variables);
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
    assertNotNull(execution);
    // when variable is set to correct value
    runtimeService.setVariableLocal(execution.getId(), VARIABLE_NAME, 1);
    // then execution and process instance is ended, since condition was true
    execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
    assertNull(execution);
    procInst = runtimeService.createProcessInstanceQuery().processDefinitionKey(CONDITIONAL_EVENT_PROCESS_KEY).singleResult();
    assertNull(procInst);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Execution (org.camunda.bpm.engine.runtime.Execution)279 Deployment (org.camunda.bpm.engine.test.Deployment)188 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)143 Task (org.camunda.bpm.engine.task.Task)99 Test (org.junit.Test)95 HashMap (java.util.HashMap)45 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)33 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)23 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 ThrowErrorDelegate.leaveExecution (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate.leaveExecution)18 ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)17 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)15 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)14 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)14 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)14 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)14 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)13 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)12 ArrayList (java.util.ArrayList)11