mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
增加嵌套循环的测试用例
This commit is contained in:
@@ -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<Integer> list = context.getData("test");
|
||||
String str = StrUtil.join(StrUtil.EMPTY, list);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("001101201", str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @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<Integer> list = context.getData("test");
|
||||
list.add(loopIndex);
|
||||
}else{
|
||||
List<Integer> list = ListUtil.toList(loopIndex);
|
||||
context.setData("test", list);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,4 +39,13 @@
|
||||
)
|
||||
);
|
||||
</chain>
|
||||
|
||||
<chain name="chain8">
|
||||
FOR(3).DO(
|
||||
THEN(
|
||||
f,
|
||||
FOR(2).DO(f)
|
||||
)
|
||||
);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user