From f37c6f64622a8cd975760868fdfcb2d970c5e4e1 Mon Sep 17 00:00:00 2001 From: bryan31 Date: Sun, 4 Apr 2021 23:33:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/parser/LFParserJsonNoSpringTest.java | 3 +- .../test/parser/LFParserJsonSpringTest.java | 27 +++++++++++++ .../parser/LFParserJsonSpringbootTest.java | 5 ++- .../test/parser/LFParserXmlNoSpringTest.java | 3 +- .../test/parser/LFParserXmlSpringTest.java | 5 +++ .../parser/LFParserXmlSpringbootTest.java | 3 +- .../test/parser/LFParserYmlNoSpringTest.java | 28 +++++++++++++ .../test/parser/LFParserYmlSpringTest.java | 32 +++++++++++++++ .../parser/LFParserYmlSpringbootTest.java | 38 ++++++++++++++++++ .../resources/parser/application-json.xml | 23 +++++++++++ .../test/resources/parser/application-yml.xml | 23 +++++++++++ .../src/test/resources/parser/flow.yml | 40 ++++++------------- 12 files changed, 197 insertions(+), 33 deletions(-) create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringTest.java create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringTest.java create mode 100644 liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringbootTest.java create mode 100644 liteflow-spring-boot-starter/src/test/resources/parser/application-json.xml create mode 100644 liteflow-spring-boot-starter/src/test/resources/parser/application-yml.xml diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java index 95984232..4964c2c5 100644 --- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java @@ -8,8 +8,9 @@ import org.junit.Assert; import org.junit.Test; /** - * 切面场景单元测试 + * 无spring环境的json parser单元测试 * @author Bryan.Zhang + * @since 2.5.0 */ public class LFParserJsonNoSpringTest { diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringTest.java new file mode 100644 index 00000000..b0feb0bc --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringTest.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test.parser; + +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.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/parser/application-json.xml") +public class LFParserJsonSpringTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试spring场景的xml parser + @Test + public void testSpring() throws Exception{ + LiteflowResponse response = flowExecutor.execute("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringbootTest.java index 4bd3b940..d0ecef59 100644 --- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringbootTest.java +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonSpringbootTest.java @@ -15,8 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 切面场景单元测试 + * spring环境的json parser单元测试 * @author Bryan.Zhang + * @since 2.5.0 */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/parser/application-json.properties") @@ -28,7 +29,7 @@ public class LFParserJsonSpringbootTest { @Resource private FlowExecutor flowExecutor; - //测试无springboot场景的json parser + //测试spring场景的json parser @Test public void testSpringboot() throws Exception{ LiteflowResponse response = flowExecutor.execute("chain2", "arg"); diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java index 6dd45062..58e145cb 100644 --- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java @@ -8,8 +8,9 @@ import org.junit.Assert; import org.junit.Test; /** - * 切面场景单元测试 + * 无spring环境的xml parser单元测试 * @author Bryan.Zhang + * @since 2.5.0 */ public class LFParserXmlNoSpringTest { diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringTest.java index efe5e343..f7666ae5 100644 --- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringTest.java +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringTest.java @@ -11,6 +11,11 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; +/** + * spring环境的xml parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/parser/application-xml.xml") public class LFParserXmlSpringTest { diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringbootTest.java index 38c06c39..0e59b088 100644 --- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringbootTest.java +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlSpringbootTest.java @@ -16,8 +16,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 切面场景单元测试 + * springboot环境的xml parser单元测试 * @author Bryan.Zhang + * @since 2.5.0 */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/parser/application-xml.properties") diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java new file mode 100644 index 00000000..07f8171d --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.property.LiteflowConfig; +import org.junit.Assert; +import org.junit.Test; + +/** + * 无spring环境的yml parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +public class LFParserYmlNoSpringTest { + + //测试无spring场景的yml parser + @Test + public void testNoSpring() throws Exception{ + FlowExecutor executor = new FlowExecutor(); + LiteflowConfig liteflowConfig = new LiteflowConfig(); + liteflowConfig.setRuleSource("parser/flow.yml"); + executor.setLiteflowConfig(liteflowConfig); + executor.init(); + LiteflowResponse response = executor.execute("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringTest.java new file mode 100644 index 00000000..4a129e54 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringTest.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.test.parser; + +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.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * spring环境的xml parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/parser/application-yml.xml") +public class LFParserYmlSpringTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试spring场景的xml parser + @Test + public void testSpring() throws Exception{ + LiteflowResponse response = flowExecutor.execute("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringbootTest.java new file mode 100644 index 00000000..018ad49e --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.parser; + +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; + +/** + * springboot下的yml parser测试用例 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-yml.properties") +@SpringBootTest(classes = LFParserYmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class LFParserYmlSpringbootTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试无springboot场景的yml parser + @Test + public void testSpringboot() throws Exception{ + LiteflowResponse response = flowExecutor.execute("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/resources/parser/application-json.xml b/liteflow-spring-boot-starter/src/test/resources/parser/application-json.xml new file mode 100644 index 00000000..097caad3 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/parser/application-json.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/parser/application-yml.xml b/liteflow-spring-boot-starter/src/test/resources/parser/application-yml.xml new file mode 100644 index 00000000..fa166b5a --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/parser/application-yml.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/parser/flow.yml b/liteflow-spring-boot-starter/src/test/resources/parser/flow.yml index 6de4e479..814f59d5 100644 --- a/liteflow-spring-boot-starter/src/test/resources/parser/flow.yml +++ b/liteflow-spring-boot-starter/src/test/resources/parser/flow.yml @@ -2,45 +2,29 @@ flow: nodes: node: - id: a - class: com.yomahub.liteflow.test.component.AComponent + class: com.yomahub.liteflow.test.parser.cmp.ACmp - id: b - class: com.yomahub.liteflow.test.component.BComponent + class: com.yomahub.liteflow.test.parser.cmp.BCmp - id: c - class: com.yomahub.liteflow.test.component.CComponent + class: com.yomahub.liteflow.test.parser.cmp.CCmp - id: d - class: com.yomahub.liteflow.test.component.DComponent + class: com.yomahub.liteflow.test.parser.cmp.DCmp - id: e - class: com.yomahub.liteflow.test.component.EComponent + class: com.yomahub.liteflow.test.parser.cmp.ECmp - id: f - class: com.yomahub.liteflow.test.component.FComponent + class: com.yomahub.liteflow.test.parser.cmp.FCmp - id: g - class: com.yomahub.liteflow.test.component.GComponent - - id: cond - class: com.yomahub.liteflow.test.component.CondComponent + class: com.yomahub.liteflow.test.parser.cmp.GCmp chain: - name: chain1 condition: - type: then - value: 'a,cond(b|d)' + value: 'a,c' + - type: when + value: 'b,d,e(f|g)' - type: then - value: 'e,f,g' + value: 'chain2' - name: chain2 condition: - type: then - value: 'a,c' - - type: when - value: 'b,d,e,f,g' - - type: then - value: 'c' - - name: chain3 - condition: - - type: then - value: 'a,c,strategy1,g' - - name: strategy1 - condition: - - type: then - value: m(m1|m2|strategy2) - - name: strategy2 - condition: - - type: then - value: 'q,p(p1|p2)' + value: 'c,g,f'