Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java new file mode 100644 index 000000000..e83723bdb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java new file mode 100644 index 000000000..17a096598 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java new file mode 100644 index 000000000..41c08bcee --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java @@ -0,0 +1,56 @@ +package com.yomahub.liteflow.test.aop; + +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 com.yomahub.liteflow.test.aop.aspect.CustomAspect; +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.context.annotation.Import; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 切面场景单元测试 + * 在声明式组件场景中,自定义aspect的aop不生效的,因为生成的代理类并不是原类,也不是原类的子类,而是NodeComponent的子类 + * 所以切不到,暂且没有想出办法来解决,这个测试类暂时不用 + * @author Bryan.Zhang + */ +/*@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = CustomAOPSpringbootTest.class) +@EnableAutoConfiguration +@Import(CustomAspect.class) +@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})*/ +public class CustomAOPSpringbootTest extends BaseTest { + + /*@Resource + private FlowExecutor flowExecutor; + + //测试自定义AOP,串行场景 + @Test + public void testCustomAopS() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java new file mode 100644 index 000000000..8b688aef5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java new file mode 100644 index 000000000..b8c52b500 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Ccomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java new file mode 100644 index 000000000..ff4680e1f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java new file mode 100644 index 000000000..99db4df8a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Ecomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java new file mode 100644 index 000000000..38b8971c7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + throw new RuntimeException("test error"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java new file mode 100644 index 000000000..b6cc97ca4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java @@ -0,0 +1,134 @@ +package com.yomahub.liteflow.test.asyncNode; + +import cn.hutool.core.collection.ListUtil; +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 com.yomahub.liteflow.test.asyncNode.exception.TestException; +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; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author ssss + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/asyncNode/application.properties") +@SpringBootTest(classes = AsyncNodeSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +public class AsyncNodeSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 + * 验证了when情况下 多个node是并行执行 + * 验证了默认参数情况下 when可以加载执行 + * **/ + @Test + public void testAsyncFlow1() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java new file mode 100644 index 000000000..0f29823cc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java new file mode 100644 index 000000000..d147a02c1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java new file mode 100644 index 000000000..937c79b9b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java @@ -0,0 +1,31 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @Resource + private TestDomain testDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + testDomain.sayHi(); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java new file mode 100644 index 000000000..16f159324 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java @@ -0,0 +1,10 @@ +package com.yomahub.liteflow.test.base.cmp; + +import org.springframework.stereotype.Component; + +@Component +public class TestDomain { + public void sayHi(){ + System.out.println("hello"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java new file mode 100644 index 000000000..55f4011c2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java @@ -0,0 +1,217 @@ +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.ExecutableEntity; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.builder.cmp1.*; +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.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +//基于builder模式的单元测试 +//这里只是最基本的builder模式的测试,只是为了验证在springboot模式下的正常性 +//更详细的builder模式测试用例会单独拉testcase去做 +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BuilderSpringbootTest1.class) +@EnableAutoConfiguration +public class BuilderSpringbootTest1 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.cmp1.ACmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition().setValue("c,d").build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setValue("a,b").build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setValue("e(f|g|chain2)").build() + ).build(); + + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java new file mode 100644 index 000000000..e13b0434f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/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.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java new file mode 100644 index 000000000..6fbbc10e6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java @@ -0,0 +1,23 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java new file mode 100644 index 000000000..27fb0fd46 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java @@ -0,0 +1,23 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java new file mode 100644 index 000000000..3fbb2daca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/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.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + System.out.println("ECmp executed!"); + return "chain2"; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java new file mode 100644 index 000000000..a300c50fd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java @@ -0,0 +1,23 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java new file mode 100644 index 000000000..4035e89ca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java @@ -0,0 +1,23 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java new file mode 100644 index 000000000..a3bd495ac --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java new file mode 100644 index 000000000..a7546b330 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("i") +@LiteflowCmpDefine +public class ICmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java new file mode 100644 index 000000000..a270fc3c9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("j") +@LiteflowCmpDefine +public class JCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("JCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java new file mode 100644 index 000000000..d744c69be --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java @@ -0,0 +1,64 @@ +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.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.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/cmpRetry/application.properties") +@SpringBootTest(classes = LiteflowRetrySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +public class LiteflowRetrySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponseTitle: 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.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java new file mode 100644 index 000000000..9107e2381 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -0,0 +1,31 @@ +/** + *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.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp { + + private int flag = 0; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java new file mode 100644 index 000000000..05ea10fd8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *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.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowRetry(5) +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java new file mode 100644 index 000000000..c3d21e729 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -0,0 +1,28 @@ +/** + *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.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java new file mode 100644 index 000000000..f33b4ca64 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -0,0 +1,28 @@ +/** + *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.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("e") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java new file mode 100644 index 000000000..140cffe60 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java @@ -0,0 +1,94 @@ +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.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 org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 组件功能点测试 + * 单元测试 + * + * @author donguo.tao + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/component/application.properties") +@SpringBootTest(classes = FlowExecutorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +public class FlowExecutorSpringbootTest extends BaseTest { + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorSpringbootTest.class); + + @Resource + private FlowExecutor flowExecutor; + + //isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + bindCmp.setIsEnd(true); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + return true; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java new file mode 100644 index 000000000..c2a30d0a5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -0,0 +1,24 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java new file mode 100644 index 000000000..360e02cb8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test.component.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("f") +@LiteflowCondCmpDefine +public class FCondCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.isNull(requestData)){ + return "d"; + } else if(requestData == 0){ + return "c"; + } else { + return "b"; + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java new file mode 100644 index 000000000..ec49601af --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.customNodes; + +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环境下自定义声明节点的测试 + * 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/customNodes/application.properties") +@SpringBootTest(classes = CustomNodesSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +public class CustomNodesSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception{ + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java new file mode 100644 index 000000000..67ed16bcf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java @@ -0,0 +1,29 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; + +@LiteflowCmpDefine +public class BCmp{ + + @Resource + private DemoDomain demoDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + demoDomain.sayHi(); + System.out.println("BCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java new file mode 100644 index 000000000..d4ee3cf17 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java @@ -0,0 +1,23 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java new file mode 100644 index 000000000..619905b1e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java @@ -0,0 +1,23 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java new file mode 100644 index 000000000..27b3243ce --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java @@ -0,0 +1,30 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; + +@LiteflowCmpDefine +public class ECmp{ + + @Resource + private DemoDomain demoDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + demoDomain.sayHi(); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java new file mode 100644 index 000000000..a7f22de97 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java @@ -0,0 +1,23 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java new file mode 100644 index 000000000..d0b10dc0b --- /dev/null +++ b/liteflow-testcase-declare-component/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-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java new file mode 100644 index 000000000..6f88c4cdd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -0,0 +1,25 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor1 implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-1-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java new file mode 100644 index 000000000..7d45e4ad5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor2 implements ExecutorBuilder { + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-2-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java new file mode 100644 index 000000000..875dc3d1d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor3 implements ExecutorBuilder { + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-3-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java new file mode 100644 index 000000000..b21eed76f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java @@ -0,0 +1,72 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +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:/customWhenThreadPool/application.properties") +@SpringBootTest(classes = CustomWhenThreadPoolSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +public class CustomWhenThreadPoolSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java new file mode 100644 index 000000000..2a00fb1a5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java @@ -0,0 +1,26 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java new file mode 100644 index 000000000..1a85ad0cb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java @@ -0,0 +1,26 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java new file mode 100644 index 000000000..d5b9f6ce1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java @@ -0,0 +1,26 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java new file mode 100644 index 000000000..c9bac33b7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/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.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java new file mode 100644 index 000000000..552ea97a0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java @@ -0,0 +1,26 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java new file mode 100644 index 000000000..de1c3a285 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java @@ -0,0 +1,83 @@ +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.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; +import org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 流程执行异常 + * 单元测试 + * + * @author zendwang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/exception/application.properties") +@SpringBootTest(classes = ExceptionSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +public class ExceptionSpringBootTest 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{ + LiteflowResponseTitle: 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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new RuntimeException("chain execute execption"); + } + LOG.info("Acomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java new file mode 100644 index 000000000..5ec0f8b04 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -0,0 +1,39 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws InterruptedException { + String str = bindCmp.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-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java new file mode 100644 index 000000000..4e4b4e25c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + LOG.info("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java new file mode 100644 index 000000000..6da4fe9a1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -0,0 +1,31 @@ +/** + *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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + if(1==1){ + int a = 1/0; + } + LOG.info("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java new file mode 100644 index 000000000..d2460105b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.execute2Future; + +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.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.concurrent.Future; + +/** + * springboot环境执行返回future的例子 + * @author Bryan.Zhang + * @since 2.6.13 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/execute2Future/application.properties") +@SpringBootTest(classes = Executor2FutureSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +public class Executor2FutureSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testFuture() throws Exception{ + FutureTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java new file mode 100644 index 000000000..2678f2557 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java new file mode 100644 index 000000000..a3ca40a89 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java new file mode 100644 index 000000000..121619827 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java new file mode 100644 index 000000000..5e7ed5727 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.flowmeta; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.flowmeta.cmp2.DCmp; +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; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/flowmeta/application.properties") +@SpringBootTest(classes = FlowMetaSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.flowmeta.cmp1"}) +public class FlowMetaSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试动态添加元信息节点 + @Test + public void testFlowMeta() { + FlowBus.addCommonNode("d", "d组件", DCmp.class.getName()); + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java new file mode 100644 index 000000000..134185aef --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java new file mode 100644 index 000000000..30c3f8bfb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java new file mode 100644 index 000000000..260ad8091 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java @@ -0,0 +1,23 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java new file mode 100644 index 000000000..6e3500217 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.lazy; + +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.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; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/lazy/application.properties") +@SpringBootTest(classes = LazySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"}) +public class LazySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testLazy() throws Exception{ + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Lazy +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java new file mode 100644 index 000000000..628760c66 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java new file mode 100644 index 000000000..781d1a209 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java new file mode 100644 index 000000000..954bee888 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.liteflowcomponent; + +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.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; + + +/** + * 测试@LiteflowComponent标注 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/liteflowComponent/application.properties") +@SpringBootTest(classes = LiteflowComponentSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.liteflowComponent.cmp"}) +public class LiteflowComponentSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "a", name = "A组件") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java new file mode 100644 index 000000000..dfab6f34b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "b", name = "B组件") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java new file mode 100644 index 000000000..1f4fdd22f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "c", name = "C组件") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java new file mode 100644 index 000000000..9f338fa01 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java new file mode 100644 index 000000000..11147d10c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java @@ -0,0 +1,50 @@ +package com.yomahub.liteflow.test.monitor; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.monitor.MonitorBus; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.AfterClass; +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环境最普通的例子测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/monitor/application.properties") +@SpringBootTest(classes = MonitorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +public class MonitorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java new file mode 100644 index 000000000..51d239b72 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java @@ -0,0 +1,32 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java new file mode 100644 index 000000000..3d802e5ea --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java @@ -0,0 +1,32 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java new file mode 100644 index 000000000..91ef144e4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.multipleType; + +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.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; + + +/** + * 测试springboot下混合格式规则的场景 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/multipleType/application.properties") +@SpringBootTest(classes = LiteflowMultipleTypeSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +public class LiteflowMultipleTypeSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java new file mode 100644 index 000000000..4f6b64dfc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java new file mode 100644 index 000000000..66dadb7ea --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java new file mode 100644 index 000000000..84b60247a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +/** + * 自定义默认的节点执行器 + */ +public class CustomerDefaultNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + slot.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java new file mode 100644 index 000000000..247bc3d47 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerNodeExecutor进行执行"); + slot.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java new file mode 100644 index 000000000..46792852a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +import java.util.concurrent.TimeUnit; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + slot.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + slot.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java new file mode 100644 index 000000000..0c13bdadb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java @@ -0,0 +1,69 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +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.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.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/nodeExecutor/application.properties") +@SpringBootTest(classes = LiteflowNodeExecutorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +public class LiteflowNodeExecutorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java new file mode 100644 index 000000000..9581a0655 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -0,0 +1,31 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + private int flag = 0; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java new file mode 100644 index 000000000..3cf2a06fa --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -0,0 +1,33 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.executor.NodeExecutor; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; + +@LiteflowComponent("c") +@LiteflowRetry(5) +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) + public Class extends NodeExecutor> getNodeExecutorClass(NodeComponent bindCmp) { + return CustomerNodeExecutor.class; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java new file mode 100644 index 000000000..61c8b4c14 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -0,0 +1,35 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.executor.NodeExecutor; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; + +@LiteflowComponent("d") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) + public Class extends NodeExecutor> getNodeExecutorClass(NodeComponent bindCmp) { + return CustomerNodeExecutorAndCustomRetry.class; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java new file mode 100644 index 000000000..5f61dc208 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.parsecustom; + +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.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环境的自定义json parser单元测试 + * @author dongguo.tao + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties") +@SpringBootTest(classes = CustomParserJsonSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +public class CustomParserJsonSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.exception.FlowSystemException; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new FlowSystemException("chain execute execption"); + } + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java new file mode 100644 index 000000000..440ea579a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java new file mode 100644 index 000000000..75ca94417 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java new file mode 100644 index 000000000..12789ff2e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java new file mode 100644 index 000000000..7b15119d0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java new file mode 100644 index 000000000..4bb6d0311 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java new file mode 100644 index 000000000..62242e698 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java new file mode 100644 index 000000000..dd3a41929 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.ClassJsonFlowParser; + +/** + * 模拟用户自定义源解析 + * @author dongguo.tao + * @since 2.5.0 + */ +public class CustomJsonFlowParser extends ClassJsonFlowParser { + @Override + public String parseCustom() { + //模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"condition\":[{\"type\":\"then\",\"value\":\"c,g,f\"}]},{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,c\"},{\"type\":\"when\",\"value\":\"b,d,e(f|g)\"},{\"type\":\"then\",\"value\":\"chain2\"}]}]}}"; + return content; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java new file mode 100644 index 000000000..064323b89 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.ClassXmlFlowParser; +import com.yomahub.liteflow.test.parsecustom.bean.TestBean; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +public class CustomXmlFlowParser extends ClassXmlFlowParser { + + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java new file mode 100644 index 000000000..6b4ee17f6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.parser; + +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.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +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") +@SpringBootTest(classes = JsonParserSpringbootTest.class) +@EnableAutoConfiguration +public class JsonParserSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java new file mode 100644 index 000000000..d40b13d2f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java new file mode 100644 index 000000000..e9d3dceb8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java new file mode 100644 index 000000000..9f86ac0f7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java new file mode 100644 index 000000000..620495a5f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java new file mode 100644 index 000000000..84e178b5b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java new file mode 100644 index 000000000..8b50f2452 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java new file mode 100644 index 000000000..0becd8269 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java @@ -0,0 +1,64 @@ +package com.yomahub.liteflow.test.preAndFinally; + +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.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环境下pre节点和finally节点的测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/preAndFinally/application.properties") +@SpringBootTest(classes = PreAndFinallySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +public class PreAndFinallySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception{ + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java new file mode 100644 index 000000000..92644fcab --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java new file mode 100644 index 000000000..23813b76a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java new file mode 100644 index 000000000..f6f948273 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -0,0 +1,26 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + int i = 1/0; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java new file mode 100644 index 000000000..fd5fed96c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -0,0 +1,24 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f1") +@LiteflowCmpDefine +public class Finally1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Finally1Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java new file mode 100644 index 000000000..e1c809727 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -0,0 +1,24 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f2") +@LiteflowCmpDefine +public class Finally2Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Finally2Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java new file mode 100644 index 000000000..a775a42ab --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -0,0 +1,32 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f3") +@LiteflowCmpDefine +public class Finally3Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception{ + Slot slot = bindCmp.getSlot(); + if (ObjectUtil.isNull(slot.getException())){ + slot.setData("hasEx", false); + }else{ + slot.setData("hasEx", true); + } + System.out.println("Finally3Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java new file mode 100644 index 000000000..ffe0556c3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -0,0 +1,24 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("p1") +@LiteflowCmpDefine +public class Pre1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Pre1Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java new file mode 100644 index 000000000..f00a75263 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -0,0 +1,24 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("p2") +@LiteflowCmpDefine +public class Pre2Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Pre2Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java new file mode 100644 index 000000000..9f2831197 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.privateDelivery; + +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.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.Set; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/privateDelivery/application.properties") +@SpringBootTest(classes = PrivateDeliverySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +public class PrivateDeliverySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception{ + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.HashSet; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + Slot slot = bindCmp.getSlot(); + slot.setData("testSet", new HashSet<>()); + + for (int i = 0; i < 100; i++) { + bindCmp.sendPrivateDeliveryData("b",i+1); + } + } +} + diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java new file mode 100644 index 000000000..3290d9ca2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -0,0 +1,30 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.Set; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + Integer value = bindCmp.getPrivateDeliveryData(); + SetTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java new file mode 100644 index 000000000..354abbb9e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java new file mode 100644 index 000000000..d4504ce59 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java @@ -0,0 +1,70 @@ +package com.yomahub.liteflow.test.refreshRule; + +import cn.hutool.core.io.resource.ResourceUtil; +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.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +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环境下重新加载规则测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/refreshRule/application.properties") +@SpringBootTest(classes = RefreshRuleSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +public class RefreshRuleSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception{ + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_XML, content); + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java new file mode 100644 index 000000000..aaef859a6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java new file mode 100644 index 000000000..7e935c272 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java new file mode 100644 index 000000000..e09edbdd1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.reload; + +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.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.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/reload/application.properties") +@SpringBootTest(classes = ReloadSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +public class ReloadSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception{ + flowExecutor.reloadRule(); + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java new file mode 100644 index 000000000..5ca7ff6d1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java new file mode 100644 index 000000000..af6e8b52c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java new file mode 100644 index 000000000..7af320ed3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java @@ -0,0 +1,65 @@ +package com.yomahub.liteflow.test.resizeSlot; + +import cn.hutool.core.util.ReflectUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DataBus; +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.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +/** + * springboot环境下slot扩容测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/resizeSlot/application.properties") +@SpringBootTest(classes = ResizeSlotSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.resizeSlot.cmp"}) +public class ResizeSlotSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testResize() throws Exception{ + ExecutorService pool = Executors.newCachedThreadPool(); + + ListTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java new file mode 100644 index 000000000..4a5e5ea8d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java new file mode 100644 index 000000000..a0156105c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java new file mode 100644 index 000000000..82540c127 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java @@ -0,0 +1,49 @@ +package com.yomahub.liteflow.test.subflow; + +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.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.HashSet; +import java.util.Set; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-implicit.properties") +@SpringBootTest(classes = ImplicitSubFlowSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +public class ImplicitSubFlowSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + public static final SetTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String testKey = "test"; + + Slot slot = bindCmp.getSlot(); + if (slot.getData(testKey) == null){ + slot.setData(testKey,bindCmp.getTag()); + }else{ + String s = slot.getData(testKey); + s += bindCmp.getTag(); + slot.setData(testKey, s); + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java new file mode 100644 index 000000000..5fb5e35e6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -0,0 +1,27 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b1") +@LiteflowCmpDefine +public class B1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + slot.setData("test",new ConcurrentHashSetTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + ConcurrentHashSetTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowCondCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + if(bindCmp.getTag().equals("2")){ + return "e"; + }else{ + return "d"; + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java new file mode 100644 index 000000000..8ee32b746 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("DCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java new file mode 100644 index 000000000..84423ee71 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("ECmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java new file mode 100644 index 000000000..e3ea2023d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -0,0 +1,29 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process() { + System.out.println("FCmp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + return Boolean.parseBoolean(bindCmp.getTag()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java new file mode 100644 index 000000000..f8aae453c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -0,0 +1,24 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java new file mode 100644 index 000000000..fee0055e5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.useTTLInWhen; + +import com.alibaba.ttl.TransmittableThreadLocal; + +public class TestTL { + + public static ThreadLocalTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + TestTL.set("hello"); + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java new file mode 100644 index 000000000..b2e30c9b0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",b"); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java new file mode 100644 index 000000000..429eca6d4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",c"); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java new file mode 100644 index 000000000..a9e657f99 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -0,0 +1,28 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",d"); + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java new file mode 100644 index 000000000..f039dbcc4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -0,0 +1,28 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",e"); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java new file mode 100644 index 000000000..2cb04f0ab --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -0,0 +1,28 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",f"); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java new file mode 100644 index 000000000..78e6a33cf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +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.WhenTimeoutException; +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:/whenTimeOut/application1.properties") +@SpringBootTest(classes = WhenTimeOutSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutSpringbootTest1 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java new file mode 100644 index 000000000..6628e838e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -0,0 +1,30 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java new file mode 100644 index 000000000..e26c064f6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -0,0 +1,30 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(3500); + }catch (Exception ignored){ + + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java new file mode 100644 index 000000000..720a4a8b8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -0,0 +1,30 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java new file mode 100644 index 000000000..6485ae74b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -0,0 +1,30 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java new file mode 100644 index 000000000..f16bda6ad --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -0,0 +1,30 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java new file mode 100644 index 000000000..474c3fd9f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +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.I0Itec.zkclient.ZkClient; +import org.I0Itec.zkclient.exception.ZkMarshallingError; +import org.I0Itec.zkclient.serialize.ZkSerializer; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.CountDownLatch; + +/** + * springboot环境下的zk配置源功能测试 + * ZK节点存储数据的格式为json文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-json.properties") +@SpringBootTest(classes = ZkNodeWithJsonSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithJsonSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingServer zkServer; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + CountDownLatch latch = new CountDownLatch(1); + new Thread(() -> { + String data = ResourceUtil.readUtf8Str("zookeeper/flow.json"); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + zkClient.createPersistent(ZK_NODE_PATH, true); + zkClient.writeData(ZK_NODE_PATH, data); + zkClient.close(); + latch.countDown(); + }).start(); + latch.await(); + } + + @Test + public void testZkNodeWithJson() { + LiteflowResponseTitle: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java new file mode 100644 index 000000000..0599bc17f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java new file mode 100644 index 000000000..cddcc3365 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *Title: liteflow
+ *Description: 轻量级的组件式流程框架
+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties new file mode 100644 index 000000000..55fe91fd8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=/usr/local/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml new file mode 100644 index 000000000..a6fda5aa0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml @@ -0,0 +1,7 @@ + + +