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 c43b60df..4da9bf67 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,5 +1,6 @@ package com.yomahub.liteflow.annotation; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import java.lang.annotation.*; @@ -11,4 +12,14 @@ import java.lang.annotation.*; public @interface LiteflowMethod { LiteFlowMethodEnum value(); + + // 节点ID,用于区分节点 + // 默认为空 则按照Spring模式下BeanName为准。 + String nodeId() default ""; + + /** + * CMP类型定义 + * @return AnnotationNodeTypeEnum + */ + AnnotationNodeTypeEnum nodeType() default AnnotationNodeTypeEnum.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 7f4ca10e..bb49d4c5 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/builder/LiteFlowNodeBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java index 33d3f763..e4720e29 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java @@ -122,7 +122,7 @@ public class LiteFlowNodeBuilder { FlowBus.addIfScriptNode(this.node.getId(), this.node.getName(), this.node.getScript()); } } catch (Exception e) { - String errMsg = StrUtil.format("An exception occurred while building the node[{}]", this.node.getId()); + String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(),e.getMessage()); LOG.error(errMsg, e); throw new NodeBuildException(errMsg); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 23afa587..18afa290 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -6,21 +6,22 @@ import com.ql.util.express.DefaultContext; import com.ql.util.express.ExpressRunner; import com.ql.util.express.exception.QLException; import com.yomahub.liteflow.builder.el.operator.*; +import com.yomahub.liteflow.exception.DataNofFoundException; import com.yomahub.liteflow.exception.ELParseException; import com.yomahub.liteflow.exception.FlowSystemException; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.element.Chain; import com.yomahub.liteflow.flow.element.Executable; -import com.yomahub.liteflow.flow.element.condition.Condition; -import com.yomahub.liteflow.flow.element.condition.FinallyCondition; -import com.yomahub.liteflow.flow.element.condition.PreCondition; +import com.yomahub.liteflow.flow.element.condition.*; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Chain基于代码形式的组装器 * EL表达式规则专属组装器 + * * @author Bryan.Zhang * @since 2.8.0 */ @@ -41,7 +42,7 @@ public class LiteFlowChainELBuilder { private final List finallyConditionList; //EL解析引擎 - private final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner();; + private final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner(); static { //初始化QLExpress的Runner @@ -86,13 +87,13 @@ public class LiteFlowChainELBuilder { } public LiteFlowChainELBuilder setEL(String elStr) { - if (StrUtil.isBlank(elStr)){ + if (StrUtil.isBlank(elStr)) { String errMsg = StrUtil.format("no conditionList in this chain[{}]", chain.getChainName()); throw new FlowSystemException(errMsg); } List errorList = new ArrayList<>(); - try{ + try { DefaultContext context = new DefaultContext<>(); //这里一定要先放chain,再放node,因为node优先于chain,所以当重名时,node会覆盖掉chain @@ -111,8 +112,8 @@ public class LiteFlowChainELBuilder { //为什么只寻找第一层,而不往下寻找了呢? //因为这是一个规范,如果在后面的层级中出现pre和finally,语义上也不好理解,所以pre和finally只能定义在第一层 //如果硬是要在后面定义,则执行的时候会忽略,相关代码已做了判断 - for (Executable executable : condition.getExecutableList()){ - if (executable instanceof PreCondition){ + for (Executable executable : condition.getExecutableList()) { + if (executable instanceof PreCondition) { this.preConditionList.add((PreCondition) executable); } else if (executable instanceof FinallyCondition) { this.finallyConditionList.add((FinallyCondition) executable); @@ -122,9 +123,13 @@ public class LiteFlowChainELBuilder { //把主要的condition加入 this.conditionList.add(condition); return this; - }catch (QLException e){ + } catch (QLException e) { + // EL 底层会包装异常,这里是曲线处理 + if (Objects.equals(e.getCause().getMessage(), DataNofFoundException.MSG)) { + throw new ELParseException(String.format("[node/chain is not exist or node/chain not register]elStr=%s", elStr)); + } throw new ELParseException(e.getCause().getMessage()); - }catch (Exception e){ + } catch (Exception e) { throw new ELParseException(e.getMessage()); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java index 4a1028c6..4e676fae 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java @@ -11,10 +11,10 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class AnyOperator extends BaseOperator { +public class AnyOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public WhenCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqTwo(objects); WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java index 7b77e238..273bf750 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java @@ -15,10 +15,10 @@ import com.yomahub.liteflow.flow.element.condition.IfCondition; * @author Bryan.Zhang * @since 2.8.5 */ -public class ElifOperator extends BaseOperator { +public class ElifOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public IfCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqThree(objects); //解析caller diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java index 8fa76382..80db05b4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java @@ -11,10 +11,10 @@ import com.yomahub.liteflow.flow.element.condition.IfCondition; * @author Bryan.Zhang * @since 2.8.5 */ -public class ElseOperator extends BaseOperator { +public class ElseOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public IfCondition build(Object[] objects) throws Exception { // 参数只能是1个,但这里为什么是2个呢?第一个是caller,第二个才是参数 OperatorHelper.checkObjectSizeEqTwo(objects); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java index 445f6f3e..c9c5c171 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java @@ -12,10 +12,10 @@ import com.yomahub.liteflow.flow.element.condition.FinallyCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class FinallyOperator extends BaseOperator { +public class FinallyOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public FinallyCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeGtZero(objects); FinallyCondition finallyCondition = new FinallyCondition(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java index 0b415efe..490e1cdb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java @@ -13,12 +13,12 @@ import org.slf4j.LoggerFactory; * @author Bryan.Zhang * @since 2.8.0 */ -public class IdOperator extends BaseOperator { +public class IdOperator extends BaseOperator { private final Logger LOG = LoggerFactory.getLogger(this.getClass()); @Override - public Object buildCondition(Object[] objects) throws Exception { + public Condition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqTwo(objects); Condition condition = OperatorHelper.convert(objects[0], Condition.class); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java index e9522a14..18814819 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java @@ -15,10 +15,10 @@ import com.yomahub.liteflow.flow.element.condition.IfCondition; * @author Bryan.Zhang * @since 2.8.5 */ -public class IfOperator extends BaseOperator { +public class IfOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public IfCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEq(objects, 2, 3); //解析第一个参数 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java index 7c8b11b0..7deb530b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java @@ -11,10 +11,10 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class IgnoreErrorOperator extends BaseOperator { +public class IgnoreErrorOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public WhenCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqTwo(objects); WhenCondition condition = OperatorHelper.convert(objects[0], WhenCondition.class); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java index db07bd69..d179f9cc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java @@ -16,10 +16,10 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter; * @author Bryan.Zhang * @since 2.8.3 */ -public class NodeOperator extends BaseOperator { +public class NodeOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public Node build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeNeqOne(objects); String nodeId; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java index d5c1e015..66183d35 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java @@ -12,10 +12,10 @@ import com.yomahub.liteflow.flow.element.condition.PreCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class PreOperator extends BaseOperator { +public class PreOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public PreCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeGtZero(objects); PreCondition preCondition = new PreCondition(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java index a9827e1b..95aa0f76 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java @@ -14,10 +14,10 @@ import com.yomahub.liteflow.flow.element.condition.SwitchCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class SwitchOperator extends BaseOperator { +public class SwitchOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public SwitchCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeNeqOne(objects); Node switchNode; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java index 112e2b86..652f45e6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java @@ -12,10 +12,10 @@ import com.yomahub.liteflow.flow.element.Node; * @author Bryan.Zhang * @since 2.8.0 */ -public class TagOperator extends BaseOperator { +public class TagOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public Node build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqTwo(objects); Node node = OperatorHelper.convert(objects[0], Node.class); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java index 7a1618f2..77bd8459 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java @@ -12,10 +12,10 @@ import com.yomahub.liteflow.flow.element.condition.ThenCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class ThenOperator extends BaseOperator { +public class ThenOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public ThenCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeGtZero(objects); ThenCondition thenCondition = new ThenCondition(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java index aa0f7d99..265c2ed6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java @@ -11,10 +11,10 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class ThreadPoolOperator extends BaseOperator { +public class ThreadPoolOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public WhenCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqTwo(objects); WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ToOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ToOperator.java index d41a9260..25421397 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ToOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ToOperator.java @@ -12,10 +12,10 @@ import com.yomahub.liteflow.flow.element.condition.SwitchCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class ToOperator extends BaseOperator { +public class ToOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public SwitchCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeGtTwo(objects); SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java index 00e289b0..974c50e2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java @@ -11,10 +11,10 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; * @author Bryan.Zhang * @since 2.8.0 */ -public class WhenOperator extends BaseOperator { +public class WhenOperator extends BaseOperator { @Override - public Object buildCondition(Object[] objects) throws Exception { + public WhenCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeGtZero(objects); WhenCondition whenCondition = new WhenCondition(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java index 94ee54f0..c5410530 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.builder.el.operator.base; import com.ql.util.express.Operator; import com.ql.util.express.exception.QLException; import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.element.Executable; /** * BaseOperator 为了强化 executeInner 方法,会捕获抛出的 QLException 错误,输出友好的错误提示 @@ -10,25 +11,27 @@ import com.yomahub.liteflow.exception.ELParseException; * @author gaibu * @since 2.8.6 */ -public abstract class BaseOperator extends Operator { +public abstract class BaseOperator extends Operator { - @Override - public Object executeInner(Object[] objects) throws Exception { - try { - return buildCondition(objects); - } catch (QLException e) { - throw e; - } catch (Exception e) { - throw new ELParseException("errors occurred in EL parsing"); - } - } + @Override + public T executeInner(Object[] objects) throws Exception { + try { + // 检查 node 和 chain 是否已经注册 + OperatorHelper.checkNodeAndChainExist(objects); + return build(objects); + } catch (QLException e) { + throw e; + } catch (Exception e) { + throw new ELParseException("errors occurred in EL parsing"); + } + } - /** - * 构建 EL 条件 - * - * @param objects objects - * @return Condition - * @throws Exception Exception - */ - public abstract Object buildCondition(Object[] objects) throws Exception; + /** + * 构建 EL 条件 + * + * @param objects objects + * @return Condition + * @throws Exception Exception + */ + public abstract T build(Object[] objects) throws Exception; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/OperatorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/OperatorHelper.java index dbfd86e3..4fe837d1 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/OperatorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/OperatorHelper.java @@ -1,6 +1,9 @@ package com.yomahub.liteflow.builder.el.operator.base; import com.ql.util.express.exception.QLException; +import com.yomahub.liteflow.exception.DataNofFoundException; + +import java.util.Objects; /** * Operator 常用工具类 @@ -9,121 +12,134 @@ import com.ql.util.express.exception.QLException; */ public class OperatorHelper { - /** - * 检查参数数量,不等于1 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeNeqOne(Object[] objects) throws QLException { - checkObjectSizeNeq(objects, 1); - } + /** + * 检查参数数量,不等于1 + * + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeNeqOne(Object[] objects) throws QLException { + checkObjectSizeNeq(objects, 1); + } - /** - * 检查参数数量,不等于 size - * - * @param objects objects - * @param size 参数数量 - * @throws QLException QLException - */ - public static void checkObjectSizeNeq(Object[] objects, int size) throws QLException { - checkObjectSizeGtZero(objects); - if (objects.length != size) { - throw new QLException("parameter error"); - } - } + /** + * 检查参数数量,不等于 size + * + * @param objects objects + * @param size 参数数量 + * @throws QLException QLException + */ + public static void checkObjectSizeNeq(Object[] objects, int size) throws QLException { + checkObjectSizeGtZero(objects); + if (objects.length != size) { + throw new QLException("parameter error"); + } + } - /** - * 检查参数数量,大于 0 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeGtZero(Object[] objects) throws QLException { - if (objects.length == 0) { - throw new QLException("parameter is empty"); - } - } + /** + * 检查参数数量,大于 0 + * + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeGtZero(Object[] objects) throws QLException { + if (objects.length == 0) { + throw new QLException("parameter is empty"); + } + } - /** - * 检查参数数量,大于 2 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeGtTwo(Object[] objects) throws QLException { - checkObjectSizeGtZero(objects); - if (objects.length <= 1) { - throw new QLException("parameter error"); - } - } + /** + * 检查参数数量,大于 2 + * + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeGtTwo(Object[] objects) throws QLException { + checkObjectSizeGtZero(objects); + if (objects.length <= 1) { + throw new QLException("parameter error"); + } + } - /** - * 检查参数数量,等于 2 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeEqTwo(Object[] objects) throws QLException { - checkObjectSizeEq(objects, 2); - } + /** + * 检查参数数量,等于 2 + * + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeEqTwo(Object[] objects) throws QLException { + checkObjectSizeEq(objects, 2); + } - /** - * 检查参数数量,等于 3 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeEqThree(Object[] objects) throws QLException { - checkObjectSizeEq(objects, 3); - } + /** + * 检查参数数量,等于 3 + * + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeEqThree(Object[] objects) throws QLException { + checkObjectSizeEq(objects, 3); + } - /** - * 检查参数数量,等于 size - * - * @param objects objects - * @param size 参数数量 - * @throws QLException QLException - */ - public static void checkObjectSizeEq(Object[] objects, int size) throws QLException { - checkObjectSizeGtZero(objects); + /** + * 检查参数数量,等于 size + * + * @param objects objects + * @param size 参数数量 + * @throws QLException QLException + */ + public static void checkObjectSizeEq(Object[] objects, int size) throws QLException { + checkObjectSizeGtZero(objects); - if (objects.length != size) { - throw new QLException("parameter error"); - } - } + if (objects.length != size) { + throw new QLException("parameter error"); + } + } - /** - * 检查参数数量,等于 size1 或 size2 - * - * @param objects objects - * @param size1 参数数量1 - * @param size2 参数数量2 - * @throws QLException QLException - */ - public static void checkObjectSizeEq(Object[] objects, int size1, int size2) throws QLException { - checkObjectSizeGtZero(objects); + /** + * 检查参数数量,等于 size1 或 size2 + * + * @param objects objects + * @param size1 参数数量1 + * @param size2 参数数量2 + * @throws QLException QLException + */ + public static void checkObjectSizeEq(Object[] objects, int size1, int size2) throws QLException { + checkObjectSizeGtZero(objects); - if (objects.length != size1 && objects.length != size2) { - throw new QLException("parameter error"); - } - } + if (objects.length != size1 && objects.length != size2) { + throw new QLException("parameter error"); + } + } - /** - * 转换 object 为指定的类型 - * - * @param object object - * @param tClass 指定类型 - * @param 返回类型 - * @return T - * @throws QLException QLException - */ - public static T convert(Object object, Class tClass) throws QLException { - if (tClass.isInstance(object)) { - return (T) object; - } + /** + * 转换 object 为指定的类型 + * + * @param object object + * @param tClass 指定类型 + * @param 返回类型 + * @return T + * @throws QLException QLException + */ + public static T convert(Object object, Class tClass) throws QLException { + if (tClass.isInstance(object)) { + return (T) object; + } - throw new QLException("The caller must be " + tClass.getName() + " item"); - } + throw new QLException("The caller must be " + tClass.getName() + " item"); + } + /** + * 检查 node 和 chain 是否已经注册 + * + * @param objects objects + * @throws QLException QLException + */ + public static void checkNodeAndChainExist(Object[] objects) throws QLException { + for (Object object : objects) { + if (Objects.isNull(object)) { + throw new QLException(DataNofFoundException.MSG); + } + } + } } 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 50b8d5ba..d643664e 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 @@ -1,10 +1,18 @@ package com.yomahub.liteflow.core.proxy; import cn.hutool.core.collection.ListUtil; -import cn.hutool.core.util.*; +import cn.hutool.core.lang.Tuple; +import cn.hutool.core.util.ClassUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.exception.ComponentMethodDefineErrorException; +import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.util.LiteFlowProxyUtil; import com.yomahub.liteflow.util.SerialsUtil; import net.bytebuddy.ByteBuddy; @@ -12,13 +20,16 @@ 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; import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; /** @@ -42,7 +53,7 @@ public class ComponentProxy { this.clazz = clazz; } - public Object getProxy() throws Exception{ + public List getProxyList() throws Exception{ //这里要判断bean是否是spring代理过的bean,如果是代理过的bean需要取到原class对象 Class beanClazz; if (LiteFlowProxyUtil.isCglibProxyClass(bean.getClass())){ @@ -50,31 +61,104 @@ public class ComponentProxy { }else{ beanClazz = bean.getClass(); } - - //得到当前bean里所覆盖的组件方法(一定是被@LiteFlowMethod修饰的),自己定义的不算 - List methodStrList = Arrays.stream(beanClazz.getDeclaredMethods()).filter( + //得到当前bean里所覆盖的LiteflowMethod(一定是被@LiteFlowMethod修饰的),自己定义的不算 + Map> methodListMap = Arrays.stream(beanClazz.getDeclaredMethods()).filter( m -> m.getAnnotation(LiteflowMethod.class) != null - ).map(m -> { - LiteflowMethod liteflowMethod = m.getAnnotation(LiteflowMethod.class); - return liteflowMethod.value().getMethodName(); - }).collect(Collectors.toList()); + ).collect(Collectors.groupingBy( + m -> m.getAnnotation(LiteflowMethod.class).nodeId() + )); - //创建对象 - //这里package进行了重设,放到了被代理对象的所在目录 - //生成的对象也加了上被代理对象拥有的注解 - //被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断 - return new ByteBuddy().subclass(clazz) - .name(StrUtil.format("{}.ByteBuddy${}${}", - ClassUtil.getPackage(bean.getClass()), - nodeId, - SerialsUtil.generateShortUUID())) - .method(ElementMatchers.namedOneOf(methodStrList.toArray(new String[]{}))) - .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean))) - .annotateType(bean.getClass().getAnnotations()) - .make() - .load(ComponentProxy.class.getClassLoader()) - .getLoaded() - .newInstance(); + return methodListMap.entrySet().stream().map(entry -> { + // 获取当前节点的原有注解,如:LiteFlowRetry 之类的规则注解 + Annotation[] beanClassAnnotation = bean.getClass().getAnnotations(); + // 如果entry的key为空字符串,则是为了兼容老版本的写法,即:没有指定nodeId的情况 + // 判断是否是方法级创造节点 + boolean isMethodCreate = !StrUtil.isEmpty(entry.getKey()); + // 获取当前bean 真实的nodeId + String activeNodeId = isMethodCreate ? entry.getKey() : nodeId; + // 获取当前节点所有的@LiteflowRetry @LiteflowMethod注解对 + List tupleList = entry.getValue().stream().map(m -> + new Tuple(m.getAnnotation(LiteflowRetry.class), m.getAnnotation(LiteflowMethod.class)) + ).collect(Collectors.toList()); + // 获取当前节点的所有LiteFlowMethod注解 + List methodList = tupleList.stream().map(tuple -> ((LiteflowMethod)tuple.get(1))) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + // nodeType去重 + List> classes = methodList.stream() + .map(LiteflowMethod::nodeType) + .map(AnnotationNodeTypeEnum::getCmpClass) + .distinct() + .collect(Collectors.toList()); + // 相同nodeId里只能定义同一种的类型的NodeComponent + 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注解 + AtomicReference liteflowRetryAtomicReference = new AtomicReference<>(null); + // 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上 + boolean illegal = tupleList.stream().anyMatch( + tuple -> { + LiteflowRetry liteflowRetry = tuple.get(0); + LiteflowMethod liteflowMethod = tuple.get(1); + boolean existRetry = liteflowRetry != null; + boolean isProcess = liteflowMethod.value().equals(LiteFlowMethodEnum.PROCESS) + || liteflowMethod.value().equals(LiteFlowMethodEnum.PROCESS_IF) + || liteflowMethod.value().equals(LiteFlowMethodEnum.PROCESS_SWITCH); + // 如果是再Process方法上的liteflowRetry注解,则默认为真实节点。 + if (isProcess && existRetry) { + liteflowRetryAtomicReference.set(liteflowRetry); + } + // 如果存在existRetry注解,但是不是在Process方法上,则为非法 + return existRetry && !isProcess; + } + ); + if (illegal){ + throw new LiteFlowException("the retry annotation (@LiteflowRetry) must be declared on the PROCESS method"); + } + // 生成nodeCmp的类型,默认为全局定义的clazz + Class cmpClazz; + cmpClazz = clazz; + // 判断是否是方法声明的组件 + if (isMethodCreate){ + cmpClazz = methodList.iterator().next().nodeType().getCmpClass(); + LiteflowRetry liteflowRetry; + if ((liteflowRetry = liteflowRetryAtomicReference.get()) != null){ + // 增加LiteFlowRetry注解到注解数组里 + List annotations = Arrays.stream(beanClassAnnotation) + .filter(a -> !a.annotationType().equals(LiteflowRetry.class)) + .collect(Collectors.toList()); + annotations.add(liteflowRetry); + beanClassAnnotation = new Annotation[annotations.size()]; + annotations.toArray(beanClassAnnotation); + } + } + try { + //创建对象 + //这里package进行了重设,放到了被代理对象的所在目录 + //生成的对象也加了上被代理对象拥有的注解 + //被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断 + Object instance = new ByteBuddy().subclass(cmpClazz) + .name(StrUtil.format("{}.ByteBuddy${}${}", + ClassUtil.getPackage(bean.getClass()), + activeNodeId, + SerialsUtil.generateShortUUID())) + .method(ElementMatchers.namedOneOf(methodList.stream().map(m -> m.value().getMethodName()).toArray(String[]::new))) + .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean))) + .annotateType(beanClassAnnotation) + .make() + .load(ComponentProxy.class.getClassLoader()) + .getLoaded() + .newInstance(); + NodeComponent nodeComponent = (NodeComponent) instance; + // 重设nodeId + nodeComponent.setNodeId(activeNodeId); + return nodeComponent; + } catch (Exception e) { + throw new LiteFlowException(e); + } + }).collect(Collectors.toList()); } public class AopInvocationHandler implements InvocationHandler { @@ -93,6 +177,10 @@ public class ComponentProxy { List liteFlowMethodBeanList = Arrays.stream(ReflectUtil.getMethods(bean.getClass())).filter(m -> { LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); return ObjectUtil.isNotNull(liteFlowMethod); + }).filter(m -> { + // 过滤不属于当前NodeComponent的方法 + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return StrUtil.isEmpty(liteFlowMethod.nodeId())|| Objects.equals(liteFlowMethod.nodeId(),((NodeComponent) proxy).getNodeId()); }).map(m -> { LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); return new LiteFlowMethodBean(liteFlowMethod.value().getMethodName(), m); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/AnnotationNodeTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/AnnotationNodeTypeEnum.java new file mode 100644 index 00000000..e6ad007a --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/AnnotationNodeTypeEnum.java @@ -0,0 +1,47 @@ +package com.yomahub.liteflow.enums; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +/** + * 注解节点类型枚举 + * + * @author Sorghum + * @since 2.9.0 + */ +public enum AnnotationNodeTypeEnum { + /** + * 普通节点 + */ + COMMON("普通", NodeComponent.class), + /** + * 选择节点 + */ + SWITCH("选择", NodeSwitchComponent.class), + /** + * 条件节点 + */ + IF("条件", NodeIfComponent.class),; + /** + * 描述 + */ + final String desc; + /** + * cmp类 + */ + final Class cmpClass; + + AnnotationNodeTypeEnum(String desc, Class cmpClass) { + this.desc = desc; + this.cmpClass = cmpClass; + } + + /** + * 得到Node定义类 + * @return node定义类 + */ + public Class getCmpClass() { + return cmpClass; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/DataNofFoundException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/DataNofFoundException.java new file mode 100644 index 00000000..e9b44e39 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/DataNofFoundException.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.exception; + +/** + * @author tangkc + */ +public class DataNofFoundException extends RuntimeException { + public static final String MSG = "DataNofFoundException"; + + private static final long serialVersionUID = 1L; + + /** + * 异常信息 + */ + private String message; + + public DataNofFoundException() { + this.message = MSG; + } + + public DataNofFoundException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index ebf5b53c..32e2f15b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -9,16 +9,17 @@ package com.yomahub.liteflow.flow; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.core.*; -import com.yomahub.liteflow.exception.NullNodeTypeException; -import com.yomahub.liteflow.flow.element.Chain; -import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.enums.FlowParserTypeEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.exception.ComponentCannotRegisterException; +import com.yomahub.liteflow.exception.NullNodeTypeException; +import com.yomahub.liteflow.flow.element.Chain; +import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.parser.LocalJsonFlowParser; import com.yomahub.liteflow.parser.LocalXmlFlowParser; import com.yomahub.liteflow.parser.LocalYmlFlowParser; @@ -36,7 +37,10 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * 流程元数据类 @@ -156,7 +160,7 @@ public class FlowBus { try { //判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例 //如果不是声明式的,就用传统的方式进行判断 - NodeComponent cmpInstance = null; + List cmpInstances = new ArrayList<>(); if (LiteFlowProxyUtil.isDeclareCmp(cmpClazz)){ //这里的逻辑要仔细看下 //如果是spring体系,把原始的类往spring上下文中进行注册,那么会走到ComponentScanner中 @@ -167,42 +171,50 @@ public class FlowBus { ContextAware contextAware = ContextAwareHolder.loadContextAware(); Object bean = ContextAwareHolder.loadContextAware().registerBean(nodeId, cmpClazz); if (LocalContextAware.class.isAssignableFrom(contextAware.getClass())){ - cmpInstance = LiteFlowProxyUtil.proxy2NodeComponent(bean, nodeId); + cmpInstances = LiteFlowProxyUtil.proxy2NodeComponent(bean, nodeId); }else { - cmpInstance = (NodeComponent) bean; + cmpInstances = ListUtil.toList((NodeComponent) bean); } }else{ //以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置 //这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了 //如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance if (!CollectionUtil.newArrayList(NodeTypeEnum.SCRIPT, NodeTypeEnum.SWITCH_SCRIPT, NodeTypeEnum.IF_SCRIPT).contains(type)){ - cmpInstance = (NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz); + cmpInstances = ListUtil.toList((NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz)); } - - if (ObjectUtil.isNull(cmpInstance)) { - cmpInstance = (NodeComponent) cmpClazz.newInstance(); + // 去除null元素 + cmpInstances.remove(null); + // 如果为空 + if (cmpInstances.isEmpty()) { + NodeComponent cmpInstance = (NodeComponent) cmpClazz.newInstance(); + cmpInstances.add(cmpInstance); } } - //进行初始化 - cmpInstance = ComponentInitializer.loadInstance().initComponent(cmpInstance, type, name, nodeId); + cmpInstances = cmpInstances.stream() + .map( + cmpInstance -> ComponentInitializer.loadInstance().initComponent(cmpInstance, type, name, cmpInstance.getNodeId() == null ? nodeId : cmpInstance.getNodeId())).collect(Collectors.toList()); //初始化Node - Node node = new Node(cmpInstance); + List nodes = cmpInstances.stream().map(Node::new).collect(Collectors.toList()); - //如果是脚本节点(普通脚本节点/条件脚本节点),则还要加载script脚本 - if (StrUtil.isNotBlank(script)){ - node.setScript(script); - if (type.equals(NodeTypeEnum.SCRIPT)){ - ((ScriptComponent)cmpInstance).loadScript(script); - }else if(type.equals(NodeTypeEnum.SWITCH_SCRIPT)){ - ((ScriptSwitchComponent)cmpInstance).loadScript(script); - }else if(type.equals(NodeTypeEnum.IF_SCRIPT)){ - ((ScriptIfComponent)cmpInstance).loadScript(script); + for (int i = 0; i < nodes.size(); i++) { + Node node = nodes.get(i); + NodeComponent cmpInstance = cmpInstances.get(i); + if (StrUtil.isNotBlank(script)){ + node.setScript(script); + if (type.equals(NodeTypeEnum.SCRIPT)){ + ((ScriptComponent)cmpInstance).loadScript(script); + }else if(type.equals(NodeTypeEnum.SWITCH_SCRIPT)){ + ((ScriptSwitchComponent)cmpInstance).loadScript(script); + }else if(type.equals(NodeTypeEnum.IF_SCRIPT)){ + ((ScriptIfComponent)cmpInstance).loadScript(script); + } } + String activeNodeId = StrUtil.isEmpty(cmpInstance.getNodeId()) ? nodeId : cmpInstance.getNodeId(); + //如果是脚本节点(普通脚本节点/条件脚本节点),则还要加载script脚本 + nodeMap.put(activeNodeId, node); } - - nodeMap.put(nodeId, node); } catch (Exception e) { String error = StrUtil.format("component[{}] register error", StrUtil.isEmpty(name)?nodeId:StrUtil.format("{}({})",nodeId,name)); LOG.error(error); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java index 43fd55c6..6d18e2d9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java @@ -331,8 +331,7 @@ public class ParserHelper { } /** * 解析一个chain的过程 - *

- * param e chain 节点 + * @param e chain 节点 */ public static void parseOneChain(Element e) { String condValueStr; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java index e5cb5687..8328cfc8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java @@ -1,21 +1,22 @@ package com.yomahub.liteflow.util; -import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.annotation.LiteflowCmpDefine; import com.yomahub.liteflow.annotation.LiteflowIfCmpDefine; -import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine; import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.core.NodeIfComponent; import com.yomahub.liteflow.core.NodeSwitchComponent; import com.yomahub.liteflow.core.proxy.ComponentProxy; import com.yomahub.liteflow.exception.ComponentProxyErrorException; +import com.yomahub.liteflow.exception.LiteFlowException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Arrays; +import java.util.List; /** * 组件代理类通用方法 @@ -29,23 +30,6 @@ public class LiteFlowProxyUtil { //判断一个bean是否是声明式组件 public static boolean isDeclareCmp(Class clazz){ - //判断bean是否标记了@LiteflowCmpDefine,@LiteflowCondCmpDefine,LiteflowIfCmpDefine这3个标注之一 - boolean flag1 = clazz.getAnnotation(LiteflowCmpDefine.class) != null - || clazz.getAnnotation(LiteflowSwitchCmpDefine.class) != null - || clazz.getAnnotation(LiteflowIfCmpDefine.class) != null; - - if (!flag1){ - return false; - } - - //看超类是否是NodeComponent,NodeCondComponent,NodeIfComponent中的一个,如果不是,则说明满足条件。是的话,也不满足 - boolean flag2 = !ListUtil.toList(NodeComponent.class, NodeSwitchComponent.class, NodeIfComponent.class) - .contains(clazz.getSuperclass()); - - if (!flag2){ - return false; - } - //查看bean里的method是否有方法标记了@LiteflowMethod标注 //这里的bean有可能是cglib加强过的class,所以要先进行个判断 Class targetClass; @@ -54,15 +38,14 @@ public class LiteFlowProxyUtil { }else{ targetClass = clazz; } - boolean flag3 = Arrays.stream(targetClass.getMethods()).anyMatch( + // 判断是否有方法标记了@LiteflowMethod标注,有则为声明式组件 + return Arrays.stream(targetClass.getMethods()).anyMatch( method -> method.getAnnotation(LiteflowMethod.class) != null ); - - return flag3; } - //对一个满足声明式的bean进行代理 - public static NodeComponent proxy2NodeComponent(Object bean, String nodeId){ + //对一个满足声明式的bean进行代理,生成代理类数组 + public static List proxy2NodeComponent(Object bean, String nodeId){ try{ LiteflowCmpDefine liteflowCmpDefine = bean.getClass().getAnnotation(LiteflowCmpDefine.class); LiteflowSwitchCmpDefine liteflowSwitchCmpDefine = bean.getClass().getAnnotation(LiteflowSwitchCmpDefine.class); @@ -71,21 +54,23 @@ public class LiteFlowProxyUtil { ComponentProxy proxy; if (ObjectUtil.isNotNull(liteflowCmpDefine)){ proxy = new ComponentProxy(nodeId, bean, NodeComponent.class); - return (NodeComponent) proxy.getProxy(); + return proxy.getProxyList(); } if (ObjectUtil.isNotNull(liteflowSwitchCmpDefine)){ proxy = new ComponentProxy(nodeId, bean, NodeSwitchComponent.class); - return (NodeSwitchComponent) proxy.getProxy(); + return proxy.getProxyList(); } if (ObjectUtil.isNotNull(liteflowIfCmpDefine)){ proxy = new ComponentProxy(nodeId, bean, NodeIfComponent.class); - return (NodeIfComponent) proxy.getProxy(); + return proxy.getProxyList(); } - - throw new RuntimeException(); - }catch (Exception e){ + return new ComponentProxy(nodeId, bean, NodeIfComponent.class).getProxyList(); + }catch (LiteFlowException liteFlowException){ + throw liteFlowException; + } + catch (Exception e){ String errMsg = StrUtil.format("Error while proxying bean[{}]",bean.getClass().getName()); LOG.error(errMsg); throw new ComponentProxyErrorException(errMsg); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java index 4cd90c6b..de9f3bec 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java @@ -55,6 +55,8 @@ public class SerialsUtil { /** * 生成一个12位随机数 + * @param seed 种子值 + * @return String 随机数 */ public static String randomNum12(long seed) { // 被除数 @@ -64,6 +66,8 @@ public class SerialsUtil { /** * 生成一个8位随机数 + * @param seed 种子值 + * @return String 随机数 */ public static String randomNum8(long seed) { // 被除数 diff --git a/liteflow-rule-plugin/liteflow-rule-sql/pom.xml b/liteflow-rule-plugin/liteflow-rule-sql/pom.xml new file mode 100644 index 00000000..af48a726 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/pom.xml @@ -0,0 +1,23 @@ + + + + liteflow + com.yomahub + ${revision} + ../../pom.xml + + 4.0.0 + + liteflow-rule-sql + + + + com.yomahub + liteflow-core + ${revision} + true + + + \ No newline at end of file diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/spi/sql/SQLParserClassNameSpi.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/spi/sql/SQLParserClassNameSpi.java new file mode 100644 index 00000000..19017fcc --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/spi/sql/SQLParserClassNameSpi.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.parser.spi.sql; + +import com.yomahub.liteflow.parser.spi.ParserClassNameSpi; +import com.yomahub.liteflow.parser.sql.SQLXmlELParser; + +/** + * SQL 解析器 SPI 实现 + * + * @author tangkc + * @since 2.9.0 + */ +public class SQLParserClassNameSpi implements ParserClassNameSpi { + + @Override + public String getSpiClassName() { + return SQLXmlELParser.class.getName(); + } + +} \ No newline at end of file diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java new file mode 100644 index 00000000..87ea0976 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java @@ -0,0 +1,84 @@ +package com.yomahub.liteflow.parser.sql; + +import cn.hutool.core.text.StrFormatter; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser; +import com.yomahub.liteflow.parser.sql.exception.ELSQLException; +import com.yomahub.liteflow.parser.sql.util.JDBCHelper; +import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.util.JsonUtil; + +import java.util.Objects; + +/** + * SQL 解析器实现,只支持 EL 形式的 XML,不支持其他的形式 + * + * @author tangkc + * @since 2.9.0 + */ +public class SQLXmlELParser extends ClassXmlFlowELParser { + + private static final String ERROR_MSG_PATTERN = "rule-source-ext-data {} is blank"; + private static final String ERROR_COMMON_MSG = "rule-source-ext-data is empty"; + + /** + * 构造函数 + */ + public SQLXmlELParser() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + + if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData())) { + throw new ELSQLException(ERROR_COMMON_MSG); + } + + try { + SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); + if (Objects.isNull(sqlParserVO)) { + throw new ELSQLException(ERROR_COMMON_MSG); + } + + // 检查配置文件 + checkParserVO(sqlParserVO); + + // 初始化 JDBCHelper + JDBCHelper.init(sqlParserVO); + + } catch (ELSQLException elsqlException) { + throw elsqlException; + } catch (Exception ex) { + throw new ELSQLException(ex.getMessage()); + } + + } + + @Override + public String parseCustom() { + return JDBCHelper.getInstance().getElDataContent(); + } + + + /** + * 检查配置文件并设置默认值 + * + * @param sqlParserVO sqlParserVO + */ + private void checkParserVO(SQLParserVO sqlParserVO) { + if (StrUtil.isEmpty(sqlParserVO.getUrl())) { + throw new ELSQLException(StrFormatter.format(ERROR_MSG_PATTERN, "url")); + } + if (StrUtil.isEmpty(sqlParserVO.getDriverClassName())) { + throw new ELSQLException(StrFormatter.format(ERROR_MSG_PATTERN, "driverClassName")); + } + if (Objects.isNull(sqlParserVO.getUsername())) { + throw new ELSQLException(StrFormatter.format(ERROR_MSG_PATTERN, "username")); + } + if (Objects.isNull(sqlParserVO.getPassword())) { + throw new ELSQLException(StrFormatter.format(ERROR_MSG_PATTERN, "password")); + } + if (Objects.isNull(sqlParserVO.getElTable())) { + sqlParserVO.setElTable(new SQLParserVO.ElTable()); + } + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/exception/ELSQLException.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/exception/ELSQLException.java new file mode 100644 index 00000000..e0a4a24a --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/exception/ELSQLException.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.parser.sql.exception; + +/** + * SQL 相关业务异常 + * + * @author tangkc + * @since 2.9.0 + */ +public class ELSQLException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * 异常信息 + */ + private String message; + + public ELSQLException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java new file mode 100644 index 00000000..c529b542 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java @@ -0,0 +1,157 @@ +package com.yomahub.liteflow.parser.sql.util; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.text.StrFormatter; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.parser.sql.exception.ELSQLException; +import com.yomahub.liteflow.parser.sql.vo.SQLParserVO; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * jdbc 工具类 + * + * @author tangkc + * @since 2.9.0 + */ +public class JDBCHelper { + + private static final String SQL_PATTERN = "SELECT {},{} FROM {} "; + + private static final String CHAIN_XML_PATTERN = "{}"; + private static final String XML_PATTERN = "{}"; + private static final Integer FETCH_SIZE_MAX = 1000; + + private SQLParserVO sqlParserVO; + + private static JDBCHelper INSTANCE; + + /** + * 初始化 INSTANCE + */ + public static void init(SQLParserVO sqlParserVO) { + try { + INSTANCE = new JDBCHelper(); + Class.forName(sqlParserVO.getDriverClassName()); + INSTANCE.setSqlParserVO(sqlParserVO); + } catch (ClassNotFoundException e) { + throw new ELSQLException(e.getMessage()); + } + } + + /** + * 获取 INSTANCE + */ + public static JDBCHelper getInstance() { + return INSTANCE; + } + + /** + * 获取链接 + */ + public Connection getConn() { + Connection connection = null; + try { + connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), sqlParserVO.getPassword()); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + return connection; + } + + /** + * 获取 ElData 数据内容 + */ + public String getElDataContent() { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + + String elDataField = sqlParserVO.getElTable().getElDataField(); + String chainNameField = sqlParserVO.getElTable().getChainNameField(); + String tableName = sqlParserVO.getElTable().getTableName(); + String sqlCmd = StrFormatter.format(SQL_PATTERN, chainNameField, elDataField, tableName); + + List result = new ArrayList<>(); + try { + conn = getConn(); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + // 设置游标拉取数量 + stmt.setFetchSize(FETCH_SIZE_MAX); + rs = stmt.executeQuery(); + + while (rs.next()) { + String elData = rs.getString(elDataField); + if (StrUtil.isBlank(elData)) { + throw new ELSQLException(StrFormatter.format("{} table exist {} field value is empty", tableName, elDataField)); + } + String chainName = rs.getString(chainNameField); + if (StrUtil.isBlank(elData)) { + throw new ELSQLException(StrFormatter.format("{} table exist {} field value is empty", tableName, elDataField)); + } + + result.add(StrFormatter.format(CHAIN_XML_PATTERN, chainName, elData)); + } + } catch (Exception e) { + throw new ELSQLException(e.getMessage()); + } finally { + // 关闭连接 + close(conn, stmt, rs); + } + + String chains = CollUtil.join(result, StrUtil.CRLF); + return StrFormatter.format(XML_PATTERN, chains); + } + + /** + * 关闭连接 + * + * @param conn conn + * @param stmt stmt + * @param rs rs + */ + private void close(Connection conn, PreparedStatement stmt, ResultSet rs) { + // 关闭连接 + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + // 关闭 statement + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + //关闭结果集 + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + } + + + //#region get set method + private SQLParserVO getSqlParserVO() { + return sqlParserVO; + } + + private JDBCHelper setSqlParserVO(SQLParserVO sqlParserVO) { + this.sqlParserVO = sqlParserVO; + return this; + } + //#endregion +} diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java new file mode 100644 index 00000000..6eb9f9c6 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java @@ -0,0 +1,116 @@ +package com.yomahub.liteflow.parser.sql.vo; + +/** + * 用于解析 RuleSourceExtData 的 VO 类,用于 sql 模式中 + * + * @author tangkc + * @since 2.9.0 + */ +public class SQLParserVO { + + /** + * 连接地址 + */ + private String url; + + /** + * 驱动 + */ + private String driverClassName; + + /** + * 账号名 + */ + private String username; + + /** + * 密码 + */ + private String password; + + /** + * EL 表相关配置 + */ + private ElTable elTable; + + public static class ElTable { + /** + * 表名 + */ + private String tableName = "el_table"; + + /** + * chainName + */ + private String chainNameField = "chain_name"; + + /** + * el 表达式相关数据 + */ + private String elDataField = "el_data"; + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public String getChainNameField() { + return chainNameField; + } + + public void setChainNameField(String chainNameField) { + this.chainNameField = chainNameField; + } + + public String getElDataField() { + return elDataField; + } + + public void setElDataField(String elDataField) { + this.elDataField = elDataField; + } + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getDriverClassName() { + return driverClassName; + } + + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public ElTable getElTable() { + return elTable; + } + + public void setElTable(ElTable elTable) { + this.elTable = elTable; + } +} diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/resources/META-INF/services/com.yomahub.liteflow.parser.spi.ParserClassNameSpi b/liteflow-rule-plugin/liteflow-rule-sql/src/main/resources/META-INF/services/com.yomahub.liteflow.parser.spi.ParserClassNameSpi new file mode 100644 index 00000000..4a0937b2 --- /dev/null +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/resources/META-INF/services/com.yomahub.liteflow.parser.spi.ParserClassNameSpi @@ -0,0 +1 @@ +com.yomahub.liteflow.parser.spi.sql.SQLParserClassNameSpi \ No newline at end of file diff --git a/liteflow-rule-plugin/pom.xml b/liteflow-rule-plugin/pom.xml index d02f6372..9599dbec 100644 --- a/liteflow-rule-plugin/pom.xml +++ b/liteflow-rule-plugin/pom.xml @@ -12,7 +12,7 @@ pom liteflow-rule-zk - liteflow-rule-nacos + liteflow-rule-sql liteflow-rule-plugin diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java index 9a41122d..a4f2b33d 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java @@ -8,6 +8,7 @@ */ package com.yomahub.liteflow.spring; +import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.aop.ICmpAroundAspect; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.property.LiteflowConfig; @@ -19,6 +20,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -61,9 +63,19 @@ public class ComponentScanner implements BeanPostProcessor { //如果是,就缓存到类属性的map中 if (LiteFlowProxyUtil.isDeclareCmp(bean.getClass())){ LOG.info("proxy component[{}] has been found", beanName); - NodeComponent nodeComponent = LiteFlowProxyUtil.proxy2NodeComponent(bean, beanName); - nodeComponentMap.put(beanName, nodeComponent); - return nodeComponent; + List nodeComponents = LiteFlowProxyUtil.proxy2NodeComponent(bean, beanName); + nodeComponents.forEach( + nodeComponent -> { + String nodeId = nodeComponent.getNodeId(); + nodeId = StrUtil.isEmpty(nodeId) ? beanName : nodeId; + nodeComponentMap.put(nodeId, nodeComponent); + } + ); + // 只有注解支持单bean多Node,所以一个直接返回 + if (nodeComponents.size() == 1){ + return nodeComponents.get(0); + } + return bean; } // 组件的扫描发现,扫到之后缓存到类属性map中 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 00000000..33ba94e3 --- /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 00000000..3a79ad7b --- /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/AbsoluteConfigPathELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..5cae44d2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.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 = AbsoluteConfigPathELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"}) +public class AbsoluteConfigPathELDeclMultiSpringbootTest 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 00000000..98ad4852 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +public class CmpMultiDefine{ + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a",nodeType = AnnotationNodeTypeEnum.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/GlobalAOPELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..5621ee8d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclMultiSpringbootTest.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 = GlobalAOPELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@Import(CmpAspect.class) +@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +public class GlobalAOPELDeclMultiSpringbootTest 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 00000000..3704a146 --- /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 00000000..a8df2001 --- /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,27 @@ +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 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 00000000..6f0b6e97 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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 00000000..49e50512 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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/AsyncNodeELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..30c4445b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclMultiSpringbootTest.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 = AsyncNodeELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +public class AsyncNodeELDeclMultiSpringbootTest 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 00000000..5e1edd49 --- /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,138 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.asyncNode.exception.TestException; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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 = AnnotationNodeTypeEnum.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 00000000..e786e9f8 --- /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-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..1ab13fcb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclMultiSpringbootTest.java @@ -0,0 +1,38 @@ +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 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:/base/application.properties") +@SpringBootTest(classes = BaseELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.base.cmp"}) +public class BaseELDeclMultiSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testBase() 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/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 00000000..0156fae9 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import javax.annotation.Resource; + +@LiteflowComponent +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 00000000..16f15932 --- /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/BuilderELDeclMultiSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest1.java new file mode 100644 index 00000000..3d376ed4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest1.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.builder.entity.ExecutableEntity; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.flow.LiteflowResponse; +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 = BuilderELDeclMultiSpringbootTest1.class) +@EnableAutoConfiguration +public class BuilderELDeclMultiSpringbootTest1 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/BuilderELDeclMultiSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest2.java new file mode 100644 index 00000000..8db32fe8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest2.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.builder; + +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 = BuilderELDeclMultiSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"}) +public class BuilderELDeclMultiSpringbootTest2 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 00000000..a9ffd1f0 --- /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 00000000..e13b0434 --- /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 00000000..6fbbc10e --- /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 00000000..27fb0fd4 --- /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 00000000..dc6596a0 --- /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.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine; +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 00000000..a300c50f --- /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 00000000..4035e89c --- /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 00000000..a3bd495a --- /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 00000000..a7546b33 --- /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 00000000..a270fc3c --- /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/LiteflowRetryELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..5eba736f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclMultiSpringbootTest.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 = LiteflowRetryELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +public class LiteflowRetryELDeclMultiSpringbootTest 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 00000000..4bf32252 --- /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,69 @@ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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"); + } + + @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") + public void processF(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.AFTER_PROCESS,nodeId = "f") + public void after(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 00000000..d07e7100 --- /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 00000000..d7a446f0 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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/LiteflowNodeELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..e959fbb1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELDeclMultiSpringbootTest.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 = LiteflowNodeELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.comments.cmp"}) +public class LiteflowNodeELDeclMultiSpringbootTest 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 00000000..465d26f5 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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/complex/ComplexELDeclMultiSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest1.java new file mode 100644 index 00000000..d787e6a7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest1.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 = ComplexELDeclMultiSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.complex.cmp1"}) +public class ComplexELDeclMultiSpringbootTest1 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/ComplexELDeclMultiSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest2.java new file mode 100644 index 00000000..c3074ac6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest2.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 = ComplexELDeclMultiSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.complex.cmp2"}) +public class ComplexELDeclMultiSpringbootTest2 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 00000000..75b4c4e2 --- /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,82 @@ +package com.yomahub.liteflow.test.complex.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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 00000000..eca509c6 --- /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 00000000..3e619506 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +public class CmpConfig2 { + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "A") + public void processA(NodeComponent bindCmp) { + + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeType = AnnotationNodeTypeEnum.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 = AnnotationNodeTypeEnum.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 00000000..08d07119 --- /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/FlowExecutorELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..b6d3224b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclMultiSpringbootTest.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 = FlowExecutorELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +public class FlowExecutorELDeclMultiSpringbootTest extends BaseTest { + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELDeclMultiSpringbootTest.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 00000000..887c98e6 --- /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.LiteflowComponent; +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 java.util.Objects; + +@LiteflowComponent +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 00000000..d6171cd6 --- /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,25 @@ +package com.yomahub.liteflow.test.component.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.Objects; + + +@LiteflowComponent +public class FCondCmp{ + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "f",nodeType = AnnotationNodeTypeEnum.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/CustomMethodNameELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..f0d0312b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclMultiSpringbootTest.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 = CustomMethodNameELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customMethodName.cmp"}) +public class CustomMethodNameELDeclMultiSpringbootTest 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 00000000..fd6293ca --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.Slot; + +@LiteflowComponent +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/CustomNodesELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..b5ffa105 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclMultiSpringbootTest.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 = CustomNodesELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +public class CustomNodesELDeclMultiSpringbootTest 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 00000000..fb8982c2 --- /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 00000000..67ed16bc --- /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 00000000..d4ee3cf1 --- /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 00000000..619905b1 --- /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 00000000..27b3243c --- /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 00000000..a7f22de9 --- /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 00000000..d0b10dc0 --- /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 00000000..6f88c4cd --- /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 00000000..7d45e4ad --- /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 00000000..875dc3d1 --- /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/CustomWhenThreadPoolELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..f5d8e322 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.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 = CustomWhenThreadPoolELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +public class CustomWhenThreadPoolELDeclMultiSpringbootTest 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 00000000..68e6f5d1 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent +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/EventELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..90a0f853 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclMultiSpringbootTest.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 = EventELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.event.cmp"}) +public class EventELDeclMultiSpringbootTest 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 00000000..ba0fadf3 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent +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 00000000..11441ab5 --- /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/Exception1ELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclMultiSpringBootTest.java new file mode 100644 index 00000000..0c3f203d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclMultiSpringBootTest.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 = Exception1ELDeclMultiSpringBootTest.class) +@EnableAutoConfiguration +public class Exception1ELDeclMultiSpringBootTest 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/Exception2ELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclMultiSpringBootTest.java new file mode 100644 index 00000000..4eca8c32 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclMultiSpringBootTest.java @@ -0,0 +1,77 @@ +package com.yomahub.liteflow.test.exception; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.ChainNotFoundException; +import com.yomahub.liteflow.exception.LiteFlowException; +import com.yomahub.liteflow.exception.NoSwitchTargetNodeException; +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 zendwang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/exception/application.properties") +@SpringBootTest(classes = Exception2ELDeclMultiSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +public class Exception2ELDeclMultiSpringBootTest 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 00000000..d34d0479 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.exception.CustomStatefulException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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/Executor2FutureELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..834b73af --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclMultiSpringbootTest.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 = Executor2FutureELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +public class Executor2FutureELDeclMultiSpringbootTest 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 00000000..5fe0d8cd --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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/CmpExtendELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..84663428 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclMultiSpringbootTest.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 = CmpExtendELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.extend.cmp"}) +public class CmpExtendELDeclMultiSpringbootTest 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 00000000..7b1936b7 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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/GetChainNameELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..d2e53886 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclMultiSpringbootTest.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 = GetChainNameELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.getChainName.cmp"}) +public class GetChainNameELDeclMultiSpringbootTest 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 00000000..2c25b9ba --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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/IfElseELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..5123b459 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclMultiSpringbootTest.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 = IfElseELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.ifelse.cmp"}) +public class IfElseELDeclMultiSpringbootTest 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 00000000..643027bb --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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/LazyELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..2512ca92 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclMultiSpringbootTest.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.lazy; + +import com.yomahub.liteflow.test.BaseTest; + +//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 LazyELDeclMultiSpringbootTest 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 00000000..01a43e2a --- /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 00000000..628760c6 --- /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 00000000..781d1a20 --- /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/LiteflowComponentELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..9cd3a9c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclMultiSpringbootTest.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 = LiteflowComponentELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lfCmpAnno.cmp"}) +public class LiteflowComponentELDeclMultiSpringbootTest 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 00000000..8081c708 --- /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 00000000..30a7e689 --- /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 00000000..6090b44f --- /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 00000000..967f00f3 --- /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/MonitorELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..6f54c4c0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclMultiSpringbootTest.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 = MonitorELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +public class MonitorELDeclMultiSpringbootTest 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 00000000..e6c0ff29 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.Random; + +@LiteflowComponent +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 00000000..af8bfad4 --- /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/MultiContextELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..0a7af8d0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclMultiSpringbootTest.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 = MultiContextELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.multiContext.cmp"}) +public class MultiContextELDeclMultiSpringbootTest 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 00000000..c477108b --- /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 00000000..ddf94e77 --- /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.LiteflowComponent; +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; + +@LiteflowComponent +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/LiteflowMultipleTypeELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..18c8c130 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclMultiSpringbootTest.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 = LiteflowMultipleTypeELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +public class LiteflowMultipleTypeELDeclMultiSpringbootTest 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 00000000..12808259 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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 00000000..9fb99224 --- /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,18 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.flow.executor.NodeExecutor; +import com.yomahub.liteflow.slot.DefaultContext; + +/** + * 自定义默认的节点执行器 + */ +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 00000000..e4ef70e0 --- /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,19 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.flow.executor.NodeExecutor; +import com.yomahub.liteflow.slot.DefaultContext; + +/** + * 自定义节点执行器 + */ +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 00000000..202005b1 --- /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,28 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.flow.executor.NodeExecutor; +import com.yomahub.liteflow.slot.DefaultContext; + +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/LiteflowNodeExecutorELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..b415a860 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclMultiSpringbootTest.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 = LiteflowNodeExecutorELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +public class LiteflowNodeExecutorELDeclMultiSpringbootTest 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 00000000..62665992 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.flow.executor.NodeExecutor; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; + +@LiteflowComponent +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/CustomParserJsonELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..fa635730 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclMultiSpringbootTest.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 = CustomParserJsonELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +public class CustomParserJsonELDeclMultiSpringbootTest 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/CustomParserXmlELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..fb476fb3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclMultiSpringbootTest.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 = CustomParserXmlELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +public class CustomParserXmlELDeclMultiSpringbootTest 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 00000000..6e6d9f57 --- /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 00000000..32d878f2 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.exception.FlowSystemException; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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 00000000..1f4eac49 --- /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 00000000..473ad502 --- /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/JsonParserELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..b0e74815 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclMultiSpringbootTest.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 = JsonParserELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class JsonParserELDeclMultiSpringbootTest 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/SpringELSupportELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..038a78aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclMultiSpringbootTest.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 = SpringELSupportELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class SpringELSupportELDeclMultiSpringbootTest 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/XmlParserELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..0b90a310 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclMultiSpringbootTest.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 = XmlParserELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class XmlParserELDeclMultiSpringbootTest 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/YmlParserELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..85cef10a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclMultiSpringbootTest.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 = YmlParserELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +public class YmlParserELDeclMultiSpringbootTest 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 00000000..e7ea59cb --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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/PreAndFinallyELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..11f4129a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclMultiSpringbootTest.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 = PreAndFinallyELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +public class PreAndFinallyELDeclMultiSpringbootTest 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 00000000..74ede4b8 --- /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.LiteflowComponent; +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; + +@LiteflowComponent +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/PrivateDeliveryELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..825e7975 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclMultiSpringbootTest.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 = PrivateDeliveryELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +public class PrivateDeliveryELDeclMultiSpringbootTest 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 00000000..4df9c375 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent +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/RefreshRuleELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..68b3e35f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclMultiSpringbootTest.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.enums.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +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:/refreshRule/application.properties") +@SpringBootTest(classes = RefreshRuleELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +public class RefreshRuleELDeclMultiSpringbootTest 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 00000000..27de6d52 --- /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,26 @@ +package com.yomahub.liteflow.test.refreshRule.cmp; + +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 +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/ReloadELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..12a26958 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclMultiSpringbootTest.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 = ReloadELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +public class ReloadELDeclMultiSpringbootTest 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 00000000..9f194fbb --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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/LiteflowRequestIdELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..33892140 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclMultiSpringbootTest.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 = LiteflowRequestIdELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.requestId.cmp"}) +public class LiteflowRequestIdELDeclMultiSpringbootTest 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 00000000..d38cbc10 --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent +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 00000000..00445932 --- /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/ImplicitSubFlowELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..3e6b09e0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclMultiSpringbootTest.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 = ImplicitSubFlowELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +public class ImplicitSubFlowELDeclMultiSpringbootTest 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/SubflowInDifferentConfigELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..99cc3da5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclMultiSpringbootTest.java @@ -0,0 +1,53 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.MultipleParsersException; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.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 = SubflowInDifferentConfigELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1","com.yomahub.liteflow.test.subflow.cmp2"}) +public class SubflowInDifferentConfigELDeclMultiSpringbootTest 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/SubflowJsonELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclMultiSpringBootTest.java new file mode 100644 index 00000000..24da8cbe --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclMultiSpringBootTest.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 = SubflowJsonELDeclMultiSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowJsonELDeclMultiSpringBootTest 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/SubflowXMLELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclMultiSpringBootTest.java new file mode 100644 index 00000000..7a030a91 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclMultiSpringBootTest.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 = SubflowXMLELDeclMultiSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowXMLELDeclMultiSpringBootTest 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/SubflowYmlELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclMultiSpringBootTest.java new file mode 100644 index 00000000..94d41724 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclMultiSpringBootTest.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 = SubflowYmlELDeclMultiSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowYmlELDeclMultiSpringBootTest 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-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java new file mode 100644 index 00000000..cc9fcf6c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +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 +public class CmpConfig1 { + @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,nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp 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 00000000..ddd179e3 --- /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.LiteflowComponent; +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 java.util.HashSet; +import java.util.Set; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclMultiSpringbootTest.RUN_TIME_SLOT; + +@LiteflowComponent +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/NodeTagELDeclMultiSpringbootJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootJsonTest.java new file mode 100644 index 00000000..35930c00 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootJsonTest.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 = NodeTagELDeclMultiSpringbootJsonTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagELDeclMultiSpringbootJsonTest 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/NodeTagELDeclMultiSpringbootXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootXmlTest.java new file mode 100644 index 00000000..3208a64c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootXmlTest.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 = NodeTagELDeclMultiSpringbootXmlTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagELDeclMultiSpringbootXmlTest 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 00000000..8ab8eb6c --- /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.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent +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 = AnnotationNodeTypeEnum.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 00000000..fee0055e --- /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/UseTTLInWhenELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclMultiSpringbootTest.java new file mode 100644 index 00000000..07269953 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclMultiSpringbootTest.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 = UseTTLInWhenELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.useTTLInWhen.cmp"}) +public class UseTTLInWhenELDeclMultiSpringbootTest 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 00000000..d44125e3 --- /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.LiteflowComponent; +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; + +@LiteflowComponent +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/WhenTimeOutELDeclMultiSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest1.java new file mode 100644 index 00000000..cebe5d99 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest1.java @@ -0,0 +1,44 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.WhenTimeoutException; +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/application1.properties") +@SpringBootTest(classes = WhenTimeOutELDeclMultiSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutELDeclMultiSpringbootTest1 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/WhenTimeOutELDeclMultiSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest2.java new file mode 100644 index 00000000..151d46fd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest2.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 = WhenTimeOutELDeclMultiSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutELDeclMultiSpringbootTest2 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 00000000..1542726d --- /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,66 @@ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +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 +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/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 00000000..348a63af --- /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 00000000..0d670c77 --- /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 00000000..0a8873bf --- /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 00000000..500a8af3 --- /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 00000000..69053aff --- /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 00000000..06373bb2 --- /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 00000000..1f5b49a0 --- /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 00000000..edf6e579 --- /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 00000000..d2049052 --- /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 00000000..2beecda5 --- /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 00000000..9dc00f45 --- /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 00000000..3aea68da --- /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 00000000..7c7eabe1 --- /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 00000000..e4a1e577 --- /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 00000000..83a0815d --- /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 00000000..0c85be0d --- /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 00000000..8375bd39 --- /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 00000000..9485d5aa --- /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 00000000..8c7e721e --- /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 00000000..cdeebfff --- /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 00000000..f353e04e --- /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 00000000..6f226168 --- /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 00000000..d69d578a --- /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 00000000..3f1a585a --- /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 00000000..07a0213a --- /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 00000000..58ca6778 --- /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 00000000..57f18618 --- /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 00000000..048cdff9 --- /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 00000000..a2f4251d --- /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 00000000..310346b4 --- /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 00000000..63d6aa6c --- /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 00000000..3f0ad68e --- /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 00000000..f88a6f72 --- /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 00000000..58eae78a --- /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 00000000..21b2b3fa --- /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 00000000..47cf6968 --- /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 00000000..52a362d3 --- /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 00000000..049210cf --- /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 00000000..14cfce7c --- /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 00000000..6c033d83 --- /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 00000000..efbbddb3 --- /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 00000000..5cc964a0 --- /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 00000000..50e059c5 --- /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 00000000..049210cf --- /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 00000000..0bc99b5a --- /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 00000000..872026cf --- /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 00000000..42c3065e --- /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 00000000..0cbf0f2e --- /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 00000000..cac2dda9 --- /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 00000000..edf6e579 --- /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 00000000..8f9ac453 --- /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 00000000..e57552e3 --- /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 00000000..34946d48 --- /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 00000000..6a26de74 --- /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 00000000..a92b50eb --- /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 00000000..27607f63 --- /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 00000000..cd30a8f0 --- /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 00000000..89b7d642 --- /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 00000000..2175bdfa --- /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 00000000..c0b83943 --- /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 00000000..233b9f81 --- /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 00000000..091e587c --- /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 00000000..23d852df --- /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 00000000..3ccd99da --- /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 00000000..c3db8e44 --- /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 00000000..fa15c186 --- /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 00000000..6d522327 --- /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 00000000..b7c8f05d --- /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 00000000..d391acd0 --- /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 00000000..7c19a9c0 --- /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 00000000..6458ae5b --- /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 00000000..d9ce5b74 --- /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 00000000..049210cf --- /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 00000000..5333b7e2 --- /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 00000000..cdde88c7 --- /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 00000000..049210cf --- /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 00000000..601cc941 --- /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 00000000..3f1a585a --- /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 00000000..424d7cb1 --- /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 00000000..4a247cad --- /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 00000000..9006564d --- /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 00000000..a0d247d8 --- /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 00000000..95b53404 --- /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 00000000..3c229580 --- /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 00000000..91498014 --- /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 00000000..0310bbf1 --- /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 00000000..829886d0 --- /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 00000000..63676b2b --- /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 00000000..3d652cf4 --- /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 00000000..a92a77b9 --- /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 00000000..dac14dbc --- /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 00000000..cc8f056d --- /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 00000000..d85de722 --- /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 00000000..9f7c2b81 --- /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 00000000..cca9b2c5 --- /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 00000000..64343b83 --- /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 00000000..ba675ca9 --- /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 00000000..736d9e72 --- /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 00000000..1c75edbd --- /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 00000000..2d4ea8b3 --- /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 00000000..85378915 --- /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 00000000..641ed9fa --- /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-springboot/src/test/resources/cmpMulti/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/cmpMulti/application.properties new file mode 100644 index 00000000..d2049052 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-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-springboot/src/test/resources/cmpMulti/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/cmpMulti/flow.el.xml new file mode 100644 index 00000000..2beecda5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-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-sql-springboot/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/pom.xml new file mode 100644 index 00000000..b1bfc69d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/pom.xml @@ -0,0 +1,70 @@ + + + + liteflow-testcase-el + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-testcase-el-sql-springboot + + + 2.1.214 + + + + + com.yomahub + liteflow-spring-boot-starter + ${revision} + + + + com.yomahub + liteflow-rule-sql + ${revision} + test + + + + org.springframework.boot + spring-boot-starter-test + + + + org.springframework.boot + spring-boot-starter-data-jpa + 2.0.5.RELEASE + test + + + + com.h2database + h2 + ${h2.version} + test + + + + + + + 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-sql-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java new file mode 100644 index 00000000..7d8cef60 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -0,0 +1,23 @@ +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; + +/** + * @author tangkc + * @since 2.8.6 + */ +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-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java new file mode 100644 index 00000000..34ceb68a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java @@ -0,0 +1,35 @@ +package com.yomahub.liteflow.test.sql; + +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 + * @since 2.9.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/application-xml.properties") +@SpringBootTest(classes = SQLWithXmlELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testSQLWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java new file mode 100644 index 00000000..4b7958ec --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java new file mode 100644 index 00000000..5d71a230 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java new file mode 100644 index 00000000..8bce5991 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-xml.properties new file mode 100644 index 00000000..8565f159 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/application-xml.properties @@ -0,0 +1,9 @@ +liteflow.rule-source-ext-data={"url":"jdbc:h2:mem:test_db;MODE=MySQL","driverClassName":"org.h2.Driver","username":"root","password":"123456","elTable":{"tableName":"EL_TABLE","elDataField":"EL_DATA"}} + +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:test_db;MODE=MySQL +spring.datasource.username=root +spring.datasource.password=123456 +spring.datasource.schema=classpath:/sql/schema.sql +spring.datasource.data=classpath:/sql/data.sql +spring.datasource.platform=h2 \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql new file mode 100644 index 00000000..4a8db084 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/data.sql @@ -0,0 +1,4 @@ +DELETE FROM EL_TABLE; + +INSERT INTO EL_TABLE (CHAIN_NAME,EL_DATA) values ('chain1','THEN(a, b, c);'); +INSERT INTO EL_TABLE (CHAIN_NAME,EL_DATA) values ('chain2','THEN(a, b, c);'); \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/schema.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/schema.sql new file mode 100644 index 00000000..38a82c58 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/schema.sql @@ -0,0 +1,6 @@ +create table `EL_TABLE` ( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `chain_name` varchar(32) NOT NULL, + `el_data` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +) ; \ No newline at end of file diff --git a/liteflow-testcase-el/pom.xml b/liteflow-testcase-el/pom.xml index 89bbc870..c3133976 100644 --- a/liteflow-testcase-el/pom.xml +++ b/liteflow-testcase-el/pom.xml @@ -19,9 +19,10 @@ 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 liteflow-testcase-el-zk-springboot - liteflow-testcase-el-nacos-springboot + liteflow-testcase-el-sql-springboot \ No newline at end of file