diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java index 25e37914f..025161b60 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java @@ -1,5 +1,7 @@ package com.yomahub.liteflow.test.loop; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.slot.DefaultContext; @@ -14,6 +16,9 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; /** * springboot环境EL循环的例子测试 @@ -93,4 +98,14 @@ public class LoopELSpringbootTest extends BaseTest { Assert.assertEquals("01234", context.getData("loop_e3")); } + // 测试嵌套循环 + @Test + public void testLoop8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + DefaultContext context = response.getFirstContextBean(); + List list = context.getData("test"); + String str = StrUtil.join(StrUtil.EMPTY, list); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("001101201", str); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/FCmp.java new file mode 100644 index 000000000..7b25b1fad --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/FCmp.java @@ -0,0 +1,33 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.loop.cmp; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + int loopIndex = this.getLoopIndex(); + DefaultContext context = this.getFirstContextBean(); + if (context.hasData("test")){ + List list = context.getData("test"); + list.add(loopIndex); + }else{ + List list = ListUtil.toList(loopIndex); + context.setData("test", list); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/loop/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/loop/flow.xml index 7bb3b9280..7ee5c0d8c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/loop/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/loop/flow.xml @@ -39,4 +39,13 @@ ) ); + + + FOR(3).DO( + THEN( + f, + FOR(2).DO(f) + ) + ); + \ No newline at end of file