use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseExecutionCompletionTest method testCompleteTaskAAndTaskB.
/**
* +-----------------+
* | Case1 \
* +-------------------+-----------------+
* | |
* | +------------------------+ |
* | / X \ |
* | + +-------+ +-------+ + |
* | | | A | | B | | |
* | + +-------+ +-------+ + |
* | \ / |
* | +------------------------+ |
* | |
* +-------------------------------------+
*/
public void testCompleteTaskAAndTaskB() {
CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
// given ///////////////////////////////////////////////////////////////
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("complete", stateTransitionCollector).createActivity("X").listener("complete", stateTransitionCollector).behavior(new StageActivityBehavior()).createActivity("A").listener("complete", stateTransitionCollector).behavior(new TaskWaitState()).endActivity().createActivity("B").listener("complete", stateTransitionCollector).behavior(new TaskWaitState()).endActivity().endActivity().buildCaseDefinition();
// an active case instance
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
// a case execution associated with Stage X
CmmnActivityExecution stageX = caseInstance.findCaseExecution("X");
// a case execution associated with Task A
CmmnActivityExecution taskA = caseInstance.findCaseExecution("A");
// a case execution associated with Task B
CmmnActivityExecution taskB = caseInstance.findCaseExecution("B");
// when ////////////////////////////////////////////////////////////////
// complete task A
taskA.complete();
// complete task B
taskB.complete();
// then ////////////////////////////////////////////////////////////////
List<String> expectedStateTransitions = new ArrayList<String>();
// expected state transitions:
// active --complete(A)--> completed
// active --complete(B)--> completed
// active --complete(X)--> completed
// active --complete(Case1)--> completed
expectedStateTransitions.add("active --complete(A)--> completed");
expectedStateTransitions.add("active --complete(B)--> completed");
expectedStateTransitions.add("active --complete(X)--> completed");
expectedStateTransitions.add("active --complete(Case1)--> completed");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
expectedStateTransitions.clear();
stateTransitionCollector.stateTransitions.clear();
// task A is completed
assertTrue(taskA.isCompleted());
// task B is completed
assertTrue(taskB.isCompleted());
// stage X is completed
assertTrue(stageX.isCompleted());
// stage X does not contain task A anymore
assertNull(caseInstance.findCaseExecution("A"));
// stage X does not contain task B anymore
assertNull(caseInstance.findCaseExecution("B"));
// stage X does not contain task X anymore
assertNull(caseInstance.findCaseExecution("X"));
// stage X has only one child
assertEquals(0, ((CaseExecutionImpl) caseInstance).getCaseExecutions().size());
// case instance is completed
assertTrue(caseInstance.isCompleted());
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseExecutionCompletionTest method testCompleteOnlyTaskA.
/**
* +-----------------+
* | Case1 \
* +-------------------+-----------------+
* | |
* | +------------------------+ |
* | / X \ |
* | + +-------+ +-------+ + |
* | | | A | | B | | |
* | + +-------+ +-------+ + |
* | \ / |
* | +------------------------+ |
* | |
* +-------------------------------------+
*/
public void testCompleteOnlyTaskA() {
CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
// given ///////////////////////////////////////////////////////////////
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("complete", stateTransitionCollector).createActivity("X").listener("complete", stateTransitionCollector).behavior(new StageActivityBehavior()).createActivity("A").listener("complete", stateTransitionCollector).behavior(new TaskWaitState()).endActivity().createActivity("B").listener("complete", stateTransitionCollector).behavior(new TaskWaitState()).endActivity().endActivity().buildCaseDefinition();
// an active case instance
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
// a case execution associated with Stage X
CmmnActivityExecution stageX = caseInstance.findCaseExecution("X");
// a case execution associated with Task A
CmmnActivityExecution taskA = caseInstance.findCaseExecution("A");
// a case execution associated with Task B
CmmnActivityExecution taskB = caseInstance.findCaseExecution("B");
// when ////////////////////////////////////////////////////////////////
// complete task A
taskA.complete();
// then ////////////////////////////////////////////////////////////////
List<String> expectedStateTransitions = new ArrayList<String>();
// expected state transitions:
// active --complete(A)--> completed
expectedStateTransitions.add("active --complete(A)--> completed");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
expectedStateTransitions.clear();
stateTransitionCollector.stateTransitions.clear();
// task A is completed
assertTrue(taskA.isCompleted());
// task B is still active
assertTrue(taskB.isActive());
// stage X is still active
assertTrue(stageX.isActive());
// stage X does not contain task A anymore
assertNull(caseInstance.findCaseExecution("A"));
// task B is still part of the case instance
assertNotNull(caseInstance.findCaseExecution("B"));
// stage X is still part of the case instance
assertNotNull(caseInstance.findCaseExecution("X"));
// case instance has only one child
assertEquals(1, ((CaseExecutionImpl) caseInstance).getCaseExecutions().size());
// stage X has two children
assertEquals(1, ((CaseExecutionImpl) stageX).getCaseExecutions().size());
// case instance is still active
assertTrue(caseInstance.isActive());
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseExecutionOccurTest method testOccurMilestone.
@Test
public void testOccurMilestone() {
// given
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").createActivity("A").behavior(new MilestoneActivityBehavior()).endActivity().buildCaseDefinition();
CmmnActivity activity = caseDefinition.findActivity("A");
// a pseudo sentry
CmmnSentryDeclaration sentryDeclaration = new CmmnSentryDeclaration("X");
caseDefinition.findActivity("Case1").addSentry(sentryDeclaration);
activity.addEntryCriteria(sentryDeclaration);
CmmnOnPartDeclaration onPartDeclaration = new CmmnOnPartDeclaration();
onPartDeclaration.setSource(new CmmnActivity("B", caseDefinition));
onPartDeclaration.setStandardEvent("complete");
sentryDeclaration.addOnPart(onPartDeclaration);
// an active case instance
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
// task A as a child of the case instance
CmmnActivityExecution milestoneA = caseInstance.findCaseExecution("A");
// when
// completing
milestoneA.occur();
// then
// task A is completed ...
assertTrue(milestoneA.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());
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseInstanceTest method testStartComplexCaseInstance.
/**
* +-----------------+
* | Case1 \
* +-------------------+-------------------+
* | |
* | +-------+ |
* | | A1 | |
* | +-------+ |
* | |
* | +------------------------+ |
* | / X1 \ |
* | + +-------+ +-------+ + |
* | | | A2 | | B1 | | |
* | + +-------+ +-------+ + |
* | \ / |
* | +------------------------+ |
* | |
* | +-----------------------------+ |
* | / Y \ |
* | + +-------+ + |
* | | | C | | |
* | | +-------+ | |
* | | | |
* | | +------------------------+ | |
* | | / X2 \ | |
* | | + +-------+ +-------+ + | |
* | | | | A3 | | B2 | | | |
* | | + +-------+ +-------+ + | |
* | | \ / | |
* | + +------------------------+ + |
* | \ / |
* | +-----------------------------+ |
* | |
* +---------------------------------------+
*/
@Test
public void testStartComplexCaseInstance() {
CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("create", stateTransitionCollector).createActivity("A1").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().createActivity("X1").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new StageActivityBehavior()).createActivity("A2").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().createActivity("B1").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().endActivity().createActivity("Y").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new StageActivityBehavior()).createActivity("C").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().createActivity("X2").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new StageActivityBehavior()).createActivity("A3").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().createActivity("B2").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().endActivity().endActivity().buildCaseDefinition();
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
// expected state transitions after the creation of a case instance:
// () --create(Case1)--> active
// () --create(A1)--> available
// available --enable(A1)--> enabled
// () --create(X1)--> available
// available --enable(X1)--> enabled
// () --create(Y)--> available
// available --enable(Y)--> enabled
List<String> expectedStateTransitions = new ArrayList<String>();
expectedStateTransitions.add("() --create(Case1)--> active");
expectedStateTransitions.add("() --create(A1)--> available");
expectedStateTransitions.add("available --enable(A1)--> enabled");
expectedStateTransitions.add("() --create(X1)--> available");
expectedStateTransitions.add("available --enable(X1)--> enabled");
expectedStateTransitions.add("() --create(Y)--> available");
expectedStateTransitions.add("available --enable(Y)--> enabled");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
CaseExecutionImpl instance = (CaseExecutionImpl) caseInstance;
// the case instance should be active
assertTrue(instance.isActive());
// the case instance should have three child plan items (A1, X1, Y)
List<CaseExecutionImpl> childPlanItems = instance.getCaseExecutions();
assertEquals(3, childPlanItems.size());
// handle plan item A1 //////////////////////////////////////////////////
CaseExecutionImpl planItemA1 = (CaseExecutionImpl) instance.findCaseExecution("A1");
// case instance should be the parent of A1
assertEquals(caseInstance, planItemA1.getParent());
// A1 should be enabled
assertTrue(planItemA1.isEnabled());
// manual start of A1
planItemA1.manualStart();
// A1 should be active
assertTrue(planItemA1.isActive());
// expected state transitions:
// enabled --manualStart(A1)--> active
expectedStateTransitions.add("enabled --manualStart(A1)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item X1 ///////////////////////////////////////////////////
CaseExecutionImpl planItemX1 = (CaseExecutionImpl) instance.findCaseExecution("X1");
// case instance should be the parent of X1
assertEquals(caseInstance, planItemX1.getParent());
// X1 should be enabled
assertTrue(planItemX1.isEnabled());
// manual start of X1
planItemX1.manualStart();
// X1 should be active
assertTrue(planItemX1.isActive());
// X1 should have two children
childPlanItems = planItemX1.getCaseExecutions();
assertEquals(2, childPlanItems.size());
// expected state transitions after manual start of X1:
// enabled --manualStart(X1)--> active
// () --create(A2)--> available
// available --enable(A2)--> enabled
// () --create(B1)--> available
// available --enable(B1)--> enabled
expectedStateTransitions.add("enabled --manualStart(X1)--> active");
expectedStateTransitions.add("() --create(A2)--> available");
expectedStateTransitions.add("available --enable(A2)--> enabled");
expectedStateTransitions.add("() --create(B1)--> available");
expectedStateTransitions.add("available --enable(B1)--> enabled");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item A2 ////////////////////////////////////////////////
CaseExecutionImpl planItemA2 = (CaseExecutionImpl) instance.findCaseExecution("A2");
// X1 should be the parent of A2
assertEquals(planItemX1, planItemA2.getParent());
// A2 should be enabled
assertTrue(planItemA2.isEnabled());
// manual start of A2
planItemA2.manualStart();
// A2 should be active
assertTrue(planItemA2.isActive());
// expected state transition after manual start of A2:
// enabled --manualStart(A2)--> active
expectedStateTransitions.add("enabled --manualStart(A2)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item B1 /////////////////////////////////////////////////
CaseExecutionImpl planItemB1 = (CaseExecutionImpl) instance.findCaseExecution("B1");
// X1 should be the parent of B1
assertEquals(planItemX1, planItemB1.getParent());
// B1 should be enabled
assertTrue(planItemB1.isEnabled());
// manual start of B1
planItemB1.manualStart();
// B1 should be active
assertTrue(planItemB1.isActive());
// expected state transition after manual start of B1:
// enabled --manualStart(B1)--> active
expectedStateTransitions.add("enabled --manualStart(B1)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item Y ////////////////////////////////////////////////
CaseExecutionImpl planItemY = (CaseExecutionImpl) instance.findCaseExecution("Y");
// case instance should be the parent of Y
assertEquals(caseInstance, planItemY.getParent());
// Y should be enabled
assertTrue(planItemY.isEnabled());
// manual start of Y
planItemY.manualStart();
// Y should be active
assertTrue(planItemY.isActive());
// Y should have two children
childPlanItems = planItemY.getCaseExecutions();
assertEquals(2, childPlanItems.size());
// expected state transitions after manual start of Y:
// enabled --manualStart(Y)--> active
// () --create(C)--> available
// available --enable(C)--> enabled
// () --create(X2)--> available
// available --enable(X2)--> enabled
expectedStateTransitions.add("enabled --manualStart(Y)--> active");
expectedStateTransitions.add("() --create(C)--> available");
expectedStateTransitions.add("available --enable(C)--> enabled");
expectedStateTransitions.add("() --create(X2)--> available");
expectedStateTransitions.add("available --enable(X2)--> enabled");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item C //////////////////////////////////////////////////
CaseExecutionImpl planItemC = (CaseExecutionImpl) instance.findCaseExecution("C");
// Y should be the parent of C
assertEquals(planItemY, planItemC.getParent());
// C should be enabled
assertTrue(planItemC.isEnabled());
// manual start of C
planItemC.manualStart();
// C should be active
assertTrue(planItemC.isActive());
// expected state transition after manual start of C:
// enabled --manualStart(C)--> active
expectedStateTransitions.add("enabled --manualStart(C)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item X2 ///////////////////////////////////////////
CaseExecutionImpl planItemX2 = (CaseExecutionImpl) instance.findCaseExecution("X2");
// Y should be the parent of X2
assertEquals(planItemY, planItemX2.getParent());
// X2 should be enabled
assertTrue(planItemX2.isEnabled());
// manual start of X2
planItemX2.manualStart();
// X2 should be active
assertTrue(planItemX2.isActive());
// X2 should have two children
childPlanItems = planItemX2.getCaseExecutions();
assertEquals(2, childPlanItems.size());
// expected state transitions after manual start of X2:
// enabled --manualStart(X2)--> active
// () --create(A3)--> available
// available --enable(A3)--> enabled
// () --create(B2)--> available
// available --enable(B2)--> enabled
expectedStateTransitions.add("enabled --manualStart(X2)--> active");
expectedStateTransitions.add("() --create(A3)--> available");
expectedStateTransitions.add("available --enable(A3)--> enabled");
expectedStateTransitions.add("() --create(B2)--> available");
expectedStateTransitions.add("available --enable(B2)--> enabled");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item A3 //////////////////////////////////////////////
CaseExecutionImpl planItemA3 = (CaseExecutionImpl) instance.findCaseExecution("A3");
// A3 should be the parent of X2
assertEquals(planItemX2, planItemA3.getParent());
// A3 should be enabled
assertTrue(planItemA3.isEnabled());
// manual start of A3
planItemA3.manualStart();
// A3 should be active
assertTrue(planItemA3.isActive());
// expected state transition after manual start of A3:
// enabled --manualStart(A3)--> active
expectedStateTransitions.add("enabled --manualStart(A3)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// handle plan item B2 /////////////////////////////////////////////////
CaseExecutionImpl planItemB2 = (CaseExecutionImpl) instance.findCaseExecution("B2");
// B2 should be the parent of X2
assertEquals(planItemX2, planItemB2.getParent());
// B2 should be enabled
assertTrue(planItemB2.isEnabled());
// manual start of B2
planItemB2.manualStart();
// B2 should be active
assertTrue(planItemB2.isActive());
// expected state transition after manual start of B2:
// enabled --manualStart(B2)--> active
expectedStateTransitions.add("enabled --manualStart(B2)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
}
use of org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl in project camunda-bpm-platform by camunda.
the class CaseInstanceTest method testCaseInstanceWithOneStateWithoutManualStartOfChildren.
@Test
public void testCaseInstanceWithOneStateWithoutManualStartOfChildren() {
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("start", stateTransitionCollector).behavior(new TaskWaitState()).endActivity().createActivity("B").listener("create", stateTransitionCollector).listener("start", stateTransitionCollector).behavior(new TaskWaitState()).endActivity().endActivity().buildCaseDefinition();
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
List<String> expectedStateTransitions = initAndAssertExpectedTransitions(stateTransitionCollector);
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// clear lists
CaseExecutionImpl planItemX = assertCaseXState(caseInstance);
// manual start of x
planItemX.manualStart();
// X should be active
assertTrue(planItemX.isActive());
// expected state transitions after a manual start of X:
expectedStateTransitions.add("enabled --manualStart(X)--> active");
expectedStateTransitions.add("() --create(A)--> available");
expectedStateTransitions.add("available --start(A)--> active");
expectedStateTransitions.add("() --create(B)--> available");
expectedStateTransitions.add("available --start(B)--> active");
assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
// clear lists
emptyCollector(stateTransitionCollector, expectedStateTransitions);
// X should have two chil plan items
List<CaseExecutionImpl> childPlanItems;
childPlanItems = planItemX.getCaseExecutions();
assertEquals(2, childPlanItems.size());
for (CmmnExecution childPlanItem : childPlanItems) {
// both children should be active
assertTrue(childPlanItem.isActive());
// X should be the parent of both children
assertEquals(planItemX, childPlanItem.getParent());
}
}
Aggregations