use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseInstanceTest method testCaseInstanceWithOneTask.
/**
* +-----------------+
* | Case1 \
* +-------------------+---+
* | |
* | +-------+ |
* | | A | |
* | +-------+ |
* | |
* +-----------------------+
*/
@Test
public void testCaseInstanceWithOneTask() {
CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("create", stateTransitionCollector).createActivity("A").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().buildCaseDefinition();
// create a new case instance
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
// expected state transitions after creation of a case instance:
// () --create(Case1)--> active
// () --create(A)--> available
// available --enable(A)--> enabled
List<String> expectedStateTransitions = new ArrayList<String>();
expectedStateTransitions.add("() --create(Case1)--> active");
expectedStateTransitions.add("() --create(A)--> available");
expectedStateTransitions.add("available --enable(A)--> enabled");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// case instance is active
assertTrue(caseInstance.isActive());
CaseExecutionImpl instance = (CaseExecutionImpl) caseInstance;
// case instance has one child plan item
List<CaseExecutionImpl> childPlanItems = instance.getCaseExecutions();
assertEquals(1, childPlanItems.size());
CaseExecutionImpl planItemA = childPlanItems.get(0);
// the child plan item is enabled
assertTrue(planItemA.isEnabled());
// the parent of the child plan item is the case instance
assertEquals(caseInstance, planItemA.getParent());
// manual start of A
planItemA.manualStart();
// expected state transition after manual start of A:
// enabled --enable(A)--> active
expectedStateTransitions.add("enabled --manualStart(A)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
assertTrue(planItemA.isActive());
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseInstanceTest method testCaseInstanceWithOneState.
/**
* +-----------------+
* | Case1 \
* +-------------------+-----------------+
* | |
* | +------------------------+ |
* | / X \ |
* | + +-------+ +-------+ + |
* | | | A | | B | | |
* | + +-------+ +-------+ + |
* | \ / |
* | +------------------------+ |
* | |
* +-------------------------------------+
*/
@Test
public void testCaseInstanceWithOneState() {
CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("create", stateTransitionCollector).createActivity("X").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new StageActivityBehavior()).createActivity("A").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().createActivity("B").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().endActivity().buildCaseDefinition();
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
// expected state transitions after the creation of a case instance:
// () --create(Case1)--> active
// () --create(X)--> available
// available --enable(X)--> enabled
List<String> expectedStateTransitions = initAndAssertExpectedTransitions(stateTransitionCollector);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
CaseExecutionImpl planItemX = assertCaseXState(caseInstance);
List<CaseExecutionImpl> childPlanItems;
// manual start of x
planItemX.manualStart();
// X should be active
assertTrue(planItemX.isActive());
// expected state transitions after a manual start of X:
// enabled --manualStart(X)--> active
// () --create(A)--> available
// available --enable(A)--> enabled
// () --create(B)--> available
// available --enable(B)--> enabled
expectedStateTransitions.add("enabled --manualStart(X)--> active");
expectedStateTransitions.add("() --create(A)--> available");
expectedStateTransitions.add("available --enable(A)--> enabled");
expectedStateTransitions.add("() --create(B)--> available");
expectedStateTransitions.add("available --enable(B)--> enabled");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// X should have two chil plan items
childPlanItems = planItemX.getCaseExecutions();
assertEquals(2, childPlanItems.size());
for (CmmnExecution childPlanItem : childPlanItems) {
// both children should be enabled
assertTrue(childPlanItem.isEnabled());
// manual start of a child
childPlanItem.manualStart();
// the child should be active
assertTrue(childPlanItem.isActive());
// X should be the parent of both children
assertEquals(planItemX, childPlanItem.getParent());
}
// expected state transitions after the manual starts of A and B:
// enabled --manualStart(A)--> active
// enabled --manualStart(B)--> active
expectedStateTransitions.add("enabled --manualStart(A)--> active");
expectedStateTransitions.add("enabled --manualStart(B)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseInstanceTest method assertCaseXState.
protected CaseExecutionImpl assertCaseXState(CmmnCaseInstance caseInstance) {
// case instance is active
assertTrue(caseInstance.isActive());
CaseExecutionImpl instance = (CaseExecutionImpl) caseInstance;
// case instance has one child plan item
List<CaseExecutionImpl> childPlanItems = instance.getCaseExecutions();
assertEquals(1, childPlanItems.size());
CaseExecutionImpl planItemX = childPlanItems.get(0);
// the case instance should be the parent of X
assertEquals(caseInstance, planItemX.getParent());
// X should be enabled
assertTrue(planItemX.isEnabled());
// before activation (ie. manual start) X should not have any children
assertTrue(planItemX.getCaseExecutions().isEmpty());
return planItemX;
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseExecutionCompletionTest method testTerminateTaskShouldCompleteCaseInstance.
/**
* +-----------------+
* | Case1 \
* +-------------------+---+
* | |
* | +-------+ |
* | | A | |
* | +-------+ |
* | |
* +-----------------------+
*/
public void testTerminateTaskShouldCompleteCaseInstance() {
CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
// given
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("complete", stateTransitionCollector).createActivity("A").listener("terminate", stateTransitionCollector).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");
// task A is active
assertTrue(taskA.isActive());
// when
// terminate A
taskA.terminate();
// then
List<String> expectedStateTransitions = new ArrayList<String>();
// expected state transition:
// active --terminate(A)--> terminated
// active --complete(Case1)--> completed
expectedStateTransitions.add("active --terminate(A)--> terminated");
expectedStateTransitions.add("active --complete(Case1)--> completed");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// task A is disabled
assertTrue(taskA.isTerminated());
// case instance is completed
assertTrue(caseInstance.isCompleted());
assertNull(caseInstance.findCaseExecution("A"));
assertTrue(((CaseExecutionImpl) caseInstance).getCaseExecutions().isEmpty());
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseExecutionCompletionTest method testManualCompleteActiveTask.
/**
* +-----------------+
* | Case1 \
* +-------------------+---+
* | |
* | +-------+ |
* | | A | |
* | +-------+ |
* | |
* +-----------------------+
*/
public void testManualCompleteActiveTask() {
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.manualComplete();
// 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());
}
Aggregations