diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java index 4933ed6b0..f692a4cef 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java @@ -1,6 +1,7 @@ package com.yomahub.liteflow.annotation; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import java.lang.annotation.*; @@ -21,5 +22,5 @@ public @interface LiteflowMethod { * cmp定义 * */ - Class cmpClass() default NodeComponent.class; + AnnotionNodeTypeEnum nodeType() default AnnotionNodeTypeEnum.COMMON; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java index 7f4ca10ea..bb49d4c57 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java @@ -8,7 +8,7 @@ import java.lang.annotation.*; * @author Bryan.Zhang * @since 2.6.0 */ -@Target({ElementType.TYPE}) +@Target({ElementType.TYPE,ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java index 9ffc3e416..bb4bf34c4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -3,7 +3,9 @@ package com.yomahub.liteflow.core.proxy; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.*; import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; import com.yomahub.liteflow.exception.ComponentMethodDefineErrorException; import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.util.LiteFlowProxyUtil; @@ -13,6 +15,8 @@ import net.bytebuddy.implementation.InvocationHandlerAdapter; import net.bytebuddy.matcher.ElementMatchers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -48,26 +52,51 @@ public class ComponentProxy { }else{ beanClazz = bean.getClass(); } - //得到当前bean里所覆盖的LiteflowMethod(一定是被@LiteFlowMethod修饰的),自己定义的不算 - Map> methodListMap = Arrays.stream(beanClazz.getDeclaredMethods()).filter( + Map> methodListMap = Arrays.stream(beanClazz.getDeclaredMethods()).filter( m -> m.getAnnotation(LiteflowMethod.class) != null - ).map(m -> m.getAnnotation(LiteflowMethod.class)).collect(Collectors.groupingBy(LiteflowMethod::nodeId)); + ).collect(Collectors.groupingBy( + m -> m.getAnnotation(LiteflowMethod.class).nodeId() + )); + return methodListMap.entrySet().stream().map(entry -> { + Annotation[] beanClassAnnotation = bean.getClass().getAnnotations(); boolean isMethodCreate = !StrUtil.isEmpty(entry.getKey()); String activeNodeId = isMethodCreate ? entry.getKey() : nodeId; - List methodList = entry.getValue(); + // 获取当前节点的所有LiteFlowMethod注解 + List methodList = entry.getValue().stream() + .map(m -> m.getAnnotation(LiteflowMethod.class)) + .collect(Collectors.toList()); // 一个节点只能有一个定义NodeCmp类 - List> classes = methodList.stream().map(LiteflowMethod::cmpClass).distinct().collect(Collectors.toList()); + List> classes = methodList.stream().map(LiteflowMethod::nodeType).map(AnnotionNodeTypeEnum::getCmpClass).distinct().collect(Collectors.toList()); boolean legal = classes.size() == 1; if (!legal){ throw new LiteFlowException("The cmpClass of the same nodeId must be the same,you declared nodeId:" + activeNodeId + ",cmpClass:" + classes); } + // 获取当前节点的所有LiteflowRetry注解 + List liteflowRetries = entry.getValue().stream() + .map(m -> m.getAnnotation(LiteflowRetry.class)) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + // 一个nodeCmp只能有一个LiteflowRetry定义方法 + legal = liteflowRetries.size() <= 1; + if (!legal){ + throw new LiteFlowException("the retry annotation must be declared in the one of declared methods ( PROCESS Method is better ),you declared "+ liteflowRetries.size()+" times."); + } Class cmpClass; cmpClass = clazz; // 判断是否是方法声明的组件 if (isMethodCreate){ - cmpClass = methodList.iterator().next().cmpClass(); + cmpClass = methodList.iterator().next().nodeType().getCmpClass(); + if (liteflowRetries.size() == 1){ + // 增加注解 + List annotations = Arrays.stream(beanClassAnnotation) + .filter(a -> !a.annotationType().equals(LiteflowRetry.class)) + .collect(Collectors.toList()); + annotations.add(liteflowRetries.get(0)); + beanClassAnnotation = new Annotation[annotations.size()]; + annotations.toArray(beanClassAnnotation); + } } try { //创建对象 @@ -81,7 +110,7 @@ public class ComponentProxy { SerialsUtil.generateShortUUID())) .method(ElementMatchers.namedOneOf(methodList.stream().map(m -> m.value().getMethodName()).toArray(String[]::new))) .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean))) - .annotateType(bean.getClass().getAnnotations()) + .annotateType(beanClassAnnotation) .make() .load(ComponentProxy.class.getClassLoader()) .getLoaded() diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/AnnotionNodeTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/AnnotionNodeTypeEnum.java new file mode 100644 index 000000000..e9ed318ea --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/AnnotionNodeTypeEnum.java @@ -0,0 +1,49 @@ +package com.yomahub.liteflow.enums; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; +import jdk.nashorn.internal.objects.annotations.Getter; + +/** + * 注解节点类型枚举 + * + * @author Sorghum + * @date 2022/09/08 + */ +public enum AnnotionNodeTypeEnum { + /** + * 普通节点 + */ + COMMON("普通", NodeComponent.class), + /** + * 选择节点 + */ + SWITCH("选择", NodeSwitchComponent.class), + /** + * 条件节点 + */ + IF("条件", NodeIfComponent.class),; + /** + * 描述 + */ + final String desc; + /** + * cmp类 + */ + final Class cmpClass; + + AnnotionNodeTypeEnum(String desc, Class cmpClass) { + this.desc = desc; + this.cmpClass = cmpClass; + } + + /** + * 得到Node定义类 + * + * @return {@link Class}<{@link ?} {@link extends} {@link NodeComponent}> + */ + public Class getCmpClass() { + return cmpClass; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/pom.xml new file mode 100644 index 000000000..33ba94e37 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/pom.xml @@ -0,0 +1,69 @@ + + + + liteflow-testcase-el + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-testcase-el-declare-multi-springboot + + + + com.yomahub + liteflow-spring-boot-starter + ${revision} + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.aspectj + aspectjweaver + test + + + org.apache.curator + curator-test + test + + + com.101tec + zkclient + test + + + org.apache.curator + curator-framework + + + org.apache.curator + curator-recipes + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${springboot.version} + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + true + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java new file mode 100644 index 000000000..3a79ad7b0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test; + +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.thread.ExecutorHelper; +import org.junit.AfterClass; + +public class BaseTest { + + @AfterClass + public static void cleanScanCache(){ + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java new file mode 100644 index 000000000..f52bea7a8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.absoluteConfigPath; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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:/absoluteConfigPath/application.properties") +@SpringBootTest(classes = AbsoluteConfigPathELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"}) +public class AbsoluteConfigPathELDeclSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CmpMultiDefine.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CmpMultiDefine.java new file mode 100644 index 000000000..43deef3d7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CmpMultiDefine.java @@ -0,0 +1,33 @@ +/** + *

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.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component() +public class CmpMultiDefine{ + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a",nodeType = AnnotionNodeTypeEnum.COMMON) + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclSpringbootTest.java new file mode 100644 index 000000000..e6eb8a154 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.aop; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.aop.aspect.CmpAspect; +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.context.annotation.Import; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 切面场景单元测试 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = GlobalAOPELDeclSpringbootTest.class) +@EnableAutoConfiguration +@Import(CmpAspect.class) +@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +public class GlobalAOPELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试全局AOP,串行场景 + @Test + public void testGlobalAopS() { + LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } + + //测试全局AOP,并行场景 + @Test + public void testGlobalAopP() { + LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } + + @Test + public void testGlobalAopException() { + LiteflowResponse response= flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("f")); + } + + @AfterClass + public static void cleanScanCache(){ + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java new file mode 100644 index 000000000..3704a146d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.aop.aspect; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.aop.ICmpAroundAspect; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.slot.Slot; + +public class CmpAspect implements ICmpAroundAspect { + @Override + public void beforeProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, "before"); + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java new file mode 100644 index 000000000..dd2e61453 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.aop.aspect; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.slot.Slot; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; + +@Aspect +public class CustomAspect { + + @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process(*))") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId(), "before"); + Object returnObj = jp.proceed(); + context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); + return returnObj; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/Cmp1Config.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/Cmp1Config.java new file mode 100644 index 000000000..dee1bcf8a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/Cmp1Config.java @@ -0,0 +1,25 @@ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class Cmp1Config { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("Ccomp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/Cmp2Config.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/Cmp2Config.java new file mode 100644 index 000000000..d023aaa93 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/Cmp2Config.java @@ -0,0 +1,25 @@ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class Cmp2Config { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("Ecomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + throw new RuntimeException("test error"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclSpringbootTest.java new file mode 100644 index 000000000..3b8c58ff9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclSpringbootTest.java @@ -0,0 +1,139 @@ +package com.yomahub.liteflow.test.asyncNode; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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 = AsyncNodeELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +public class AsyncNodeELDeclSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 + * 验证了when情况下 多个node是并行执行 + * 验证了默认参数情况下 when可以加载执行 + * **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getExecuteStepStr()); + } + + //这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", + "b==>j==>h==>g==>f","b==>j==>h==>f==>g", + "b==>j==>f==>h==>g","b==>j==>f==>g==>h" + ).contains(response.getExecuteStepStr())); + } + + //测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } + + //测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } + + //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + //因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + //因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } + + //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + //整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + //因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + //第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(1), count); + //第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + //第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + //第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //测试任意异步一个执行完即继续的场景 + //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + //最终执行效果应该是h先返回,然后执行abc,最后gd + //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("check").toString().startsWith("habc")); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CmpConfig.java new file mode 100644 index 000000000..8db658271 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CmpConfig.java @@ -0,0 +1,139 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.asyncNode.exception.TestException; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class){ + if (context.hasData("check")){ + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + }else{ + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } + + @LiteflowMethod(value =LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class){ + if (context.hasData("check")){ + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + }else{ + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class){ + if (context.hasData("check")){ + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + }else{ + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) throws Exception { + Thread.sleep(1000); + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class){ + if (context.hasData("check")){ + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + }else{ + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) throws Exception { + System.out.println("Fcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void processG(NodeComponent bindCmp) throws Exception { + Thread.sleep(500); + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class){ + if (context.hasData("check")){ + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + }else{ + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "h") + public void processH(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class){ + if (context.hasData("check")){ + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + }else{ + context.setData("check", bindCmp.getNodeId()); + } + + } + + System.out.println("Hcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "i") + public void processI(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (this){ + if (context.hasData("count")){ + Integer count = context.getData("count"); + context.setData("count", ++count); + } else{ + context.setData("count", 1); + } + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "j",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchJ(NodeComponent bindCmp) throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java new file mode 100644 index 000000000..e786e9f86 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -0,0 +1,4 @@ +package com.yomahub.liteflow.test.asyncNode.exception; + +public class TestException extends Exception{ +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpMultiNode/LiteflowMultiELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclSpringbootTest.java similarity index 59% rename from liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpMultiNode/LiteflowMultiELDeclSpringbootTest.java rename to liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclSpringbootTest.java index 0a327d954..628aab791 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpMultiNode/LiteflowMultiELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclSpringbootTest.java @@ -1,9 +1,8 @@ -package com.yomahub.liteflow.test.cmpMultiNode; +package com.yomahub.liteflow.test.base; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.test.BaseTest; -import com.yomahub.liteflow.test.cmpRetry.LiteflowRetryELDeclSpringbootTest; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,27 +14,25 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** - * 测试springboot下的节点执行器 - * @author sorghum + * springboot环境最普通的例子测试 + * @author Bryan.Zhang + * @since 2.6.4 */ @RunWith(SpringRunner.class) -@TestPropertySource(value = "classpath:/cmpMulti/application.properties") -@SpringBootTest(classes = LiteflowMultiELDeclSpringbootTest.class) +@TestPropertySource(value = "classpath:/base/application.properties") +@SpringBootTest(classes = BaseELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpMultiNode.cmp"}) -public class LiteflowMultiELDeclSpringbootTest extends BaseTest { +@ComponentScan({"com.yomahub.liteflow.test.base.cmp"}) +public class BaseELDeclSpringbootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; - //全局重试配置测试 @Test public void testBase() throws Exception{ LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); - String executeStepStr = response.getExecuteStepStr(); - Assert.assertEquals("a==>b==>c==>d==>e",executeStepStr); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java new file mode 100644 index 000000000..331ea17d2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.base.cmp; + +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 +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + + System.out.println("BCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + + @Resource + private TestDomain testDomain; + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + testDomain.sayHi(); + System.out.println("CCmp executed!"); + } + +} + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java new file mode 100644 index 000000000..16f159324 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest1.java new file mode 100644 index 000000000..7327e123f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest1.java @@ -0,0 +1,212 @@ +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.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.builder.entity.ExecutableEntity; +import com.yomahub.liteflow.flow.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 = BuilderELDeclSpringbootTest1.class) +@EnableAutoConfiguration +public class BuilderELDeclSpringbootTest1 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.SWITCH) + .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(); + + + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( + "THEN(c, d)" + ).build(); + + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( + "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } + + //基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz(GCmp.class) + .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(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } + + + //基于普通组件的builder模式测试 + @Test + public void testBuilderForConditionNode() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz(GCmp.class) + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition() + .setExecutable(new ExecutableEntity().setId("c")) + .setExecutable(new ExecutableEntity().setId("d")) + .build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setExecutable(new ExecutableEntity().setId("a").setTag("hello")) + .setExecutable(new ExecutableEntity().setId("b")) + .build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setExecutable( + new ExecutableEntity().setId("e") + .addNodeCondComponent(new ExecutableEntity().setId("f").setTag("FHello")) + .addNodeCondComponent(new ExecutableEntity().setId("g")) + .addNodeCondComponent(new ExecutableEntity().setId("chain2") + )).build() + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest2.java new file mode 100644 index 000000000..73c6402f2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest2.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.builder; + +import com.yomahub.liteflow.builder.LiteFlowChainBuilder; +import com.yomahub.liteflow.builder.LiteFlowConditionBuilder; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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.junit4.SpringRunner; + +import javax.annotation.Resource; + +//基于builder模式的单元测试 +//这里测试的是通过spring去扫描,但是通过代码去构建chain的用例 +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BuilderELDeclSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"}) +public class BuilderELDeclSpringbootTest2 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( + "THEN(h, i, j)" + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java new file mode 100644 index 000000000..a9ffd1f01 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java new file mode 100644 index 000000000..e13b0434f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java new file mode 100644 index 000000000..6fbbc10e6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java new file mode 100644 index 000000000..27fb0fd46 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java new file mode 100644 index 000000000..0e4627ec5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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.LiteflowSwitchCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowSwitchCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_SWITCH) + public String processSwitch(NodeComponent bindCmp) throws Exception { + System.out.println("ECmp executed!"); + return "chain2"; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java new file mode 100644 index 000000000..a300c50fd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java new file mode 100644 index 000000000..4035e89ca --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java new file mode 100644 index 000000000..a3bd495ac --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java new file mode 100644 index 000000000..a7546b330 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java new file mode 100644 index 000000000..a270fc3c9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclSpringbootTest.java new file mode 100644 index 000000000..a42cb248b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclSpringbootTest.java @@ -0,0 +1,63 @@ +package com.yomahub.liteflow.test.cmpRetry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = LiteflowRetryELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +public class LiteflowRetryELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); + } + + //单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); + } + + //单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + //单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CmpConfig.java new file mode 100644 index 000000000..5fd355dba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CmpConfig.java @@ -0,0 +1,55 @@ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + private int flag = 0; + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + + @LiteflowRetry(5) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + throw new RuntimeException("demo exception"); + } + + @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new RuntimeException("demo exception"); + } + + @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + + + + + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java new file mode 100644 index 000000000..d07e71009 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java @@ -0,0 +1,74 @@ +package com.yomahub.liteflow.test.cmpStep; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.flow.entity.CmpStep; +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.Map; +import java.util.Queue; +import java.util.Set; + +/** + * springboot环境最普通的例子测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/cmpStep/application.properties") +@SpringBootTest(classes = CmpStepELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.cmpStep.cmp"}) +public class CmpStepELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testStep() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); + } + + @Test + public void testStep2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testStep3() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Map stepMap = response.getExecuteSteps(); + Assert.assertEquals(2, stepMap.size()); + Queue queue = response.getExecuteStepQueue(); + Assert.assertEquals(5, queue.size()); + + Set tagSet = new HashSet<>(); + response.getExecuteStepQueue().stream().filter( + cmpStep -> cmpStep.getNodeId().equals("a") + ).forEach(cmpStep -> tagSet.add(cmpStep.getTag())); + + Assert.assertEquals(3, tagSet.size()); + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CmpConfig.java new file mode 100644 index 000000000..0d6faa35b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CmpConfig.java @@ -0,0 +1,49 @@ +package com.yomahub.liteflow.test.cmpStep.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) throws Exception{ + Thread.sleep(5000L); + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) throws Exception{ + System.out.println("CCmp executed!"); + Thread.sleep(2000); + throw new RuntimeException("test error c"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + throw new RuntimeException("test error d"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "e") + public boolean isAccessE(NodeComponent bindCmp) { + return false; + } + + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java new file mode 100644 index 000000000..cad44ba2d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java @@ -0,0 +1,35 @@ +package com.yomahub.liteflow.test.comments; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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:/comments/application.properties") +@SpringBootTest(classes = LiteflowNodeELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.comments.cmp"}) +public class LiteflowNodeELSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 测试注释 + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr())); + } +} \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CmpConfig.java new file mode 100644 index 000000000..3f17a764f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CmpConfig.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.comments.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/package-info.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/package-info.java new file mode 100644 index 000000000..8169c663e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/package-info.java @@ -0,0 +1,4 @@ +/** + * 测试注释 + */ +package com.yomahub.liteflow.test.comments; \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest1.java new file mode 100644 index 000000000..8da0296d4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest1.java @@ -0,0 +1,48 @@ +package com.yomahub.liteflow.test.complex; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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环境EL复杂例子测试1 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/complex/application1.properties") +@SpringBootTest(classes = ComplexELDeclSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.complex.cmp1"}) +public class ComplexELDeclSpringbootTest1 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试复杂例子,优化前 + //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + //测试复杂例子,优化后 + //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest2.java new file mode 100644 index 000000000..9a6aa0332 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest2.java @@ -0,0 +1,48 @@ +package com.yomahub.liteflow.test.complex; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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环境EL复杂例子测试1 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/complex/application2.properties") +@SpringBootTest(classes = ComplexELDeclSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.complex.cmp2"}) +public class ComplexELDeclSpringbootTest2 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试复杂例子,优化前 + //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + //测试复杂例子,优化后 + //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CmpConfig1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CmpConfig1.java new file mode 100644 index 000000000..0e7b986b9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CmpConfig1.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.complex.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig1 { + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "A") + public void processA(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "B") + public void processB(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "C") + public void processC(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "D") + public void processD(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "E") + public void processE(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "F") + public void processF(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "G",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchG(NodeComponent bindCmp) throws Exception { + return "t1"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "H") + public void processH(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "J") + public void processJ(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "K") + public void processK(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "L") + public void processL(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "M") + public void processM(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "N") + public void processN(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "Z") + public void processZ(NodeComponent bindCmp) { + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java new file mode 100644 index 000000000..eca509c60 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.complex.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("I") +public class ICmp extends NodeComponent { + + @Override + public void process() { + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CmpConfig2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CmpConfig2.java new file mode 100644 index 000000000..d0baed327 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CmpConfig2.java @@ -0,0 +1,82 @@ +package com.yomahub.liteflow.test.complex.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig2 { + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "A") + public void processA(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeType = AnnotionNodeTypeEnum.SWITCH,nodeId = "B") + public String processSwitchB(NodeComponent bindCmp) { + return "t3"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "C") + public void processC(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "D") + public void processD(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "E") + public void processE(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "F") + public void processF(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeType = AnnotionNodeTypeEnum.SWITCH,nodeId = "G") + public String processSwitchG(NodeComponent bindCmp) throws Exception { + return "t2"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "H") + public void processH(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "J") + public void processJ(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "K") + public void processK(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "L") + public void processL(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "M") + public void processM(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "N") + public void processN(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId ="Z") + public void processZ(NodeComponent bindCmp) { + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java new file mode 100644 index 000000000..08d071199 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.complex.cmp2; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("I") +public class ICmp extends NodeComponent { + + @Override + public void process() { + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclSpringbootTest.java new file mode 100644 index 000000000..185fe349d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclSpringbootTest.java @@ -0,0 +1,93 @@ +package com.yomahub.liteflow.test.component; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = FlowExecutorELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +public class FlowExecutorELDeclSpringbootTest extends BaseTest { + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELDeclSpringbootTest.class); + + @Resource + private FlowExecutor flowExecutor; + + //isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } + + //组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } + + //isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } + + //isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d",response.getExecuteStepStr()); + } + + //setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e",response.getExecuteStepStr()); + } + + //条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + //测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g",response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CmpConfig1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CmpConfig1.java new file mode 100644 index 000000000..7dc69c72f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CmpConfig1.java @@ -0,0 +1,116 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.util.JsonUtil; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component +public class CmpConfig1 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("AComp executed!"); + bindCmp.getSlot().setResponseData("AComp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "a") + public boolean isAccessA(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100){ + return true; + } + System.out.println("AComp isAccess false."); + return false; + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BComp executed!"); + Integer requestData = bindCmp.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "b") + public boolean isAccessB(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CComp executed!"); + Integer requestData = bindCmp.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + System.out.println("responseData="+Integer.parseInt(bindCmp.getSlot().getResponseData())); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR,nodeId = "c") + public boolean isContinueOnErrorC(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) throws Exception { + System.out.println("DComp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_END,nodeId = "d") + public boolean isEndD(NodeComponent bindCmp) { + //组件的process执行完之后才会执行isEnd + Object requestData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(requestData)){ + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) throws Exception { + System.out.println("EComp executed!"); + Object responseData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(responseData)){ + System.out.println("EComp responseData flow must be set end ."); + //执行到某个条件时,手动结束流程。 + bindCmp.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void processF(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + bindCmp.setIsEnd(true); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + return true; + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "h") + public void processH(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java new file mode 100644 index 000000000..bc34ffdfc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.component.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component +public class FCondCmp{ + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "f",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchF(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.isNull(requestData)){ + return "d"; + } else if(requestData == 0){ + return "c"; + } else { + return "b"; + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclSpringbootTest.java new file mode 100644 index 000000000..dc5890778 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.customMethodName; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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; + +/** + * 声明式组件自定义方法的测试用例 + * @author Bryan.Zhang + * @since 2.7.2 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/customMethodName/application.properties") +@SpringBootTest(classes = CustomMethodNameELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customMethodName.cmp"}) +public class CustomMethodNameELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomMethodName() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java new file mode 100644 index 000000000..7fdabc680 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java @@ -0,0 +1,54 @@ +package com.yomahub.liteflow.test.customMethodName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.Slot; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processAcmp(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "a") + public boolean isAcmpAccess(NodeComponent bindCmp){ + return true; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.BEFORE_PROCESS,nodeId = "a") + public void beforeAcmp(String nodeId, Slot slot){ + System.out.println("before A"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.AFTER_PROCESS,nodeId = "a") + public void afterAcmp(String nodeId, Slot slot){ + System.out.println("after A"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId ="a") + public void onAcmpSuccess(NodeComponent bindCmp){ + System.out.println("Acmp success"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR,nodeId = "a") + public void onAcmpError(NodeComponent bindCmp){ + System.out.println("Acmp error"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_END,nodeId = "a") + public boolean isAcmpEnd(NodeComponent bindCmp) { + System.out.println("Acmp end config"); + return false; + } + /////////////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processBcmp(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclSpringbootTest.java new file mode 100644 index 000000000..a846e3f22 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclSpringbootTest.java @@ -0,0 +1,44 @@ +package com.yomahub.liteflow.test.customNodes; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = CustomNodesELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +public class CustomNodesELDeclSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java new file mode 100644 index 000000000..fb8982c22 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java new file mode 100644 index 000000000..67ed16bcf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java new file mode 100644 index 000000000..d4ee3cf17 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java new file mode 100644 index 000000000..619905b1e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java new file mode 100644 index 000000000..27b3243ce --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java new file mode 100644 index 000000000..a7f22de97 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java new file mode 100644 index 000000000..d0b10dc0b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java new file mode 100644 index 000000000..6f88c4cdd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java new file mode 100644 index 000000000..7d45e4ad5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java new file mode 100644 index 000000000..875dc3d1d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java new file mode 100644 index 000000000..c96e897d9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java @@ -0,0 +1,75 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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 = CustomWhenThreadPoolELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +public class CustomWhenThreadPoolELDeclSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); + } + + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } + + + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CmpConfig.java new file mode 100644 index 000000000..a5f0835ae --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CmpConfig.java @@ -0,0 +1,52 @@ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("DCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ECmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclSpringbootTest.java new file mode 100644 index 000000000..0db32bc2b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclSpringbootTest.java @@ -0,0 +1,64 @@ +package com.yomahub.liteflow.test.event; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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:/event/application.properties") +@SpringBootTest(classes = EventELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.event.cmp"}) +public class EventELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试组件成功事件 + @Test + public void testEvent1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("abc", context.getData("test")); + } + + //测试组件失败事件 + @Test + public void testEvent2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("ab", context.getData("test")); + Assert.assertEquals("error:d", context.getData("error")); + } + + //测试组件失败事件本身抛出异常 + @Test + public void testEvent3() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("a", context.getData("test")); + Assert.assertEquals("error:e", context.getData("error")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CmpConfig.java new file mode 100644 index 000000000..413df954d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CmpConfig.java @@ -0,0 +1,77 @@ +package com.yomahub.liteflow.test.event.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("test",""); + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId = "a") + public void onSuccessA(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String str = context.getData("test"); + str += bindCmp.getNodeId(); + context.setData("test", str); + } + //////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId = "b") + public void onSuccessB(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String str = context.getData("test"); + str += bindCmp.getNodeId(); + context.setData("test", str); + } + /////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId = "c") + public void onSuccessC(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String str = context.getData("test"); + str += bindCmp.getNodeId(); + context.setData("test", str); + } + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) throws Exception{ + System.out.println("CCmp executed!"); + throw new NullPointerException(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR,nodeId = "d") + public void onErrorD(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("error","error:"+bindCmp.getNodeId()); + } + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) throws Exception{ + System.out.println("CCmp executed!"); + throw new NullPointerException(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR,nodeId = "e") + public void onErrorE(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("error","error:"+bindCmp.getNodeId()); + throw new IllegalAccessException("错误事件回调本身抛出异常"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java new file mode 100644 index 000000000..11441ab58 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.exception; + +import com.yomahub.liteflow.exception.LiteFlowException; + +/** + * 用户自定义带状态码的异常 + */ +public class CustomStatefulException extends LiteFlowException { + public CustomStatefulException(String code, String message) { + super(code, message); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclSpringBootTest.java new file mode 100644 index 000000000..367e14e1c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclSpringBootTest.java @@ -0,0 +1,61 @@ +package com.yomahub.liteflow.test.exception; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.ChainDuplicateException; +import com.yomahub.liteflow.exception.ConfigErrorException; +import com.yomahub.liteflow.exception.FlowExecutorNotInitException; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.test.BaseTest; +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; + +/** + * 流程执行异常 + * 单元测试 + * + * @author zendwang + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Exception1ELDeclSpringBootTest.class) +@EnableAutoConfiguration +public class Exception1ELDeclSpringBootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = ChainDuplicateException.class) + public void testChainDuplicateException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.el.xml"); + flowExecutor.init(); + } + + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.init(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("error/flow.txt"); + flowExecutor.init(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-blank.el.xml"); + flowExecutor.init(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclSpringBootTest.java new file mode 100644 index 000000000..bfd196d8b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclSpringBootTest.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.exception; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.*; +import com.yomahub.liteflow.flow.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 org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 流程执行异常 + * 单元测试 + * + * @author zendwang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/exception/application.properties") +@SpringBootTest(classes = Exception2ELDeclSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +public class Exception2ELDeclSpringBootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @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 + public void testGetSlotFromResponseWhenException() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } + + @Test(expected = NoSwitchTargetNodeException.class) + public void testNoTargetFindException() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); + Assert.assertFalse(response.isSuccess()); + throw response.getCause(); + } + + @Test + public void testInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("300", response.getCode()); + Assert.assertNotNull(response.getCause()); + Assert.assertTrue(response.getCause() instanceof LiteFlowException); + Assert.assertNotNull(response.getSlot()); + } + + @Test + public void testNotInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCode()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CmpConfig.java new file mode 100644 index 000000000..d1cbf3394 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CmpConfig.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.exception.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.exception.CustomStatefulException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + private static final Logger LOG = LoggerFactory.getLogger(CmpConfig.class); + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + String str = bindCmp.getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new RuntimeException("chain execute execption"); + } + LOG.info("Acomp executed!"); + } + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) throws InterruptedException { + String str = bindCmp.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!"); + } + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + LOG.info("Ccomp executed!"); + } + + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + if(1==1){ + int a = 1/0; + } + LOG.info("Dcomp executed!"); + } + //////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + return "a"; + } + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + String str = bindCmp.getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { + throw new CustomStatefulException("300", "chain execute custom stateful execption"); + } + LOG.info("Fcomp executed!"); + } + //////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void processG(NodeComponent bindCmp) { + LOG.info("Gcomp executed!"); + } + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclSpringbootTest.java new file mode 100644 index 000000000..95727f491 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.execute2Future; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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 = Executor2FutureELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +public class Executor2FutureELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testFuture() throws Exception{ + Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CmpConfig.java new file mode 100644 index 000000000..0cd7d4267 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CmpConfig.java @@ -0,0 +1,34 @@ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + + + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclSpringbootTest.java new file mode 100644 index 000000000..c64696b39 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.extend; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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.7.1 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/extend/application.properties") +@SpringBootTest(classes = CmpExtendELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.extend.cmp"}) +public class CmpExtendELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testExtend() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CmpConfig.java new file mode 100644 index 000000000..3eb296644 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CmpConfig.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.test.extend.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + System.out.println(this.sayHi("jack")); + } + protected String sayHi(String name){ + return StrUtil.format("hi,{}",name); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java new file mode 100644 index 000000000..76e4af170 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java @@ -0,0 +1,60 @@ +package com.yomahub.liteflow.test.getChainName; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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环境获取ChainName的测试 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/getChainName/application.properties") +@SpringBootTest(classes = GetChainNameELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.getChainName.cmp"}) +public class GetChainNameELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testGetChainName1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } + + @Test + public void testGetChainName2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CmpConfig.java new file mode 100644 index 000000000..7b7f930b2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CmpConfig.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.getChainName.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + if (context.hasData(bindCmp.getNodeId())){ + context.setData(bindCmp.getNodeId(), context.getData(bindCmp.getNodeId()) + "_" + bindCmp.getCurrChainName()); + }else{ + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void processG(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "h",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchH(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + return "j"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "j") + public void processJ(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "k") + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName()); + } + + + + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclSpringbootTest.java new file mode 100644 index 000000000..2b7bcab33 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclSpringbootTest.java @@ -0,0 +1,88 @@ +package com.yomahub.liteflow.test.ifelse; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/ifelse/application.properties") +@SpringBootTest(classes = IfElseELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.ifelse.cmp"}) +public class IfElseELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //IF只有2个参数 + @Test + public void testIf1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); + } + + //IF只有3个参数 + @Test + public void testIf2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } + + //IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } + + //IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } + + //IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } + + //标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + //IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/CmpConfig.java new file mode 100644 index 000000000..430007f58 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/CmpConfig.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.ifelse.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + + + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF,nodeId = "x1",nodeType = AnnotionNodeTypeEnum.IF) + public boolean processIfX1(NodeComponent bindCmp) throws Exception { + return Boolean.parseBoolean(bindCmp.getTag()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclSpringbootTest.java new file mode 100644 index 000000000..e02e79ad5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclSpringbootTest.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.lazy; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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; + +//spring的延迟加载在el表达形式模式下不起作用 +/*@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/lazy/application.properties") +@SpringBootTest(classes = LazyELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"})*/ +public class LazyELDeclSpringbootTest extends BaseTest { + + /*@Resource + private FlowExecutor flowExecutor; + + @Test + public void testLazy() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + }*/ +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java new file mode 100644 index 000000000..01a43e2a2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -0,0 +1,26 @@ +/** + *

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.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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java new file mode 100644 index 000000000..628760c66 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java new file mode 100644 index 000000000..781d1a209 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclSpringbootTest.java new file mode 100644 index 000000000..7d88243d0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.lfCmpAnno; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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:/lfCmpAnno/application.properties") +@SpringBootTest(classes = LiteflowComponentELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lfCmpAnno.cmp"}) +public class LiteflowComponentELDeclSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java new file mode 100644 index 000000000..8081c7084 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lfCmpAnno.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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java new file mode 100644 index 000000000..30a7e689e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/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.lfCmpAnno.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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java new file mode 100644 index 000000000..6090b44fc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/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.lfCmpAnno.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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java new file mode 100644 index 000000000..967f00f33 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/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.lfCmpAnno.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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclSpringbootTest.java new file mode 100644 index 000000000..eb1b5f9a8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclSpringbootTest.java @@ -0,0 +1,49 @@ +package com.yomahub.liteflow.test.monitor; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = MonitorELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +public class MonitorELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + + Thread.sleep(10000); + } + + @AfterClass + public static void clean(){ + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CmpConfig.java new file mode 100644 index 000000000..e82e5a8da --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CmpConfig.java @@ -0,0 +1,44 @@ +package com.yomahub.liteflow.test.monitor.cmp; + +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 +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + 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-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java new file mode 100644 index 000000000..af8bfad4a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.multiContext; + +public class CheckContext { + + private String sign; + + private int randomId; + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclSpringbootTest.java new file mode 100644 index 000000000..0556db2b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclSpringbootTest.java @@ -0,0 +1,54 @@ +package com.yomahub.liteflow.test.multiContext; + +import cn.hutool.core.date.DateUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.NoSuchContextBeanException; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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:/multiContext/application.properties") +@SpringBootTest(classes = MultiContextELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.multiContext.cmp"}) +public class MultiContextELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMultiContext1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("987XYZ", checkContext.getSign()); + Assert.assertEquals(95, checkContext.getRandomId()); + Assert.assertEquals("SO12345", orderContext.getOrderNo()); + Assert.assertEquals(2, orderContext.getOrderType()); + Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); + } + + @Test(expected = NoSuchContextBeanException.class) + public void testMultiContext2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + DefaultContext context = response.getContextBean(DefaultContext.class); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java new file mode 100644 index 000000000..c477108b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java @@ -0,0 +1,36 @@ +package com.yomahub.liteflow.test.multiContext; + +import java.util.Date; + +public class OrderContext { + + private String orderNo; + + private int orderType; + + private Date createTime; + + public String getOrderNo() { + return orderNo; + } + + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } + + public int getOrderType() { + return orderType; + } + + public void setOrderType(int orderType) { + this.orderType = orderType; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CmpConfig.java new file mode 100644 index 000000000..8873cc5bb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CmpConfig.java @@ -0,0 +1,50 @@ +package com.yomahub.liteflow.test.multiContext.cmp; + +import cn.hutool.core.date.DateUtil; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.multiContext.CheckContext; +import com.yomahub.liteflow.test.multiContext.OrderContext; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + CheckContext checkContext = bindCmp.getContextBean(CheckContext.class); + checkContext.setSign("987XYZ"); + checkContext.setRandomId(95); + System.out.println("ACmp executed!"); + + } + + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + //getContextBean无参方法是获取到第一个上下文 + OrderContext orderContext = bindCmp.getFirstContextBean(); + orderContext.setOrderNo("SO12345"); + System.out.println("BCmp executed!"); + } + + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + OrderContext orderContext = bindCmp.getContextBean(OrderContext.class); + orderContext.setOrderType(2); + System.out.println("CCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + OrderContext orderContext = bindCmp.getContextBean(OrderContext.class); + orderContext.setCreateTime(DateUtil.parseDate("2022-06-15")); + System.out.println("CCmp executed!"); + } +} + diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclSpringbootTest.java new file mode 100644 index 000000000..d4a70a251 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.multipleType; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = LiteflowMultipleTypeELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +public class LiteflowMultipleTypeELDeclSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CmpConfig.java new file mode 100644 index 000000000..6ee9e3a84 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CmpConfig.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java new file mode 100644 index 000000000..0ced9da9f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DataBus; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.slot.Slot; +import com.yomahub.liteflow.flow.executor.NodeExecutor; + +/** + * 自定义默认的节点执行器 + */ +public class CustomerDefaultNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + context.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java new file mode 100644 index 000000000..5a9f2e58d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DataBus; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.slot.Slot; +import com.yomahub.liteflow.flow.executor.NodeExecutor; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutor进行执行"); + context.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java new file mode 100644 index 000000000..003d33319 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DataBus; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.slot.Slot; +import com.yomahub.liteflow.flow.executor.NodeExecutor; + +import java.util.concurrent.TimeUnit; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + DefaultContext context = instance.getFirstContextBean(); + context.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclSpringbootTest.java new file mode 100644 index 000000000..bfbca501f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclSpringbootTest.java @@ -0,0 +1,72 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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 = LiteflowNodeExecutorELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +public class LiteflowNodeExecutorELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getExecuteStepStr()); + } + + //默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); + } + + //自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStr()); + } + + //自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CmpConfig.java new file mode 100644 index 000000000..c4250308c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CmpConfig.java @@ -0,0 +1,59 @@ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.flow.executor.NodeExecutor; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + + /////////////////// + private int flag = 0; + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + /////////////////// + + @LiteflowRetry(5) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS,nodeId = "c") + public Class getNodeExecutorClassC(NodeComponent bindCmp) { + return CustomerNodeExecutor.class; + } + + /////////////////// + @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @LiteflowMethod(value= LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS,nodeId = "d") + public Class getNodeExecutorClassD(NodeComponent bindCmp) { + return CustomerNodeExecutorAndCustomRetry.class; + } +} + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclSpringbootTest.java new file mode 100644 index 000000000..960edf709 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = CustomParserJsonELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +public class CustomParserJsonELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclSpringbootTest.java new file mode 100644 index 000000000..50340f566 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties") +@SpringBootTest(classes = CustomParserXmlELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +public class CustomParserXmlELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java new file mode 100644 index 000000000..6e6d9f57d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.parsecustom.bean; + +import org.springframework.stereotype.Component; + +@Component +public class TestBean { + + public String returnXmlContent(){ + return "THEN(a,b,c,d)"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CmpConfig.java new file mode 100644 index 000000000..8de23e385 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CmpConfig.java @@ -0,0 +1,61 @@ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.exception.FlowSystemException; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + String str = bindCmp.getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new FlowSystemException("chain execute execption"); + } + System.out.println("ACmp executed!"); + } + /////////////////// + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + /////////////////// + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + return "g"; + } + ////////////////// + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void processG(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + + +} + diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java new file mode 100644 index 000000000..1f4eac49a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -0,0 +1,31 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser; + +/** + * 模拟用户自定义源解析 + * @author dongguo.tao + * @since 2.5.0 + */ +public class CustomJsonFlowParser extends ClassJsonFlowELParser { + @Override + public String parseCustom() { + //模拟自定义解析结果 + String content = "{\n" + + " \"flow\": {\n" + + " \"chain\": [\n" + + " {\n" + + " \"name\": \"chain2\",\n" + + " \"value\": \"THEN(c, g, f)\"\n" + + " },\n" + + " {\n" + + " \"name\": \"chain1\",\n" + + " \"value\": \"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; + System.out.println(content); + return content; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java new file mode 100644 index 000000000..473ad502f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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.el.ClassXmlFlowELParser; +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 ClassXmlFlowELParser { + + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclSpringbootTest.java new file mode 100644 index 000000000..2ae729bc2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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; + +/** + * spring环境的json parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-json.properties") +@SpringBootTest(classes = JsonParserELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class JsonParserELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclSpringbootTest.java new file mode 100644 index 000000000..8a2d95b8d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclSpringbootTest.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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:/parser/application-springEL.properties") +@SpringBootTest(classes = SpringELSupportELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class SpringELSupportELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springEL的解析情况 + @Test + public void testSpringELParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclSpringbootTest.java new file mode 100644 index 000000000..ba8a681bb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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环境的xml parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-xml.properties") +@SpringBootTest(classes = XmlParserELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class XmlParserELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试无springboot场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclSpringbootTest.java new file mode 100644 index 000000000..996935875 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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下的yml parser测试用例 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-yml.properties") +@SpringBootTest(classes = YmlParserELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class YmlParserELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试无springboot场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CmpConfig.java new file mode 100644 index 000000000..2ab4f15df --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CmpConfig.java @@ -0,0 +1,56 @@ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + return "g"; + } + + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void processG(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + + + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclSpringbootTest.java new file mode 100644 index 000000000..708483344 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclSpringbootTest.java @@ -0,0 +1,72 @@ +package com.yomahub.liteflow.test.preAndFinally; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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 = PreAndFinallyELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +public class PreAndFinallyELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); + } + + //测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); + } + + //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); + } + + //测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(context.getData("hasEx")); + } + + @Test + public void testPreAndFinally5() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CmpConfig.java new file mode 100644 index 000000000..e9ff7adfc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CmpConfig.java @@ -0,0 +1,74 @@ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.slot.Slot; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + int i = 1/0; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f1") + public void processF1(NodeComponent bindCmp) { + System.out.println("Finally1Cmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f2") + public void processF2(NodeComponent bindCmp) { + System.out.println("Finally2Cmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f3") + public void processF3(NodeComponent bindCmp) throws Exception{ + Slot slot = bindCmp.getSlot(); + DefaultContext context = slot.getFirstContextBean(); + if (ObjectUtil.isNull(slot.getException())){ + context.setData("hasEx", false); + }else{ + context.setData("hasEx", true); + } + System.out.println("Finally3Cmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "p1") + public void processP1(NodeComponent bindCmp) { + System.out.println("Pre1Cmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "p2") + public void processP2(NodeComponent bindCmp) { + System.out.println("Pre2Cmp executed!"); + } + + + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclSpringbootTest.java new file mode 100644 index 000000000..ca13b8f9c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.privateDelivery; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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:/privateDelivery/application.properties") +@SpringBootTest(classes = PrivateDeliveryELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +public class PrivateDeliveryELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + ConcurrentHashSet set = context.getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CmpConfig.java new file mode 100644 index 000000000..e94eb381b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CmpConfig.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("testSet", new ConcurrentHashSet<>()); + + for (int i = 0; i < 100; i++) { + bindCmp.sendPrivateDeliveryData("b",i+1); + } } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + Integer value = bindCmp.getPrivateDeliveryData(); + DefaultContext context = bindCmp.getFirstContextBean(); + ConcurrentHashSet testSet = context.getData("testSet"); + testSet.add(value); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclSpringbootTest.java new file mode 100644 index 000000000..a7d8d5d96 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclSpringbootTest.java @@ -0,0 +1,69 @@ +package com.yomahub.liteflow.test.refreshRule; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = RefreshRuleELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +public class RefreshRuleELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception{ + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + //测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception{ + new Thread(() -> { + try { + Thread.sleep(3000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + } catch (Exception e) { + e.printStackTrace(); + } + + }).start(); + + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CmpConfig.java new file mode 100644 index 000000000..3f937728d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CmpConfig.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclSpringbootTest.java new file mode 100644 index 000000000..97657d4cc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclSpringbootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.reload; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = ReloadELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +public class ReloadELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception{ + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CmpConfig.java new file mode 100644 index 000000000..836e20c17 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CmpConfig.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclSpringbootTest.java new file mode 100644 index 000000000..77dbaf13c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.requestId; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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; + +/** + * @author tangkc + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/requestId/application.properties") +@SpringBootTest(classes = LiteflowRequestIdELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.requestId.cmp"}) +public class LiteflowRequestIdELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testRequestId() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", response.getSlot().getRequestId()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/CmpConfig.java new file mode 100644 index 000000000..37893b790 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/CmpConfig.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.requestId.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java new file mode 100644 index 000000000..004459325 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.requestId.config; + +import com.yomahub.liteflow.flow.id.RequestIdGenerator; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author tangkc + */ +public class CustomRequestIdGenerator implements RequestIdGenerator { + + private final AtomicInteger atomicInteger = new AtomicInteger(0); + + @Override + public String generate() { + return atomicInteger.incrementAndGet() + ""; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclSpringbootTest.java new file mode 100644 index 000000000..a8d7fae6e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclSpringbootTest.java @@ -0,0 +1,65 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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 = ImplicitSubFlowELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +public class ImplicitSubFlowELDeclSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + public static final Set RUN_TIME_SLOT = new HashSet<>(); + + //这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); + + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + //requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); + } + + //在p里多线程调用q 10次,每个q取到的参数都是不同的。 + @Test + public void testImplicitSubFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + + Set set = context.getData("test"); + + //requestData的取值正确 + Assert.assertEquals(10, set.size()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclSpringbootTest.java new file mode 100644 index 000000000..96eadecda --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclSpringbootTest.java @@ -0,0 +1,53 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.exception.MultipleParsersException; +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 javax.annotation.Resource; + +/** + * 测试主流程与子流程在不同的配置文件的场景 + * + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-subInDifferentConfig1.properties") +@SpringBootTest(classes = SubflowInDifferentConfigELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1","com.yomahub.liteflow.test.subflow.cmp2"}) +public class SubflowInDifferentConfigELDeclSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); + } + + @Autowired + private ApplicationContext context; + + //主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml"); + flowExecutor.init(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclSpringBootTest.java new file mode 100644 index 000000000..85e1a3f0d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclSpringBootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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; + +/** + * 测试显示调用子流程(json) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-json.properties") +@SpringBootTest(classes = SubflowJsonELDeclSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowJsonELDeclSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclSpringBootTest.java new file mode 100644 index 000000000..33e1363e7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclSpringBootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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; + +/** + * 测试显示调用子流程(xml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-xml.properties") +@SpringBootTest(classes = SubflowXMLELDeclSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowXMLELDeclSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclSpringBootTest.java new file mode 100644 index 000000000..e63159a80 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclSpringBootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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; + +/** + * 测试显示调用子流程(yml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-yml.properties") +@SpringBootTest(classes = SubflowYmlELDeclSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowYmlELDeclSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpMultiNode/cmp/MultiCmpConfiguration.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java similarity index 64% rename from liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpMultiNode/cmp/MultiCmpConfiguration.java rename to liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java index bb6aafae2..c4826a4d0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpMultiNode/cmp/MultiCmpConfiguration.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java @@ -1,33 +1,21 @@ -package com.yomahub.liteflow.test.cmpMultiNode.cmp; +package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; -import com.yomahub.liteflow.core.NodeIfComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; -/** - * 多cmp配置 - * - * @author sorghum - */ -@Configuration -public class MultiCmpConfiguration { - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a",cmpClass = NodeComponent.class) +@Component +public class CmpConfig1 { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") public void processA(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "a",cmpClass = NodeComponent.class) - public boolean isAccessA(NodeComponent bindCmp) { - System.out.println("ACmp isAccessA!"); - return true; - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b",cmpClass = NodeIfComponent.class) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") public void processB(NodeComponent bindCmp) { System.out.println("BCmp executed!"); + } @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") @@ -35,6 +23,9 @@ public class MultiCmpConfiguration { System.out.println("CCmp executed!"); } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") public void processD(NodeComponent bindCmp) { System.out.println("DCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/CmpConfig2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/CmpConfig2.java new file mode 100644 index 000000000..95997860a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/CmpConfig2.java @@ -0,0 +1,99 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashSet; +import java.util.Set; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclSpringbootTest.RUN_TIME_SLOT; + +@Component +public class CmpConfig2 { + + @Autowired + private FlowExecutor flowExecutor; + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Fcomp executed!"); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void processG(NodeComponent bindCmp) throws Exception { + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Gcmp executed!"); + + bindCmp.invoke("chain4", "it's implicit subflow."); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "h") + public void processH(NodeComponent bindCmp) { + String requestData = bindCmp.getSubChainReqData(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("innerRequest", requestData); + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); } + + + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "m") + public void processM(NodeComponent bindCmp) { + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "p") + public void processP(NodeComponent bindCmp) throws Exception { + int slotIndex = bindCmp.getSlotIndex(); + for (int i = 0; i < 10; i++) { + int finalI = i; + new Thread(() -> { + try { + flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); + } + Thread.sleep(1000); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "q") + public void processQ(NodeComponent bindCmp) throws Exception { + String requestData = bindCmp.getSubChainReqDataInAsync(); + DefaultContext context = bindCmp.getFirstContextBean(); + + synchronized (this){ + if (context.hasData("test")){ + Set set = context.getData("test"); + set.add(requestData); + }else{ + Set set = new HashSet<>(); + set.add(requestData); + context.setData("test", set); + } + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootJsonTest.java new file mode 100644 index 000000000..22d29d588 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootJsonTest.java @@ -0,0 +1,69 @@ +package com.yomahub.liteflow.test.tag; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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:/tag/application-json.properties") +@SpringBootTest(classes = NodeTagELDeclSpringbootJsonTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagELDeclSpringbootJsonTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testTag1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123",context.getData("test")); + } + + @Test + public void testTag2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } + + //测试多线程when情况下的tag取值是否正确 + //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception{ + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + //测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootXmlTest.java new file mode 100644 index 000000000..22bb4a6c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootXmlTest.java @@ -0,0 +1,69 @@ +package com.yomahub.liteflow.test.tag; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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:/tag/application-xml.properties") +@SpringBootTest(classes = NodeTagELDeclSpringbootXmlTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagELDeclSpringbootXmlTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testTag1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123",context.getData("test")); + } + + @Test + public void testTag2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } + + //测试多线程when情况下的tag取值是否正确 + //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception{ + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + //测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CmpConfig.java new file mode 100644 index 000000000..1791590c4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CmpConfig.java @@ -0,0 +1,80 @@ +package com.yomahub.liteflow.test.tag.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotionNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + String testKey = "test"; + + DefaultContext context = bindCmp.getFirstContextBean(); + if (context.getData(testKey) == null){ + context.setData(testKey,bindCmp.getTag()); + }else{ + String s = context.getData(testKey); + s += bindCmp.getTag(); + context.setData(testKey, s); + } } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b1") + public void processB1(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("test",new ConcurrentHashSet()); + + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + ConcurrentHashSet testSet = context.getData("test"); + testSet.add(bindCmp.getTag()); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "c",nodeType = AnnotionNodeTypeEnum.SWITCH) + public String processSwitchC(NodeComponent bindCmp) { + if(bindCmp.getTag().equals("2")){ + return "e"; + }else{ + return "d"; + } } + + + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("ECmp executed!"); } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("ECmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF() { + System.out.println("FCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "f") + public boolean isAccessF(NodeComponent bindCmp) { + return Boolean.parseBoolean(bindCmp.getTag()); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java new file mode 100644 index 000000000..fee0055e5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/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 ThreadLocal tl = new TransmittableThreadLocal<>(); + + public static String get(){ + return tl.get(); + } + + public static void set(String value){ + tl.set(value); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclSpringbootTest.java new file mode 100644 index 000000000..7e118a665 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclSpringbootTest.java @@ -0,0 +1,43 @@ +package com.yomahub.liteflow.test.useTTLInWhen; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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; + +/** + * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * @author Bryan.Zhang + * @since 2.6.3 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/useTTLInWhen/application.properties") +@SpringBootTest(classes = UseTTLInWhenELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.useTTLInWhen.cmp"}) +public class UseTTLInWhenELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,b", context.getData("b")); + Assert.assertEquals("hello,c", context.getData("c")); + Assert.assertEquals("hello,d", context.getData("d")); + Assert.assertEquals("hello,e", context.getData("e")); + Assert.assertEquals("hello,f", context.getData("f")); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CmpConfig.java new file mode 100644 index 000000000..31bef3718 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CmpConfig.java @@ -0,0 +1,59 @@ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + TestTL.set("hello"); + System.out.println("ACmp executed!"); } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(),value+",b"); + System.out.println("BCmp executed!"); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(),value+",c"); + System.out.println("CCmp executed!"); + } + + + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(),value+",d"); + System.out.println("DCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(),value+",e"); + System.out.println("ECmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(),value+",f"); + System.out.println("FCmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest1.java new file mode 100644 index 000000000..a0ba5e7a2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest1.java @@ -0,0 +1,44 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = WhenTimeOutELDeclSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutELDeclSpringbootTest1 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest2.java new file mode 100644 index 000000000..90c5ad12c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest2.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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:/whenTimeOut/application2.properties") +@SpringBootTest(classes = WhenTimeOutELDeclSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutELDeclSpringbootTest2 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CmpConfig.java new file mode 100644 index 000000000..790880ecb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CmpConfig.java @@ -0,0 +1,68 @@ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + try { + Thread.sleep(3500); + }catch (Exception ignored){ + + } + System.out.println("CCmp executed!"); + } + + + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") + public void processD(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("DCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") + public void processE(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("ECmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("FCmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonELDeclSpringbootTest.java new file mode 100644 index 000000000..9c4081e83 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonELDeclSpringbootTest.java @@ -0,0 +1,82 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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 = ZkNodeWithJsonELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithJsonELDeclSpringbootTest 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() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELDeclSpringbootTest.java new file mode 100644 index 000000000..d578554ad --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELDeclSpringbootTest.java @@ -0,0 +1,82 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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节点存储数据的格式为xml文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-xml.properties") +@SpringBootTest(classes = ZkNodeWithXmlELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithXmlELDeclSpringbootTest 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.xml"); + 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 testZkNodeWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlELDeclSpringbootTest.java new file mode 100644 index 000000000..4776d94ea --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlELDeclSpringbootTest.java @@ -0,0 +1,82 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.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节点存储数据的格式为yml文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-yml.properties") +@SpringBootTest(classes = ZkNodeWithYmlELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithYmlELDeclSpringbootTest 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.yml"); + 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 testZkNodeWithYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CmpConfig.java new file mode 100644 index 000000000..61d3a81f0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CmpConfig.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component +public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/absoluteConfigPath/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/absoluteConfigPath/application.properties new file mode 100644 index 000000000..348a63af9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/absoluteConfigPath/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=/usr/local/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/absoluteConfigPath/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/absoluteConfigPath/flow.el.xml new file mode 100644 index 000000000..0d670c770 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/absoluteConfigPath/flow.el.xml @@ -0,0 +1,7 @@ + + + + + WHEN(a,b,c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/aop/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/aop/application.properties new file mode 100644 index 000000000..0a8873bf3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/aop/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=aop/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/aop/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/aop/flow.el.xml new file mode 100644 index 000000000..500a8af3f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/aop/flow.el.xml @@ -0,0 +1,14 @@ + + + + THEN(a, b, c, d, e); + + + + THEN(a, b, c, WHEN(d, e)); + + + + THEN(a, b, c, f); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/asyncNode/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/asyncNode/application.properties new file mode 100644 index 000000000..69053aff5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/asyncNode/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=asyncNode/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/asyncNode/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/asyncNode/flow.el.xml new file mode 100644 index 000000000..06373bb2f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/asyncNode/flow.el.xml @@ -0,0 +1,49 @@ + + + + + THEN( + a,b,c, + WHEN(d, SWITCH(e).to(f,g)), + chain2 + ); + + + + + THEN(b, SWITCH(j).to(a, chain3)); + + + + WHEN(g, f, h); + + + + THEN(WHEN(f, g, i), WHEN(h)); + + + + THEN(WHEN(f, g, i).ignoreError(true), WHEN(h)); + + + + THEN(a, b, c, WHEN(d, i, g, i, h).ignoreError(true)); + + + + THEN(a, b, c, WHEN(d, i, g, i, h)); + + + + THEN(a, b, c, WHEN(d, i), WHEN(g, i, h).ignoreError(true)); + + + + THEN(a, b, c, WHEN(d, i).ignoreError(true), WHEN(g, i, h)); + + + + THEN(WHEN(d, g, h).any(true), THEN(a, b, c)); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/base/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/base/application.properties new file mode 100644 index 000000000..1f5b49a07 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/base/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=base/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/base/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/base/flow.el.xml new file mode 100644 index 000000000..edf6e579d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/base/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, WHEN(c, d)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpMulti/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpMulti/application.properties new file mode 100644 index 000000000..d2049052f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpMulti/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=cmpMulti/flow.el.xml +liteflow.slot-size=512 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpMulti/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpMulti/flow.el.xml new file mode 100644 index 000000000..2beecda51 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpMulti/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a,b,c,d,e); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpRetry/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpRetry/application.properties new file mode 100644 index 000000000..9dc00f45e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpRetry/application.properties @@ -0,0 +1,3 @@ +liteflow.rule-source=cmpRetry/flow.el.xml +liteflow.retry-count=3 +liteflow.slot-size=512 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpRetry/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpRetry/flow.el.xml new file mode 100644 index 000000000..3aea68da5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpRetry/flow.el.xml @@ -0,0 +1,18 @@ + + + + THEN(a, b); + + + + THEN(c); + + + + THEN(d); + + + + THEN(e); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpStep/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpStep/application.properties new file mode 100644 index 000000000..7c7eabe1b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpStep/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=cmpStep/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpStep/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpStep/flow.el.xml new file mode 100644 index 000000000..e4a1e577a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/cmpStep/flow.el.xml @@ -0,0 +1,14 @@ + + + + THEN(a.tag("A"), b.tag("B"), WHEN(c.tag("C"), d.tag("D"))); + + + + THEN(WHEN(e, a).any(true), b); + + + + THEN(a.tag("a1"), b, a.tag("a2"), a.tag("a3"), b); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/comments/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/comments/application.properties new file mode 100644 index 000000000..83a0815d2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/comments/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=comments/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/comments/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/comments/flow.el.xml new file mode 100644 index 000000000..0c85be0d5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/comments/flow.el.xml @@ -0,0 +1,18 @@ + + + + // 单行注释 + THEN( + // 单行注释 + a, + b, + WHEN( + /** + * 多行注释 + */ + c, + b + ) + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/application1.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/application1.properties new file mode 100644 index 000000000..8375bd39a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/application1.properties @@ -0,0 +1 @@ +liteflow.rule-source=complex/flow1.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/application2.properties new file mode 100644 index 000000000..9485d5aaa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/application2.properties @@ -0,0 +1 @@ +liteflow.rule-source=complex/flow2.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/flow1.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/flow1.el.xml new file mode 100644 index 000000000..8c7e721ec --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/flow1.el.xml @@ -0,0 +1,34 @@ + + + + THEN( + A, + WHEN( + THEN(B, C), + THEN(D, E, F), + THEN( + SWITCH(G).to( + THEN(H, I, WHEN(J, K)).id("t1"), + THEN(L, M).id("t2") + ), + N + ) + ), + Z + ); + + + + item1 = THEN(B, C); + item2 = THEN(D, E, F); + item3_1 = THEN(H, I, WHEN(J, K)).id("t1"); + item3_2 = THEN(L, M).id("t2"); + item3 = THEN(SWITCH(G).to(item3_1, item3_2), N); + + THEN( + A, + WHEN(item1, item2, item3), + Z + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/flow2.el.xml new file mode 100644 index 000000000..cdeebfff6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/complex/flow2.el.xml @@ -0,0 +1,44 @@ + + + + THEN( + A, + SWITCH(B).to( + THEN(D, E, F).id("t1"), + THEN( + C, + WHEN( + THEN( + SWITCH(G).to(THEN(H, I).id("t2"), J), + K + ), + THEN(L, M) + ) + ).id("t3") + ), + Z + ); + + + + item1 = THEN(D, E, F).id("t1"); + + item2_1 = THEN( + SWITCH(G).to( + THEN(H, I).id("t2"), + J + ), + K + ); + + item2_2 = THEN(L, M); + + item2 = THEN(C, WHEN(item2_1, item2_2)).id("t3"); + + THEN( + A, + SWITCH(B).to(item1, item2), + Z + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/component/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/component/application.properties new file mode 100644 index 000000000..f353e04e7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/component/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=component/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/component/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/component/flow.el.xml new file mode 100644 index 000000000..6f2261684 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/component/flow.el.xml @@ -0,0 +1,30 @@ + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(a, d, c); + + + + THEN(a, e, c); + + + + SWITCH(f).to(d, c, b); + + + + THEN(g, h); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customMethodName/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customMethodName/application.properties new file mode 100644 index 000000000..d69d578ad --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customMethodName/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customMethodName/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customMethodName/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customMethodName/flow.el.xml new file mode 100644 index 000000000..3f1a585ab --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customMethodName/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customNodes/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customNodes/application.properties new file mode 100644 index 000000000..07a0213a4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customNodes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customNodes/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customNodes/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customNodes/flow.el.xml new file mode 100644 index 000000000..58ca6778f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customNodes/flow.el.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + WHEN(a, b, c); + + + + WHEN(d, e, f); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customWhenThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customWhenThreadPool/application.properties new file mode 100644 index 000000000..57f18618a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customWhenThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customWhenThreadPool/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customWhenThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customWhenThreadPool/flow.el.xml new file mode 100644 index 000000000..048cdff97 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/customWhenThreadPool/flow.el.xml @@ -0,0 +1,12 @@ + + + + WHEN(a, b); + + + WHEN(c, d).threadPool("com.yomahub.liteflow.test.customWhenThreadPool.CustomThreadExecutor1"); + + + WHEN(e, f).threadPool("com.yomahub.liteflow.test.customWhenThreadPool.CustomThreadExecutor1"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/event/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/event/application.properties new file mode 100644 index 000000000..a2f4251d8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/event/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=event/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/event/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/event/flow.el.xml new file mode 100644 index 000000000..310346b4e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/event/flow.el.xml @@ -0,0 +1,14 @@ + + + + THEN(a, b, c); + + + + THEN(a, b, d); + + + + THEN(a, e, b); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/application.properties new file mode 100644 index 000000000..63d6aa6ca --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=exception/flow.el.xml +liteflow.when-max-wait-seconds=1 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow-blank.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow-blank.el.xml new file mode 100644 index 000000000..3f0ad68e5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow-blank.el.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow-exception.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow-exception.el.xml new file mode 100644 index 000000000..f88a6f727 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow-exception.el.xml @@ -0,0 +1,12 @@ + + + + THEN(a, b, c); + + + + THEN(a, b, c); + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow.el.xml new file mode 100644 index 000000000..58eae78ac --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/exception/flow.el.xml @@ -0,0 +1,22 @@ + + + + THEN(a, b, c); + + + + THEN(a, WHEN(b, c).ignoreError(false)); + + + + THEN(c, d); + + + + SWITCH(e).to(b, c); + + + + THEN(f, g); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/execute2Future/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/execute2Future/application.properties new file mode 100644 index 000000000..21b2b3fa5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/execute2Future/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=execute2Future/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/execute2Future/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/execute2Future/flow.el.xml new file mode 100644 index 000000000..47cf69680 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/execute2Future/flow.el.xml @@ -0,0 +1,7 @@ + + + + THEN(a, b, WHEN(c, d)); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/extend/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/extend/application.properties new file mode 100644 index 000000000..52a362d3e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/extend/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=extend/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/extend/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/extend/flow.el.xml new file mode 100644 index 000000000..049210cf4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/extend/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/getChainName/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/getChainName/application.properties new file mode 100644 index 000000000..14cfce7c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/getChainName/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=getChainName/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/getChainName/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/getChainName/flow.el.xml new file mode 100644 index 000000000..6c033d839 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/getChainName/flow.el.xml @@ -0,0 +1,38 @@ + + + + WHEN(sub1, sub2, sub3, sub4); + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(d); + + + + THEN(e, f); + + + + SWITCH(h).to(j, k); + + + + THEN( + g, + WHEN(sub1, WHEN(sub2, sub3)), + sub4, sub5, e, sub6 + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/ifelse/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/ifelse/application.properties new file mode 100644 index 000000000..efbbddb30 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/ifelse/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=ifelse/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/ifelse/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/ifelse/flow.el.xml new file mode 100644 index 000000000..5cc964a0e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/ifelse/flow.el.xml @@ -0,0 +1,40 @@ + + + + IF(x1.tag("true"), THEN(a, b)); + + + + IF(x1.tag("false"), THEN(a, b), THEN(c, d)); + + + + item = IF(x1.tag("false"), a, THEN(c, c, b)); + IF( + x1.tag("false"), + a, + item + ); + + + + IF(x1.tag("false"), THEN(a, b)).ELSE(THEN(c, d)); + + + + item = IF(x1.tag("false"), a, THEN(c, c, b)); + + IF(x1.tag("false"), THEN(a, b)).ELSE(item); + + + + IF(x1.tag("false"), THEN(a, b)).ELIF(x1.tag("true"), THEN(c, c)).ELSE(d); + + + + IF(x1.tag("false"), a).ELIF(x1.tag("false"), b) + .ELIF(x1.tag("false"), c) + .ELIF(x1.tag("false"), d) + .ELSE(THEN(d, b, a)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lazy/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lazy/application.properties new file mode 100644 index 000000000..50e059c5e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lazy/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=lazy/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lazy/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lazy/flow.el.xml new file mode 100644 index 000000000..049210cf4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lazy/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lfCmpAnno/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lfCmpAnno/application.properties new file mode 100644 index 000000000..0bc99b5a3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lfCmpAnno/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=lfCmpAnno/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lfCmpAnno/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lfCmpAnno/flow.el.xml new file mode 100644 index 000000000..872026cf1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/lfCmpAnno/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, THEN(c, b, a, d)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitor/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitor/application.properties new file mode 100644 index 000000000..42c3065ef --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitor/application.properties @@ -0,0 +1,5 @@ +liteflow.rule-source=monitor/flow.el.xml +liteflow.monitor.enable-log=true +liteflow.monitor.queue-limit=200 +liteflow.monitor.delay=5000 +liteflow.monitor.period=5000 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitor/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitor/flow.el.xml new file mode 100644 index 000000000..0cbf0f2ed --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/monitor/flow.el.xml @@ -0,0 +1,7 @@ + + + + THEN(a, WHEN(b, c)); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multiContext/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multiContext/application.properties new file mode 100644 index 000000000..cac2dda98 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multiContext/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=multiContext/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multiContext/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multiContext/flow.el.xml new file mode 100644 index 000000000..edf6e579d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multiContext/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, WHEN(c, d)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/application.properties new file mode 100644 index 000000000..8f9ac4539 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/application.properties @@ -0,0 +1,2 @@ +liteflow.support-multiple-type=true +liteflow.rule-source=multipleType/flow.el.xml,multipleType/flow.el.yml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/flow.el.xml new file mode 100644 index 000000000..e57552e35 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, THEN(c, b, a)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/flow.el.yml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/flow.el.yml new file mode 100644 index 000000000..34946d48b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/multipleType/flow.el.yml @@ -0,0 +1,4 @@ +flow: + chain: + - name: chain3 + value: "THEN(a, b, c);" diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/nodeExecutor/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/nodeExecutor/application.properties new file mode 100644 index 000000000..6a26de74b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/nodeExecutor/application.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=nodeExecutor/flow.el.xml +liteflow.retry-count=3 +liteflow.slot-size=512 +liteflow.node-executor-class=com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/nodeExecutor/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/nodeExecutor/flow.el.xml new file mode 100644 index 000000000..a92b50eb7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/nodeExecutor/flow.el.xml @@ -0,0 +1,18 @@ + + + + THEN(a); + + + + THEN(b); + + + + THEN(c); + + + + THEN(d); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parsecustom/application-custom-json.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parsecustom/application-custom-json.properties new file mode 100644 index 000000000..27607f630 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parsecustom/application-custom-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=el_json:com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parsecustom/application-custom-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parsecustom/application-custom-xml.properties new file mode 100644 index 000000000..cd30a8f09 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parsecustom/application-custom-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=el_xml:com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-json.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-json.properties new file mode 100644 index 000000000..89b7d642b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.el.json \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-springEL.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-springEL.properties new file mode 100644 index 000000000..2175bdfaf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-springEL.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/**/*.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-xml.properties new file mode 100644 index 000000000..c0b83943a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-yml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-yml.properties new file mode 100644 index 000000000..233b9f810 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.el.yml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.json b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.json new file mode 100644 index 000000000..091e587c3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.json @@ -0,0 +1,14 @@ +{ + "flow": { + "chain": [ + { + "name": "chain2", + "value": "THEN(c,g,f);" + }, + { + "name": "chain1", + "value": "THEN(a,c,WHEN(b,d,SWITCH(e).to(f,g)), chain2);" + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.xml new file mode 100644 index 000000000..23d852df0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.xml @@ -0,0 +1,11 @@ + + + + + THEN(a, c, WHEN(b, d, SWITCH(e).to(f,g)), chain2); + + + + THEN(c, g, f); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.yml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.yml new file mode 100644 index 000000000..3ccd99da8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/flow.el.yml @@ -0,0 +1,6 @@ +flow: + chain: + - name: chain1 + value: "THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g)), chain2);" + - name: chain2 + value: "THEN(c, g, f);" diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow1.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow1.el.xml new file mode 100644 index 000000000..c3db8e44b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow1.el.xml @@ -0,0 +1,12 @@ + + + + + + THEN(a, c, WHEN(b, d, SWITCH(e).to(f,g)), chain2) + + + + THEN(c, g, f) + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow2.el.xml new file mode 100644 index 000000000..fa15c1865 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow2.el.xml @@ -0,0 +1,7 @@ + + + + + THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g)), chain2) + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow3.el.xml new file mode 100644 index 000000000..6d5223279 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parser/subFoder1/subFoder2/flow3.el.xml @@ -0,0 +1,6 @@ + + + + THEN(c, g, f) + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/preAndFinally/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/preAndFinally/application.properties new file mode 100644 index 000000000..b7c8f05df --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/preAndFinally/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=preAndFinally/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/preAndFinally/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/preAndFinally/flow.el.xml new file mode 100644 index 000000000..d391acd07 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/preAndFinally/flow.el.xml @@ -0,0 +1,22 @@ + + + + THEN(PRE(p1, p2), THEN(a, b, c), FINALLY(f1, f2)); + + + + THEN(a, PRE(p1, p2), FINALLY(f1, f2), THEN(b, c)); + + + + THEN(PRE(p1, p2), THEN(a, d, c), FINALLY(f1, f2)); + + + + THEN(a, d, c, FINALLY(f3)); + + + + THEN(PRE(p1, p2), chain1, FINALLY(f1)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/privateDelivery/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/privateDelivery/application.properties new file mode 100644 index 000000000..7c19a9c06 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/privateDelivery/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=privateDelivery/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/privateDelivery/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/privateDelivery/flow.el.xml new file mode 100644 index 000000000..6458ae5bd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/privateDelivery/flow.el.xml @@ -0,0 +1,21 @@ + + + + THEN( + a, + WHEN( + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b, + b,b,b,b,b,b,b,b,b,b + ), + c + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/application.properties new file mode 100644 index 000000000..d9ce5b748 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=refreshRule/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/flow.el.xml new file mode 100644 index 000000000..049210cf4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/flow_update.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/flow_update.el.xml new file mode 100644 index 000000000..5333b7e2d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/refreshRule/flow_update.el.xml @@ -0,0 +1,6 @@ + + + + THEN(c, b, a); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/reload/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/reload/application.properties new file mode 100644 index 000000000..cdde88c73 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/reload/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=reload/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/reload/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/reload/flow.el.xml new file mode 100644 index 000000000..049210cf4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/reload/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/requestId/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/requestId/application.properties new file mode 100644 index 000000000..601cc9417 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/requestId/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=requestId/flow.el.xml +liteflow.request-id-generator-class=com.yomahub.liteflow.test.requestId.config.CustomRequestIdGenerator \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/requestId/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/requestId/flow.el.xml new file mode 100644 index 000000000..3f1a585ab --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/requestId/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-implicit.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-implicit.properties new file mode 100644 index 000000000..424d7cb10 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-implicit.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow-implicit.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-json.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-json.properties new file mode 100644 index 000000000..4a247cadf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.el.json \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-subInDifferentConfig1.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-subInDifferentConfig1.properties new file mode 100644 index 000000000..9006564d9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-subInDifferentConfig1.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-subInDifferentConfig2.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-subInDifferentConfig2.properties new file mode 100644 index 000000000..a0d247d83 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-subInDifferentConfig2.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.yml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-xml.properties new file mode 100644 index 000000000..95b534046 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-yml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-yml.properties new file mode 100644 index 000000000..3c2295809 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.el.yml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-implicit.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-implicit.el.xml new file mode 100644 index 000000000..91498014a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-implicit.el.xml @@ -0,0 +1,18 @@ + + + + THEN(f, g); + + + + THEN(h, m); + + + + THEN(p); + + + + THEN(q); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-main.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-main.el.xml new file mode 100644 index 000000000..0310bbf15 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-main.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, chain2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub1.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub1.el.xml new file mode 100644 index 000000000..829886d02 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub1.el.xml @@ -0,0 +1,6 @@ + + + + THEN(b, a, chain3); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub2.el.xml new file mode 100644 index 000000000..63676b2b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub2.el.xml @@ -0,0 +1,6 @@ + + + + THEN(e, d); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub2.el.yml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub2.el.yml new file mode 100644 index 000000000..3d652cf48 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow-sub2.el.yml @@ -0,0 +1,4 @@ +flow: + chain: + - name: chain3 + value: "THEN(e, d);" \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.json b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.json new file mode 100644 index 000000000..a92a77b90 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.json @@ -0,0 +1,22 @@ +{ + "flow": { + "chain": [ + { + "name": "chain3", + "value": "THEN(e,d);" + }, + { + "name": "chain2", + "value": "THEN(b, a, chain3);" + }, + { + "name": "chain1", + "value": "THEN(a, b, c, chain2);" + }, + { + "name": "c", + "value": "THEN(d, e);" + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.xml new file mode 100644 index 000000000..dac14dbca --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.xml @@ -0,0 +1,18 @@ + + + + THEN(a, b, c, chain2); + + + + THEN(d, e); + + + + THEN(b, a, chain3); + + + + THEN(e, d); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.yml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.yml new file mode 100644 index 000000000..cc8f056df --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/subflow/flow.el.yml @@ -0,0 +1,10 @@ +flow: + chain: + - name: chain3 + value: "THEN(e, d);" + - name: chain1 + value: "THEN(a, b, c, chain2);" + - name: c + value: "THEN(d, e);" + - name: chain2 + value: "THEN(b, a, chain3);" \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/application-json.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/application-json.properties new file mode 100644 index 000000000..d85de7220 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=tag/flow.el.json \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/application-xml.properties new file mode 100644 index 000000000..9f7c2b81e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=tag/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/flow.el.json b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/flow.el.json new file mode 100644 index 000000000..cca9b2c58 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/flow.el.json @@ -0,0 +1,22 @@ +{ + "flow": { + "chain": [ + { + "name": "chain1", + "value": "THEN(a.tag(\"1\"), a.tag(\"2\"), a.tag(\"3\"));" + }, + { + "name": "chain2", + "value": "THEN(a.tag(\"1\"), a.tag(\"2\"), a.tag(\"3\"), SWITCH(c.tag(\"2\")).to(d.tag(\"5\"), e.tag(\"6\")));" + }, + { + "name": "chain3", + "value": "THEN(b1, WHEN(b.tag(\"1\"), b.tag(\"2\"), b.tag(\"3\")));" + }, + { + "name": "chain4", + "value": "THEN(f.tag(\"false\"), g);" + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/flow.el.xml new file mode 100644 index 000000000..64343b83f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/tag/flow.el.xml @@ -0,0 +1,18 @@ + + + + THEN(a.tag("1"), a.tag("2"), a.tag("3")); + + + + THEN(a.tag("1"), a.tag("2"), a.tag("3"), SWITCH(c.tag("2")).to(d.tag("5"), e.tag("6"))); + + + + THEN(b1, WHEN(b.tag("1"), b.tag("2"), b.tag("3"))); + + + + THEN(f.tag("false"), g); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/useTTLInWhen/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/useTTLInWhen/application.properties new file mode 100644 index 000000000..ba675ca9b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/useTTLInWhen/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=useTTLInWhen/flow.el.xml +liteflow.when-max-workers=2 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/useTTLInWhen/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/useTTLInWhen/flow.el.xml new file mode 100644 index 000000000..736d9e72d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/useTTLInWhen/flow.el.xml @@ -0,0 +1,6 @@ + + + + THEN(a, WHEN(b, c, d, e, f)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/application1.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/application1.properties new file mode 100644 index 000000000..1c75edbd0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/application1.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=whenTimeOut/flow1.el.xml +liteflow.when-max-wait-seconds=3 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/application2.properties new file mode 100644 index 000000000..2d4ea8b30 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=whenTimeOut/flow2.el.xml +liteflow.when-max-wait-seconds=5 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/flow1.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/flow1.el.xml new file mode 100644 index 000000000..85378915f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/flow1.el.xml @@ -0,0 +1,6 @@ + + + + WHEN(a, b, c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/flow2.el.xml new file mode 100644 index 000000000..641ed9faf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/whenTimeOut/flow2.el.xml @@ -0,0 +1,6 @@ + + + + THEN(WHEN(d), WHEN(e), WHEN(f)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-json.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-json.properties new file mode 100644 index 000000000..e8d44c429 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=el_json:127.0.0.1:21810 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-xml.properties new file mode 100644 index 000000000..e3a6e33db --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=el_xml:127.0.0.1:21810 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-yml.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-yml.properties new file mode 100644 index 000000000..8022eb56f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=el_yml:127.0.0.1:21810 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.json b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.json new file mode 100644 index 000000000..e78b1e919 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.json @@ -0,0 +1,10 @@ +{ + "flow": { + "chain": [ + { + "name": "chain1", + "value": "THEN(a, b, c);" + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.xml new file mode 100644 index 000000000..049210cf4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.xml @@ -0,0 +1,6 @@ + + + + THEN(a, b, c); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.yml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.yml new file mode 100644 index 000000000..2b7bfd1dc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/zookeeper/flow.yml @@ -0,0 +1,4 @@ +flow: + chain: + - name: chain1 + value: "THEN(a, b, c);" \ No newline at end of file diff --git a/liteflow-testcase-el/pom.xml b/liteflow-testcase-el/pom.xml index 5574f1226..ee0907db5 100644 --- a/liteflow-testcase-el/pom.xml +++ b/liteflow-testcase-el/pom.xml @@ -19,6 +19,7 @@ liteflow-testcase-el-springnative liteflow-testcase-el-nospring liteflow-testcase-el-declare-springboot + liteflow-testcase-el-declare-multi-springboot liteflow-testcase-el-script-groovy-springboot liteflow-testcase-el-script-qlexpress-springboot