From 07e4909f7db0bfbc3b2f5ee58c9c5bba6e633449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AF=B7=E5=8F=AB=E6=88=91=E7=8C=BF=E5=8F=94=E5=8F=94?= <1956025812@qq.com> Date: Tue, 28 Sep 2021 20:56:40 +0800 Subject: [PATCH] =?UTF-8?q?https://gitee.com/dromara/liteFlow/issues/I4BGK?= =?UTF-8?q?9=20=E3=80=90=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E3=80=91litef?= =?UTF-8?q?low=E5=BC=80=E5=90=AF=E5=92=8C=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enable/LiteflowEnableSpringbootTest.java | 19 +++++++- .../resources/enable/application.properties | 2 +- .../test/enable/LiteflowEnableSpringTest.java | 45 +++++++++++++++++++ .../liteflow/test/enable/cmp/ACmp.java | 20 +++++++++ .../liteflow/test/enable/cmp/BCmp.java | 21 +++++++++ .../liteflow/test/enable/cmp/CCmp.java | 21 +++++++++ .../resources/enable/application-local.xml | 24 ++++++++++ .../src/test/resources/enable/flow.json | 28 ++++++++++++ 8 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringTest.java create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/BCmp.java create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/CCmp.java create mode 100644 liteflow-testcase-springnative/src/test/resources/enable/application-local.xml create mode 100644 liteflow-testcase-springnative/src/test/resources/enable/flow.json diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringbootTest.java index e5b8ee402..3194e0d71 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringbootTest.java @@ -1,10 +1,14 @@ package com.yomahub.liteflow.test.enable; +import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -12,6 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner; /** * 测试springboot下的enable参数 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -22,8 +27,18 @@ import org.springframework.test.context.junit4.SpringRunner; @ComponentScan({"com.yomahub.liteflow.test.enable.cmp"}) public class LiteflowEnableSpringbootTest extends BaseTest { + @Autowired + private ApplicationContext context; + + @Test - public void testConfig() { - System.out.println("成功启动,并且打印"); + public void testEnable() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + Boolean enable = config.getEnable(); + if (enable) { + System.out.println("成功启动,并且打印"); + return; + } + Assert.assertFalse(enable); } } diff --git a/liteflow-testcase-springboot/src/test/resources/enable/application.properties b/liteflow-testcase-springboot/src/test/resources/enable/application.properties index dfe9a5f9a..64bcf0011 100644 --- a/liteflow-testcase-springboot/src/test/resources/enable/application.properties +++ b/liteflow-testcase-springboot/src/test/resources/enable/application.properties @@ -1,2 +1,2 @@ liteflow.enable=false -liteflow.rule-source=enable/flow.xml \ No newline at end of file +liteflow.rule-source=enable/flow.xml diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringTest.java new file mode 100644 index 000000000..04a2d05e6 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableSpringTest.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.enable; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * spring环境下enable参数 + * + * @author qjwyss + * @since 2.6.0 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/enable/application-local.xml") +public class LiteflowEnableSpringTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + @Autowired + private ApplicationContext context; + + @Test + public void testEnable() throws Exception { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + Boolean enable = config.getEnable(); + if (enable) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + return; + } + + Assert.assertFalse(enable); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java new file mode 100644 index 000000000..1028beae5 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.enable.cmp; + +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("ACmp executed!"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/BCmp.java new file mode 100644 index 000000000..e4ed668c4 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.enable.cmp; + +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("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/CCmp.java new file mode 100644 index 000000000..f4c86c323 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.enable.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/resources/enable/application-local.xml b/liteflow-testcase-springnative/src/test/resources/enable/application-local.xml new file mode 100644 index 000000000..8c70f978f --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/enable/application-local.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/liteflow-testcase-springnative/src/test/resources/enable/flow.json b/liteflow-testcase-springnative/src/test/resources/enable/flow.json new file mode 100644 index 000000000..027f2811f --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/enable/flow.json @@ -0,0 +1,28 @@ +{ + "flow": { + "nodes": { + "node": [ + { + "id": "a", + "class": "com.yomahub.liteflow.test.enable.cmp.ACmp" + }, + { + "id": "b", + "class": "com.yomahub.liteflow.test.enable.cmp.BCmp" + }, + { + "id": "c", + "class": "com.yomahub.liteflow.test.enable.cmp.CCmp" + } + ] + }, + "chain": [ + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a,b,c"} + ] + } + ] + } +}