Search in sources :

Example 6 with StageActivityBehavior

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

Example 7 with StageActivityBehavior

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

Example 8 with StageActivityBehavior

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

the class CaseExecutionResumeTest method testResumeTask.

@Test
public void testResumeTask() {
    // 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");
    taskA.suspend();
    // a case execution associated with Task B
    CmmnActivityExecution taskB = caseInstance.findCaseExecution("B");
    // when
    taskA.resume();
    // then
    assertTrue(caseInstance.isActive());
    assertTrue(stageX.isActive());
    assertTrue(taskA.isActive());
    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 9 with StageActivityBehavior

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

the class CasePlanModelHandlerTest method testActivityBehavior.

@Test
public void testActivityBehavior() {
    // given: a case plan model
    // when
    CmmnActivity activity = handler.handleElement(casePlanModel, context);
    // then
    CmmnActivityBehavior behavior = activity.getActivityBehavior();
    assertTrue(behavior instanceof StageActivityBehavior);
}
Also used : StageActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior) CmmnActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.CmmnActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Example 10 with StageActivityBehavior

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

the class CaseExecutionReactivateTest method testReactivateCaseInstance.

@Test
public void testReactivateCaseInstance() {
    // 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");
    // a case execution associated with Task A
    CmmnActivityExecution taskA = caseInstance.findCaseExecution("A");
    // a case execution associated with Task B
    CmmnActivityExecution taskB = caseInstance.findCaseExecution("B");
    caseInstance.suspend();
    // when
    caseInstance.reactivate();
    // 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)

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