Search in sources :

Example 31 with CaseDefinitionBuilder

use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.

the class CaseInstanceCloseTest method testCloseSuspendedCaseInstance.

/**
 *   +-----------------+
 *   | Case1            \
 *   +-------------------+---+
 *   |                       |
 *   |     +-------+         |
 *   |     |   A   |         |
 *   |     +-------+         |
 *   |                       |
 *   +-----------------------+
 */
@Test
public void testCloseSuspendedCaseInstance() {
    CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
    // given
    // a case definition
    CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("close", stateTransitionCollector).createActivity("A").behavior(new TaskWaitState()).endActivity().buildCaseDefinition();
    // an active case instance
    CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
    caseInstance.create();
    caseInstance.suspend();
    assertTrue(caseInstance.isSuspended());
    // when
    // close case
    caseInstance.close();
    // then
    List<String> expectedStateTransitions = new ArrayList<String>();
    // expected state transition:
    // suspended --close(Case1)--> closed
    expectedStateTransitions.add("suspended --close(Case1)--> closed");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
    assertTrue(caseInstance.isClosed());
    assertNull(caseInstance.findCaseExecution("A"));
}
Also used : 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) Test(org.junit.Test)

Example 32 with CaseDefinitionBuilder

use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.

the class CaseInstanceCloseTest method testCloseCompletedCaseInstance.

/**
 *   +-----------------+
 *   | Case1            \
 *   +-------------------+---+
 *   |                       |
 *   |     +-------+         |
 *   |     |   A   |         |
 *   |     +-------+         |
 *   |                       |
 *   +-----------------------+
 */
@Test
public void testCloseCompletedCaseInstance() {
    CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
    // given
    // a case definition
    CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("close", stateTransitionCollector).createActivity("A").behavior(new TaskWaitState()).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).endActivity().buildCaseDefinition();
    // an active case instance
    CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
    caseInstance.create();
    // task A as a child of the case instance
    CmmnActivityExecution taskA = caseInstance.findCaseExecution("A");
    // disable task A -> completes case instance
    taskA.disable();
    assertTrue(caseInstance.isCompleted());
    // when
    // close case
    caseInstance.close();
    // then
    List<String> expectedStateTransitions = new ArrayList<String>();
    // expected state transition:
    // completed --close(Case1)--> closed
    expectedStateTransitions.add("completed --close(Case1)--> closed");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
    assertTrue(caseInstance.isClosed());
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) 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) Test(org.junit.Test)

Example 33 with CaseDefinitionBuilder

use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.

the class CaseInstanceCloseTest method testCloseTerminatedCaseInstance.

/**
 *   +-----------------+
 *   | Case1            \
 *   +-------------------+---+
 *   |                       |
 *   |     +-------+         |
 *   |     |   A   |         |
 *   |     +-------+         |
 *   |                       |
 *   +-----------------------+
 */
@Test
public void testCloseTerminatedCaseInstance() {
    CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
    // given
    // a case definition
    CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("close", stateTransitionCollector).createActivity("A").behavior(new TaskWaitState()).endActivity().buildCaseDefinition();
    // an active case instance
    CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
    caseInstance.create();
    caseInstance.terminate();
    assertTrue(caseInstance.isTerminated());
    // when
    // close case
    caseInstance.close();
    // then
    List<String> expectedStateTransitions = new ArrayList<String>();
    // expected state transition:
    // terminated --close(Case1)--> closed
    expectedStateTransitions.add("terminated --close(Case1)--> closed");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
    assertTrue(caseInstance.isClosed());
}
Also used : 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) Test(org.junit.Test)

Example 34 with CaseDefinitionBuilder

use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.

the class CaseExecutionCompletionTest method testManualCompleteActiveCaseInstanceWithEnabledTask.

/**
 *   +-----------------+
 *   | Case1            \
 *   +-------------------+---+
 *   |                       |
 *   |     +-------+         |
 *   |     |   A   |         |
 *   |     +-------+         |
 *   |                       |
 *   +-----------------------+
 */
public void testManualCompleteActiveCaseInstanceWithEnabledTask() {
    CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
    // given
    // a case definition
    CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("complete", stateTransitionCollector).createActivity("A").listener("complete", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().buildCaseDefinition();
    // an active case instance
    CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
    caseInstance.create();
    // task A as a child of the case instance
    CmmnActivityExecution taskA = caseInstance.findCaseExecution("A");
    // task A is enabled
    assertTrue(taskA.isEnabled());
    // when
    // complete caseInstance (manualCompletion == true)
    caseInstance.manualComplete();
    // then
    List<String> expectedStateTransitions = new ArrayList<String>();
    // expected state transition:
    // active --complete(Case1)--> completed
    expectedStateTransitions.add("active --complete(Case1)--> completed");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
    // the case instance
    assertTrue(caseInstance.isCompleted());
    // task A is not a child of the case instance anymore
    assertNull(caseInstance.findCaseExecution("A"));
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) 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 35 with CaseDefinitionBuilder

use of org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder in project camunda-bpm-platform by camunda.

the class CaseExecutionCompletionTest method testAutoCompletionStageWithoutChildren.

/**
 *   +-----------------+
 *   | Case1            \
 *   +-------------------+-----------------+
 *   |                                     |
 *   |     +------------------------+      |
 *   |    / X                        \     |
 *   |   +                            +    |
 *   |   |                            |    |
 *   |   +                            +    |
 *   |    \                          /     |
 *   |     +------------------------+      |
 *   |                                     |
 *   +-------------------------------------+
 */
public void testAutoCompletionStageWithoutChildren() {
    CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
    // given
    // a case definition
    CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("complete", stateTransitionCollector).createActivity("X").listener("complete", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new StageActivityBehavior()).endActivity().buildCaseDefinition();
    CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
    caseInstance.create();
    CmmnActivityExecution stageX = caseInstance.findCaseExecution("X");
    // when
    stageX.manualStart();
    // then
    assertTrue(caseInstance.isCompleted());
    assertTrue(stageX.isCompleted());
    List<String> expectedStateTransitions = new ArrayList<String>();
    // expected state transition:
    // active --complete(X)-->     completed
    // active --complete(Case1)--> completed
    expectedStateTransitions.add("active --complete(X)--> completed");
    expectedStateTransitions.add("active --complete(Case1)--> completed");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
}
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) ArrayList(java.util.ArrayList) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder)

Aggregations

CmmnCaseInstance (org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance)46 CaseDefinitionBuilder (org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder)46 CmmnCaseDefinition (org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition)46 CmmnActivityExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution)38 StageActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior)22 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)18 CaseExecutionImpl (org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl)17 CaseIllegalStateTransitionException (org.camunda.bpm.engine.exception.cmmn.CaseIllegalStateTransitionException)14 CmmnExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution)2 MilestoneActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.MilestoneActivityBehavior)1 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)1 CmmnOnPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration)1 CmmnSentryDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration)1