增加嵌套循环的测试用例

This commit is contained in:
everywhere.z
2023-03-22 15:34:11 +08:00
parent 308698145a
commit 98f5ddfb1e
3 changed files with 57 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}
}

View File

@@ -39,4 +39,13 @@
)
);
</chain>
<chain name="chain8">
FOR(3).DO(
THEN(
f,
FOR(2).DO(f)
)
);
</chain>
</flow>