Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cmmn: fix plan item java delegate trigger not possible
- Loading branch information
Showing
8 changed files
with
256 additions
and
18 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
20 changes: 20 additions & 0 deletions
20
...s/org/flowable/cmmn/test/runtime/ServiceTaskTest.testCmmnTriggerableActivityBehavior.cmmn
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" | ||
xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" | ||
xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" | ||
xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:flowable="http://flowable.org/cmmn" | ||
targetNamespace="http://flowable.org/cmmn"> | ||
|
||
<case id="myCase"> | ||
<casePlanModel id="myPlanModel" name="My CasePlanModel"> | ||
|
||
<planItem id="planItem1" name="Task One" definitionRef="serviceTask" /> | ||
|
||
<task id="serviceTask" flowable:type="java" flowable:class="org.flowable.cmmn.test.runtime.ServiceTaskTest$TestJavaDelegate03" /> | ||
|
||
</casePlanModel> | ||
</case> | ||
|
||
</definitions> |
96 changes: 96 additions & 0 deletions
96
...g/src/test/java/org/flowable/spring/test/el/SpringPlanItemJavaDelegateExpressionTest.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,96 @@ | ||
/* 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.spring.test.el; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.flowable.cmmn.api.CmmnRuntimeService; | ||
import org.flowable.cmmn.api.delegate.DelegatePlanItemInstance; | ||
import org.flowable.cmmn.api.delegate.PlanItemJavaDelegate; | ||
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.impl.behavior.CmmnTriggerableActivityBehavior; | ||
import org.flowable.cmmn.engine.impl.persistence.entity.PlanItemInstanceEntity; | ||
import org.flowable.cmmn.engine.impl.util.CommandContextUtil; | ||
import org.flowable.cmmn.engine.test.CmmnDeployment; | ||
import org.flowable.cmmn.engine.test.FlowableCmmnRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Joram Barrez | ||
*/ | ||
public class SpringPlanItemJavaDelegateExpressionTest { | ||
|
||
@Rule | ||
public FlowableCmmnRule cmmnRule = new FlowableCmmnRule("org/flowable/spring/test/el/SpringBeanTest-context.xml"); | ||
|
||
@Test | ||
@CmmnDeployment | ||
public void testCmmnTriggerableActivityBehaviorDelegateExpression() { | ||
CmmnRuntimeService cmmnRuntimeService = cmmnRule.getCmmnRuntimeService(); | ||
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder() | ||
.caseDefinitionKey("myCase") | ||
.start(); | ||
|
||
// The service task here acts like a wait state. | ||
// When the case instance is started, it will wait and be in state ACTIVE. | ||
|
||
PlanItemInstance planItemInstance = cmmnRuntimeService.createPlanItemInstanceQuery().caseInstanceId(caseInstance.getId()).singleResult(); | ||
assertThat(planItemInstance.getState()).isEqualTo(PlanItemInstanceState.ACTIVE); | ||
|
||
// When triggered, the plan item will complete | ||
cmmnRuntimeService.createPlanItemInstanceTransitionBuilder(planItemInstance.getId()).trigger(); | ||
|
||
assertThat(cmmnRule.getCmmnHistoryService().createHistoricPlanItemInstanceQuery().planItemInstanceCaseInstanceId(caseInstance.getId()).singleResult().getState()) | ||
.isEqualTo(PlanItemInstanceState.COMPLETED); | ||
} | ||
|
||
@Test | ||
@CmmnDeployment | ||
public void testPlanItemJavaDelegateExpression() { | ||
CmmnRuntimeService cmmnRuntimeService = cmmnRule.getCmmnRuntimeService(); | ||
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder() | ||
.caseDefinitionKey("myCase") | ||
.start(); | ||
|
||
assertThat(cmmnRule.getCmmnHistoryService().createHistoricVariableInstanceQuery() | ||
.caseInstanceId(caseInstance.getId()).singleResult().getValue()).isEqualTo(true); | ||
} | ||
|
||
public static class TestJavaDelegate01 implements CmmnTriggerableActivityBehavior { | ||
|
||
@Override | ||
public void execute(DelegatePlanItemInstance delegatePlanItemInstance) { | ||
// Do nothing, wait state | ||
} | ||
|
||
@Override | ||
public void trigger(DelegatePlanItemInstance planItemInstance) { | ||
CommandContextUtil.getAgenda().planCompletePlanItemInstanceOperation((PlanItemInstanceEntity) planItemInstance); | ||
} | ||
|
||
} | ||
|
||
public static class TestJavaDelegate02 implements PlanItemJavaDelegate { | ||
|
||
@Override | ||
public void execute(DelegatePlanItemInstance delegatePlanItemInstance) { | ||
delegatePlanItemInstance.setVariable("delegateVariable", true); | ||
} | ||
|
||
} | ||
|
||
|
||
} |
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
20 changes: 20 additions & 0 deletions
20
...ItemJavaDelegateExpressionTest.testCmmnTriggerableActivityBehaviorDelegateExpression.cmmn
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" | ||
xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" | ||
xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" | ||
xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:flowable="http://flowable.org/cmmn" | ||
targetNamespace="http://flowable.org/cmmn"> | ||
|
||
<case id="myCase"> | ||
<casePlanModel id="myPlanModel" name="My CasePlanModel"> | ||
|
||
<planItem id="planItem1" name="Task One" definitionRef="serviceTask" /> | ||
|
||
<task id="serviceTask" flowable:type="java" flowable:delegateExpression="${testTriggerableDelegate01}" /> | ||
|
||
</casePlanModel> | ||
</case> | ||
|
||
</definitions> |
20 changes: 20 additions & 0 deletions
20
.../test/el/SpringPlanItemJavaDelegateExpressionTest.testPlanItemJavaDelegateExpression.cmmn
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions xmlns="http://www.omg.org/spec/CMMN/20151109/MODEL" | ||
xmlns:dc="http://www.omg.org/spec/CMMN/20151109/DC" | ||
xmlns:di="http://www.omg.org/spec/CMMN/20151109/DI" | ||
xmlns:cmmndi="http://www.omg.org/spec/CMMN/20151109/CMMNDI" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:flowable="http://flowable.org/cmmn" | ||
targetNamespace="http://flowable.org/cmmn"> | ||
|
||
<case id="myCase"> | ||
<casePlanModel id="myPlanModel" name="My CasePlanModel"> | ||
|
||
<planItem id="planItem1" name="Task One" definitionRef="serviceTask" /> | ||
|
||
<task id="serviceTask" flowable:type="java" flowable:delegateExpression="${testTriggerableDelegate02}" /> | ||
|
||
</casePlanModel> | ||
</case> | ||
|
||
</definitions> |