use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder 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());
}
}
use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.
the class CaseExecutionTerminationTest method testTerminateCaseInstance.
@Test
public void testTerminateCaseInstance() {
// given ///////////////////////////////////////////////////////////////
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").createActivity("X").behavior(new StageActivityBehavior()).createActivity("A").behavior(new TaskWaitState()).endActivity().createActivity("B").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
caseInstance.terminate();
// then
assertTrue(caseInstance.isTerminated());
assertTrue(stageX.isTerminated());
assertTrue(taskA.isTerminated());
assertTrue(taskB.isTerminated());
}
use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.
the class CaseExecutionTerminationTest method testTerminateStage.
@Test
public void testTerminateStage() {
// given ///////////////////////////////////////////////////////////////
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").createActivity("X").behavior(new StageActivityBehavior()).createActivity("A").behavior(new TaskWaitState()).endActivity().createActivity("B").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
stageX.terminate();
// then
assertTrue(caseInstance.isCompleted());
assertTrue(stageX.isTerminated());
assertTrue(taskA.isTerminated());
assertTrue(taskB.isTerminated());
}
use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder 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.model.CaseDefinitionBuilder 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);
}
Aggregations