diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/BaseConditionFlowTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/BaseConditionFlowTest.java new file mode 100644 index 000000000..06a79ed15 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/BaseConditionFlowTest.java @@ -0,0 +1,109 @@ +package com.yomahub.liteflow.test.condition; + +import com.google.common.collect.Lists; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.entity.data.Slot; +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 org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author ssss + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/condition/application-condition.properties") +@SpringBootTest(classes = BaseConditionFlowTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.condition.cmp1"}) +public class BaseConditionFlowTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + public static final List RUN_TIME_SLOT = Lists.newArrayList(); + + //正常 then,when,多chain可以执行 + @Test + public void testBaseConditionFlow() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getData().printStep()); + } + + //正常 when 多个并联 合并 errorMessage参照上一组配置 导致error异常 都可以继续执行 + @Test + public void testBaseErrorResumeConditionFlow4() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain4", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Assert.assertEquals(2, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); + } + + //正常 when 多个并联 合并 errorMessage参照上一组配置 导致error异常 直接第一组error 就拦截 + @Test + public void testBaseErrorResumeConditionFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain5", "it's a base request"); + System.out.println(response.isSuccess()); + System.out.println(response.getData().printStep()); + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Assert.assertEquals(2, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); + } + + @Test + public void testBaseErrorResumeConditionFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain6", "it's a base request"); + System.out.println(response.isSuccess()); + System.out.println(response.getData().printStep()); + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); + ReflectionUtils.rethrowException(response.getCause()); + } + + + @Test + public void testBaseErrorResumeConditionFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain7", "it's a base request"); + System.out.println(response.isSuccess()); + System.out.println(response.getData().printStep()); + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Assert.assertEquals(2, BaseConditionFlowTest.RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); + } + + @Test + public void testBaseErrorResumeConditionFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain8", "it's a base request"); + System.out.println(response.isSuccess()); + System.out.println(response.getData().printStep()); + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Assert.assertEquals(2, BaseConditionFlowTest.RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ACmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ACmp.java new file mode 100644 index 000000000..b1af3e08b --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ACmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("a") +public class ACmp extends NodeComponent { + @Override + public void process() { + System.out.println("Acomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/BCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/BCmp.java new file mode 100644 index 000000000..36cc501e6 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/BCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("b") +public class BCmp extends NodeComponent { + @Override + public void process() { + System.out.println("Bcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/CCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/CCmp.java new file mode 100644 index 000000000..0d0630e3d --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/CCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("c") +public class CCmp extends NodeComponent { + @Override + public void process() throws Exception { + System.out.println("Ccomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/DCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/DCmp.java new file mode 100644 index 000000000..53a188b7b --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/DCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("d") +public class DCmp extends NodeComponent { + @Override + public void process() throws Exception { + System.out.println("Dcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ECmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ECmp.java new file mode 100644 index 000000000..5b1e01042 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ECmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import org.springframework.stereotype.Component; + + +@Component("e") +public class ECmp extends NodeCondComponent { + + @Override + public String processCond() throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/FCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/FCmp.java new file mode 100644 index 000000000..db2b77c8c --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/FCmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() throws Exception { + System.out.println("Fcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/GCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/GCmp.java new file mode 100644 index 000000000..519f76c05 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/GCmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("g") +public class GCmp extends NodeComponent { + + @Override + public void process() throws Exception { + System.out.println("Gcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/HCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/HCmp.java new file mode 100644 index 000000000..1d9202d2e --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/HCmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("h") +public class HCmp extends NodeComponent { + + @Override + public void process() throws Exception { + System.out.println("Hcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ICmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ICmp.java new file mode 100644 index 000000000..05ff95470 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/ICmp.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.condition.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.test.condition.BaseConditionFlowTest; +import org.springframework.stereotype.Component; + + + +@Component("i") +public class ICmp extends NodeComponent { + + @Override + public void process() throws Exception { + BaseConditionFlowTest.RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + System.out.println(BaseConditionFlowTest.RUN_TIME_SLOT.size()); + System.out.println("Icomp executed! throw Exception!"); + throw new RuntimeException("主动抛出异常"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/resources/condition/application-condition.properties b/liteflow-spring-boot-starter/src/test/resources/condition/application-condition.properties new file mode 100644 index 000000000..15371f39d --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/condition/application-condition.properties @@ -0,0 +1 @@ +liteflow.rule-source=condition/flow.xml \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/condition/application-xml.properties b/liteflow-spring-boot-starter/src/test/resources/condition/application-xml.properties new file mode 100644 index 000000000..15371f39d --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/condition/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=condition/flow.xml \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/condition/flow.xml b/liteflow-spring-boot-starter/src/test/resources/condition/flow.xml new file mode 100644 index 000000000..e87f8d409 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/condition/flow.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md index 6a570571f..72c536c9a 100644 --- a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md +++ b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md @@ -35,7 +35,7 @@ - [x] Json方式在springboot环境下测试 - [x] Yml方式在无spring环境下测试 - [x] Yml方式在spring环境下测试 - - [x] Yml方式在springboot环境下测试 + - [] Yml方式在springboot环境下测试 - [ ] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可) - [ ] 非spring环境下的参数测试,必要参数测试,非必须参数的默认值测试。 @@ -44,16 +44,16 @@ - [ ] zk配置源的功能测试(zk请自己本地安装提供) - [ ] spring环境下的zk配置源功能测试 - [ ] springboot环境下的zk配置源功能测试 -- [ ] 自定义源的功能测试 - - [ ] spring环境下的自定义配置源功能测试 - - [ ] springboot环境下的自定义配置源功能测试 -- [ ] 组件功能点测试(基于springboot环境即可) - - [ ] isAccess方法的功能测试 - - [ ] 组件抛错的功能点测试 - - [ ] isContinueOnError方法的功能点测试 - - [ ] isEnd方法和this.setIsEnd(true)的功能点测试 -- [ ] 条件组件功能点测试(基于springboot环境) - - [ ] 条件组件的功能点测试 +- [x] 自定义源的功能测试 + - [x] spring环境下的自定义配置源功能测试 + - [x] springboot环境下的自定义配置源功能测试 +- [x] 组件功能点测试(基于springboot环境即可) + - [x] isAccess方法的功能测试 + - [x] 组件抛错的功能点测试 + - [x] isContinueOnError方法的功能点测试 + - [x] isEnd方法和this.setIsEnd(true)的功能点测试 +- [x] 条件组件功能点测试(基于springboot环境) + - [x] 条件组件的功能点测试 - [x] 显式子流程测试(基于springboot环境) - [x] 子流程功能点测试,是否能进入子流程 - [x] 多个子流程是否能串联衔接 @@ -62,11 +62,11 @@ - [x] 隐式子流程测试(基于springboot环境) - [x] 隐式子流程的功能点测试 - [x] 多个隐式子流程是否能共享同一个上下文 -- [ ] when condition下的线程池功能测试(基于springboot环境) - - [ ] 线程池的基本功能点测试 - - [ ] 线程池满了情况下基于errorResume参数的功能点测试 -- [ ] when并行组功能测试(基于springboot环境) - - [ ] 默认不配参数情况下并行组的功能点测试 - - [ ] 配置相同并行组情况下的功能点测试 - - [ ] 配置不同并行组情况下的功能点测试 +- [x] when condition下的线程池功能测试(基于springboot环境) + - [x] 线程池的基本功能点测试 + - [x] 线程池满了情况下基于errorResume参数的功能点测试 +- [x] when并行组功能测试(基于springboot环境) + - [x] 默认不配参数情况下并行组的功能点测试 + - [x] 配置相同并行组情况下的功能点测试 + - [x] 配置不同并行组情况下的功能点测试