Search in sources :

Example 46 with CaseDefinitionBuilder

use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.

the class CaseExecutionCompletionTest method testCompleteActiveTask.

/**
 *   +-----------------+
 *   | Case1            \
 *   +-------------------+---+
 *   |                       |
 *   |     +-------+         |
 *   |     |   A   |         |
 *   |     +-------+         |
 *   |                       |
 *   +-----------------------+
 */
public void testCompleteActiveTask() {
    CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
    // given
    // a case definition
    CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("complete", stateTransitionCollector).createActivity("A").listener("complete", stateTransitionCollector).behavior(new TaskWaitState()).endActivity().buildCaseDefinition();
    // an active case instance
    CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
    caseInstance.create();
    // task A as a child of the case instance
    CmmnActivityExecution taskA = caseInstance.findCaseExecution("A");
    // when
    // completing task A
    taskA.complete();
    // then
    List<String> expectedStateTransitions = new ArrayList<String>();
    // expected state transition:
    // active --complete(A)--> completed
    // active --complete(Case1)--> completed
    expectedStateTransitions.add("active --complete(A)--> completed");
    expectedStateTransitions.add("active --complete(Case1)--> completed");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
    // task A is completed ...
    assertTrue(taskA.isCompleted());
    // ... and the case instance is also completed
    assertTrue(caseInstance.isCompleted());
    // task A is not part of the case instance anymore
    assertNull(caseInstance.findCaseExecution("A"));
    // the case instance has no children
    assertTrue(((CaseExecutionImpl) caseInstance).getCaseExecutions().isEmpty());
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) CaseExecutionImpl(org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl) CmmnCaseDefinition(org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition) ArrayList(java.util.ArrayList) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder)

Aggregations

CmmnCaseInstance (org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance)46 CaseDefinitionBuilder (org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder)46 CmmnCaseDefinition (org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition)46 CmmnActivityExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution)38 StageActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior)22 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)18 CaseExecutionImpl (org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl)17 CaseIllegalStateTransitionException (org.camunda.bpm.engine.exception.cmmn.CaseIllegalStateTransitionException)14 CmmnExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution)2 MilestoneActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.MilestoneActivityBehavior)1 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)1 CmmnOnPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration)1 CmmnSentryDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration)1