Search in sources :

Example 16 with StageActivityBehavior

use of org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior 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);
}
Also used : CaseExecutionImpl(org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl) StageActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior) CmmnCaseDefinition(org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CmmnExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder) Test(org.junit.Test)

Example 17 with StageActivityBehavior

use of org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior 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());
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) StageActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior) CmmnCaseDefinition(org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder) Test(org.junit.Test)

Example 18 with StageActivityBehavior

use of org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior 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());
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) StageActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior) CmmnCaseDefinition(org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder) Test(org.junit.Test)

Example 19 with StageActivityBehavior

use of org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior 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());
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) StageActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior) CmmnCaseDefinition(org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder) Test(org.junit.Test)

Example 20 with StageActivityBehavior

use of org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior in project camunda-bpm-platform by camunda.

the class CaseExecutionSuspensionTest method testSuspendCaseInstance.

@Test
public void testSuspendCaseInstance() {
    // 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.suspend();
    // then
    assertTrue(caseInstance.isSuspended());
    assertTrue(stageX.isSuspended());
    assertTrue(taskA.isSuspended());
    assertTrue(taskB.isSuspended());
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) StageActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior) CmmnCaseDefinition(org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder) Test(org.junit.Test)

Aggregations

StageActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior)25 CmmnCaseInstance (org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance)22 CaseDefinitionBuilder (org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder)22 CmmnCaseDefinition (org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition)22 CmmnActivityExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution)19 Test (org.junit.Test)16 CaseExecutionImpl (org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl)11 ArrayList (java.util.ArrayList)8 CmmnActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.CmmnActivityBehavior)3 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)3 CmmnExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution)2 CaseIllegalStateTransitionException (org.camunda.bpm.engine.exception.cmmn.CaseIllegalStateTransitionException)1