diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest.java index 0ececacb5..a2518b089 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest.java @@ -24,7 +24,6 @@ import javax.annotation.Resource; @RunWith(SpringRunner.class) @SpringBootTest(classes = BuilderSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.builder.cmp"}) public class BuilderSpringbootTest extends BaseTest { @Resource diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java index 12fb3cb82..8edfa211c 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java @@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境下异步线程超时日志打印测试 + * springboot环境下自定义声明节点的测试 * @author Bryan.Zhang * @since 2.6.4 */ diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadExecutor.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadExecutor.java deleted file mode 100644 index 0985362bb..000000000 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadExecutor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.yomahub.liteflow.test.customThreadPool; - -import com.yomahub.liteflow.thread.ExecutorBuilder; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomThreadExecutor implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - return Executors.newCachedThreadPool(); - } -} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadPoolSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadPoolSpringbootTest.java deleted file mode 100644 index 67a7a2ebd..000000000 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadPoolSpringbootTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.yomahub.liteflow.test.customThreadPool; - -import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.entity.data.DefaultSlot; -import com.yomahub.liteflow.entity.data.LiteflowResponse; -import com.yomahub.liteflow.test.BaseTest; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -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环境下异步线程超时日志打印测试 - * @author Bryan.Zhang - * @since 2.6.4 - */ -@RunWith(SpringRunner.class) -@TestPropertySource(value = "classpath:/customThreadPool/application.properties") -@SpringBootTest(classes = CustomThreadPoolSpringbootTest.class) -@EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customThreadPool.cmp"}) -public class CustomThreadPoolSpringbootTest extends BaseTest { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - @Resource - private FlowExecutor flowExecutor; - - @Test - public void testCustomThreadPool() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertFalse(response.getSlot().getData("threadName").toString().startsWith("lf-when-thead")); - } -} 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 3194e0d71..b75e94701 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,6 +1,8 @@ package com.yomahub.liteflow.test.enable; import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; import com.yomahub.liteflow.test.BaseTest; import org.junit.Assert; import org.junit.Test; @@ -27,13 +29,9 @@ 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 testEnable() { - LiteflowConfig config = context.getBean(LiteflowConfig.class); + LiteflowConfig config = LiteflowConfigGetter.get(); Boolean enable = config.getEnable(); if (enable) { System.out.println("成功启动,并且打印"); diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/FlowExecutorSpringBootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java similarity index 84% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/FlowExecutorSpringBootTest.java rename to liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java index 3cb043358..de1c3a285 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/FlowExecutorSpringBootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java @@ -3,7 +3,6 @@ package com.yomahub.liteflow.test.exception; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.entity.data.DefaultSlot; import com.yomahub.liteflow.entity.data.LiteflowResponse; -import com.yomahub.liteflow.entity.data.Slot; import com.yomahub.liteflow.exception.ChainNotFoundException; import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.exception.FlowExecutorNotInitException; @@ -32,10 +31,10 @@ import javax.annotation.Resource; */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/exception/application.properties") -@SpringBootTest(classes = FlowExecutorSpringBootTest.class) +@SpringBootTest(classes = ExceptionSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.exception.cmp1"}) -public class FlowExecutorSpringBootTest extends BaseTest { +@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +public class ExceptionSpringBootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; @@ -65,7 +64,7 @@ public class FlowExecutorSpringBootTest extends BaseTest { public void testComponentCustomException() throws Exception { flowExecutor.execute("chain1", "exception"); } - + @Test(expected = FlowSystemException.class) public void testNoConditionInChainException() throws Exception { LiteflowResponse response = flowExecutor.execute2Resp("chain2", "test"); @@ -81,11 +80,4 @@ public class FlowExecutorSpringBootTest extends BaseTest { Assert.assertNotNull(response.getCause()); Assert.assertNotNull(response.getSlot()); } - -// @Test(expected = WhenExecuteException.class) -// public void testWhenExecuteTimeoutException() throws Exception { -// LiteflowResponse response = flowExecutor.execute("chain3", "when"); -// Assert.assertFalse(response.isSuccess()); -// ReflectionUtils.rethrowException(response.getCause()); -// } } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/ACmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java similarity index 93% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/ACmp.java rename to liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java index 4aff91482..6466673d6 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/ACmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.exception.cmp1; +package com.yomahub.liteflow.test.exception.cmp; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.NodeComponent; diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/BCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java similarity index 94% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/BCmp.java rename to liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java index 058cd507a..3ad089fcb 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/BCmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.exception.cmp1; +package com.yomahub.liteflow.test.exception.cmp; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.NodeComponent; diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/CCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java similarity index 91% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/CCmp.java rename to liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java index 748381f80..ab1759ade 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/CCmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.exception.cmp1; +package com.yomahub.liteflow.test.exception.cmp; import com.yomahub.liteflow.core.NodeComponent; import org.slf4j.Logger; diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/DCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java similarity index 91% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/DCmp.java rename to liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java index cd59be68b..3aebcc420 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp1/DCmp.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -5,7 +5,7 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.exception.cmp1; +package com.yomahub.liteflow.test.exception.cmp; import com.yomahub.liteflow.core.NodeComponent; import org.slf4j.Logger; diff --git a/liteflow-testcase-springboot/src/test/resources/customThreadPool/application.properties b/liteflow-testcase-springboot/src/test/resources/customThreadPool/application.properties deleted file mode 100644 index c50032c04..000000000 --- a/liteflow-testcase-springboot/src/test/resources/customThreadPool/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -liteflow.rule-source=customThreadPool/flow.xml -liteflow.thread-executor-class=com.yomahub.liteflow.test.customThreadPool.CustomThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/customThreadPool/flow.xml b/liteflow-testcase-springboot/src/test/resources/customThreadPool/flow.xml deleted file mode 100644 index 657f64cc3..000000000 --- a/liteflow-testcase-springboot/src/test/resources/customThreadPool/flow.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringTest.java new file mode 100644 index 000000000..fc5d093b9 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringTest.java @@ -0,0 +1,84 @@ +package com.yomahub.liteflow.test.builder; + +import com.yomahub.liteflow.builder.LiteFlowChainBuilder; +import com.yomahub.liteflow.builder.LiteFlowConditionBuilder; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.BaseTest; +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; + +//基于builder模式的单元测试 +//这里只是最基本的builder模式的测试,只是为了验证在spring模式下的正常性 +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/builder/application.xml") +public class BuilderSpringTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.BCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.CCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.DCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.ECmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.FCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.GCmp") + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createWhenCondition().setValue("c,d").build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createWhenCondition() + .setValue("a,b").build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setValue("e(f|g|chain2)").build() + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/ACmp.java similarity index 73% rename from liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/ACmp.java rename to liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/ACmp.java index 32e859264..79528ab3c 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/ACmp.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/ACmp.java @@ -5,12 +5,10 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.customThreadPool.cmp; +package com.yomahub.liteflow.test.builder.cmp; import com.yomahub.liteflow.core.NodeComponent; -import org.springframework.stereotype.Component; -@Component("a") public class ACmp extends NodeComponent { @Override diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/BCmp.java similarity index 63% rename from liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/BCmp.java rename to liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/BCmp.java index cc7e0310c..15104749e 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/BCmp.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/BCmp.java @@ -5,17 +5,14 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.customThreadPool.cmp; +package com.yomahub.liteflow.test.builder.cmp; import com.yomahub.liteflow.core.NodeComponent; -import org.springframework.stereotype.Component; -@Component("b") public class BCmp extends NodeComponent { @Override public void process() { - this.getSlot().setData("threadName", Thread.currentThread().getName()); System.out.println("BCmp executed!"); } diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/CCmp.java similarity index 73% rename from liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/CCmp.java rename to liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/CCmp.java index 276e035ba..09bbb546d 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/CCmp.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/CCmp.java @@ -5,12 +5,10 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.customThreadPool.cmp; +package com.yomahub.liteflow.test.builder.cmp; import com.yomahub.liteflow.core.NodeComponent; -import org.springframework.stereotype.Component; -@Component("c") public class CCmp extends NodeComponent { @Override diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/DCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/DCmp.java new file mode 100644 index 000000000..4de902484 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/DCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class DCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/ECmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/ECmp.java new file mode 100644 index 000000000..4b11789ac --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/ECmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp; + +import com.yomahub.liteflow.core.NodeCondComponent; + +public class ECmp extends NodeCondComponent { + + @Override + public String processCond() throws Exception { + System.out.println("ECmp executed!"); + return "chain2"; + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/FCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/FCmp.java new file mode 100644 index 000000000..a26c3223e --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/FCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class FCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/GCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/GCmp.java new file mode 100644 index 000000000..4fd5944bb --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp/GCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class GCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringTest.java new file mode 100644 index 000000000..25d97575b --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringTest.java @@ -0,0 +1,60 @@ +package com.yomahub.liteflow.test.cmpRetry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + + +/** + * 测试spring下的节点重试 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/cmpRetry/application.xml") +@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +public class LiteflowRetrySpringTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getSlot().getExecuteStepStr()); + } + + //单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getSlot().getExecuteStepStr()); + } + + //单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + //单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java new file mode 100644 index 000000000..a1b1b3fb4 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/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.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("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/cmpRetry/cmp/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java new file mode 100644 index 000000000..3c50ded2d --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + + private int flag = 0; + + @Override + public void process() { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java new file mode 100644 index 000000000..89c59fba9 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +@LiteflowRetry(5) +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java new file mode 100644 index 000000000..b9232e5ae --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("d") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +public class DCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("DCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java new file mode 100644 index 000000000..ba3f92d65 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("e") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +public class ECmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/ComponentSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/ComponentSpringTest.java new file mode 100644 index 000000000..08e5d4a02 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/ComponentSpringTest.java @@ -0,0 +1,89 @@ +package com.yomahub.liteflow.test.component; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; +import java.lang.reflect.UndeclaredThrowableException; + +/** + * 组件功能点测试 + * 单元测试 + * + * @author donguo.tao + */ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/component/application.xml") +public class ComponentSpringTest extends BaseTest { + private static final Logger LOG = LoggerFactory.getLogger(ComponentSpringTest.class); + + @Resource + private FlowExecutor flowExecutor; + + //isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } + + //组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } + + //isContinueOnError方法的功能点测试 + @Test(expected = UndeclaredThrowableException.class) + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + ReflectionUtils.rethrowException(response.getCause()); + } + + //isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d",response.getSlot().getExecuteStepStr()); + } + + //setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e",response.getSlot().getExecuteStepStr()); + } + + //条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + //测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g",response.getSlot().getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java new file mode 100644 index 000000000..4170f2400 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("a") +public class ACmp extends NodeComponent { + @Override + public void process() { + System.out.println("AComp executed!"); + this.getSlot().setResponseData("AComp executed!"); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getSlot().getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100){ + return true; + } + System.out.println("AComp isAccess false."); + return false; + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java new file mode 100644 index 000000000..7ddec3907 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("b") +public class BCmp extends NodeComponent { + @Override + public void process() { + System.out.println("BComp executed!"); + Integer requestData = this.getSlot().getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getSlot().getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java new file mode 100644 index 000000000..1fabb87a8 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("c") +public class CCmp extends NodeComponent { + @Override + public void process() { + System.out.println("CComp executed!"); + Integer requestData = this.getSlot().getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + System.out.println("responseData="+Integer.parseInt(this.getSlot().getResponseData())); + } + + @Override + public boolean isContinueOnError() { + Integer requestData = this.getSlot().getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java new file mode 100644 index 000000000..c28a41e34 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("d") +public class DCmp extends NodeComponent { + @Override + public void process() throws Exception { + System.out.println("DComp executed!"); + } + + @Override + public boolean isEnd() { + //组件的process执行完之后才会执行isEnd + Object requestData = this.getSlot().getResponseData(); + if (Objects.isNull(requestData)){ + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java new file mode 100644 index 000000000..50995a670 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.alibaba.fastjson.JSON; +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("e") +public class ECmp extends NodeComponent { + + @Override + public void process() throws Exception { + System.out.println("EComp executed!"); + Object responseData = this.getSlot().getResponseData(); + if (Objects.isNull(responseData)){ + System.out.println("EComp responseData flow must be set end ."); + //执行到某个条件时,手动结束流程。 + this.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JSON.toJSONString(responseData)); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java new file mode 100644 index 000000000..f7917cfae --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("g") +public class GCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("GCmp executed!"); + this.setIsEnd(true); + } + + @Override + public boolean isContinueOnError() { + return true; + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java new file mode 100644 index 000000000..df41a9c13 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("h") +public class HCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("HCmp executed!"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java new file mode 100644 index 000000000..c72a2601e --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.component.cmp2; + +import com.yomahub.liteflow.core.NodeCondComponent; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("f") +public class FCondCmp extends NodeCondComponent { + @Override + public String processCond() { + Integer requestData = this.getSlot().getRequestData(); + if (Objects.isNull(requestData)){ + return "d"; + } else if(requestData == 0){ + return "c"; + } else { + return "b"; + } + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadPoolSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringTest.java similarity index 68% rename from liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadPoolSpringTest.java rename to liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringTest.java index 05ab24f34..96ab2c0b5 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadPoolSpringTest.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringTest.java @@ -1,4 +1,4 @@ -package com.yomahub.liteflow.test.customThreadPool; +package com.yomahub.liteflow.test.customNodes; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.entity.data.DefaultSlot; @@ -15,13 +15,13 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境下异步线程超时日志打印测试 + * spring环境下自定义声明节点的测试 * @author Bryan.Zhang * @since 2.6.4 */ @RunWith(SpringRunner.class) -@ContextConfiguration("classpath:/customThreadPool/application.xml") -public class CustomThreadPoolSpringTest extends BaseTest { +@ContextConfiguration("classpath:/customNodes/application.xml") +public class CustomNodesSpringTest extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -29,9 +29,10 @@ public class CustomThreadPoolSpringTest extends BaseTest { private FlowExecutor flowExecutor; @Test - public void testCustomThreadPool() throws Exception{ + public void testCustomNodes() throws Exception{ LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); - Assert.assertFalse(response.getSlot().getData("threadName").toString().startsWith("lf-when-thead")); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); } } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java similarity index 73% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/ACmp.java rename to liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java index 32e859264..d7cf0644f 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/ACmp.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -5,12 +5,10 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.customThreadPool.cmp; +package com.yomahub.liteflow.test.customNodes.cmp; import com.yomahub.liteflow.core.NodeComponent; -import org.springframework.stereotype.Component; -@Component("a") public class ACmp extends NodeComponent { @Override diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java similarity index 60% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/BCmp.java rename to liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java index cc7e0310c..73814cd6d 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/BCmp.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java @@ -5,17 +5,21 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.customThreadPool.cmp; +package com.yomahub.liteflow.test.customNodes.cmp; import com.yomahub.liteflow.core.NodeComponent; -import org.springframework.stereotype.Component; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; -@Component("b") public class BCmp extends NodeComponent { + @Resource + private DemoDomain demoDomain; + @Override public void process() { - this.getSlot().setData("threadName", Thread.currentThread().getName()); + demoDomain.sayHi(); System.out.println("BCmp executed!"); } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java similarity index 73% rename from liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/CCmp.java rename to liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java index 276e035ba..9913ec102 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/customThreadPool/cmp/CCmp.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java @@ -5,12 +5,10 @@ * @email weenyc31@163.com * @Date 2020/4/1 */ -package com.yomahub.liteflow.test.customThreadPool.cmp; +package com.yomahub.liteflow.test.customNodes.cmp; import com.yomahub.liteflow.core.NodeComponent; -import org.springframework.stereotype.Component; -@Component("c") public class CCmp extends NodeComponent { @Override diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java new file mode 100644 index 000000000..cc6000418 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class DCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java new file mode 100644 index 000000000..697ab62e3 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; + +public class ECmp extends NodeComponent { + + @Resource + private DemoDomain demoDomain; + + @Override + public void process() { + demoDomain.sayHi(); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java new file mode 100644 index 000000000..de5c0820d --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java @@ -0,0 +1,19 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class FCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java new file mode 100644 index 000000000..d0b10dc0b --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.customNodes.domain; + +import org.springframework.stereotype.Component; + +@Component +public class DemoDomain { + + public void sayHi(){ + System.out.println("hi"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadExecutor.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadExecutor.java deleted file mode 100644 index 0985362bb..000000000 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/customThreadPool/CustomThreadExecutor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.yomahub.liteflow.test.customThreadPool; - -import com.yomahub.liteflow.thread.ExecutorBuilder; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class CustomThreadExecutor implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - return Executors.newCachedThreadPool(); - } -} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/emptyflow/EmptyFlowTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/emptyflow/EmptyFlowTest.java new file mode 100644 index 000000000..1b140e93f --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/emptyflow/EmptyFlowTest.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.emptyflow; + +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; + +/** + * 切面场景单元测试 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/emptyFlow/application.xml") +public class EmptyFlowTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试空flow的情况下,liteflow是否能正常启动 + @Test + public void testEmptyFlow() { + //不做任何事,为的是能正常启动 + } +} 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 index 04a2d05e6..9552b74ea 100644 --- 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 @@ -4,6 +4,7 @@ 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.property.LiteflowConfigGetter; import com.yomahub.liteflow.test.BaseTest; import org.junit.Assert; import org.junit.Test; @@ -27,12 +28,9 @@ 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); + LiteflowConfig config = LiteflowConfigGetter.get(); Boolean enable = config.getEnable(); if (enable) { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringTest.java new file mode 100644 index 000000000..0a525d81b --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringTest.java @@ -0,0 +1,77 @@ +package com.yomahub.liteflow.test.exception; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.ChainNotFoundException; +import com.yomahub.liteflow.exception.ConfigErrorException; +import com.yomahub.liteflow.exception.FlowExecutorNotInitException; +import com.yomahub.liteflow.exception.FlowSystemException; +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 org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 流程执行异常 + * 单元测试 + * + * @author zendwang + */ +@RunWith(SpringRunner.class) +@ContextConfiguration("classpath:/exception/application.xml") +public class ExceptionSpringTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Autowired + private ApplicationContext context; + + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.init(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("error/flow.txt"); + flowExecutor.init(); + } + + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } + + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } + + @Test(expected = FlowSystemException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("no conditionList in this chain[chain2]", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } + + @Test + public void testGetSlotFromResponseWhenException() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java new file mode 100644 index 000000000..6466673d6 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); + + @Override + public void process() { + String str = this.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new RuntimeException("chain execute execption"); + } + LOG.info("Acomp executed!"); + } + +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java new file mode 100644 index 000000000..3ad089fcb --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -0,0 +1,35 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); + + @Override + public void process() throws InterruptedException { + String str = this.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("when")) { + try { + LOG.info("Bcomp sleep begin"); + Thread.sleep(3000); + LOG.info("Bcomp sleep end"); + } catch (InterruptedException e) { + throw e; + } + } + LOG.info("Bcomp executed!"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java new file mode 100644 index 000000000..ab1759ade --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); + + @Override + public void process() { + LOG.info("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java new file mode 100644 index 000000000..3aebcc420 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); + + @Override + public void process() { + if(1==1){ + int a = 1/0; + } + LOG.info("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-springnative/src/test/resources/builder/application.xml b/liteflow-testcase-springnative/src/test/resources/builder/application.xml new file mode 100644 index 000000000..cccbd4550 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/builder/application.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/customThreadPool/application.xml b/liteflow-testcase-springnative/src/test/resources/cmpRetry/application.xml similarity index 81% rename from liteflow-testcase-springnative/src/test/resources/customThreadPool/application.xml rename to liteflow-testcase-springnative/src/test/resources/cmpRetry/application.xml index 9032948a9..75fd71f42 100644 --- a/liteflow-testcase-springnative/src/test/resources/customThreadPool/application.xml +++ b/liteflow-testcase-springnative/src/test/resources/cmpRetry/application.xml @@ -7,15 +7,16 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> - + - - + + + diff --git a/liteflow-testcase-springnative/src/test/resources/cmpRetry/flow.xml b/liteflow-testcase-springnative/src/test/resources/cmpRetry/flow.xml new file mode 100644 index 000000000..d44e3ee05 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/cmpRetry/flow.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/component/application.xml b/liteflow-testcase-springnative/src/test/resources/component/application.xml new file mode 100644 index 000000000..4dce697ea --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/component/application.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/component/flow.xml b/liteflow-testcase-springnative/src/test/resources/component/flow.xml new file mode 100644 index 000000000..2a504fd01 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/component/flow.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/customNodes/application.xml b/liteflow-testcase-springnative/src/test/resources/customNodes/application.xml new file mode 100644 index 000000000..c575cc693 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/customNodes/application.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/customNodes/flow.xml b/liteflow-testcase-springnative/src/test/resources/customNodes/flow.xml new file mode 100644 index 000000000..ecc1abcd6 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/customNodes/flow.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/customThreadPool/flow.xml b/liteflow-testcase-springnative/src/test/resources/customThreadPool/flow.xml deleted file mode 100644 index 657f64cc3..000000000 --- a/liteflow-testcase-springnative/src/test/resources/customThreadPool/flow.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/emptyFlow/application.xml b/liteflow-testcase-springnative/src/test/resources/emptyFlow/application.xml new file mode 100644 index 000000000..22ab5c50e --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/emptyFlow/application.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/emptyFlow/flow.xml b/liteflow-testcase-springnative/src/test/resources/emptyFlow/flow.xml new file mode 100644 index 000000000..e69de29bb diff --git a/liteflow-testcase-springnative/src/test/resources/exception/application.xml b/liteflow-testcase-springnative/src/test/resources/exception/application.xml new file mode 100644 index 000000000..741f6451b --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/exception/application.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-springnative/src/test/resources/exception/flow.xml b/liteflow-testcase-springnative/src/test/resources/exception/flow.xml new file mode 100644 index 000000000..e975ef328 --- /dev/null +++ b/liteflow-testcase-springnative/src/test/resources/exception/flow.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file