-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug: stage plan item instance automatically being completed when …
…setting variable through runtimeService in a lifecycleListener
- Loading branch information
Showing
11 changed files
with
327 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...owable-cmmn-engine/src/test/java/org/flowable/cmmn/test/delegate/TestSetVariableBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flowable.cmmn.test.delegate; | ||
|
||
import org.flowable.cmmn.api.CmmnRuntimeService; | ||
import org.flowable.cmmn.engine.impl.util.CommandContextUtil; | ||
|
||
/** | ||
* @author Joram Barrez | ||
*/ | ||
public class TestSetVariableBean { | ||
|
||
public void setVariable(String caseInstanceId, String variableName, Object variableValue) { | ||
CmmnRuntimeService cmmnRuntimeService = CommandContextUtil.getCmmnEngineConfiguration().getCmmnRuntimeService(); | ||
cmmnRuntimeService.setVariable(caseInstanceId, variableName, variableValue); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...lowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/runtime/StageCompletionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flowable.cmmn.test.runtime; | ||
|
||
import java.util.List; | ||
|
||
import org.flowable.cmmn.api.runtime.CaseInstance; | ||
import org.flowable.cmmn.api.runtime.PlanItemInstance; | ||
import org.flowable.cmmn.api.runtime.PlanItemInstanceState; | ||
import org.flowable.cmmn.engine.test.CmmnDeployment; | ||
import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; | ||
import org.flowable.task.api.Task; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Joram Barrez | ||
*/ | ||
public class StageCompletionTest extends FlowableCmmnTestCase { | ||
|
||
@Test | ||
@CmmnDeployment | ||
public void testSetVariableInLifecycleListener() { | ||
|
||
/* | ||
* This test has a case which has a stage with a lifecycle listener that sets a variable through the cmmnRuntimeService. | ||
* Before introducing the flag 'isStateChangeUnprocessed' on PlanItemInstanceEntity, this would lead to the following problem: | ||
* | ||
* startCaseInstance --> new CommandContext --> plan operations for initialization + moving stage plan item instance to state 'active' | ||
* setVariable, through a service, will reuse the existing commandContext. However, the SetVariableCmd plans an explicit evaluation operation (for good reasons) | ||
* | ||
* When the evaluation operations executes, the stage has moved into the 'active' state, however when the lifecycle listener executes | ||
* no child plan item instances are created yet. The logic deems correctly that this constellation means the stage should complete. | ||
* | ||
* Introducing the stateChangeUnprocessed flag on the stage plan item instance fixes this problem: it avoids looking into stages that | ||
* are still being initialized but have a setup that would otherwise automatically complete the stage plan item instance. | ||
*/ | ||
|
||
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("myCase").start(); | ||
List<PlanItemInstance> planItemInstances = cmmnRuntimeService.createPlanItemInstanceQuery().caseInstanceId(caseInstance.getId()).list(); | ||
assertPlanItemInstanceState(caseInstance, "stageWithLifecycleListener", PlanItemInstanceState.AVAILABLE); | ||
|
||
// Triggering the user event listener activates the stage | ||
cmmnRuntimeService.completeUserEventListenerInstance(planItemInstances.stream() | ||
.filter(planItemInstance -> "A".equalsIgnoreCase(planItemInstance.getName())).findAny().get().getId()); | ||
|
||
assertPlanItemInstanceState(caseInstance, "stageWithLifecycleListener", PlanItemInstanceState.ACTIVE); | ||
|
||
// Completing the user tasks should complete the case instance | ||
Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult(); | ||
cmmnTaskService.complete(task.getId()); | ||
|
||
assertCaseInstanceEnded(caseInstance); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.