diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java index bc3482f3a..8988f8bc4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java @@ -42,16 +42,6 @@ public abstract class Condition implements Executable{ //如果对于子流程来说,那这个就是子流程所在的Chain private String currChainName; - @Override - public void execute(Integer slotIndex) throws Exception { - String currChainName = this.getCurrChainName(); - //设置当前ChainName - this.getExecutableList().forEach(executable -> executable.setCurrChainName(currChainName)); - executeCondition(slotIndex); - } - - protected abstract void executeCondition(Integer slotIndex) throws Exception; - @Override public ExecuteTypeEnum getExecuteType() { return ExecuteTypeEnum.CONDITION; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java index e7f4f56c1..51a17f541 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java @@ -18,8 +18,9 @@ import com.yomahub.liteflow.flow.element.Executable; public class FinallyCondition extends Condition { @Override - public void executeCondition(Integer slotIndex) throws Exception { + public void execute(Integer slotIndex) throws Exception { for(Executable executableItem : this.getExecutableList()){ + executableItem.setCurrChainName(this.getCurrChainName()); executableItem.execute(slotIndex); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java index 6e3cf62d5..6b98b77ac 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java @@ -18,8 +18,9 @@ import com.yomahub.liteflow.flow.element.Executable; public class PreCondition extends Condition { @Override - public void executeCondition(Integer slotIndex) throws Exception { + public void execute(Integer slotIndex) throws Exception { for(Executable executableItem : this.getExecutableList()){ + executableItem.setCurrChainName(this.getCurrChainName()); executableItem.execute(slotIndex); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java index 610b3684e..d6ad659b8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java @@ -26,9 +26,10 @@ public class SwitchCondition extends Condition{ private final Map targetMap = new HashMap<>(); @Override - public void executeCondition(Integer slotIndex) throws Exception { + public void execute(Integer slotIndex) throws Exception { if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())){ //先执行switch节点 + this.getSwitchNode().setCurrChainName(this.getCurrChainName()); this.getSwitchNode().execute(slotIndex); //根据switch节点执行出来的结果选择 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java index 82086f730..d07b0d64f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java @@ -21,12 +21,13 @@ public class ThenCondition extends Condition { } @Override - public void executeCondition(Integer slotIndex) throws Exception { + public void execute(Integer slotIndex) throws Exception { for (Executable executableItem : this.getExecutableList()) { //前置和后置组不执行,因为在build的时候会抽出来放在chain里面 if (executableItem instanceof PreCondition || executableItem instanceof FinallyCondition){ continue; } + executableItem.setCurrChainName(this.getCurrChainName()); executableItem.execute(slotIndex); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java index e4f9fa115..1b65c8df5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java @@ -37,7 +37,7 @@ public class WhenCondition extends Condition { @Override - public void executeCondition(Integer slotIndex) throws Exception { + public void execute(Integer slotIndex) throws Exception { executeAsyncCondition(slotIndex); } @@ -51,6 +51,8 @@ public class WhenCondition extends Condition { private void executeAsyncCondition(Integer slotIndex) throws Exception{ Slot slot = DataBus.getSlot(slotIndex); + String currChainName = this.getCurrChainName(); + //此方法其实只会初始化一次Executor,不会每次都会初始化。Executor是唯一的 ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutor(this.getThreadExecutorClass()); @@ -78,7 +80,7 @@ public class WhenCondition extends Condition { } }).map(executable -> CompletableFutureTimeout.completeOnTimeout( WhenFutureObj.timeOut(executable.getExecuteName()), - CompletableFuture.supplyAsync(new ParallelSupplier(executable, slotIndex), parallelExecutor), + CompletableFuture.supplyAsync(new ParallelSupplier(executable, currChainName, slotIndex), parallelExecutor), liteflowConfig.getWhenMaxWaitSeconds(), TimeUnit.SECONDS )).collect(Collectors.toList()); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/ParallelSupplier.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/ParallelSupplier.java index b057e7685..0d3f37c6d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/ParallelSupplier.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/ParallelSupplier.java @@ -16,16 +16,20 @@ public class ParallelSupplier implements Supplier { private final Executable executableItem; + private final String currChainName; + private final Integer slotIndex; - public ParallelSupplier(Executable executableItem, Integer slotIndex) { + public ParallelSupplier(Executable executableItem, String currChainName, Integer slotIndex) { this.executableItem = executableItem; + this.currChainName = currChainName; this.slotIndex = slotIndex; } @Override public WhenFutureObj get() { try { + executableItem.setCurrChainName(currChainName); executableItem.execute(slotIndex); return WhenFutureObj.success(executableItem.getExecuteName()); } catch (Exception e){ diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java new file mode 100644 index 000000000..76e4af170 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java @@ -0,0 +1,60 @@ +package com.yomahub.liteflow.test.getChainName; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境获取ChainName的测试 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/getChainName/application.properties") +@SpringBootTest(classes = GetChainNameELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.getChainName.cmp"}) +public class GetChainNameELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testGetChainName1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } + + @Test + public void testGetChainName2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java new file mode 100644 index 000000000..90fe3f145 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java new file mode 100644 index 000000000..a9f202cdb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java new file mode 100644 index 000000000..2bb23b1fd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java new file mode 100644 index 000000000..8fa5a2265 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java new file mode 100644 index 000000000..d9314b43a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + if (context.hasData(bindCmp.getNodeId())){ + context.setData(bindCmp.getNodeId(), context.getData(bindCmp.getNodeId()) + "_" + bindCmp.getCurrChainName()); + }else{ + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java new file mode 100644 index 000000000..00fe59dd3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java new file mode 100644 index 000000000..0fd79a63f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java new file mode 100644 index 000000000..205aed7b9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java @@ -0,0 +1,29 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("h") +@LiteflowSwitchCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_SWITCH) + public String processSwitch(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + return "j"; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java new file mode 100644 index 000000000..3cbf4f03c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("j") +@LiteflowCmpDefine +public class JCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java new file mode 100644 index 000000000..0ebc0f9bb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("k") +@LiteflowCmpDefine +public class KCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/getChainName/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/getChainName/application.properties new file mode 100644 index 000000000..14cfce7c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/getChainName/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=getChainName/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/getChainName/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/getChainName/flow.el.xml new file mode 100644 index 000000000..6c033d839 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/getChainName/flow.el.xml @@ -0,0 +1,38 @@ + + + + WHEN(sub1, sub2, sub3, sub4); + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(d); + + + + THEN(e, f); + + + + SWITCH(h).to(j, k); + + + + THEN( + g, + WHEN(sub1, WHEN(sub2, sub3)), + sub4, sub5, e, sub6 + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELTest.java new file mode 100644 index 000000000..bff523d48 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELTest.java @@ -0,0 +1,56 @@ +package com.yomahub.liteflow.test.getChainName; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * nospring环境获取ChainName的测试 + * @author Bryan.Zhang + */ +public class GetChainNameELTest extends BaseTest { + + private static FlowExecutor flowExecutor; + + @BeforeClass + public static void init(){ + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("getChainName/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testGetChainName1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } + + @Test + public void testGetChainName2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java new file mode 100644 index 000000000..39d61a16a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class ACmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java new file mode 100644 index 000000000..33826ddc8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class BCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java new file mode 100644 index 000000000..94f8b51e4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class CCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java new file mode 100644 index 000000000..c80aa3347 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java new file mode 100644 index 000000000..c0e1b96fe --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class ECmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + if (context.hasData(this.getNodeId())){ + context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainName()); + }else{ + context.setData(this.getNodeId(), this.getCurrChainName()); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java new file mode 100644 index 000000000..ecb6bd4ff --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java new file mode 100644 index 000000000..7f5ebb593 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class GCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java new file mode 100644 index 000000000..d9d68e79e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class HCmp extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + return "j"; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java new file mode 100644 index 000000000..04fbc2b16 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class JCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java new file mode 100644 index 000000000..76bbfd4c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class KCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/getChainName/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/getChainName/flow.el.xml new file mode 100644 index 000000000..55eebe22b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/getChainName/flow.el.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + WHEN(sub1, sub2, sub3, sub4); + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(d); + + + + THEN(e, f); + + + + SWITCH(h).to(j, k); + + + + THEN( + g, + WHEN(sub1, WHEN(sub2, sub3)), + sub4, sub5, e, sub6 + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java index 38586a4f3..5fa15051e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java @@ -16,7 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境EL常规的例子测试 + * springboot环境获取ChainName的测试 * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @@ -29,7 +29,6 @@ public class GetChainNameELSpringbootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; - //最简单的情况 @Test public void testGetChainName1() throws Exception{ LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); @@ -41,4 +40,21 @@ public class GetChainNameELSpringbootTest extends BaseTest { Assert.assertEquals("sub4", context.getData("d")); } + @Test + public void testGetChainName2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java new file mode 100644 index 000000000..858ba7e30 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("e") +public class ECmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + if (context.hasData(this.getNodeId())){ + context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainName()); + }else{ + context.setData(this.getNodeId(), this.getCurrChainName()); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java new file mode 100644 index 000000000..685f6bf78 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java new file mode 100644 index 000000000..a04b2a2ec --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("g") +public class GCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java new file mode 100644 index 000000000..ac0e22a78 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("h") +public class HCmp extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + return "j"; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java new file mode 100644 index 000000000..0e9052cc4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("j") +public class JCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java new file mode 100644 index 000000000..6d2d01652 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("k") +public class KCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/getChainName/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/getChainName/flow.el.xml index c5a2d6549..6c033d839 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/getChainName/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/getChainName/flow.el.xml @@ -19,4 +19,20 @@ THEN(d); + + + THEN(e, f); + + + + SWITCH(h).to(j, k); + + + + THEN( + g, + WHEN(sub1, WHEN(sub2, sub3)), + sub4, sub5, e, sub6 + ); + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringTest.java new file mode 100644 index 000000000..74fea4fd3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringTest.java @@ -0,0 +1,54 @@ +package com.yomahub.liteflow.test.getChainName; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * spring环境获取ChainName的测试 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/getChainName/application.xml") +public class GetChainNameELSpringTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testGetChainName1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } + + @Test + public void testGetChainName2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java new file mode 100644 index 000000000..47aa2aa46 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java new file mode 100644 index 000000000..97d505bd5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java new file mode 100644 index 000000000..054f8e638 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java new file mode 100644 index 000000000..8aa5b9a35 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java new file mode 100644 index 000000000..858ba7e30 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("e") +public class ECmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + if (context.hasData(this.getNodeId())){ + context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainName()); + }else{ + context.setData(this.getNodeId(), this.getCurrChainName()); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java new file mode 100644 index 000000000..685f6bf78 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java new file mode 100644 index 000000000..a04b2a2ec --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("g") +public class GCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java new file mode 100644 index 000000000..ac0e22a78 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("h") +public class HCmp extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + return "j"; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java new file mode 100644 index 000000000..0e9052cc4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("j") +public class JCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java new file mode 100644 index 000000000..6d2d01652 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("k") +public class KCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData(this.getNodeId(), this.getCurrChainName()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/getChainName/application.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/getChainName/application.xml new file mode 100644 index 000000000..048015cf5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/getChainName/application.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/getChainName/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/getChainName/flow.el.xml new file mode 100644 index 000000000..6c033d839 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/getChainName/flow.el.xml @@ -0,0 +1,38 @@ + + + + WHEN(sub1, sub2, sub3, sub4); + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(d); + + + + THEN(e, f); + + + + SWITCH(h).to(j, k); + + + + THEN( + g, + WHEN(sub1, WHEN(sub2, sub3)), + sub4, sub5, e, sub6 + ); + + \ No newline at end of file