diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java new file mode 100644 index 000000000..d8427bb67 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java @@ -0,0 +1,46 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.entity.data.Slot; +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.HashSet; +import java.util.Set; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-implicit.properties") +@SpringBootTest(classes = ImplicitSubFlowTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +public class ImplicitSubFlowTest { + @Resource + private FlowExecutor flowExecutor; + + public static final Set RUN_TIME_SLOT = new HashSet<>(); + + //这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain3", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getData().printStep()); + + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java new file mode 100644 index 000000000..bf70613a5 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.entity.data.Slot; +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; + +/** + * 测试显示调用子流程(json) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-json.properties") +@SpringBootTest(classes = SubflowJsonSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowJsonSpringBootTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getData().printStep()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java new file mode 100644 index 000000000..9668c7cef --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.entity.data.Slot; +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; + +/** + * 测试显示调用子流程(xml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-xml.properties") +@SpringBootTest(classes = SubflowXMLSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowXMLSpringBootTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getData().printStep()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java new file mode 100644 index 000000000..4fb8b70b9 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.subflow; + +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.parser.LFParserXmlSpringbootTest; +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; + +/** + * 测试显示调用子流程(yml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-yml.properties") +@SpringBootTest(classes = SubflowYmlSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowYmlSpringBootTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() throws Exception { + LiteflowResponse response = flowExecutor.execute("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getData().printStep()); + } + + +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java new file mode 100644 index 000000000..75a7fb49b --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.subflow.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/subflow/cmp1/BCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java new file mode 100644 index 000000000..9fb3c9326 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.subflow.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/subflow/cmp1/CCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java new file mode 100644 index 000000000..ce8ea149f --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.subflow.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/subflow/cmp1/DCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java new file mode 100644 index 000000000..309196e9b --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.subflow.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/subflow/cmp1/ECmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java new file mode 100644 index 000000000..b855a1ae0 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + + +@Component("e") +public class ECmp extends NodeComponent { + + @Override + public void process() throws Exception { + System.out.println("Ecomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java new file mode 100644 index 000000000..f55e796e9 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; + + +@Component("f") +public class FCmp extends NodeComponent { + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlotIndex()); + + System.out.println("Fcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java new file mode 100644 index 000000000..96e0952b8 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; + + +@Component("g") +public class GCmp extends NodeComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlotIndex()); + + System.out.println("Gcomp executed!"); + + flowExecutor.invoke("chain4", "it's implicit subflow.", DefaultSlot.class, this.getSlotIndex()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java new file mode 100644 index 000000000..2f3352eba --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; + + +@Component("h") +public class HCmp extends NodeComponent { + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlotIndex()); + + System.out.println("Hcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java new file mode 100644 index 000000000..1b185bb7c --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; + + +@Component("m") +public class MCmp extends NodeComponent { + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlotIndex()); + + System.out.println("Mcomp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md index 340f12fb1..6a570571f 100644 --- a/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md +++ b/liteflow-spring-boot-starter/src/test/resources/liteflow单测.md @@ -54,14 +54,14 @@ - [ ] isEnd方法和this.setIsEnd(true)的功能点测试 - [ ] 条件组件功能点测试(基于springboot环境) - [ ] 条件组件的功能点测试 -- [ ] 显式子流程测试(基于springboot环境) - - [ ] 子流程功能点测试,是否能进入子流程 - - [ ] 多个子流程是否能串联衔接 - - [ ] 同名节点和同名chain是否chain为优先级最高 - - [ ] 多个子流程配置顺序是否和最终执行结果无关(这个需要结合xml,json,yml来测,分3种配置方式,因为这个和parser有一定的关系) -- [ ] 隐式子流程测试(基于springboot环境) - - [ ] 隐式子流程的功能点测试 - - [ ] 多个隐式子流程是否能共享同一个上下文 +- [x] 显式子流程测试(基于springboot环境) + - [x] 子流程功能点测试,是否能进入子流程 + - [x] 多个子流程是否能串联衔接 + - [x] 同名节点和同名chain是否节点为优先级最高 + - [x] 多个子流程配置顺序是否和最终执行结果无关(这个需要结合xml,json,yml来测,分3种配置方式,因为这个和parser有一定的关系) +- [x] 隐式子流程测试(基于springboot环境) + - [x] 隐式子流程的功能点测试 + - [x] 多个隐式子流程是否能共享同一个上下文 - [ ] when condition下的线程池功能测试(基于springboot环境) - [ ] 线程池的基本功能点测试 - [ ] 线程池满了情况下基于errorResume参数的功能点测试 diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/application-implicit.properties b/liteflow-spring-boot-starter/src/test/resources/subflow/application-implicit.properties new file mode 100644 index 000000000..3fc4f024e --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/application-implicit.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow-implicit.xml \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/application-json.properties b/liteflow-spring-boot-starter/src/test/resources/subflow/application-json.properties new file mode 100644 index 000000000..7ca7b7bec --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.json \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/application-xml.properties b/liteflow-spring-boot-starter/src/test/resources/subflow/application-xml.properties new file mode 100644 index 000000000..1abd50496 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.xml \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/application-yml.properties b/liteflow-spring-boot-starter/src/test/resources/subflow/application-yml.properties new file mode 100644 index 000000000..72074ec82 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.yml \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/flow-implicit.xml b/liteflow-spring-boot-starter/src/test/resources/subflow/flow-implicit.xml new file mode 100644 index 000000000..5baca7072 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/flow-implicit.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/flow.json b/liteflow-spring-boot-starter/src/test/resources/subflow/flow.json new file mode 100644 index 000000000..143589315 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/flow.json @@ -0,0 +1,33 @@ +{ + "flow": { + "chain": [ + { + "name": "chain3", + "condition": [ + {"type": "then", "value": "e,d"} + ] + }, + { + "name": "chain2", + "condition": [ + {"type": "then", "value": "b,a"}, + {"type": "then", "value": "chain3"} + ] + }, + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a,b"}, + {"type": "then", "value": "c"}, + {"type": "then", "value": "chain2"} + ] + }, + { + "name": "c", + "condition": [ + {"type": "then", "value": "d,e"} + ] + } + ] + } +} \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/flow.xml b/liteflow-spring-boot-starter/src/test/resources/subflow/flow.xml new file mode 100644 index 000000000..03cf81299 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/flow.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/subflow/flow.yml b/liteflow-spring-boot-starter/src/test/resources/subflow/flow.yml new file mode 100644 index 000000000..cdd8de74b --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/subflow/flow.yml @@ -0,0 +1,24 @@ +flow: + chain: + - name: chain3 + condition: + - type: then + value: 'e,d' + - name: chain1 + condition: + - type: then + value: 'a,b' + - type: then + value: 'c' + - type: then + value: 'chain2' + - name: c + condition: + - type: then + value: 'd,e' + - name: chain2 + condition: + - type: then + value: 'b,a' + - type: then + value: 'chain3' \ No newline at end of file