use of org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition 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.CmmnCaseDefinition 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.model.CmmnCaseDefinition in project camunda-bpm-platform by camunda.
the class CaseExecutionResumeTest method testResumeStage.
@Test
public void testResumeStage() {
// given ///////////////////////////////////////////////////////////////
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").createActivity("X").behavior(new StageActivityBehavior()).createActivity("A").behavior(new TaskWaitState()).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).endActivity().createActivity("B").behavior(new TaskWaitState()).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).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");
stageX.suspend();
// a case execution associated with Task A
CmmnActivityExecution taskA = caseInstance.findCaseExecution("A");
assertTrue(taskA.isSuspended());
// a case execution associated with Task B
CmmnActivityExecution taskB = caseInstance.findCaseExecution("B");
assertTrue(taskB.isSuspended());
// when
stageX.resume();
// then
assertTrue(caseInstance.isActive());
assertTrue(stageX.isActive());
assertTrue(taskA.isEnabled());
assertTrue(taskB.isEnabled());
}
use of org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition in project camunda-bpm-platform by camunda.
the class CaseExecutionSuspensionTest method testSuspendTask.
@Test
public void testSuspendTask() {
// 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()).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).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
taskA.suspend();
// then
assertTrue(caseInstance.isActive());
assertTrue(stageX.isActive());
assertTrue(taskA.isSuspended());
assertTrue(taskB.isEnabled());
}
use of org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition in project camunda-bpm-platform by camunda.
the class CaseExecutionSuspensionTest method testSuspendStage.
@Test
public void testSuspendStage() {
// 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.suspend();
// then
assertTrue(caseInstance.isActive());
assertTrue(stageX.isSuspended());
assertTrue(taskA.isSuspended());
assertTrue(taskB.isSuspended());
}
Aggregations