mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
feature #I6A2GL 增加迭代器表达式特性,用于迭代循环中的集合
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.yomahub.liteflow.test.iterator;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* springboot环境最普通的例子测试
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/iterator/application.properties")
|
||||
@SpringBootTest(classes = IteratorELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.iterator.cmp"})
|
||||
public class IteratorELDeclMultiSpringbootTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
//最简单的情况
|
||||
@Test
|
||||
public void testIt1() throws Exception{
|
||||
List<String> list = ListUtil.toList("1","2","3");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", list);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
String str = context.getData("test");
|
||||
Assert.assertEquals("123", str);
|
||||
}
|
||||
|
||||
//迭代器带break
|
||||
@Test
|
||||
public void testIt2() throws Exception{
|
||||
List<String> list = ListUtil.toList("1","2","3");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", list);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
String str = context.getData("test");
|
||||
Assert.assertEquals("12", str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.yomahub.liteflow.test.iterator.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.annotation.LiteflowMethod;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.base.cmp.TestDomain;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@LiteflowComponent
|
||||
public class CmpConfig {
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
|
||||
public void processA(NodeComponent bindCmp) {
|
||||
String key = "test";
|
||||
DefaultContext context = bindCmp.getFirstContextBean();
|
||||
if (!context.hasData(key)){
|
||||
context.setData(key, bindCmp.getCurrLoopObj());
|
||||
}else{
|
||||
String str = context.getData(key);
|
||||
str += bindCmp.getCurrLoopObj();
|
||||
context.setData(key, str);
|
||||
}
|
||||
}
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "b", nodeType = NodeTypeEnum.BREAK)
|
||||
public boolean processB(NodeComponent bindCmp) {
|
||||
return bindCmp.getLoopIndex() == 1;
|
||||
}
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "it", nodeType = NodeTypeEnum.ITERATOR)
|
||||
public Iterator<?> processIT(NodeComponent bindCmp) {
|
||||
List<String> list = bindCmp.getRequestData();
|
||||
return list.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=iterator/flow.xml
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
ITERATOR(it).DO(a);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
ITERATOR(it).DO(a).BREAK(b);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user