From abb888e40ac0507b40d6f516a5d9240ccdadc1a5 Mon Sep 17 00:00:00 2001 From: LeoLee <512240816@qq.com> Date: Sat, 11 Dec 2021 21:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/nullParam/NullParamTest.java | 43 +++++++++++++++++++ .../liteflow/test/nullParam/cmp/ACmp.java | 22 ++++++++++ .../liteflow/test/nullParam/cmp/BCmp.java | 23 ++++++++++ .../liteflow/test/nullParam/cmp/CCmp.java | 22 ++++++++++ .../nullParam/application.properties | 2 + .../src/test/resources/nullParam/flow.xml | 8 ++++ .../test/nullParam/NullParamTest.java | 38 ++++++++++++++++ .../liteflow/test/nullParam/cmp/ACmp.java | 22 ++++++++++ .../liteflow/test/nullParam/cmp/BCmp.java | 23 ++++++++++ .../liteflow/test/nullParam/cmp/CCmp.java | 22 ++++++++++ .../resources/nullParam/application-local.xml | 23 ++++++++++ .../src/test/resources/nullParam/flow.xml | 8 ++++ 12 files changed, 256 insertions(+) create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java create mode 100644 liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java create mode 100644 liteflow-testcase-springboot/src/test/resources/nullParam/application.properties create mode 100644 liteflow-testcase-springboot/src/test/resources/nullParam/flow.xml create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java create mode 100644 liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java create mode 100644 liteflow-testcase-springnative/src/test/resources/nullParam/application-local.xml create mode 100644 liteflow-testcase-springnative/src/test/resources/nullParam/flow.xml diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java new file mode 100644 index 000000000..26bc2d2f8 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java @@ -0,0 +1,43 @@ +package com.yomahub.liteflow.test.nullParam; + +import com.yomahub.liteflow.core.FlowExecutor; +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.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * 单元测试:传递null param导致NPE的优化代码 + * + * @Author LeoLee + * @Date 2021/12/9 16:58 + * @Version 1.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/nullParam/application.properties") +@SpringBootTest(classes = NullParamTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.nullParam.cmp"}) +public class NullParamTest { + + @Autowired + private FlowExecutor flowExecutor; + + /** + * 支持无参的flow执行,以及param 为null时的异常抛出 + * @Author LeoLee + * @Date 17:25 2021/12/9 + */ + @Test + public void testNullParam() throws Exception { + //flowExecutor.execute("chain1", null);//NullParamException: data slot can't accept null param + flowExecutor.execute("chain1"); + //flowExecutor.execute2Resp("chain1", null);//NullParamException: data slot can't accept null param + flowExecutor.execute2Resp("chain1"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java new file mode 100644 index 000000000..3acf3c2c8 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nullParam.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!"); + System.out.println("get request data:" + this.getSlot().getRequestData()); + this.getSlot().setInput("BCmp", "param for BCmp"); + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java new file mode 100644 index 000000000..52bdc4633 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nullParam.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!"); + System.out.println("BCmp param:" + this.getSlot().getInput("BCmp")); + this.getSlot().setOutput("CCmp", "param for CCmp"); + } + +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java new file mode 100644 index 000000000..5707caf27 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nullParam.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!"); + System.out.println("CCmp param:" + this.getSlot().getOutput("CCmp")); + } + +} diff --git a/liteflow-testcase-springboot/src/test/resources/nullParam/application.properties b/liteflow-testcase-springboot/src/test/resources/nullParam/application.properties new file mode 100644 index 000000000..e98eccac3 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/nullParam/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=nullParam/flow.xml +liteflow.print-banner=true diff --git a/liteflow-testcase-springboot/src/test/resources/nullParam/flow.xml b/liteflow-testcase-springboot/src/test/resources/nullParam/flow.xml new file mode 100644 index 000000000..cd45c1a17 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/resources/nullParam/flow.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java new file mode 100644 index 000000000..709544449 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.nullParam; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.test.BaseTest; +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; + +/** + * 单元测试:传递null param导致NPE的优化代码 + * + * @Author LeoLee + * @Date 2021/12/11 + * @Version V1.0 + **/ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/nullParam/application-local.xml") +public class NullParamTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + /** + * 支持无参的flow执行,以及param 为null时的异常抛出 + * @Author: LeoLee + * @Date: 2021/12/11 21:38 + */ + @Test + public void testNullParam() throws Exception { + //flowExecutor.execute("chain1", null);//NullParamException: data slot can't accept null param + flowExecutor.execute("chain1"); + //flowExecutor.execute2Resp("chain1", null);//NullParamException: data slot can't accept null param + flowExecutor.execute2Resp("chain1"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java new file mode 100644 index 000000000..3acf3c2c8 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nullParam.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!"); + System.out.println("get request data:" + this.getSlot().getRequestData()); + this.getSlot().setInput("BCmp", "param for BCmp"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java new file mode 100644 index 000000000..52bdc4633 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/BCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nullParam.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!"); + System.out.println("BCmp param:" + this.getSlot().getInput("BCmp")); + this.getSlot().setOutput("CCmp", "param for CCmp"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java new file mode 100644 index 000000000..5707caf27 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/CCmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nullParam.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!"); + System.out.println("CCmp param:" + this.getSlot().getOutput("CCmp")); + } + +} diff --git a/liteflow-testcase-springnative/src/test/resources/nullParam/application-local.xml b/liteflow-testcase-springnative/src/test/resources/nullParam/application-local.xml new file mode 100644 index 000000000..36bf18e53 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/nullParam/application-local.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/liteflow-testcase-springnative/src/test/resources/nullParam/flow.xml b/liteflow-testcase-springnative/src/test/resources/nullParam/flow.xml new file mode 100644 index 000000000..cd45c1a17 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/nullParam/flow.xml @@ -0,0 +1,8 @@ + + + + + + + +