diff --git a/README.md b/README.md index 31d5086b9..dc7523213 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,31 @@ Looking forward to your use! Discord Link: [https://discord.gg/MpdBSBnFTu](https://discord.gg/MpdBSBnFTu) +## 👑LF CLUB Community + +LF CLUB is a premium paid community founded by the author of LiteFlow. + +LF CLUB can help all users of the LiteFlow framework, as well as potential developers who want to use LiteFlow. + +LF CLUB provides the following services: + +**1.Weekly releases of a condensed analysis series for LF. As long as users study along with the Planet series articles, they will definitely be able to fully grasp LF.** + +**2.Provide a Q&A service where members can ask unlimited questions and receive detailed replies and guidance on the same day.** + +**3.Each enrolled user is entitled to two remote one-on-one tutoring sessions per year as part of the remote assistance service.** + +**4.Every 1 to 2 days, there will be updates on LF's current progress and the focus of the next version.** + +The LF CLUB can solve all the problems you encounter when using the LiteFlow framework. It offers a series of courses to help you gain a deep understanding of the LiteFlow framework. Unlike the WeChat community, the LF CLUB prioritizes the importance of questions and provides detailed answers. + +Exclusive content helps you gain a profound understanding without the need to search for answers on other platforms. The author personally teaches, providing expert guidance at your fingertips, eliminating the need to seek help from others. + +To join the LF CLUB, please scan the QR code below or click on the image to go directly to the website. + + + + ## 🦾Sponsor **MISBoot低代码开发平台** @@ -76,6 +101,10 @@ Discord Link: [https://discord.gg/MpdBSBnFTu](https://discord.gg/MpdBSBnFTu) +**FastBee物联网平台** + + + **WECHAT OFFICIAL ACCOUNT** Since the community group is over 200 people, you need to be invited to join the group. Follow the WECHAT OFFICIAL ACCOUNT and click `Personal WeChat` to add me, I can invite you into the group diff --git a/README.zh-CN.md b/README.zh-CN.md index 66de111d2..d15e96de6 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -57,6 +57,30 @@ LiteFlow拥有极其详细易懂的文档体系,能帮助你解决在使用框 LiteFlow期待你的了解! +## 👑LF CLUB社区 + +LF CLUB是由LiteFlow作者创办的高级付费社区 + +LF CLUB能帮助到所有LiteFlow框架的使用者,以及想使用LiteFlow的潜在开发者。 + +LF CLUB提供以下服务: + +**1.每周发布一篇LF的解析精华系列。从头开始解析LF,只要跟着星球解析系列走,使用者一定能完全掌握LF。** + +**2.提供答疑服务,会员可以无限制提问,当天必定得到详细的回复和指导建议。** + +**3.每个加入的用户每年提供2次远程一对一答疑,远程协助服务。** + +**4.每1到2天会分享LF目前的进度,以及下一个版本的重点。** + +LF CLUB里能解决你在使用LiteFlow框架时碰到的所有问题,并有系列课程能帮助你深刻理解LiteFlow框架,不同于微信社区,LF CLUB的问题优先级程度是最高的,且答疑非常详细。 + +独家内容帮助深刻理解,不用在其他平台去搜索问题的答案。作者亲授,相当于随时拥有专家在身边,不用再去求助其他人。 + +加入LF CLUB,请扫描以下二维码,或者直接点击图片也可以直达: + + + ## 🦾赞助商 **MISBoot低代码开发平台** @@ -71,6 +95,10 @@ LiteFlow期待你的了解! +**FastBee物联网平台** + + + **微信公众号** 社区群需要邀请入群。关注公众号后点击`个人微信`加我,我可以拉你入群 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java index a1e9ae2bd..dbc1cf57f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.annotation; +import com.yomahub.liteflow.enums.BooleanTypeEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import java.lang.annotation.Documented; @@ -20,4 +21,6 @@ import java.lang.annotation.Target; @Documented @Inherited public @interface FallbackCmp { + + BooleanTypeEnum value() default BooleanTypeEnum.NOT_BOOL; } 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 2af9f5dae..f436c6554 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 @@ -12,6 +12,12 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited +@Deprecated +/** + * This class has been deprecated due to its only component retry function. Please use the retry method in the EL expression. + * @Deprecated + * @see # retry(int retryTimes) e.g. THEN( a, b.retry(3) ); WHEN( a, b ).retry(3); + */ public @interface LiteflowRetry { @LFAliasFor("retry") diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java index ab86d02ea..3074c4bb2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.annotation.util; import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.annotation.LFAliasFor; import java.lang.annotation.Annotation; @@ -10,15 +11,25 @@ import java.lang.reflect.AnnotatedElement; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * 注解工具类 + * 此工具类带缓存 * * @author Bryan.Zhang */ public class AnnoUtil { + private static Map annoCacheMap = new ConcurrentHashMap<>(); + public static A getAnnotation(AnnotatedElement annotatedElement, Class annotationType) { + String cacheKey = StrUtil.format("{}-{}", annotatedElement, annotationType.getSimpleName()); + + if (annoCacheMap.containsKey(cacheKey)){ + return (A)annoCacheMap.get(cacheKey); + } + A annotation = AnnotationUtil.getAnnotation(annotatedElement, annotationType); if (ObjectUtil.isNull(annotation)) { return null; @@ -42,6 +53,8 @@ public class AnnoUtil { } }); + annoCacheMap.put(cacheKey, annotation); + return annotation; } @@ -53,5 +66,4 @@ public class AnnoUtil { return null; } } - } 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 932cd6b62..d125e33cb 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 @@ -34,22 +34,14 @@ public class LiteFlowNodeBuilder { return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH); } - public static LiteFlowNodeBuilder createIfNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.IF); + public static LiteFlowNodeBuilder createBooleanNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.BOOLEAN); } public static LiteFlowNodeBuilder createForNode() { return new LiteFlowNodeBuilder(NodeTypeEnum.FOR); } - public static LiteFlowNodeBuilder createWhileNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE); - } - - public static LiteFlowNodeBuilder createBreakNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK); - } - public static LiteFlowNodeBuilder createIteratorNode() { return new LiteFlowNodeBuilder(NodeTypeEnum.ITERATOR); } @@ -62,22 +54,14 @@ public class LiteFlowNodeBuilder { return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH_SCRIPT); } - public static LiteFlowNodeBuilder createScriptIfNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.IF_SCRIPT); + public static LiteFlowNodeBuilder createScriptBooleanNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.BOOLEAN_SCRIPT); } public static LiteFlowNodeBuilder createScriptForNode() { return new LiteFlowNodeBuilder(NodeTypeEnum.FOR_SCRIPT); } - public static LiteFlowNodeBuilder createScriptWhileNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE_SCRIPT); - } - - public static LiteFlowNodeBuilder createScriptBreakNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK_SCRIPT); - } - public LiteFlowNodeBuilder() { this.node = new Node(); } 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 0f1a65ad7..91431715d 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 @@ -21,6 +21,7 @@ import com.yomahub.liteflow.exception.ParseException; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.element.Chain; import com.yomahub.liteflow.flow.element.Condition; +import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; @@ -44,6 +45,11 @@ public class LiteFlowChainELBuilder { private Chain chain; + /** + * 这是route EL的文本 + */ + private Executable route; + /** * 这是主体的Condition //声明这个变量,而不是用chain.getConditionList的目的,是为了辅助平滑加载 * 虽然FlowBus里面的map都是CopyOnWrite类型的,但是在buildCondition的时候,为了平滑加载,所以不能事先把chain.getConditionList给设为空List @@ -92,6 +98,7 @@ public class LiteFlowChainELBuilder { EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.MAX_WAIT_SECONDS, Object.class, new MaxWaitSecondsOperator()); EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.MAX_WAIT_MILLISECONDS, Object.class, new MaxWaitMillisecondsOperator()); EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.PARALLEL, Object.class, new ParallelOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.RETRY, Object.class, new RetryOperator()); } public static LiteFlowChainELBuilder createChain() { @@ -129,6 +136,45 @@ public class LiteFlowChainELBuilder { return this; } + public LiteFlowChainELBuilder setRoute(String routeEl){ + if (StrUtil.isBlank(routeEl)) { + String errMsg = StrUtil.format("You have defined the label but there is no content in the chain[{}].", chain.getChainId()); + throw new FlowSystemException(errMsg); + } + List errorList = new ArrayList<>(); + try { + DefaultContext context = new DefaultContext<>(); + + // 往上下文里放入所有的node,使得el表达式可以直接引用到nodeId + FlowBus.getNodeMap().keySet().forEach(nodeId -> context.put(nodeId, FlowBus.getNode(nodeId))); + + // 解析route el成为一个executable + Executable routeExecutable = (Executable) EXPRESS_RUNNER.execute(routeEl, context, errorList, true, true); + + if (Objects.isNull(routeExecutable)){ + throw new QLException(StrUtil.format("parse route el fail,el:[{}]", routeEl)); + } + + // 把主要的condition加入 + this.route = routeExecutable; + return this; + } catch (QLException e) { + // EL 底层会包装异常,这里是曲线处理 + if (ObjectUtil.isNotNull(e.getCause()) && Objects.equals(e.getCause().getMessage(), DataNotFoundException.MSG)) { + // 构建错误信息 + String msg = buildDataNotFoundExceptionMsg(routeEl); + throw new ELParseException(msg); + }else if (ObjectUtil.isNotNull(e.getCause())){ + throw new ELParseException(e.getCause().getMessage()); + }else{ + throw new ELParseException(e.getMessage()); + } + } catch (Exception e) { + String errMsg = StrUtil.format("parse el fail in this chain[{}];\r\n", chain.getChainId()); + throw new ELParseException(errMsg + e.getMessage()); + } + } + public LiteFlowChainELBuilder setEL(String elStr) { if (StrUtil.isBlank(elStr)) { String errMsg = StrUtil.format("no content in this chain[{}]", chain.getChainId()); @@ -196,6 +242,7 @@ public class LiteFlowChainELBuilder { } public void build() { + this.chain.setRouteItem(this.route); this.chain.setConditionList(this.conditionList); //暂且去掉循环依赖检测,因为有发现循环依赖检测在对大的EL进行检测的时候,会导致CPU飙升,也或许是jackson低版本的问题 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AndOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AndOperator.java index 0e5f731ab..29d663cbe 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AndOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AndOperator.java @@ -16,7 +16,7 @@ import com.yomahub.liteflow.flow.element.condition.BooleanConditionTypeEnum; public class AndOperator extends BaseOperator { @Override public AndOrCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtTwo(objects); + OperatorHelper.checkObjectSizeGteTwo(objects); AndOrCondition andOrCondition = new AndOrCondition(); andOrCondition.setBooleanConditionType(BooleanConditionTypeEnum.AND); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MustOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MustOperator.java index b3e3f0c28..8a903008c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MustOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MustOperator.java @@ -19,7 +19,7 @@ public class MustOperator extends BaseOperator { @Override public WhenCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtTwo(objects); + OperatorHelper.checkObjectSizeGteTwo(objects); String errorMsg = "The caller must be WhenCondition item"; WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class, errorMsg); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/OrOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/OrOperator.java index d084a7536..361ab62bb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/OrOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/OrOperator.java @@ -16,7 +16,7 @@ import com.yomahub.liteflow.flow.element.condition.BooleanConditionTypeEnum; public class OrOperator extends BaseOperator { @Override public AndOrCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtTwo(objects); + OperatorHelper.checkObjectSizeGteTwo(objects); AndOrCondition andOrCondition = new AndOrCondition(); andOrCondition.setBooleanConditionType(BooleanConditionTypeEnum.OR); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/RetryOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/RetryOperator.java new file mode 100644 index 000000000..38f8c6b6c --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/RetryOperator.java @@ -0,0 +1,35 @@ +package com.yomahub.liteflow.builder.el.operator; + +import com.yomahub.liteflow.builder.el.operator.base.BaseOperator; +import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper; +import com.yomahub.liteflow.flow.element.Condition; +import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.condition.RetryCondition; + +/** + * + * @author Rain + * @since 2.12.0 + * + */ +public class RetryOperator extends BaseOperator { + @Override + public Condition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeGteTwo(objects); + Executable executable = OperatorHelper.convert(objects[0], Executable.class); + Integer retryTimes = OperatorHelper.convert(objects[1], Integer.class); + RetryCondition retryCondition = new RetryCondition(); + retryCondition.addExecutable(executable); + retryCondition.setRetryTimes(retryTimes); + if(objects.length > 2) { + Class[] forExceptions = new Class[objects.length - 2]; + for(int i = 2; i < objects.length; i ++) { + String className = OperatorHelper.convert(objects[i], String.class); + forExceptions[i - 2] = Class.forName(className); + } + retryCondition.setRetryForExceptions(forExceptions); + } + return retryCondition; + } + +} 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 d38722a03..4eede8779 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 @@ -15,7 +15,7 @@ public class ToOperator extends BaseOperator { @Override public SwitchCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtTwo(objects); + OperatorHelper.checkObjectSizeGteTwo(objects); String errorMsg = "The caller must be SwitchCondition item"; SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class, errorMsg); 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 c54681a63..ee0be1f6c 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 @@ -10,8 +10,6 @@ import com.yomahub.liteflow.exception.DataNotFoundException; import com.yomahub.liteflow.flow.element.Condition; import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.flow.element.Node; -import com.yomahub.liteflow.flow.element.condition.AndOrCondition; -import com.yomahub.liteflow.flow.element.condition.NotCondition; import java.util.Objects; @@ -35,13 +33,13 @@ public class OperatorHelper { } /** - * 检查参数数量,大于 2 + * 检查参数数量,大于等于 2 * @param objects objects * @throws QLException QLException */ - public static void checkObjectSizeGtTwo(Object[] objects) throws QLException { + public static void checkObjectSizeGteTwo(Object[] objects) throws QLException { checkObjectSizeGtZero(objects); - if (objects.length <= 1) { + if (objects.length < 2) { throw new QLException("parameter error"); } } @@ -119,7 +117,7 @@ public class OperatorHelper { if (clazz.isAssignableFrom(object.getClass())) { if (object instanceof Node) { Node node = (Node) object; - return (T) node.copy(); + return (T) node.clone(); } else { return (T) object; @@ -169,12 +167,8 @@ public class OperatorHelper { Executable item = (Executable) object; if (item.getExecuteType().equals(ExecuteTypeEnum.NODE)){ Node node = (Node) item; - if (!ListUtil.toList(NodeTypeEnum.IF, - NodeTypeEnum.IF_SCRIPT, - NodeTypeEnum.WHILE, - NodeTypeEnum.WHILE_SCRIPT, - NodeTypeEnum.BREAK, - NodeTypeEnum.BREAK_SCRIPT, + if (!ListUtil.toList(NodeTypeEnum.BOOLEAN, + NodeTypeEnum.BOOLEAN_SCRIPT, NodeTypeEnum.FALLBACK).contains(node.getType())){ throw new QLException(StrUtil.format("The node[{}] must be boolean type Node.", node.getId())); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java index 105c8b755..ad64b36e5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java @@ -10,6 +10,10 @@ public interface ChainConstant { String CHAIN = "chain"; + String ROUTE = "route"; + + String BODY = "body"; + String FLOW = "flow"; String NODES = "nodes"; @@ -96,4 +100,6 @@ public interface ChainConstant { String EXTENDS = "extends"; + String RETRY = "retry"; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBooleanComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBooleanComponent.java new file mode 100644 index 000000000..5625fe780 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBooleanComponent.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.core; + +import com.yomahub.liteflow.slot.DataBus; + +/** + * BOOLEAN类型的抽象节点 + * + * @author Bryan.Zhang + * @since 2.12.0 + */ +public abstract class NodeBooleanComponent extends NodeComponent { + + @Override + public void process() throws Exception { + boolean result = this.processBoolean(); + this.getSlot().setIfResult(this.getMetaValueKey(), result); + } + + public abstract boolean processBoolean() throws Exception; + + @Override + @SuppressWarnings("unchecked") + public Boolean getItemResultMetaValue(Integer slotIndex) { + return DataBus.getSlot(slotIndex).getIfResult(this.getMetaValueKey()); + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBreakComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBreakComponent.java deleted file mode 100644 index a26bdb8cc..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBreakComponent.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.yomahub.liteflow.core; - -import com.yomahub.liteflow.slot.DataBus; -import com.yomahub.liteflow.slot.Slot; -import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil; - -/** - * 循环跳出节点逻辑抽象类 - * - * @author Bryan.Zhang - * @since 2.9.0 - */ -public abstract class NodeBreakComponent extends NodeComponent { - - @Override - public void process() throws Exception { - boolean breakFlag = processBreak(); - Slot slot = this.getSlot(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - slot.setBreakResult(originalClass.getName(), breakFlag); - } - - public abstract boolean processBreak() throws Exception; - - @Override - @SuppressWarnings("unchecked") - public Boolean getItemResultMetaValue(Integer slotIndex) { - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - return DataBus.getSlot(slotIndex).getBreakResult(originalClass.getName()); - } - -} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index 283de4216..02140db44 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -7,44 +7,37 @@ */ package com.yomahub.liteflow.core; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.StopWatch; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.ttl.TransmittableThreadLocal; -import com.yomahub.liteflow.exception.ChainEndException; +import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil; +import com.yomahub.liteflow.enums.CmpStepTypeEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.flow.LiteflowResponse; import com.yomahub.liteflow.flow.element.Node; -import com.yomahub.liteflow.flow.executor.NodeExecutor; +import com.yomahub.liteflow.flow.entity.CmpStep; import com.yomahub.liteflow.flow.executor.DefaultNodeExecutor; -import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.flow.executor.NodeExecutor; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; -import com.yomahub.liteflow.spi.holder.CmpAroundAspectHolder; -import com.yomahub.liteflow.util.JsonUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.yomahub.liteflow.flow.entity.CmpStep; -import com.yomahub.liteflow.enums.CmpStepTypeEnum; -import com.yomahub.liteflow.slot.DataBus; -import com.yomahub.liteflow.slot.Slot; -import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.monitor.CompStatistics; import com.yomahub.liteflow.monitor.MonitorBus; +import com.yomahub.liteflow.slot.DataBus; +import com.yomahub.liteflow.slot.Slot; +import com.yomahub.liteflow.spi.holder.CmpAroundAspectHolder; +import com.yomahub.liteflow.util.JsonUtil; import java.lang.reflect.Method; import java.util.Date; -import java.util.Deque; -import java.util.Map; -import java.util.function.Predicate; /** * 普通组件抽象类 * * @author Bryan.Zhang + * @author luo yi */ -public abstract class NodeComponent { +public abstract class NodeComponent{ private final LFLog LOG = LFLoggerManager.getLogger(this.getClass()); @@ -77,16 +70,11 @@ public abstract class NodeComponent { private final TransmittableThreadLocal refNodeTL = new TransmittableThreadLocal<>(); /** - ******************* 以下的属性为线程附加属性******************** 线程属性是指每一个request的值都是不一样的 + ******************* 以下的属性为线程附加属性******************** + * 线程属性是指每一个request的值都是不一样的 * 这里NodeComponent是单例,所以要用ThreadLocal来修饰 */ - // 当前slot的index - private final TransmittableThreadLocal slotIndexTL = new TransmittableThreadLocal<>(); - - // 是否结束整个流程,这个只对串行流程有效,并行流程无效 - private final TransmittableThreadLocal isEndTL = new TransmittableThreadLocal<>(); - public NodeComponent() { // 反射判断是否重写了rollback方法 Class clazz = this.getClass(); @@ -237,39 +225,29 @@ public abstract class NodeComponent { // 是否结束整个流程(不往下继续执行) public boolean isEnd() { - Boolean isEnd = isEndTL.get(); + Boolean isEnd = this.refNodeTL.get().getIsEnd(); if (ObjectUtil.isNull(isEnd)) { return false; - } - else { - return isEndTL.get(); + }else { + return isEnd; } } // 设置是否结束整个流程 public void setIsEnd(boolean isEnd) { - this.isEndTL.set(isEnd); + this.refNodeTL.get().setIsEnd(isEnd); } - public void removeIsEnd() { - this.isEndTL.remove(); - } - - public NodeComponent setSlotIndex(Integer slotIndex) { - this.slotIndexTL.set(slotIndex); - return this; + public void setIsContinueOnError(boolean isContinueOnError) { + this.refNodeTL.get().setIsContinueOnErrorResult(isContinueOnError); } public Integer getSlotIndex() { - return this.slotIndexTL.get(); - } - - public void removeSlotIndex() { - this.slotIndexTL.remove(); + return this.refNodeTL.get().getSlotIndex(); } public Slot getSlot() { - return DataBus.getSlot(this.slotIndexTL.get()); + return DataBus.getSlot(this.getSlotIndex()); } public T getFirstContextBean() { @@ -280,6 +258,10 @@ public abstract class NodeComponent { return this.getSlot().getContextBean(contextBeanClazz); } + public T getContextBean(String contextName) { + return this.getSlot().getContextBean(contextName); + } + public String getNodeId() { return nodeId; } @@ -454,4 +436,9 @@ public abstract class NodeComponent { public T getItemResultMetaValue(Integer slotIndex){ return null; } + + protected String getMetaValueKey(){ + Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); + return originalClass.getName(); + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeForComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeForComponent.java index 53675e614..7f65a57e4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeForComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeForComponent.java @@ -16,8 +16,7 @@ public abstract class NodeForComponent extends NodeComponent { public void process() throws Exception { int forCount = processFor(); Slot slot = this.getSlot(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - slot.setForResult(originalClass.getName(), forCount); + slot.setForResult(this.getMetaValueKey(), forCount); } public abstract int processFor() throws Exception; @@ -25,8 +24,7 @@ public abstract class NodeForComponent extends NodeComponent { @Override @SuppressWarnings("unchecked") public Integer getItemResultMetaValue(Integer slotIndex) { - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - return DataBus.getSlot(slotIndex).getForResult(originalClass.getName()); + return DataBus.getSlot(slotIndex).getForResult(this.getMetaValueKey()); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIfComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIfComponent.java deleted file mode 100644 index 341051279..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIfComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.yomahub.liteflow.core; - -import com.yomahub.liteflow.slot.DataBus; -import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil; - -/** - * IF节点抽象类 - * - * @author Bryan.Zhang - * @since 2.8.5 - */ -public abstract class NodeIfComponent extends NodeComponent { - - @Override - public void process() throws Exception { - boolean result = this.processIf(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - this.getSlot().setIfResult(originalClass.getName(), result); - } - - public abstract boolean processIf() throws Exception; - - @Override - @SuppressWarnings("unchecked") - public Boolean getItemResultMetaValue(Integer slotIndex) { - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - return DataBus.getSlot(slotIndex).getIfResult(originalClass.getName()); - } -} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIteratorComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIteratorComponent.java index f8aec09ea..6f5068da7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIteratorComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIteratorComponent.java @@ -18,8 +18,7 @@ public abstract class NodeIteratorComponent extends NodeComponent { public void process() throws Exception { Iterator it = processIterator(); Slot slot = this.getSlot(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - slot.setIteratorResult(originalClass.getName(), it); + slot.setIteratorResult(this.getMetaValueKey(), it); } public abstract Iterator processIterator() throws Exception; @@ -27,8 +26,7 @@ public abstract class NodeIteratorComponent extends NodeComponent { @Override @SuppressWarnings("unchecked") public Iterator getItemResultMetaValue(Integer slotIndex) { - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - return DataBus.getSlot(slotIndex).getIteratorResult(originalClass.getName()); + return DataBus.getSlot(slotIndex).getIteratorResult(this.getMetaValueKey()); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeSwitchComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeSwitchComponent.java index b24e32296..c4320a4e2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeSwitchComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeSwitchComponent.java @@ -20,8 +20,7 @@ public abstract class NodeSwitchComponent extends NodeComponent { @Override public void process() throws Exception { String nodeId = this.processSwitch(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - this.getSlot().setSwitchResult(originalClass.getName(), nodeId); + this.getSlot().setSwitchResult(this.getMetaValueKey(), nodeId); } // 用以返回路由节点的beanId @@ -30,8 +29,7 @@ public abstract class NodeSwitchComponent extends NodeComponent { @Override @SuppressWarnings("unchecked") public String getItemResultMetaValue(Integer slotIndex) { - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - return DataBus.getSlot(slotIndex).getSwitchResult(originalClass.getName()); + return DataBus.getSlot(slotIndex).getSwitchResult(this.getMetaValueKey()); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeWhileComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeWhileComponent.java deleted file mode 100644 index 446b6587a..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeWhileComponent.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.yomahub.liteflow.core; - -import com.yomahub.liteflow.slot.DataBus; -import com.yomahub.liteflow.slot.Slot; -import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil; - -/** - * WHILE条件节点抽象类 - * - * @author Bryan.Zhang - * @since 2.9.0 - */ -public abstract class NodeWhileComponent extends NodeComponent { - - @Override - public void process() throws Exception { - boolean whileFlag = processWhile(); - Slot slot = this.getSlot(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - slot.setWhileResult(originalClass.getName(), whileFlag); - } - - public abstract boolean processWhile() throws Exception; - - @Override - @SuppressWarnings("unchecked") - public Boolean getItemResultMetaValue(Integer slotIndex) { - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - return DataBus.getSlot(slotIndex).getWhileResult(originalClass.getName()); - } - -} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptIfComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBooleanComponent.java similarity index 74% rename from liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptIfComponent.java rename to liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBooleanComponent.java index a55cb8ed3..995563531 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptIfComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBooleanComponent.java @@ -3,18 +3,16 @@ package com.yomahub.liteflow.core; import com.yomahub.liteflow.script.ScriptExecuteWrap; import com.yomahub.liteflow.script.ScriptExecutorFactory; -import java.util.Map; - /** - * 脚本IF节点 + * 脚本BOOLEAN节点 * * @author Bryan.Zhang - * @since 2.8.5 + * @since 2.12.0 */ -public class ScriptIfComponent extends NodeIfComponent implements ScriptComponent { +public class ScriptBooleanComponent extends NodeBooleanComponent implements ScriptComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { ScriptExecuteWrap wrap = this.buildWrap(this); return (boolean) ScriptExecutorFactory.loadInstance() .getScriptExecutor(this.getRefNode().getLanguage()) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBreakComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBreakComponent.java deleted file mode 100644 index 379993cb4..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBreakComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.yomahub.liteflow.core; - -import com.yomahub.liteflow.script.ScriptExecuteWrap; -import com.yomahub.liteflow.script.ScriptExecutorFactory; - -import java.util.Map; - -/** - * 脚本BREAK节点 - * - * @author Bryan.Zhang - * @since 2.9.0 - */ -public class ScriptBreakComponent extends NodeBreakComponent implements ScriptComponent { - - @Override - public boolean processBreak() throws Exception { - ScriptExecuteWrap wrap = this.buildWrap(this); - return (boolean) ScriptExecutorFactory.loadInstance() - .getScriptExecutor(this.getRefNode().getLanguage()) - .execute(wrap); - } - - @Override - public void loadScript(String script, String language) { - ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script); - } - -} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptComponent.java index c6fe31637..77fa7ffe6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptComponent.java @@ -21,10 +21,8 @@ public interface ScriptComponent { { put(NodeTypeEnum.SCRIPT, ScriptCommonComponent.class); put(NodeTypeEnum.SWITCH_SCRIPT, ScriptSwitchComponent.class); - put(NodeTypeEnum.IF_SCRIPT, ScriptIfComponent.class); + put(NodeTypeEnum.BOOLEAN_SCRIPT, ScriptBooleanComponent.class); put(NodeTypeEnum.FOR_SCRIPT, ScriptForComponent.class); - put(NodeTypeEnum.WHILE_SCRIPT, ScriptWhileComponent.class); - put(NodeTypeEnum.BREAK_SCRIPT, ScriptBreakComponent.class); } }; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptWhileComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptWhileComponent.java deleted file mode 100644 index ef07d31e3..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptWhileComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.yomahub.liteflow.core; - -import com.yomahub.liteflow.script.ScriptExecuteWrap; -import com.yomahub.liteflow.script.ScriptExecutorFactory; - -import java.util.Map; - -/** - * 脚本WHILE节点 - * - * @author Bryan.Zhang - * @since 2.9.0 - */ -public class ScriptWhileComponent extends NodeWhileComponent implements ScriptComponent { - - @Override - public boolean processWhile() throws Exception { - ScriptExecuteWrap wrap = this.buildWrap(this); - return (boolean) ScriptExecutorFactory.loadInstance() - .getScriptExecutor(this.getRefNode().getLanguage()) - .execute(wrap); - } - - @Override - public void loadScript(String script, String language) { - ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script); - } - -} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/BooleanTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/BooleanTypeEnum.java new file mode 100644 index 000000000..33ec35257 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/BooleanTypeEnum.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.enums; + +/** + * 布尔节点的细分TYPE + * 主要用于组件降级 + * + * @author Bryan.Zhang + * @since 2.12.0 + */ +public enum BooleanTypeEnum { + + NOT_BOOL,IF,WHILE,BREAK +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java index be015b2a0..5b6d0034e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java @@ -4,10 +4,8 @@ public enum LiteFlowMethodEnum { PROCESS("process", true), PROCESS_SWITCH("processSwitch", true), - PROCESS_IF("processIf", true), + PROCESS_BOOLEAN("processBoolean", true), PROCESS_FOR("processFor", true), - PROCESS_WHILE("processWhile", true), - PROCESS_BREAK("processBreak", true), PROCESS_ITERATOR("processIterator", true), diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/NodeTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/NodeTypeEnum.java index 7ca1efff7..a02ae6287 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/NodeTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/NodeTypeEnum.java @@ -25,28 +25,20 @@ public enum NodeTypeEnum { SWITCH("switch", "选择", false, NodeSwitchComponent.class), - IF("if", "条件", false, NodeIfComponent.class), + BOOLEAN("boolean", "布尔", false, NodeBooleanComponent.class), FOR("for", "循环次数", false, NodeForComponent.class), - WHILE("while", "循环条件", false, NodeWhileComponent.class), - - BREAK("break", "循环跳出", false, NodeBreakComponent.class), - ITERATOR("iterator", "循环迭代", false, NodeIteratorComponent.class), SCRIPT("script", "脚本", true, ScriptCommonComponent.class), SWITCH_SCRIPT("switch_script", "选择脚本", true, ScriptSwitchComponent.class), - IF_SCRIPT("if_script", "条件脚本", true, ScriptIfComponent.class), + BOOLEAN_SCRIPT("boolean_script", "布尔脚本", true, ScriptBooleanComponent.class), FOR_SCRIPT("for_script", "循环次数脚本", true, ScriptForComponent.class), - WHILE_SCRIPT("while_script", "循环条件脚本", true, ScriptWhileComponent.class), - - BREAK_SCRIPT("break_script", "循环跳出脚本", true, ScriptBreakComponent.class), - FALLBACK("fallback", "降级", false, null); private static final LFLog LOG = LFLoggerManager.getLogger(NodeTypeEnum.class); 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 c7ea30335..34a11d3a7 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 @@ -16,11 +16,13 @@ import com.yomahub.liteflow.core.ComponentInitializer; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.core.ScriptComponent; import com.yomahub.liteflow.core.proxy.DeclWarpBean; +import com.yomahub.liteflow.enums.BooleanTypeEnum; 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.Condition; import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; @@ -40,7 +42,9 @@ import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * 流程元数据类 @@ -56,7 +60,7 @@ public class FlowBus { private static final Map nodeMap; - private static final Map fallbackNodeMap; + private static final Map fallbackNodeMap; private static AtomicBoolean initStat = new AtomicBoolean(false); @@ -241,6 +245,14 @@ public class FlowBus { return nodeMap.get(nodeId); } + // 获取某一个 chainId 下的所有 nodeId + public static List getNodesByChainId(String chainId) { + Chain chain = getChain(chainId); + return chain.getConditionList().stream().flatMap( + (Function>) condition -> condition.getAllNodeInCondition().stream() + ).collect(Collectors.toList()); + } + public static Map getNodeMap() { return nodeMap; } @@ -250,7 +262,12 @@ public class FlowBus { } public static Node getFallBackNode(NodeTypeEnum nodeType) { - return fallbackNodeMap.get(nodeType); + return getFallBackNode(nodeType, BooleanTypeEnum.NOT_BOOL); + } + + public static Node getFallBackNode(NodeTypeEnum nodeType, BooleanTypeEnum booleanTypeEnum){ + String key = StrUtil.format("{}_{}", nodeType.name(), booleanTypeEnum.name()); + return fallbackNodeMap.get(key); } public static void cleanCache() { @@ -297,6 +314,11 @@ public class FlowBus { Arrays.stream(chainIds).forEach(FlowBus::removeChain); } + // 移除节点 + public static boolean removeNode(String nodeId) { + return nodeMap.remove(nodeId) != null; + } + // 判断是否是降级组件,如果是则添加到 fallbackNodeMap private static void addFallbackNode(Node node) { NodeComponent nodeComponent = node.getInstance(); @@ -306,7 +328,35 @@ public class FlowBus { } NodeTypeEnum nodeType = node.getType(); - fallbackNodeMap.put(nodeType, node); + String key = StrUtil.format("{}_{}", nodeType.name(), fallbackCmp.value().name()); + fallbackNodeMap.put(key, node); + } + + // 重新加载脚本 + public static void reloadScript(String nodeId, String script) { + Node node = getNode(nodeId); + if (node == null || !node.getType().isScript()) { + return; + } + // 更新脚本 + node.setScript(script); + ScriptExecutorFactory.loadInstance() + .getScriptExecutor(node.getLanguage()) + .load(nodeId, script); + } + + // 卸载脚本节点 + public static boolean unloadScriptNode(String nodeId) { + Node node = getNode(nodeId); + if (node == null || !node.getType().isScript()) { + return false; + } + // 卸载脚本 + ScriptExecutorFactory.loadInstance() + .getScriptExecutor(node.getLanguage()) + .unLoad(nodeId); + // 移除脚本 + return removeNode(nodeId); } public static void clearStat(){ diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java index c2645a299..51e1ddc28 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/LiteflowResponse.java @@ -101,6 +101,10 @@ public class LiteflowResponse { return this.getSlot().getContextBean(contextBeanClazz); } + public T getContextBean(String contextName) { + return this.getSlot().getContextBean(contextName); + } + public Map> getExecuteSteps() { Map> map = new LinkedHashMap<>(); this.getSlot().getExecuteSteps().forEach(cmpStep -> { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java index 16cc12546..04cada75d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java @@ -30,6 +30,8 @@ public class Chain implements Executable{ private String chainId; + private Executable routeItem; + private List conditionList = new ArrayList<>(); public Chain(String chainName) { @@ -133,4 +135,12 @@ public class Chain implements Executable{ public String getTag() { return null; } + + public Executable getRouteItem() { + return routeItem; + } + + public void setRouteItem(Executable routeItem) { + this.routeItem = routeItem; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Condition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Condition.java index 0d4eec6a7..667b78be8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Condition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Condition.java @@ -22,6 +22,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Condition的抽象类 @@ -103,6 +108,24 @@ public abstract class Condition implements Executable{ } } + public List getAllNodeInCondition(){ + List executableList = this.executableGroup.entrySet().stream().flatMap( + (Function>, Stream>) entry -> entry.getValue().stream() + ).collect(Collectors.toList()); + + List resultList = new ArrayList<>(); + + executableList.stream().forEach(executable -> { + if (executable instanceof Condition){ + resultList.addAll(((Condition)executable).getAllNodeInCondition()); + }else if(executable instanceof Node){ + resultList.add((Node)executable); + } + }); + + return resultList; + } + public void setExecutableList(List executableList) { this.executableGroup.put(ConditionKey.DEFAULT_KEY, executableList); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNode.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNode.java index 966f37a61..f6302b915 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNode.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNode.java @@ -2,6 +2,8 @@ package com.yomahub.liteflow.flow.element; import cn.hutool.core.text.StrFormatter; import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; import com.yomahub.liteflow.enums.ConditionTypeEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.exception.FallbackCmpNotFoundException; @@ -64,7 +66,7 @@ public class FallbackNode extends Node { this.getCurrChainId())); } // 使用 node 的副本 - this.fallbackNode = node.copy(); + this.fallbackNode = node.clone(); } private Node findFallbackNode(Condition condition) { @@ -88,7 +90,8 @@ public class FallbackNode extends Node { return findNodeInIterator((IteratorCondition) condition); case TYPE_NOT_OPT: case TYPE_AND_OR_OPT: - return FlowBus.getFallBackNode(NodeTypeEnum.IF); + //组件降级用在与并或中,只能用在IF表达式中 + return FlowBus.getFallBackNode(NodeTypeEnum.BOOLEAN, BooleanTypeEnum.IF); default: return null; } @@ -98,7 +101,7 @@ public class FallbackNode extends Node { Executable ifItem = ifCondition.getIfItem(); if (ifItem == this) { // 需要条件组件 - return FlowBus.getFallBackNode(NodeTypeEnum.IF); + return FlowBus.getFallBackNode(NodeTypeEnum.BOOLEAN, BooleanTypeEnum.IF); } // 需要普通组件 @@ -126,7 +129,7 @@ public class FallbackNode extends Node { private Node findNodeInWhile(WhileCondition whileCondition) { Executable whileItem = whileCondition.getWhileItem(); if (whileItem == this) { - return FlowBus.getFallBackNode(NodeTypeEnum.WHILE); + return FlowBus.getFallBackNode(NodeTypeEnum.BOOLEAN, BooleanTypeEnum.WHILE); } return findNodeInLoop(whileCondition); @@ -144,7 +147,7 @@ public class FallbackNode extends Node { private Node findNodeInLoop(LoopCondition loopCondition) { Executable breakItem = loopCondition.getExecutableOne(ConditionKey.BREAK_KEY); if (breakItem == this) { - return FlowBus.getFallBackNode(NodeTypeEnum.BREAK); + return FlowBus.getFallBackNode(NodeTypeEnum.BOOLEAN, BooleanTypeEnum.BREAK); } return FlowBus.getFallBackNode(NodeTypeEnum.COMMON); @@ -162,13 +165,21 @@ public class FallbackNode extends Node { return this.fallbackNode.isAccess(slotIndex); } + @Override + public NodeComponent getInstance() { + if (fallbackNode == null){ + return null; + } + return fallbackNode.getInstance(); + } + @Override public String getId() { return this.fallbackNode == null ? null : this.fallbackNode.getId(); } @Override - public Node copy() { + public Node clone() { // 代理节点不复制 return this; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Node.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Node.java index 269a4dd62..683bfd8dd 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Node.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Node.java @@ -21,8 +21,6 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; import com.yomahub.liteflow.flow.executor.NodeExecutorHelper; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.property.LiteflowConfigGetter; import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.slot.Slot; @@ -30,6 +28,7 @@ import com.yomahub.liteflow.slot.Slot; * Node节点,实现可执行器 Node节点并不是单例的,每构建一次都会copy出一个新的实例 * * @author Bryan.Zhang + * @author luo yi */ public class Node implements Executable, Cloneable, Rollbackable{ @@ -57,10 +56,24 @@ public class Node implements Executable, Cloneable, Rollbackable{ private String currChainId; + // node 的 isAccess 结果,主要用于 WhenCondition 的提前 isAccess 判断,避免 isAccess 方法重复执行 + private TransmittableThreadLocal accessResult = new TransmittableThreadLocal<>(); + + // 循环下标 private TransmittableThreadLocal loopIndexTL = new TransmittableThreadLocal<>(); + // 迭代对象 private TransmittableThreadLocal currLoopObject = new TransmittableThreadLocal<>(); + // 当前slot的index + private TransmittableThreadLocal slotIndexTL = new TransmittableThreadLocal<>(); + + // 是否结束整个流程,这个只对串行流程有效,并行流程无效 + private TransmittableThreadLocal isEndTL = new TransmittableThreadLocal<>(); + + // isContinueOnError 结果 + private TransmittableThreadLocal isContinueOnErrorResult = new TransmittableThreadLocal<>(); + public Node() { } @@ -125,16 +138,13 @@ public class Node implements Executable, Cloneable, Rollbackable{ throw new FlowSystemException("there is no instance for node id " + id); } - Slot slot = DataBus.getSlot(slotIndex); try { // 把线程属性赋值给组件对象 - instance.setSlotIndex(slotIndex); + this.setSlotIndex(slotIndex); instance.setRefNode(this); - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - // 判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性 - if (instance.isAccess()) { + if (getAccessResult() || instance.isAccess()) { LOG.info("[O]start component[{}] execution", instance.getDisplayName()); // 这里开始进行重试的逻辑和主逻辑的运行 @@ -142,8 +152,7 @@ public class Node implements Executable, Cloneable, Rollbackable{ .buildNodeExecutor(instance.getNodeExecutorClass()); // 调用节点执行器进行执行 nodeExecutor.execute(instance); - } - else { + } else { LOG.info("[X]skip component[{}] execution", instance.getDisplayName()); } // 如果组件覆盖了isEnd方法,或者在在逻辑中主要调用了setEnd(true)的话,流程就会立马结束 @@ -162,7 +171,7 @@ public class Node implements Executable, Cloneable, Rollbackable{ throw new ChainEndException(errorInfo); } // 如果组件覆盖了isContinueOnError方法,返回为true,那即便出了异常,也会继续流程 - else if (instance.isContinueOnError()) { + else if (getIsContinueOnErrorResult() || instance.isContinueOnError()) { String errorMsg = StrUtil.format("component[{}] cause error,but flow is still go on", id); LOG.error(errorMsg); } @@ -174,10 +183,12 @@ public class Node implements Executable, Cloneable, Rollbackable{ } finally { // 移除threadLocal里的信息 - instance.removeSlotIndex(); - instance.removeIsEnd(); - instance.removeRefNode(); + this.getInstance().removeRefNode(); + removeSlotIndex(); + removeIsEnd(); removeLoopIndex(); + removeAccessResult(); + removeIsContinueOnErrorResult(); } } @@ -188,7 +199,7 @@ public class Node implements Executable, Cloneable, Rollbackable{ Slot slot = DataBus.getSlot(slotIndex); try { // 把线程属性赋值给组件对象 - instance.setSlotIndex(slotIndex); + this.setSlotIndex(slotIndex); instance.setRefNode(this); instance.doRollback(); } @@ -198,7 +209,7 @@ public class Node implements Executable, Cloneable, Rollbackable{ } finally { // 移除threadLocal里的信息 - instance.removeSlotIndex(); + this.removeSlotIndex(); instance.removeRefNode(); } } @@ -210,7 +221,7 @@ public class Node implements Executable, Cloneable, Rollbackable{ @Override public boolean isAccess(Integer slotIndex) throws Exception { // 把线程属性赋值给组件对象 - instance.setSlotIndex(slotIndex); + this.setSlotIndex(slotIndex); instance.setRefNode(this); return instance.isAccess(); } @@ -253,6 +264,32 @@ public class Node implements Executable, Cloneable, Rollbackable{ return currChainId; } + public boolean getAccessResult() { + Boolean result = this.accessResult.get(); + return result != null && result; + } + + public void setAccessResult(boolean accessResult) { + this.accessResult.set(accessResult); + } + + public void removeAccessResult() { + this.accessResult.remove(); + } + + public boolean getIsContinueOnErrorResult() { + Boolean result = this.isContinueOnErrorResult.get(); + return result != null && result; + } + + public void setIsContinueOnErrorResult(boolean accessResult) { + this.isContinueOnErrorResult.set(accessResult); + } + + public void removeIsContinueOnErrorResult() { + this.isContinueOnErrorResult.remove(); + } + public void setLoopIndex(int index) { this.loopIndexTL.set(index); } @@ -277,6 +314,30 @@ public class Node implements Executable, Cloneable, Rollbackable{ this.currLoopObject.remove(); } + public Integer getSlotIndex(){ + return this.slotIndexTL.get(); + } + + public void setSlotIndex(Integer slotIndex){ + this.slotIndexTL.set(slotIndex); + } + + public void removeSlotIndex(){ + this.slotIndexTL.remove(); + } + + public Boolean getIsEnd(){ + return this.isEndTL.get(); + } + + public void setIsEnd(Boolean isEnd){ + this.isEndTL.set(isEnd); + } + + public void removeIsEnd(){ + this.isEndTL.remove(); + } + public String getLanguage() { return language; } @@ -291,14 +352,14 @@ public class Node implements Executable, Cloneable, Rollbackable{ } @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - public Node copy() throws Exception { - Node node = (Node)this.clone(); + public Node clone() throws CloneNotSupportedException { + Node node = (Node)super.clone(); node.loopIndexTL = new TransmittableThreadLocal<>(); node.currLoopObject = new TransmittableThreadLocal<>(); + node.accessResult = new TransmittableThreadLocal<>(); + node.slotIndexTL = new TransmittableThreadLocal<>(); + node.isEndTL = new TransmittableThreadLocal<>(); + node.isContinueOnErrorResult = new TransmittableThreadLocal<>(); return node; } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java index f3aeabaae..50f0a56e3 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java @@ -33,13 +33,15 @@ public class ForCondition extends LoopCondition { throw new NoForNodeException(errorInfo); } + // 提前设置 chainId,避免无法在 isAccess 方法中获取到 + forNode.setCurrChainId(this.getCurrChainId()); + // 先去判断isAccess方法,如果isAccess方法都返回false,整个FOR表达式不执行 - if (!this.getForNode().isAccess(slotIndex)) { + if (!forNode.isAccess(slotIndex)) { return; } // 执行forCount组件 - forNode.setCurrChainId(this.getCurrChainId()); forNode.execute(slotIndex); // 获得循环次数 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IfCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IfCondition.java index 5fa272a30..91f3a8e41 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IfCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IfCondition.java @@ -3,7 +3,8 @@ package com.yomahub.liteflow.flow.element.condition; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ConditionTypeEnum; -import com.yomahub.liteflow.exception.*; +import com.yomahub.liteflow.exception.IfTargetCannotBePreOrFinallyException; +import com.yomahub.liteflow.exception.NoIfTrueNodeException; import com.yomahub.liteflow.flow.element.Condition; import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.slot.DataBus; @@ -21,13 +22,15 @@ public class IfCondition extends Condition { public void executeCondition(Integer slotIndex) throws Exception { Executable ifItem = this.getIfItem(); + // 提前设置 chainId,避免无法在 isAccess 方法中获取到 + ifItem.setCurrChainId(this.getCurrChainId()); + // 先去判断isAccess方法,如果isAccess方法都返回false,整个IF表达式不执行 if (!ifItem.isAccess(slotIndex)) { return; } // 先执行IF节点 - ifItem.setCurrChainId(this.getCurrChainId()); ifItem.execute(slotIndex); // 拿到If执行过的结果 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java index f80ac43d7..2a2a640b0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java @@ -29,13 +29,15 @@ public class IteratorCondition extends LoopCondition { throw new NoIteratorNodeException(errorInfo); } + // 提前设置 chainId,避免无法在 isAccess 方法中获取到 + iteratorNode.setCurrChainId(this.getCurrChainId()); + // 先去判断isAccess方法,如果isAccess方法都返回false,整个ITERATOR表达式不执行 if (!iteratorNode.isAccess(slotIndex)) { return; } // 执行Iterator组件 - iteratorNode.setCurrChainId(this.getCurrChainId()); iteratorNode.execute(slotIndex); Iterator it = iteratorNode.getItemResultMetaValue(slotIndex); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java index 5e53f8434..3a8f3d9f9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/NotCondition.java @@ -26,7 +26,7 @@ public class NotCondition extends Condition { Slot slot = DataBus.getSlot(slotIndex); String resultKey = StrUtil.format("{}_{}",this.getClass().getName(),this.hashCode()); - slot.setAndOrResult(resultKey, !flag); + slot.setNotResult(resultKey, !flag); } @@ -35,7 +35,7 @@ public class NotCondition extends Condition { public Boolean getItemResultMetaValue(Integer slotIndex) { Slot slot = DataBus.getSlot(slotIndex); String resultKey = StrUtil.format("{}_{}",this.getClass().getName(),this.hashCode()); - return slot.getAndOrResult(resultKey); + return slot.getNotResult(resultKey); } @Override diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/RetryCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/RetryCondition.java new file mode 100644 index 000000000..6d5b42906 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/RetryCondition.java @@ -0,0 +1,108 @@ +package com.yomahub.liteflow.flow.element.condition; + +import cn.hutool.core.text.StrFormatter; +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.exception.ChainEndException; +import com.yomahub.liteflow.flow.element.Chain; +import com.yomahub.liteflow.flow.element.Condition; +import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.Node; +import com.yomahub.liteflow.log.LFLog; +import com.yomahub.liteflow.log.LFLoggerManager; +import com.yomahub.liteflow.slot.DataBus; + +import java.util.Arrays; +import java.util.List; + +/** + * + * @author Rain + * @since 2.12.0 + * + */ +public class RetryCondition extends ThenCondition{ + + private final LFLog LOG = LFLoggerManager.getLogger(this.getClass()); + + private Integer retryTimes; + + private Class[] retryForExceptions = new Class[] { Exception.class }; + + public Class[] getRetryForExceptions() { + return retryForExceptions; + } + + public void setRetryForExceptions(Class[] retryForExceptions) { + this.retryForExceptions = retryForExceptions; + } + + public Integer getRetryTimes() { + return retryTimes; + } + + public void setRetryTimes(Integer retryTimes) { + this.retryTimes = retryTimes; + } + + @Override + public void executeCondition(Integer slotIndex) throws Exception { + int retryTimes = this.getRetryTimes() < 0 ? 0 : this.getRetryTimes(); + List> forExceptions = Arrays.asList(this.getRetryForExceptions()); + for (int i = 0; i <= retryTimes; i ++) { + try { + if(i == 0) { + super.executeCondition(slotIndex); + } else { + retry(slotIndex, i); + } + break; + } catch (ChainEndException e) { + throw e; + } catch (Exception e) { + // 判断抛出的异常是不是指定异常的子类 + boolean flag = forExceptions.stream().anyMatch(clazz -> clazz.isAssignableFrom(e.getClass())); + if(!flag || i >= retryTimes) { + if(retryTimes > 0) { + String retryFailMsg = StrFormatter.format("retry fail when executing the chain[{}] because {} occurs {}.", + this.getCurrChainId(), this.getCurrentExecutableId(), e); + LOG.error(retryFailMsg); + } + throw e; + } else { + DataBus.getSlot(slotIndex).removeException(); + } + } + } + } + + private void retry(Integer slotIndex, int retryTime) throws Exception { + LOG.info("{} performs {} retry ", this.getCurrentExecutableId(), retryTime); + super.executeCondition(slotIndex); + } + + /** + * 获取当前组件的 id + * + * @return + */ + private String getCurrentExecutableId() { + // retryCondition 只有一个 Executable + Executable executable = this.getExecutableList().get(0); + if (ObjectUtil.isNotNull(executable.getId())) { + // 已经有 id 了 + return executable.getId(); + } + // 定义 id + switch (executable.getExecuteType()) { + // chain 和 node 一般都有 id + case CHAIN: + return ((Chain) executable).getChainId(); + case CONDITION: + return "condition-" + ((Condition) executable).getConditionType().getName(); + case NODE: + return "node-" + ((Node) executable).getType().getCode(); + default: + return "unknown-executable"; + } + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java index 2a208d8ee..3c575f2f4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java @@ -1,13 +1,10 @@ package com.yomahub.liteflow.flow.element.condition; -import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ConditionTypeEnum; -import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.exception.NoSwitchTargetNodeException; import com.yomahub.liteflow.exception.SwitchTargetCannotBePreOrFinallyException; -import com.yomahub.liteflow.exception.SwitchTypeErrorException; import com.yomahub.liteflow.flow.element.Condition; import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.flow.element.Node; @@ -35,13 +32,15 @@ public class SwitchCondition extends Condition { // 获取target List List targetList = this.getTargetList(); + // 提前设置 chainId,避免无法在 isAccess 方法中获取到 + switchNode.setCurrChainId(this.getCurrChainId()); + // 先去判断isAccess方法,如果isAccess方法都返回false,整个SWITCH表达式不执行 if (!switchNode.isAccess(slotIndex)) { return; } // 先执行switch节点 - switchNode.setCurrChainId(this.getCurrChainId()); switchNode.execute(slotIndex); // 拿到switch节点的结果 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java index 5f41b9aec..7a7b99d5d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java @@ -51,13 +51,17 @@ public class ThenCondition extends Condition { } catch (Exception e) { Slot slot = DataBus.getSlot(slotIndex); - String chainId = this.getCurrChainId(); - // 这里事先取到exception set到slot里,为了方便finally取到exception - if (slot.isSubChain(chainId)) { - slot.setSubException(chainId, e); - } - else { - slot.setException(e); + //正常情况下slot不可能为null + //当设置了超时后,还在运行的组件就有可能因为主流程已经结束释放slot而导致slot为null + if (slot != null){ + String chainId = this.getCurrChainId(); + // 这里事先取到exception set到slot里,为了方便finally取到exception + if (slot.isSubChain(chainId)) { + slot.setSubException(chainId, e); + } + else { + slot.setException(e); + } } throw e; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java index df85bfe86..0e00e761f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java @@ -3,7 +3,6 @@ package com.yomahub.liteflow.flow.element.condition; import cn.hutool.core.util.ObjectUtil; import com.yomahub.liteflow.enums.ConditionTypeEnum; import com.yomahub.liteflow.flow.element.Executable; -import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.parallel.LoopFutureObj; import com.yomahub.liteflow.thread.ExecutorHelper; @@ -24,6 +23,9 @@ public class WhileCondition extends LoopCondition { public void executeCondition(Integer slotIndex) throws Exception { Executable whileItem = this.getWhileItem(); + // 提前设置 chainId,避免无法在 isAccess 方法中获取到 + whileItem.setCurrChainId(this.getCurrChainId()); + // 先去判断isAccess方法,如果isAccess方法都返回false,整个WHILE表达式不执行 if (!whileItem.isAccess(slotIndex)) { return; @@ -84,7 +86,6 @@ public class WhileCondition extends LoopCondition { private boolean getWhileResult(Integer slotIndex, int loopIndex) throws Exception { Executable whileItem = this.getWhileItem(); // 执行while组件 - whileItem.setCurrChainId(this.getCurrChainId()); setLoopIndex(whileItem, loopIndex); whileItem.execute(slotIndex); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/CompletableFutureExpand.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/CompletableFutureExpand.java new file mode 100644 index 000000000..37ba6dbb6 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/CompletableFutureExpand.java @@ -0,0 +1,87 @@ +package com.yomahub.liteflow.flow.parallel; + +import java.util.concurrent.*; +import java.util.function.BiConsumer; + +public class CompletableFutureExpand { + + /** + * 如果在给定超时之前未完成,则异常完成此 CompletableFuture 并抛出 {@link TimeoutException} 。 + * + * @param timeout 在出现 TimeoutException 异常完成之前等待多长时间,以 {@code unit} 为单位 + * @param unit 一个 {@link TimeUnit},结合 {@code timeout} 参数,表示给定粒度单位的持续时间 + * @return 入参的 CompletableFuture + */ + public static CompletableFuture completeOnTimeout(CompletableFuture future, long timeout, TimeUnit unit, T timeoutDefaultObj) { + if (future.isDone()) { + return future; + } + + return future.whenComplete(new Canceller(Delayer.delay(new Timeout<>(future, timeoutDefaultObj), timeout, unit))); + } + + /** + * 超时时异常完成的操作 + */ + static final class Timeout implements Runnable { + final CompletableFuture future; + + final T timeoutDefaultObj; + + Timeout(CompletableFuture future, T timeoutDefaultObj) { + this.future = future; + this.timeoutDefaultObj = timeoutDefaultObj; + } + + public void run() { + if (null != future && !future.isDone()) { + future.complete(timeoutDefaultObj); + } + } + } + + /** + * 取消不需要的超时的操作 + */ + static final class Canceller implements BiConsumer { + final Future future; + + Canceller(Future future) { + this.future = future; + } + + public void accept(Object ignore, Throwable ex) { + if (null == ex && null != future && !future.isDone()) { + future.cancel(false); + } + } + } + + /** + * 单例延迟调度器,仅用于启动和取消任务,一个线程就足够 + */ + static final class Delayer { + + static final ScheduledThreadPoolExecutor delayer; + + static ScheduledFuture delay(Runnable command, long delay, TimeUnit unit) { + return delayer.schedule(command, delay, unit); + } + + static final class DaemonThreadFactory implements ThreadFactory { + + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + t.setName("CompletableFutureExpandUtilsDelayScheduler"); + return t; + } + } + + static { + delayer = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory()); + delayer.setRemoveOnCancelPolicy(true); + } + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/CompletableFutureTimeout.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/CompletableFutureTimeout.java index e73ec8c78..54e645ebc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/CompletableFutureTimeout.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/CompletableFutureTimeout.java @@ -63,8 +63,7 @@ public class CompletableFutureTimeout { } // 哪个先完成 就apply哪一个结果 这是一个关键的API,exceptionally出现异常后返回默认值 - public static CompletableFuture completeOnTimeout(T t, CompletableFuture future, long timeout, - TimeUnit unit) { + public static CompletableFuture completeOnTimeout(CompletableFuture future, long timeout, TimeUnit unit, T t) { final CompletableFuture timeoutFuture = timeoutAfter(timeout, unit); return future.applyToEither(timeoutFuture, Function.identity()).exceptionally((throwable) -> t); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AllOfParallelExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AllOfParallelExecutor.java index 3ca243fbd..6b637dbe4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AllOfParallelExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AllOfParallelExecutor.java @@ -31,9 +31,10 @@ public class AllOfParallelExecutor extends ParallelStrategyExecutor { } - //在allOf这个场景中,不需要过滤 + // 在 allOf 这个场景中,不需要过滤 @Override - protected Stream filterAccess(Stream stream, Integer slotIndex) { + protected Stream filterAccess(Stream stream, Integer slotIndex, String currentChainId) { return stream; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AnyOfParallelExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AnyOfParallelExecutor.java index 6f4c19257..ca1475dec 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AnyOfParallelExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/AnyOfParallelExecutor.java @@ -1,12 +1,10 @@ package com.yomahub.liteflow.flow.parallel.strategy; -import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.flow.element.condition.WhenCondition; import com.yomahub.liteflow.flow.parallel.WhenFutureObj; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.stream.Stream; /** * 完成任一任务 @@ -31,18 +29,4 @@ public class AnyOfParallelExecutor extends ParallelStrategyExecutor { } - //在anyOf这个场景中,需要过滤掉isAccess为false的场景 - //因为不过滤这个的话,如果加上了 any,那么 isAccess 为 false 那就是最快的了 - //换句话说,就是anyOf这个场景,isAccess会被执行两次 - @Override - protected Stream filterAccess(Stream stream, Integer slotIndex) { - return stream.filter(executable -> { - try { - return executable.isAccess(slotIndex); - } catch (Exception e) { - LOG.error("there was an error when executing the when component isAccess", e); - return false; - } - }); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java index b8199419e..4ca07a9d4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java @@ -6,10 +6,11 @@ import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ParallelStrategyEnum; import com.yomahub.liteflow.exception.WhenExecuteException; import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.element.condition.FinallyCondition; import com.yomahub.liteflow.flow.element.condition.PreCondition; import com.yomahub.liteflow.flow.element.condition.WhenCondition; -import com.yomahub.liteflow.flow.parallel.CompletableFutureTimeout; +import com.yomahub.liteflow.flow.parallel.CompletableFutureExpand; import com.yomahub.liteflow.flow.parallel.ParallelSupplier; import com.yomahub.liteflow.flow.parallel.WhenFutureObj; import com.yomahub.liteflow.log.LFLog; @@ -44,19 +45,19 @@ public abstract class ParallelStrategyExecutor { * @param executable * @param parallelExecutor * @param whenCondition - * @param currChainName + * @param currChainId * @param slotIndex * @return */ protected CompletableFuture wrappedFutureObj(Executable executable, ExecutorService parallelExecutor, - WhenCondition whenCondition, String currChainName, Integer slotIndex) { + WhenCondition whenCondition, String currChainId, Integer slotIndex) { // 套入 CompletableFutureTimeout 方法进行超时判断,如果超时则用 WhenFutureObj.timeOut 返回超时的对象 // 第 2 个参数是主要的本体 CompletableFuture,传入了 ParallelSupplier 和线程池对象 - return CompletableFutureTimeout.completeOnTimeout( - WhenFutureObj.timeOut(executable.getId()), - CompletableFuture.supplyAsync(new ParallelSupplier(executable, currChainName, slotIndex), parallelExecutor), + return CompletableFutureExpand.completeOnTimeout( + CompletableFuture.supplyAsync(new ParallelSupplier(executable, currChainId, slotIndex), parallelExecutor), whenCondition.getMaxWaitTime(), - whenCondition.getMaxWaitTimeUnit()); + whenCondition.getMaxWaitTimeUnit(), + WhenFutureObj.timeOut(executable.getId())); } /** @@ -87,26 +88,34 @@ public abstract class ParallelStrategyExecutor { * 过滤 WHEN 待执行任务 * @param executableList 所有任务列表 * @param slotIndex + * @param currentChainId 当前执行的 chainId * @return */ - protected Stream filterWhenTaskList(List executableList, Integer slotIndex) { + protected Stream filterWhenTaskList(List executableList, Integer slotIndex, String currentChainId) { // 1.先进行过滤,前置和后置组件过滤掉,因为在 EL Chain 处理的时候已经提出来了 // 2.过滤 isAccess 为 false 的情况,因为不过滤这个的话,如果加上了 any,那么 isAccess 为 false 那就是最快的了 Stream stream = executableList.stream() - .filter(executable -> !(executable instanceof PreCondition) && !(executable instanceof FinallyCondition)) - .filter(executable -> { - try { - return executable.isAccess(slotIndex); - } catch (Exception e) { - LOG.error("there was an error when executing the when component isAccess", e); - return false; - } - }); - return filterAccess(stream, slotIndex); + .filter(executable -> !(executable instanceof PreCondition) && !(executable instanceof FinallyCondition)); + return filterAccess(stream, slotIndex, currentChainId); } - //过滤isAccess的抽象接口方法 - protected abstract Stream filterAccess(Stream stream, Integer slotIndex); + // 过滤 isAccess 的方法,默认实现,同时为避免同一个 node 的 isAccess 方法重复执行,给 node 设置 isAccess 方法执行结果 + protected Stream filterAccess(Stream stream, Integer slotIndex, String currentChainId) { + return stream.filter(executable -> { + try { + // 提前设置 chainId,避免无法在 isAccess 方法中获取到 + executable.setCurrChainId(currentChainId); + boolean access = executable.isAccess(slotIndex); + if (executable instanceof Node) { + ((Node) executable).setAccessResult(access); + } + return access; + } catch (Exception e) { + LOG.error("there was an error when executing the when component isAccess", e); + return false; + } + }); + } /** * 获取 WHEN 所需线程池 @@ -140,18 +149,18 @@ public abstract class ParallelStrategyExecutor { */ protected List> getWhenAllTaskList(WhenCondition whenCondition, Integer slotIndex) { - String currChainName = whenCondition.getCurrChainId(); + String currChainId = whenCondition.getCurrChainId(); // 设置 whenCondition 参数 - setWhenConditionParams(whenCondition); + this.setWhenConditionParams(whenCondition); // 获取 WHEN 所需线程池 ExecutorService parallelExecutor = getWhenExecutorService(whenCondition); // 这里主要是做了封装 CompletableFuture 对象,用 lambda 表达式做了很多事情,这句代码要仔细理清 // 根据 condition.getNodeList() 的集合进行流处理,用 map 进行把 executable 对象转换成 List> - List> completableFutureList = filterWhenTaskList(whenCondition.getExecutableList(), slotIndex) - .map(executable -> wrappedFutureObj(executable, parallelExecutor, whenCondition, currChainName, slotIndex)) + List> completableFutureList = filterWhenTaskList(whenCondition.getExecutableList(), slotIndex, currChainId) + .map(executable -> wrappedFutureObj(executable, parallelExecutor, whenCondition, currChainId, slotIndex)) .collect(Collectors.toList()); return completableFutureList; @@ -161,11 +170,11 @@ public abstract class ParallelStrategyExecutor { * 任务结果处理 * @param whenCondition 并行组件对象 * @param slotIndex 当前 slot 的 index - * @param whenAllTaskList 并行组件中所有任务列表 + * @param whenAllFutureList 并行组件中所有任务列表 * @param specifyTask 指定预先完成的任务,详见 {@link ParallelStrategyEnum} * @throws Exception */ - protected void handleTaskResult(WhenCondition whenCondition, Integer slotIndex, List> whenAllTaskList, + protected void handleTaskResult(WhenCondition whenCondition, Integer slotIndex, List> whenAllFutureList, CompletableFuture specifyTask) throws Exception { Slot slot = DataBus.getSlot(slotIndex); @@ -187,17 +196,23 @@ public abstract class ParallelStrategyExecutor { // 如果 any 为 true,那么这里拿到的是第一个完成的任务 // 如果为 must,那么这里获取到的就是指定的任务 // 这里过滤和转换一起用 lambda 做了 - List allCompletableWhenFutureObjList = whenAllTaskList.stream().filter(f -> { + List allCompletableWhenFutureObjList = whenAllFutureList.stream().filter(f -> { // 过滤出已经完成的,没完成的就直接终止 if (f.isDone()) { return true; } else { + //事实上CompletableFuture并不能cancel掉底层的线程 f.cancel(true); return false; } }).map(f -> { try { - return f.get(); + WhenFutureObj whenFutureObj = f.get(); + if (whenFutureObj.isTimeout()){ + //事实上CompletableFuture并不能cancel掉底层的线程 + f.cancel(true); + } + return whenFutureObj; } catch (InterruptedException | ExecutionException e) { interrupted[0] = true; return null; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java index c345a83fd..bfa89cdc5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java @@ -1,14 +1,12 @@ package com.yomahub.liteflow.flow.parallel.strategy; import cn.hutool.core.collection.CollUtil; -import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.flow.element.condition.WhenCondition; import com.yomahub.liteflow.flow.parallel.WhenFutureObj; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; -import java.util.stream.Stream; /** * 完成指定任务执行器,使用 ID 进行比较 @@ -22,7 +20,7 @@ public class SpecifyParallelExecutor extends ParallelStrategyExecutor { @Override public void execute(WhenCondition whenCondition, Integer slotIndex) throws Exception { - String currChainName = whenCondition.getCurrChainId(); + String currChainId = whenCondition.getCurrChainId(); // 设置 whenCondition 参数 this.setWhenConditionParams(whenCondition); @@ -43,10 +41,10 @@ public class SpecifyParallelExecutor extends ParallelStrategyExecutor { List> allTaskList = new ArrayList<>(); // 遍历 when 所有 node,进行筛选及处理 - filterWhenTaskList(whenCondition.getExecutableList(), slotIndex) + filterWhenTaskList(whenCondition.getExecutableList(), slotIndex, currChainId) .forEach(executable -> { // 处理 task,封装成 CompletableFuture 对象 - CompletableFuture completableFutureTask = wrappedFutureObj(executable, parallelExecutor, whenCondition, currChainName, slotIndex); + CompletableFuture completableFutureTask = wrappedFutureObj(executable, parallelExecutor, whenCondition, currChainId, slotIndex); // 存在 must 指定 ID 的 task,且该任务只会有一个或者没有 if (whenCondition.getSpecifyIdSet().contains(executable.getId())) { // 设置指定任务 future 对象 @@ -77,19 +75,4 @@ public class SpecifyParallelExecutor extends ParallelStrategyExecutor { } - //在must这个场景中,需要过滤掉isAccess为false的场景 - //因为不过滤这个的话,如果加上了 any,那么 isAccess 为 false 那就是最快的了 - //换句话说,就是must这个场景,isAccess会被执行两次 - @Override - protected Stream filterAccess(Stream stream, Integer slotIndex) { - return stream.filter(executable -> { - try { - return executable.isAccess(slotIndex); - } catch (Exception e) { - LOG.error("there was an error when executing the when component isAccess", e); - return false; - } - }); - } - } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutor.java index 0f4be12dd..45702c7cb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutor.java @@ -2,14 +2,12 @@ package com.yomahub.liteflow.script; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.yomahub.liteflow.annotation.util.AnnoUtil; -import com.yomahub.liteflow.context.ContextBean; import com.yomahub.liteflow.enums.ScriptTypeEnum; import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.slot.Slot; +import java.util.List; import java.util.Map; import java.util.function.BiConsumer; @@ -27,6 +25,12 @@ public abstract class ScriptExecutor { public abstract void load(String nodeId, String script); + // 卸载脚本(不包含 node) + public abstract void unLoad(String nodeId); + + // 获取该执行器下的所有 nodeId + public abstract List getNodeIds(); + public Object execute(ScriptExecuteWrap wrap) throws Exception{ try { return executeScript(wrap); @@ -54,17 +58,7 @@ public abstract class ScriptExecutor { // key的规则为自定义上下文的simpleName // 比如你的自定义上下文为AbcContext,那么key就为:abcContext // 这里不统一放一个map的原因是考虑到有些用户会调用上下文里的方法,而不是参数,所以脚本语言的绑定表里也是放多个上下文 - DataBus.getContextBeanList(wrap.getSlotIndex()).forEach(o -> { - ContextBean contextBean = AnnoUtil.getAnnotation(o.getClass(), ContextBean.class); - String key; - if (contextBean != null && contextBean.value().trim().length() > 0) { - key = contextBean.value(); - } - else { - key = StrUtil.lowerFirst(o.getClass().getSimpleName()); - } - putConsumer.accept(key, o); - }); + DataBus.getContextBeanList(wrap.getSlotIndex()).forEach(tuple -> putConsumer.accept(tuple.get(0), tuple.get(1))); // 把wrap对象转换成元数据map Map metaMap = BeanUtil.beanToMap(wrap); @@ -86,4 +80,12 @@ public abstract class ScriptExecutor { ScriptBeanManager.getScriptBeanMap().forEach(putIfAbsentConsumer); } + /** + * 利用相应框架编译脚本 + * + * @param script 脚本 + * @return boolean + * @throws Exception 例外 + */ + public abstract Object compile(String script) throws Exception; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/jsr223/JSR223ScriptExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/jsr223/JSR223ScriptExecutor.java index 0bb20d921..4fd1cf69f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/jsr223/JSR223ScriptExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/jsr223/JSR223ScriptExecutor.java @@ -7,7 +7,16 @@ import com.yomahub.liteflow.script.ScriptExecuteWrap; import com.yomahub.liteflow.script.ScriptExecutor; import com.yomahub.liteflow.script.exception.ScriptLoadException; import com.yomahub.liteflow.util.CopyOnWriteHashMap; -import javax.script.*; + +import javax.script.Bindings; +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.SimpleBindings; +import javax.script.ScriptException; +import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -38,14 +47,22 @@ public abstract class JSR223ScriptExecutor extends ScriptExecutor { @Override public void load(String nodeId, String script) { try { - CompiledScript compiledScript = ((Compilable) scriptEngine).compile(convertScript(script)); - compiledScriptMap.put(nodeId, compiledScript); + compiledScriptMap.put(nodeId, (CompiledScript) compile(script)); } catch (Exception e) { String errorMsg = StrUtil.format("script loading error for node[{}], error msg:{}", nodeId, e.getMessage()); throw new ScriptLoadException(errorMsg); } + } + @Override + public void unLoad(String nodeId) { + compiledScriptMap.remove(nodeId); + } + + @Override + public List getNodeIds() { + return new ArrayList<>(compiledScriptMap.keySet()); } @Override @@ -68,4 +85,12 @@ public abstract class JSR223ScriptExecutor extends ScriptExecutor { compiledScriptMap.clear(); } + @Override + public Object compile(String script) throws ScriptException { + if(scriptEngine == null) { + LOG.error("script engine has not init"); + } + return ((Compilable) scriptEngine).compile(convertScript(script)); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/validator/ScriptValidator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/validator/ScriptValidator.java new file mode 100644 index 000000000..a05ce0606 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/validator/ScriptValidator.java @@ -0,0 +1,104 @@ +package com.yomahub.liteflow.script.validator; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.log.LFLog; +import com.yomahub.liteflow.log.LFLoggerManager; +import com.yomahub.liteflow.script.ScriptExecutor; + +import java.util.*; + +/** + * 脚本验证类 + * + * @author Ge_Zuao + * @since 2.12.0 + */ +public class ScriptValidator { + + private static final LFLog LOG = LFLoggerManager.getLogger(ScriptValidator.class); + + private static Map scriptExecutors; + + static { + List scriptExecutorList = new ArrayList<>(); + scriptExecutors = new HashMap<>(); + ServiceLoader.load(ScriptExecutor.class).forEach(scriptExecutorList::add); + scriptExecutorList.stream() + .peek(ScriptExecutor::init) + .forEach(scriptExecutor -> scriptExecutors.put(scriptExecutor.scriptType(), scriptExecutor)); + } + + /** + * 验证脚本逻辑的公共部分 + * + * @param script 脚本 + * @param scriptType 脚本类型 + * @return boolean + */ + private static boolean validateScript(String script, ScriptTypeEnum scriptType){ + // 未加载任何脚本模块 + if(scriptExecutors.isEmpty()){ + LOG.error("The loaded script modules not found."); + return false; + } + + // 指定脚本语言未加载 + if (scriptType != null && !scriptExecutors.containsKey(scriptType)) { + LOG.error(StrUtil.format("Specified script language {} was not found.", scriptType)); + return false; + } + + // 加载多个脚本语言需要指定语言验证 + if (scriptExecutors.size() > 1 && scriptType == null) { + LOG.error("The loaded script modules more than 1. Please specify the script language."); + return false; + } + + ScriptExecutor scriptExecutor = (scriptType != null) ? scriptExecutors.get(scriptType) : scriptExecutors.values().iterator().next(); + try { + scriptExecutor.compile(script); + } catch (Exception e) { + LOG.error(StrUtil.format("{} Script component validate failure. ", scriptExecutor.scriptType()) + e.getMessage()); + return false; + } + return true; + } + + /** + * 只引入一种脚本语言时,可以不指定语言验证 + * + * @param script 脚本 + * @return boolean + */ + public static boolean validate(String script){ + return validateScript(script, null); + } + + /** + * 指定脚本语言验证 + * + * @param script 脚本 + * @param scriptType 脚本类型 + * @return boolean + */ + public static boolean validate(String script, ScriptTypeEnum scriptType){ + return validateScript(script, scriptType); + } + + /** + * 多语言脚本批量验证 + * + * @param scripts 脚本 + * @return boolean + */ + public static boolean validate(Map scripts){ + for(Map.Entry script : scripts.entrySet()){ + if(!validate(script.getValue(), script.getKey())){ + return false; + } + } + return true; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DataBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DataBus.java index 3b2d6b1dd..00e3032e6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DataBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DataBus.java @@ -7,10 +7,14 @@ */ package com.yomahub.liteflow.slot; +import cn.hutool.core.lang.Tuple; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.util.AnnoUtil; +import com.yomahub.liteflow.context.ContextBean; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.property.LiteflowConfig; @@ -74,13 +78,22 @@ public class DataBus { .map((Function, Object>) ReflectUtil::newInstanceIfPossible) .collect(Collectors.toList()); - Slot slot = new Slot(contextBeanList); - - return offerIndex(slot); + return offerSlotByBean(contextBeanList); } public static int offerSlotByBean(List contextList) { - Slot slot = new Slot(contextList); + List contextBeanList = contextList.stream().map(object -> { + ContextBean contextBean = AnnoUtil.getAnnotation(object.getClass(), ContextBean.class); + String contextKey; + if (contextBean != null && StrUtil.isNotBlank(contextBean.value())){ + contextKey = contextBean.value(); + }else{ + contextKey = StrUtil.lowerFirst(object.getClass().getSimpleName()); + } + return new Tuple(contextKey, object); + }).collect(Collectors.toList()); + + Slot slot = new Slot(contextBeanList); return offerIndex(slot); } @@ -128,7 +141,7 @@ public class DataBus { return SLOTS.get(slotIndex); } - public static List getContextBeanList(int slotIndex) { + public static List getContextBeanList(int slotIndex) { Slot slot = getSlot(slotIndex); return slot.getContextBeanList(); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java index 8bd133c14..8bb39dafe 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/Slot.java @@ -9,8 +9,10 @@ package com.yomahub.liteflow.slot; import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.lang.Tuple; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.ttl.TransmittableThreadLocal; import com.yomahub.liteflow.exception.NoSuchContextBeanException; import com.yomahub.liteflow.exception.NullParamException; import com.yomahub.liteflow.flow.element.Condition; @@ -29,6 +31,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.function.Predicate; /** * Slot的抽象类实现 @@ -90,14 +93,14 @@ public class Slot { protected ConcurrentHashMap metaDataMap = new ConcurrentHashMap<>(); - private List contextBeanList; + private List contextBeanList; - private static final ThreadLocal> conditionStack = ThreadLocal.withInitial(LinkedList::new); + private static final TransmittableThreadLocal> conditionStack = TransmittableThreadLocal.withInitial(ConcurrentLinkedDeque::new); public Slot() { } - public Slot(List contextBeanList) { + public Slot(List contextBeanList) { this.contextBeanList = contextBeanList; } @@ -448,21 +451,30 @@ public class Slot { metaDataMap.remove(SUB_EXCEPTION_PREFIX + chainId); } - public List getContextBeanList() { + public List getContextBeanList() { return this.contextBeanList; } public T getContextBean(Class contextBeanClazz) { - T t = (T) contextBeanList.stream().filter(o -> o.getClass().getName().equals(contextBeanClazz.getName())).findFirst().orElse(null); - if (t == null) { + Tuple contextTuple = contextBeanList.stream().filter(tuple -> tuple.get(1).getClass().getName().equals(contextBeanClazz.getName())).findFirst().orElse(null); + if (contextTuple == null) { contextBeanList.forEach(o -> LOG.info("ChainId[{}], Context class:{},Request class:{}", this.getChainId(), o.getClass().getName(), contextBeanClazz.getName())); throw new NoSuchContextBeanException("this type is not in the context type passed in"); } - return t; + return contextTuple.get(1); + } + + public T getContextBean(String contextBeanKey) { + Tuple contextTuple = contextBeanList.stream().filter(tuple -> tuple.get(0).equals(contextBeanKey)).findFirst().orElse(null); + if (contextTuple == null) { + contextBeanList.forEach(o -> LOG.info("ChainId[{}], Context class:{},Request contextBeanKey:{}", this.getChainId(), o.getClass().getName(), contextBeanKey)); + throw new NoSuchContextBeanException("this context key is not defined"); + } + return contextTuple.get(1); } public T getFirstContextBean() { - Class firstContextBeanClazz = (Class) this.getContextBeanList().get(0).getClass(); + Class firstContextBeanClazz = (Class) this.getContextBeanList().get(0).get(1).getClass(); return this.getContextBean(firstContextBeanClazz); } diff --git a/liteflow-core/src/main/resources/dtd/liteflow.dtd b/liteflow-core/src/main/resources/dtd/liteflow.dtd index 7312b9230..1e12d37e7 100644 --- a/liteflow-core/src/main/resources/dtd/liteflow.dtd +++ b/liteflow-core/src/main/resources/dtd/liteflow.dtd @@ -3,7 +3,9 @@ - + + + getNodeIds() { + return new ArrayList<>(scriptMap.keySet()); + } + @Override public Object executeScript(ScriptExecuteWrap wrap) { if (!scriptMap.containsKey(wrap.getNodeId())) { @@ -84,4 +96,12 @@ public class GraalJavaScriptExecutor extends ScriptExecutor { return ScriptTypeEnum.JS; } + @Override + public Object compile(String script) throws Exception { + String wrapScript = StrUtil.format("function process(){{}} process();", script); + Context context = Context.newBuilder().allowAllAccess(true).engine(engine).build(); + context.parse(Source.create("js", wrapScript)); + return wrapScript; + } + } diff --git a/liteflow-script-plugin/liteflow-script-java/src/main/java/com/yomahub/liteflow/script/java/JavaExecutor.java b/liteflow-script-plugin/liteflow-script-java/src/main/java/com/yomahub/liteflow/script/java/JavaExecutor.java index b0693fda4..5ad4ffb87 100644 --- a/liteflow-script-plugin/liteflow-script-java/src/main/java/com/yomahub/liteflow/script/java/JavaExecutor.java +++ b/liteflow-script-plugin/liteflow-script-java/src/main/java/com/yomahub/liteflow/script/java/JavaExecutor.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.script.java; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.script.ScriptExecuteWrap; import com.yomahub.liteflow.script.ScriptExecutor; import com.yomahub.liteflow.script.body.JaninoCommonScriptBody; @@ -10,6 +11,9 @@ import com.yomahub.liteflow.script.exception.ScriptLoadException; import com.yomahub.liteflow.util.CopyOnWriteHashMap; import org.codehaus.commons.compiler.CompilerFactoryFactory; import org.codehaus.commons.compiler.IScriptEvaluator; + +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class JavaExecutor extends ScriptExecutor { @@ -19,12 +23,7 @@ public class JavaExecutor extends ScriptExecutor { @Override public void load(String nodeId, String script) { try{ - IScriptEvaluator se = CompilerFactoryFactory.getDefaultCompilerFactory(this.getClass().getClassLoader()).newScriptEvaluator(); - se.setTargetVersion(8); - se.setReturnType(Object.class); - se.setParameters(new String[] {"_meta"}, new Class[] {ScriptExecuteWrap.class}); - se.cook(convertScript(script)); - compiledScriptMap.put(nodeId, se); + compiledScriptMap.put(nodeId, (IScriptEvaluator) compile(script)); }catch (Exception e){ String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getMessage()); throw new ScriptLoadException(errorMsg); @@ -32,6 +31,16 @@ public class JavaExecutor extends ScriptExecutor { } + @Override + public void unLoad(String nodeId) { + compiledScriptMap.remove(nodeId); + } + + @Override + public List getNodeIds() { + return new ArrayList<>(compiledScriptMap.keySet()); + } + @Override public Object executeScript(ScriptExecuteWrap wrap) throws Exception { if (!compiledScriptMap.containsKey(wrap.getNodeId())) { @@ -52,6 +61,16 @@ public class JavaExecutor extends ScriptExecutor { return ScriptTypeEnum.JAVA; } + @Override + public Object compile(String script) throws Exception { + IScriptEvaluator se = CompilerFactoryFactory.getDefaultCompilerFactory(this.getClass().getClassLoader()).newScriptEvaluator(); + se.setTargetVersion(8); + se.setReturnType(Object.class); + se.setParameters(new String[] {"_meta"}, new Class[] {ScriptExecuteWrap.class}); + se.cook(convertScript(script)); + return se; + } + private String convertScript(String script){ //替换掉public,private,protected等修饰词 String script1 = script.replaceAll("public class", "class") diff --git a/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java b/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java index f83a4833e..eacf3c38c 100644 --- a/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-qlexpress/src/main/java/com/yomahub/liteflow/script/qlexpress/QLExpressScriptExecutor.java @@ -13,7 +13,10 @@ import com.yomahub.liteflow.script.exception.ScriptLoadException; import com.yomahub.liteflow.util.CopyOnWriteHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import javax.script.ScriptException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -40,8 +43,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor { @Override public void load(String nodeId, String script) { try { - InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(script); - compiledScriptMap.put(nodeId, instructionSet); + compiledScriptMap.put(nodeId, (InstructionSet) compile(script)); } catch (Exception e) { String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getMessage()); @@ -49,6 +51,16 @@ public class QLExpressScriptExecutor extends ScriptExecutor { } } + @Override + public void unLoad(String nodeId) { + compiledScriptMap.remove(nodeId); + } + + @Override + public List getNodeIds() { + return new ArrayList<>(compiledScriptMap.keySet()); + } + @Override public Object executeScript(ScriptExecuteWrap wrap) throws Exception { List errorList = new ArrayList<>(); @@ -85,4 +97,9 @@ public class QLExpressScriptExecutor extends ScriptExecutor { return ScriptTypeEnum.QLEXPRESS; } + @Override + public Object compile(String script) throws Exception { + return expressRunner.getInstructionSetFromLocalCache(script); + } + } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeIfComponentOfMethod.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeBooleanComponentOfMethod.java similarity index 80% rename from liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeIfComponentOfMethod.java rename to liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeBooleanComponentOfMethod.java index ac25d7c72..46f16025b 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeIfComponentOfMethod.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeBooleanComponentOfMethod.java @@ -1,6 +1,6 @@ package com.yomahub.liteflow.solon; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.exception.LiteFlowException; import org.noear.solon.core.BeanWrap; @@ -11,7 +11,7 @@ import java.lang.reflect.Method; * @author noear * @since 1.11 */ -public class NodeIfComponentOfMethod extends NodeIfComponent { +public class NodeBooleanComponentOfMethod extends NodeBooleanComponent { final BeanWrap beanWrap; @@ -19,7 +19,7 @@ public class NodeIfComponentOfMethod extends NodeIfComponent { final LiteFlowMethodEnum methodEnum; - public NodeIfComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { + public NodeBooleanComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { this.beanWrap = beanWrap; this.method = method; this.methodEnum = methodEnum; @@ -45,7 +45,7 @@ public class NodeIfComponentOfMethod extends NodeIfComponent { } @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return (boolean) exec(); } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeBreakComponentOfMethod.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeBreakComponentOfMethod.java deleted file mode 100644 index 9b16e8be7..000000000 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeBreakComponentOfMethod.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.yomahub.liteflow.solon; - -import com.yomahub.liteflow.core.NodeBreakComponent; -import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -import com.yomahub.liteflow.exception.LiteFlowException; -import org.noear.solon.core.BeanWrap; - -import java.lang.reflect.Method; - -/** - * @author noear - * @since 1.11 - */ -public class NodeBreakComponentOfMethod extends NodeBreakComponent { - - final BeanWrap beanWrap; - - final Method method; - - final LiteFlowMethodEnum methodEnum; - - public NodeBreakComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { - this.beanWrap = beanWrap; - this.method = method; - this.methodEnum = methodEnum; - - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException( - "NodeBreakComponent method parameter cannot be more than one: " + methodFullName); - } - - if (method.getReturnType() != Boolean.class && method.getReturnType() != boolean.class) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeBreakComponent method returnType can only be boolean: " + methodFullName); - } - } - - private Object exec() throws Exception { - if (method.getParameterCount() == 0) { - return method.invoke(beanWrap.get()); - } - else { - return method.invoke(beanWrap.get(), this); - } - } - - @Override - public boolean processBreak() throws Exception { - return (boolean) exec(); - } - -} diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeWhileComponentOfMethod.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeWhileComponentOfMethod.java deleted file mode 100644 index cf99791ee..000000000 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeWhileComponentOfMethod.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.yomahub.liteflow.solon; - -import com.yomahub.liteflow.core.NodeWhileComponent; -import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -import com.yomahub.liteflow.exception.LiteFlowException; -import org.noear.solon.core.BeanWrap; - -import java.lang.reflect.Method; - -/** - * @author noear - * @since 1.11 - */ -public class NodeWhileComponentOfMethod extends NodeWhileComponent { - - final BeanWrap beanWrap; - - final Method method; - - final LiteFlowMethodEnum methodEnum; - - public NodeWhileComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { - this.beanWrap = beanWrap; - this.method = method; - this.methodEnum = methodEnum; - - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException( - "NodeWhileComponent method parameter cannot be more than one: " + methodFullName); - } - - if (method.getReturnType() != Boolean.class && method.getReturnType() != boolean.class) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeWhileComponent method returnType can only be boolean: " + methodFullName); - } - } - - private Object exec() throws Exception { - if (method.getParameterCount() == 0) { - return method.invoke(beanWrap.get()); - } - else { - return method.invoke(beanWrap.get(), this); - } - } - - @Override - public boolean processWhile() throws Exception { - return (boolean) exec(); - } - -} diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMainAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMainAutoConfiguration.java index e40faa398..319ed9edf 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMainAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMainAutoConfiguration.java @@ -5,7 +5,7 @@ import com.yomahub.liteflow.property.LiteflowConfig; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Init; import org.noear.solon.annotation.Inject; -import org.noear.solon.core.AopContext; +import org.noear.solon.core.AppContext; /** * 主要的业务装配器 在这个装配器里装配了执行器,执行器初始化类,监控器 @@ -22,7 +22,7 @@ public class LiteflowMainAutoConfiguration { boolean parseOnStart; @Inject - AopContext aopContext; + AppContext appContext; @Inject LiteflowConfig liteflowConfig; @@ -39,7 +39,7 @@ public class LiteflowMainAutoConfiguration { flowExecutor.init(true); } - aopContext.wrapAndPut(FlowExecutor.class, flowExecutor); + appContext.wrapAndPut(FlowExecutor.class, flowExecutor); } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/integration/XPluginImpl.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/integration/XPluginImpl.java index 0fbc1dfa0..9a3211110 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/integration/XPluginImpl.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/integration/XPluginImpl.java @@ -58,18 +58,12 @@ public class XPluginImpl implements Plugin { case PROCESS_SWITCH: node1 = new NodeSwitchComponentOfMethod(bw, method, anno.value()); break; - case PROCESS_IF: - node1 = new NodeIfComponentOfMethod(bw, method, anno.value()); + case PROCESS_BOOLEAN: + node1 = new NodeBooleanComponentOfMethod(bw, method, anno.value()); break; case PROCESS_FOR: node1 = new NodeForComponentOfMethod(bw, method, anno.value()); break; - case PROCESS_WHILE: - node1 = new NodeWhileComponentOfMethod(bw, method, anno.value()); - break; - case PROCESS_BREAK: - node1 = new NodeBreakComponentOfMethod(bw, method, anno.value()); - break; default: node1 = new NodeComponentOfMethod(bw, method, anno.value()); } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java index 137208541..c77ef8443 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringPathContentParser.java @@ -29,6 +29,7 @@ public class SpringPathContentParser implements PathContentParser { public List parseContent(List pathList) throws Exception { List absolutePathList = PathMatchUtil.searchAbsolutePath(pathList); List allResource = getResources(absolutePathList); + verifyFileExtName(allResource); // 转换成内容List List contentList = new ArrayList<>(); @@ -90,14 +91,16 @@ public class SpringPathContentParser implements PathContentParser { allResource.addAll(ListUtil.toList(resources)); } } + return allResource; + } + private void verifyFileExtName(List allResource) { // 检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 Set fileTypeSet = new HashSet<>(); allResource.forEach(resource -> fileTypeSet.add(FileUtil.extName(resource.getFilename()))); if (fileTypeSet.size() > 1) { throw new ConfigErrorException("config error,please use the same type of configuration"); } - return allResource; } @Override 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 52791bdd8..4a2a45dbf 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 @@ -72,6 +72,11 @@ public class ComponentScanner implements BeanPostProcessor { } } + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + @SuppressWarnings("rawtypes") @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/DeclBeanDefinition.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/DeclBeanDefinition.java index 017211abf..7d4d396b6 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/DeclBeanDefinition.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/DeclBeanDefinition.java @@ -4,6 +4,8 @@ import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.proxy.DeclWarpBean; +import com.yomahub.liteflow.log.LFLog; +import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.spi.holder.DeclComponentParserHolder; import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; @@ -12,6 +14,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.*; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -23,34 +26,42 @@ import java.util.Map; * @since 2.11.4 */ public class DeclBeanDefinition implements BeanDefinitionRegistryPostProcessor { + + private final LFLog LOG = LFLoggerManager.getLogger(this.getClass()); @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) registry; - Map beanDefinitionHolderMap = (Map)ReflectUtil.getFieldValue(defaultListableBeanFactory, "mergedBeanDefinitions"); - beanDefinitionHolderMap.entrySet().stream().filter(entry -> { - Class rawClass = entry.getValue().getResolvableType().getRawClass(); - return Arrays.stream(rawClass.getMethods()).anyMatch(method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class) != null); - }).forEach(entry -> { - Class rawClass = entry.getValue().getResolvableType().getRawClass(); + String[] beanDefinitionNames = defaultListableBeanFactory.getBeanDefinitionNames(); + + Arrays.stream(beanDefinitionNames).filter(beanName -> { + BeanDefinition beanDefinition = defaultListableBeanFactory.getMergedBeanDefinition(beanName); + Class rawClass = getRawClassFromBeanDefinition(beanDefinition); + if (rawClass == null){ + return false; + }else{ + return Arrays.stream(rawClass.getMethods()).anyMatch(method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class) != null); + } + }).forEach(beanName -> { + BeanDefinition beanDefinition = defaultListableBeanFactory.getMergedBeanDefinition(beanName); + Class rawClass = getRawClassFromBeanDefinition(beanDefinition); List declWarpBeanList = DeclComponentParserHolder.loadDeclComponentParser().parseDeclBean(rawClass); declWarpBeanList.forEach(declWarpBean -> { - GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); - beanDefinition.setBeanClass(DeclWarpBean.class); - beanDefinition.setScope(ConfigurableBeanFactory.SCOPE_SINGLETON); + GenericBeanDefinition newBeanDefinition = new GenericBeanDefinition(); + newBeanDefinition.setBeanClass(DeclWarpBean.class); + newBeanDefinition.setScope(ConfigurableBeanFactory.SCOPE_SINGLETON); MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(); mutablePropertyValues.add("nodeId", declWarpBean.getNodeId()); mutablePropertyValues.add("nodeName", declWarpBean.getNodeName()); mutablePropertyValues.add("nodeType", declWarpBean.getNodeType()); mutablePropertyValues.add("rawClazz", declWarpBean.getRawClazz()); mutablePropertyValues.add("methodWrapBeanList", declWarpBean.getMethodWrapBeanList()); - mutablePropertyValues.add("rawBean", entry.getValue()); - beanDefinition.setPropertyValues(mutablePropertyValues); + mutablePropertyValues.add("rawBean", beanDefinition); + newBeanDefinition.setPropertyValues(mutablePropertyValues); defaultListableBeanFactory.setAllowBeanDefinitionOverriding(true); - defaultListableBeanFactory.registerBeanDefinition(declWarpBean.getNodeId(), beanDefinition); + defaultListableBeanFactory.registerBeanDefinition(declWarpBean.getNodeId(), newBeanDefinition); }); - }); } @@ -58,4 +69,19 @@ public class DeclBeanDefinition implements BeanDefinitionRegistryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { } + + private Class getRawClassFromBeanDefinition(BeanDefinition beanDefinition){ + try{ + Method method = ReflectUtil.getMethodByName(DeclBeanDefinition.class, "getResolvableType"); + if (method != null){ + Object resolvableType = ReflectUtil.invoke(beanDefinition, method); + return ReflectUtil.invoke(resolvableType, "getRawClass"); + }else{ + return ReflectUtil.invoke(beanDefinition, "getTargetType"); + } + }catch (Exception e){ + LOG.error("An error occurred while obtaining the rowClass.",e); + return null; + } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CmpConfig.java index 9c9f78502..bbbc5e41b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CmpConfig.java @@ -25,7 +25,7 @@ public class CmpConfig { System.out.println("BCmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "c", nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "c", nodeType = NodeTypeEnum.BOOLEAN) public boolean processIfC(NodeComponent bindCmp) throws Exception{ return true; } 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 index 4957712c9..28a3129da 100644 --- 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 @@ -30,7 +30,7 @@ public class CmpConfig { System.out.println("DCmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "x1", nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "x1", nodeType = NodeTypeEnum.BOOLEAN) 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/iterator/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/CmpConfig.java index fede383f1..f638ddfab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/CmpConfig.java @@ -29,7 +29,7 @@ public class CmpConfig { } } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "b", nodeType = NodeTypeEnum.BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "b", nodeType = NodeTypeEnum.BOOLEAN) public boolean processB(NodeComponent bindCmp) { return bindCmp.getLoopIndex() == 1; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CmpConfig.java index 52902d557..3d70742d5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CmpConfig.java @@ -59,14 +59,14 @@ public class CmpConfig { return 3; } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "y", nodeType = NodeTypeEnum.BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "y", nodeType = NodeTypeEnum.BOOLEAN) public boolean processY(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); int count = context.getData("test"); return count > 3; } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "z", nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "z", nodeType = NodeTypeEnum.BOOLEAN) public boolean processZ(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); String key = "test"; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/CmpConfig.java index 2e2194dfc..efc87c7c4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/CmpConfig.java @@ -69,7 +69,7 @@ public class CmpConfig { System.out.println("DCmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "f", nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "f", nodeType = NodeTypeEnum.BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return true; } @@ -79,7 +79,7 @@ public class CmpConfig { return "b"; } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "w", nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "w", nodeType = NodeTypeEnum.BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { // 判断是否切换了 chain if (!executedChain.contains(bindCmp.getCurrChainId())) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CmpConfig.java index db6967be4..18f23a083 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CmpConfig.java @@ -69,7 +69,7 @@ public class CmpConfig { System.out.println("DCmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "f", nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "f", nodeType = NodeTypeEnum.BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return true; } @@ -79,7 +79,7 @@ public class CmpConfig { return "b"; } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "w", nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "w", nodeType = NodeTypeEnum.BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { // 判断是否切换了 chain if (!executedChain.contains(bindCmp.getCurrChainId())) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/CmpConfig.java index 83fedcabf..91164fdd5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/CmpConfig.java @@ -94,7 +94,7 @@ public class CmpConfig { return 3; } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "y", nodeType = NodeTypeEnum.BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "y", nodeType = NodeTypeEnum.BOOLEAN) public boolean processY(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); int count = 0; @@ -104,7 +104,7 @@ public class CmpConfig { return count > 3; } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "z", nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "z", nodeType = NodeTypeEnum.BOOLEAN) public boolean processZ(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); String key = "test"; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetryELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetryELDeclMultiSpringbootTest.java new file mode 100644 index 000000000..664816a7d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetryELDeclMultiSpringbootTest.java @@ -0,0 +1,120 @@ +package com.yomahub.liteflow.test.retry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/retry/application.properties") +@SpringBootTest(classes = RetryELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.retry.cmp"}) +public class RetryELDeclMultiSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + + // 指定异常重试测试1 + @Test + public void testException1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // 指定异常重试测试2 + @Test + public void testException2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain12", "arg"); + Assertions.assertFalse(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CmpConfig.java new file mode 100644 index 000000000..9750a61d5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CmpConfig.java @@ -0,0 +1,89 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import cn.hutool.core.collection.ListUtil; +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.enums.NodeTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent +public class CmpConfig { + + int flagb = 0; + int flagc = 0; + int flagd = 0; + int flagf = 0; + int flagi = 0; + int flagn = 0; + int flagm = 0; + + @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) { + flagb ++; + System.out.println("BCmp executed!"); + if(flagb < 4) throw new RuntimeException(); + else flagb = 0; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeId = "c", nodeType = NodeTypeEnum.FOR) + public int processC(NodeComponent bindCmp) { + flagc ++; + System.out.println("CCmp executed!"); + if(flagc < 4) throw new RuntimeException(); + else return 1; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "d", nodeType = NodeTypeEnum.SWITCH) + public String processD(NodeComponent bindCmp) { + flagd ++; + System.out.println("DCmp executed!"); + if(flagd < 4) throw new RuntimeException(); + else return "a"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "f", nodeType = NodeTypeEnum.BOOLEAN) + public boolean processF(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + flagf ++; + if(flagf < 4) throw new RuntimeException(); + else return true; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "i", nodeType = NodeTypeEnum.ITERATOR) + public Iterator processI(NodeComponent bindCmp) { + flagi ++; + if(flagi < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "m") + public void processM(NodeComponent bindCmp) { + flagm ++; + System.out.println("MCmp executed!"); + if(flagm < 4) throw new ELParseException("MCmp error!"); + else flagm = 0; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "n", nodeType = NodeTypeEnum.BOOLEAN) + public boolean processN(NodeComponent bindCmp) { + flagn ++; + System.out.println("NCmp executed!"); + if(flagn < 4) throw new RuntimeException(); + else return flagn == 4 ? true : false; + } + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/CmpConfig.java index b88545014..58941d993 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/CmpConfig.java @@ -102,13 +102,13 @@ public class CmpConfig { System.out.println("GCmp rollback!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "h", nodeType = NodeTypeEnum.BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "h", nodeType = NodeTypeEnum.BOOLEAN) public int processH(NodeComponent bindCmp) { System.out.println("HCmp executed!"); throw new RuntimeException(); } - @LiteflowMethod(value = LiteFlowMethodEnum.ROLLBACK, nodeId = "h", nodeType = NodeTypeEnum.BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.ROLLBACK, nodeId = "h", nodeType = NodeTypeEnum.BOOLEAN) public void rollbackH() throws Exception { System.out.println("HCmp rollback!"); } @@ -124,24 +124,24 @@ public class CmpConfig { System.out.println("ICmp rollback!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "w", nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "w", nodeType = NodeTypeEnum.BOOLEAN) public boolean processW(NodeComponent bindCmp) { System.out.println("WCmp executed!"); return true; } - @LiteflowMethod(value = LiteFlowMethodEnum.ROLLBACK, nodeId = "w", nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.ROLLBACK, nodeId = "w", nodeType = NodeTypeEnum.BOOLEAN) public void rollbackW() throws Exception { System.out.println("WCmp rollback!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "x", nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "x", nodeType = NodeTypeEnum.BOOLEAN) public boolean processX(NodeComponent bindCmp) { System.out.println("XCmp executed!"); return true; } - @LiteflowMethod(value = LiteFlowMethodEnum.ROLLBACK, nodeId = "x", nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.ROLLBACK, nodeId = "x", nodeType = NodeTypeEnum.BOOLEAN) public void rollbackX() throws Exception { System.out.println("XCmp rollback!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retry/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retry/application.properties new file mode 100644 index 000000000..4323c74b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retry/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retry/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retry/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retry/flow.el.xml new file mode 100644 index 000000000..c567d84d5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retry/flow.el.xml @@ -0,0 +1,51 @@ + + + + THEN( a, b ).retry(3); + + + + WHEN( a, b ).retry(3); + + + + THEN( a, b.retry(3) ); + + + + FOR(c).DO(a).retry(3); + + + + SWITCH(d).TO(a).retry(3); + + + + IF(f, a).retry(3); + + + + WHILE(n).DO(a).retry(3); + + + + ITERATOR(i).DO(a).retry(3); + + + + THEN( a, b ).retry(1); + + + + THEN( a, FINALLY(b, a).retry(3) ); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.ELParseException", "com.yomahub.liteflow.exception.FlowSystemException"); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.AndOrConditionException"); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java index 9666e7141..15b2d01ac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java @@ -8,9 +8,9 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("c") -@LiteflowCmpDefine(NodeTypeEnum.IF) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class CCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java index fcbd8e7eb..0fb9436fb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -5,15 +5,16 @@ 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.BooleanTypeEnum; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("bn1") -@LiteflowCmpDefine(NodeTypeEnum.BREAK) -@FallbackCmp +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) +@FallbackCmp(BooleanTypeEnum.BREAK) public class BreakCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN) public boolean processBreak(NodeComponent bindCmp) throws Exception { return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java index bd1c6f51e..5899ae0ee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -8,10 +8,10 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("ifn1") -@LiteflowCmpDefine(NodeTypeEnum.IF) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class IfCmp1 { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java index 5af938e89..88787398a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -5,15 +5,16 @@ 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.BooleanTypeEnum; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("ifn2") -@LiteflowCmpDefine(NodeTypeEnum.IF) -@FallbackCmp +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) +@FallbackCmp(BooleanTypeEnum.IF) public class IfCmp2 { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return false; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java index 0d65cfb12..8f030ec79 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -11,14 +11,14 @@ import java.util.HashSet; import java.util.Set; @LiteflowComponent("wn1") -@LiteflowCmpDefine(NodeTypeEnum.WHILE) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class WhileCmp1 { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { // 判断是否切换了 chain if (!executedChain.contains(bindCmp.getCurrChainId())) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java index a9bef49b7..31ff5d86b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -5,15 +5,16 @@ 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.BooleanTypeEnum; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("wn2") -@LiteflowCmpDefine(NodeTypeEnum.WHILE) -@FallbackCmp +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) +@FallbackCmp(BooleanTypeEnum.WHILE) public class WhileCmp2 { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { return false; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java index 79c6b3bb4..dccf513a1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @Component("x1") public class X1Cmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return Boolean.parseBoolean(bindCmp.getTag()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java index 58181ba84..93aead7ca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java @@ -3,17 +3,17 @@ package com.yomahub.liteflow.test.iterator.cmp; import com.yomahub.liteflow.annotation.LiteflowCmpDefine; import com.yomahub.liteflow.annotation.LiteflowMethod; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("b") -@LiteflowCmpDefine(NodeTypeEnum.BREAK) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class BCmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS_BREAK) + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_BOOLEAN) public boolean processBreak(NodeComponent bindCmp) throws Exception { return bindCmp.getLoopIndex() == 1; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java index 34967f9f3..70ab241f6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java @@ -10,7 +10,7 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") public class YCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeType = NodeTypeEnum.BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processBreak(NodeComponent bindCmp) throws Exception { DefaultContext context = bindCmp.getFirstContextBean(); int count = context.getData("test"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java index ec4945110..0b2509c91 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java @@ -10,7 +10,7 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") public class ZCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { DefaultContext context = bindCmp.getFirstContextBean(); String key = "test"; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java index 652e2e682..6990eca9b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java @@ -8,10 +8,10 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("f") -@LiteflowCmpDefine(NodeTypeEnum.IF) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class FCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java index 4809d114c..afd560a13 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java @@ -11,14 +11,14 @@ import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -@LiteflowCmpDefine(NodeTypeEnum.WHILE) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class WCmp { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { // 判断是否切换了 chain if (!executedChain.contains(bindCmp.getCurrChainId())) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java index f2b3bd1c3..43c16cf09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java @@ -8,10 +8,10 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("f") -@LiteflowCmpDefine(NodeTypeEnum.IF) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class FCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeType = NodeTypeEnum.IF) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processIf(NodeComponent bindCmp) throws Exception { return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java index 4085405c2..ee756d3e8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java @@ -11,14 +11,14 @@ import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -@LiteflowCmpDefine(NodeTypeEnum.WHILE) +@LiteflowCmpDefine(NodeTypeEnum.BOOLEAN) public class WCmp { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { // 判断是否切换了 chain if (!executedChain.contains(bindCmp.getCurrChainId())) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java index 9e7713c34..b1311b010 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java @@ -10,7 +10,7 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") public class YCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeType = NodeTypeEnum.BREAK) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processBreak(NodeComponent bindCmp) throws Exception { DefaultContext context = bindCmp.getFirstContextBean(); int count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java index 8f01b2c24..b89bf6c2f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java @@ -10,7 +10,7 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") public class ZCmp { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) public boolean processWhile(NodeComponent bindCmp) throws Exception { DefaultContext context = bindCmp.getFirstContextBean(); String key = "test"; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetryELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetryELDeclSpringbootTest.java new file mode 100644 index 000000000..486aaddf6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetryELDeclSpringbootTest.java @@ -0,0 +1,117 @@ +package com.yomahub.liteflow.test.retry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 javax.annotation.Resource; + + +@TestPropertySource(value = "classpath:/retry/application.properties") +@SpringBootTest(classes = RetryELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.retry.cmp"}) +public class RetryELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + + // 指定异常重试测试1 + @Test + public void testException1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // 指定异常重试测试2 + @Test + public void testException2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain12", "arg"); + Assertions.assertFalse(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java new file mode 100644 index 000000000..98bcc2379 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java new file mode 100644 index 000000000..991f5e68a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java new file mode 100644 index 000000000..ecf7f1a25 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeForComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java new file mode 100644 index 000000000..34e9bb5b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java new file mode 100644 index 000000000..81704f493 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("f") +public class FCmp extends NodeBooleanComponent { + int flag = 0; + @Override + public boolean processBoolean() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java new file mode 100644 index 000000000..9ccd8457e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java new file mode 100644 index 000000000..0498cee17 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.ELParseException; + +@LiteflowComponent("m") +public class MCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() throws Exception { + flag ++; + System.out.println("MCmp executed!"); + if(flag < 4) throw new ELParseException("MCmp error!"); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java new file mode 100644 index 000000000..e72524abb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("n") +public class NCmp extends NodeBooleanComponent { + int flag = 0; + + @Override + public boolean processBoolean() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java index 19ebef9b3..a2d3ebe5f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("h") -public class HCmp extends NodeBreakComponent { +public class HCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("HCmp executed!"); throw new RuntimeException(); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java index 3f0fd80d4..81233ca78 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("WCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java index 9928246c4..7d161a2d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x") -public class XCmp extends NodeIfComponent { +public class XCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("XCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retry/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retry/application.properties new file mode 100644 index 000000000..4323c74b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retry/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retry/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retry/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retry/flow.el.xml new file mode 100644 index 000000000..c567d84d5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retry/flow.el.xml @@ -0,0 +1,51 @@ + + + + THEN( a, b ).retry(3); + + + + WHEN( a, b ).retry(3); + + + + THEN( a, b.retry(3) ); + + + + FOR(c).DO(a).retry(3); + + + + SWITCH(d).TO(a).retry(3); + + + + IF(f, a).retry(3); + + + + WHILE(n).DO(a).retry(3); + + + + ITERATOR(i).DO(a).retry(3); + + + + THEN( a, b ).retry(1); + + + + THEN( a, FINALLY(b, a).retry(3) ); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.ELParseException", "com.yomahub.liteflow.exception.FlowSystemException"); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.AndOrConditionException"); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java index d24811911..f5b11e2b7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java @@ -1,11 +1,11 @@ package com.yomahub.liteflow.test.abstractChain.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class CCmp extends NodeIfComponent { +public class CCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { //do your biz return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java index 155bdfae6..a3d1c7aff 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -1,13 +1,14 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; -@FallbackCmp -public class BreakCmp extends NodeBreakComponent { +@FallbackCmp(BooleanTypeEnum.BREAK) +public class BreakCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java index 5437cc8fe..bb607e5d9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -1,11 +1,11 @@ package com.yomahub.liteflow.test.fallback.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class IfCmp1 extends NodeIfComponent { +public class IfCmp1 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java index 67187c399..a83ac4e6f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -1,13 +1,14 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; -@FallbackCmp -public class IfCmp2 extends NodeIfComponent { +@FallbackCmp(BooleanTypeEnum.IF) +public class IfCmp2 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java index d525911ba..9d7f40f73 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -1,18 +1,18 @@ package com.yomahub.liteflow.test.fallback.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; -public class WhileCmp1 extends NodeWhileComponent { +public class WhileCmp1 extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java index 531a77d7e..5954a7683 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -1,13 +1,14 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; -@FallbackCmp -public class WhileCmp2 extends NodeWhileComponent { +@FallbackCmp(BooleanTypeEnum.WHILE) +public class WhileCmp2 extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java index 65e08778c..552f1efcf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java @@ -7,12 +7,12 @@ */ package com.yomahub.liteflow.test.ifelse.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class X1Cmp extends NodeIfComponent { +public class X1Cmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return Boolean.parseBoolean(this.getTag()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java index 2240c45d3..dfd877c73 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.iterator.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class BCmp extends NodeBreakComponent { +public class BCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return this.getLoopIndex() == 1; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java index c201f9ebb..42474f04d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.loop.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); int count = context.getData("test"); return count > 3; diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java index 657bc890d..7638978fb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.loop.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); String key = "test"; if (context.hasData(key)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java index 8b003e024..b1ec5b042 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java @@ -1,10 +1,10 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java index 3f0c50cc2..5b23a8ffb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java @@ -1,18 +1,18 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java index d22ecdf4f..4f4650aed 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java @@ -1,10 +1,10 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java index ecad318d1..c6641d235 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java @@ -1,18 +1,18 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java index 692bf6957..26292f825 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); int count = 0; if(context.hasData("test")) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java index dc4bdfc50..7eccbcef1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); String key = "test"; if (context.hasData(key)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/RetryTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/RetryTest.java new file mode 100644 index 000000000..19cde5ca8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/RetryTest.java @@ -0,0 +1,116 @@ +package com.yomahub.liteflow.test.retry; + + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class RetryTest extends BaseTest { + + private static FlowExecutor flowExecutor; + + @BeforeAll + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("retry/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + + // 指定异常重试测试1 + @Test + public void testException1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // 指定异常重试测试2 + @Test + public void testException2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain12", "arg"); + Assertions.assertFalse(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java new file mode 100644 index 000000000..689fe29f6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import com.yomahub.liteflow.core.NodeComponent; + +public class ACmp extends NodeComponent { + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java new file mode 100644 index 000000000..1c5ecbf14 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import com.yomahub.liteflow.core.NodeComponent; + +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java new file mode 100644 index 000000000..cad5acb41 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import com.yomahub.liteflow.core.NodeForComponent; + +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java new file mode 100644 index 000000000..b845c6008 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import com.yomahub.liteflow.core.NodeSwitchComponent; + +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java new file mode 100644 index 000000000..b09f5b290 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import com.yomahub.liteflow.core.NodeBooleanComponent; + +public class FCmp extends NodeBooleanComponent { + int flag = 0; + @Override + public boolean processBoolean() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java new file mode 100644 index 000000000..8fbc1c767 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Iterator; +import java.util.List; + +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java new file mode 100644 index 000000000..9dd76d1bd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.ELParseException; + +public class MCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() throws Exception { + flag ++; + System.out.println("MCmp executed!"); + if(flag < 4) throw new ELParseException("MCmp error!"); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java new file mode 100644 index 000000000..bb28da952 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import com.yomahub.liteflow.core.NodeBooleanComponent; + +public class NCmp extends NodeBooleanComponent { + int flag = 0; + + @Override + public boolean processBoolean() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java index 7f8378ce7..1ecfc3877 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java @@ -1,11 +1,11 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class HCmp extends NodeBreakComponent { +public class HCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("HCmp executed!"); throw new RuntimeException(); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java index 921e83e77..1d7c73337 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java @@ -1,11 +1,11 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("WCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java index 120006aca..c47313371 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java @@ -1,10 +1,10 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; -public class XCmp extends NodeIfComponent { +public class XCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("XCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/retry/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/retry/flow.el.xml new file mode 100644 index 000000000..175044312 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/retry/flow.el.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + THEN( a, b ).retry(3); + + + + WHEN( a, b ).retry(3); + + + + THEN( a, b.retry(3) ); + + + + FOR(c).DO(a).retry(3); + + + + SWITCH(d).TO(a).retry(3); + + + + IF(f, a).retry(3); + + + + WHILE(n).DO(a).retry(3); + + + + ITERATOR(i).DO(a).retry(3); + + + + THEN( a, b ).retry(1); + + + + THEN( a, FINALLY(b, a).retry(3) ); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.ELParseException", "com.yomahub.liteflow.exception.FlowSystemException"); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.AndOrConditionException"); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/java/com/yomahub/liteflow/test/script/aviator/remove/LiteFlowAviatorScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/java/com/yomahub/liteflow/test/script/aviator/remove/LiteFlowAviatorScriptRemoveELTest.java new file mode 100644 index 000000000..91dda522c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/java/com/yomahub/liteflow/test/script/aviator/remove/LiteFlowAviatorScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.aviator.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowAviatorScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowAviatorScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.AVIATOR.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Long.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Long.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "setData(defaultContext,\"s1\",\"abc\");"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/java/com/yomahub/liteflow/test/script/aviator/validate/ValidateAviatorScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/java/com/yomahub/liteflow/test/script/aviator/validate/ValidateAviatorScriptComponentTest.java new file mode 100644 index 000000000..6f43ed8f5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/java/com/yomahub/liteflow/test/script/aviator/validate/ValidateAviatorScriptComponentTest.java @@ -0,0 +1,47 @@ +package com.yomahub.liteflow.test.script.aviator.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.aviator.AviatorScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@SpringBootTest(classes = ValidateAviatorScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateAviatorScriptComponentTest { + + @Test + public void testAviatorScriptComponentValidateFunction(){ + String correctScript = " use java.util.Date;\n" + + " use cn.hutool.core.date.DateUtil;\n" + + " let d = DateUtil.formatDateTime(new Date());\n" + + " println(d);\n" + + "\n" + + " a = 2;\n" + + " b = 3;\n" + + "\n" + + " setData(defaultContext, \"s1\", a*b);"; + // 语法错误 + String wrongScript = " use java.util.Date;\n" + + " use cn.hutool.core.date.DateUtil;\n" + + " lt d = DateUtil.formatDateTime(new Date());\n" + + " println(d);\n" + + "\n" + + " a = 2;\n" + + " b = 3;\n" + + "\n" + + " setData(defaultContext, \"s1\", a*b);"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.AVIATOR)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.PYTHON)); + + + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/resources/remove/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/resources/remove/application.properties new file mode 100644 index 000000000..21b596255 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/resources/remove/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=remove/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/resources/remove/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/resources/remove/flow.xml new file mode 100644 index 000000000..a9c631831 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-aviator-springboot/src/test/resources/remove/flow.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/LiteFlowScriptGetNodesGraaljsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/LiteFlowScriptGetNodesGraaljsELTest.java new file mode 100644 index 000000000..e834f4f40 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/LiteFlowScriptGetNodesGraaljsELTest.java @@ -0,0 +1,139 @@ +package com.yomahub.liteflow.test.script.graaljs.getnodes; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.flow.element.Node; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 根据 chainId 获取节点测试 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/getnodes/application.properties") +@SpringBootTest(classes = LiteFlowScriptGetNodesGraaljsELTest.class) +@EnableAutoConfiguration +@ComponentScan("com.yomahub.liteflow.test.script.graaljs.getnodes.cmp") +public class LiteFlowScriptGetNodesGraaljsELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void getNodesTest1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain1"); + // 判断数量 + Assertions.assertEquals(5, nodes.size()); + // 判断 id + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + List targetIds = Arrays.asList("a", "b", "c", "s1", "s2"); + for (String id : targetIds) { + Assertions.assertTrue(nodeIds.contains(id)); + } + } + + @Test + public void getNodesTest2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain2"); + // 判断总数量 + Assertions.assertEquals(6, nodes.size()); + // 判断 id 与数量 + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + Map map = listToMap(nodeIds); + Map targetMap = new HashMap<>(); + targetMap.put("a", 3); + targetMap.put("b", 1); + targetMap.put("s1", 2); + Assertions.assertTrue(targetMap.equals(map)); + // 判断 tag + List nodeTags = nodes.stream().map(Node::getTag) + .collect(Collectors.toList()); + List targetTags = Arrays.asList("a1", "a2", "a3", "b1", "s11", "s12"); + for (String id : targetTags) { + Assertions.assertTrue(nodeTags.contains(id)); + } + } + + @Test + public void getNodesTest3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain3"); + // 判断总数量 + Assertions.assertEquals(8, nodes.size()); + // 判断 id 与数量 + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + Map map = listToMap(nodeIds); + Map targetMap = new HashMap<>(); + targetMap.put("a", 2); + targetMap.put("b", 2); + targetMap.put("c", 1); + targetMap.put("f", 1); + targetMap.put("s1", 1); + targetMap.put("s2", 1); + Assertions.assertTrue(targetMap.equals(map)); + } + + @Test + public void getNodesTest4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain4"); + // 判断数量 + Assertions.assertEquals(5, nodes.size()); + // 判断 id + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + List targetIds = Arrays.asList("a", "b", "c", "s"); + for (String id : targetIds) { + Assertions.assertTrue(nodeIds.contains(id)); + } + } + + @Test + public void getNodesTest5() { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain5"); + // 判断数量 + Assertions.assertEquals(3, nodes.size()); + // 判断 id + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + List targetIds = Arrays.asList("x", "y", "s1"); + for (String id : targetIds) { + Assertions.assertTrue(nodeIds.contains(id)); + } + } + + // 统计节点 id 出现的数量 + private Map listToMap(List list) { + Map map = new HashMap<>(); + for (String s : list) { + map.put(s, map.getOrDefault(s, 0) + 1); + } + return map; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/ACmp.java new file mode 100644 index 000000000..2eb120512 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.graaljs.getnodes.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-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/BCmp.java new file mode 100644 index 000000000..9818266eb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/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.script.graaljs.getnodes.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-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/CCmp.java new file mode 100644 index 000000000..f42ce1b19 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/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.script.graaljs.getnodes.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-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/FCmp.java new file mode 100644 index 000000000..35beaf2e6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/FCmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.graaljs.getnodes.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/SCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/SCmp.java new file mode 100644 index 000000000..a064993d4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/getnodes/cmp/SCmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.graaljs.getnodes.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import org.springframework.stereotype.Component; + +@Component("s") +public class SCmp extends NodeSwitchComponent { + @Override + public String processSwitch() throws Exception { + return "f1"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/remove/LiteFlowJsScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/remove/LiteFlowJsScriptRemoveELTest.java new file mode 100644 index 000000000..f717aa0ac --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/remove/LiteFlowJsScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.graaljs.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowJsScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowJsScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.JS.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "defaultContext.setData(\"s1\",\"abc\");"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/validate/ValidateGraaljsScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/validate/ValidateGraaljsScriptComponentTest.java new file mode 100644 index 000000000..7cea4b72b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/validate/ValidateGraaljsScriptComponentTest.java @@ -0,0 +1,55 @@ +package com.yomahub.liteflow.test.script.graaljs.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.graaljs.GraalJavaScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidateGraaljsScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateGraaljsScriptComponentTest { + @Test + public void testGraaljsScriptComponentValidateFunction(){ + String correctScript = " var a=3;\n" + + " var b=2;\n" + + " var c=1;\n" + + " var d=5;\n" + + "\n" + + " function addByArray(values) {\n" + + " var sum = 0;\n" + + " for (var i = 0; i < values.length; i++) {\n" + + " sum += values[i];\n" + + " }\n" + + " return sum;\n" + + " }\n" + + "\n" + + " var result = addByArray([a,b,c,d]);\n" + + "\n" + + " defaultContext.setData(\"s1\",parseInt(result));"; + // 语法错误 + String wrongScript = " var a=3;\n" + + " var b=2;\n" + + " var c=1;\n" + + " var d=5;\n" + + "\n" + + " fn addByArray(values) {\n" + + " var sum = 0;\n" + + " for (var i = 0; i < values.length; i++) {\n" + + " sum += values[i];\n" + + " }\n" + + " return sum;\n" + + " }\n" + + "\n" + + " var result = addByArray([a,b,c,d]);\n" + + "\n" + + " defaultContext.setData(\"s1\",parseInt(result));"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.JS)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.AVIATOR)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/getnodes/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/getnodes/application.properties new file mode 100644 index 000000000..4acf0f012 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/getnodes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=getnodes/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/getnodes/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/getnodes/flow.xml new file mode 100644 index 000000000..13e96568b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/getnodes/flow.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + THEN(a, b, c, s1, s2); + + + + + THEN(a.tag("a1"), a.tag("a2"), a.tag("a3"), b.tag("b1"), s1.tag("s11"), s1.tag("s12")); + + + + + THEN(WHEN(a, b), IF(f, WHEN(THEN(c, s2, WHEN(s1, b)), a))); + + + + SWITCH(s).to(FOR(3).DO(a).id("f1"), b, c); + + + + WHILE(x).DO(s1).BREAK(y); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/ifelse/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/ifelse/flow.xml index db5d0d591..f69385aaa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/ifelse/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/ifelse/flow.xml @@ -1,13 +1,13 @@ - + - + diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/loop/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/loop/flow.xml index 603cf721a..b960180d1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/loop/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/resources/loop/flow.xml @@ -8,14 +8,14 @@ ]]> - + 3; ]]> - + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/remove/LiteFlowGroovyScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/remove/LiteFlowGroovyScriptRemoveELTest.java new file mode 100644 index 000000000..fe0d8ec21 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/remove/LiteFlowGroovyScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.groovy.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowGroovyScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowGroovyScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.GROOVY.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "defaultContext.setData(\"s1\",\"abc\");"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/validate/ValidateGroovyScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/validate/ValidateGroovyScriptComponentTest.java new file mode 100644 index 000000000..ff3a705f5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/validate/ValidateGroovyScriptComponentTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.script.groovy.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.groovy.GroovyScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidateGroovyScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateGroovyScriptComponentTest { + @Test + public void testGroovyScriptComponentValidateFunction(){ + String correctScript = " import cn.hutool.core.collection.ListUtil\n" + + " import cn.hutool.core.date.DateUtil\n" + + "\n" + + " import java.util.function.Consumer\n" + + " import java.util.function.Function\n" + + " import java.util.stream.Collectors\n" + + "\n" + + " def date = DateUtil.parse(\"2022-10-17 13:31:43\")\n" + + " println(date)\n" + + " defaultContext.setData(\"demoDate\", date)\n" + + "\n" + + " List list = ListUtil.toList(\"a\", \"b\", \"c\")\n" + + "\n" + + " List resultList = list.stream().map(s -> \"hello,\" + s).collect(Collectors.toList())\n" + + "\n" + + " defaultContext.setData(\"resultList\", resultList)\n" + + "\n" + + " class Student {\n" + + " int studentID\n" + + " String studentName\n" + + " }\n" + + "\n" + + " Student student = new Student()\n" + + " student.studentID = 100301\n" + + " student.studentName = \"张三\"\n" + + " defaultContext.setData(\"student\", student)\n" + + "\n" + + " def a = 3\n" + + " def b = 2\n" + + " defaultContext.setData(\"s1\", a * b)"; + // 语法错误 + String wrongScript = " import cn.hutool.core.collection.ListUtil\n" + + " import cn.hutool.core.date.DateUtil\n" + + "\n" + + " import java.util.function.Consumer\n" + + " import java.util.function.Function\n" + + " import java.util.stream.Collectors\n" + + "\n" + + " d date = DateUtil.parse(\"2022-10-17 13:31:43\")\n" + + " println(date)\n" + + " defaultContext.setData(\"demoDate\", date)\n" + + "\n" + + " List list = ListUtil.toList(\"a\", \"b\", \"c\")\n" + + "\n" + + " List resultList = list.stream().map(s -> \"hello,\" + s).collect(Collectors.toList())\n" + + "\n" + + " defaultContext.setData(\"resultList\", resultList)\n" + + "\n" + + " class Student {\n" + + " int studentID\n" + + " String studentName\n" + + " }\n" + + "\n" + + " Student student = new Student()\n" + + " student.studentID = 100301\n" + + " student.studentName = \"张三\"\n" + + " defaultContext.setData(\"student\", student)\n" + + "\n" + + " def a = 3\n" + + " def b = 2\n" + + " defaultContext.setData(\"s1\", a * b)"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.GROOVY)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.JS)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/ifelse/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/ifelse/flow.el.xml index c48071a97..4ed30d2a3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/ifelse/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/ifelse/flow.el.xml @@ -1,13 +1,13 @@ - + - + diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml index a6ef34abb..850fdb0d9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/loop/flow.xml @@ -8,14 +8,14 @@ ]]> - + 3 ]]> - + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptOrder/flow1.xml b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptOrder/flow1.xml index 7d8648171..ce07c3cae 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptOrder/flow1.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/resources/scriptOrder/flow1.xml @@ -2,7 +2,7 @@ - + nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = " import com.yomahub.liteflow.slot.DefaultContext;\n" + + " import com.yomahub.liteflow.script.body.JaninoCommonScriptBody;\n" + + " import com.yomahub.liteflow.script.ScriptExecuteWrap;\n" + + "\n" + + " public class Demo implements JaninoCommonScriptBody {\n" + + " public Void body(ScriptExecuteWrap wrap) {\n" + + " DefaultContext ctx = (DefaultContext) wrap.getCmp().getFirstContextBean();\n" + + " ctx.setData(\"s1\", \"abc\");\n" + + " return null;\n" + + " }\n" + + " }"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/java/com/yomahub/liteflow/test/script/java/validate/ValidateJavaScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/java/com/yomahub/liteflow/test/script/java/validate/ValidateJavaScriptComponentTest.java new file mode 100644 index 000000000..033ac15fa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/java/com/yomahub/liteflow/test/script/java/validate/ValidateJavaScriptComponentTest.java @@ -0,0 +1,67 @@ +package com.yomahub.liteflow.test.script.java.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.java.JavaExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidateJavaScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateJavaScriptComponentTest { + @Test + public void testJavaScriptComponentValidateFunction(){ + String correctScript = "import com.alibaba.fastjson2.JSON;\n" + + " import com.yomahub.liteflow.slot.DefaultContext;\n" + + " import com.yomahub.liteflow.spi.holder.ContextAwareHolder;\n" + + " import com.yomahub.liteflow.test.script.java.common.cmp.TestDomain;\n" + + " import com.yomahub.liteflow.script.body.JaninoCommonScriptBody;\n" + + " import com.yomahub.liteflow.script.ScriptExecuteWrap;\n" + + "\n" + + " public class Demo implements JaninoCommonScriptBody {\n" + + " public Void body(ScriptExecuteWrap wrap) {\n" + + " int v1 = 2;\n" + + " int v2 = 3;\n" + + " DefaultContext ctx = (DefaultContext) wrap.getCmp().getFirstContextBean();\n" + + " ctx.setData(\"s1\", v1 * v2);\n" + + "\n" + + " TestDomain domain = (TestDomain) ContextAwareHolder.loadContextAware().getBean(TestDomain.class);\n" + + " System.out.println(JSON.toJSONString(domain));\n" + + " String str = domain.sayHello(\"jack\");\n" + + " ctx.setData(\"hi\", str);\n" + + "\n" + + " return null;\n" + + " }\n" + + " }"; + // 未指定类型名错误 + String wrongScript = "import com.alibaba.fastjson2.JSON;\n" + + " import com.yomahub.liteflow.slot.DefaultContext;\n" + + " import com.yomahub.liteflow.spi.holder.ContextAwareHolder;\n" + + " import com.yomahub.liteflow.test.script.java.common.cmp.TestDomain;\n" + + " import com.yomahub.liteflow.script.body.JaninoCommonScriptBody;\n" + + " import com.yomahub.liteflow.script.ScriptExecuteWrap;\n" + + "\n" + + " public class Demo implements JaninoCommonScriptBody {\n" + + " public Void body(ScriptExecuteWrap wrap) {\n" + + " v1 = 2;\n" + + " int v2 = 3;\n" + + " DefaultContext ctx = (DefaultContext) wrap.getCmp().getFirstContextBean();\n" + + " ctx.setData(\"s1\", v1 * v2);\n" + + "\n" + + " TestDomain domain = (TestDomain) ContextAwareHolder.loadContextAware().getBean(TestDomain.class);\n" + + " System.out.println(JSON.toJSONString(domain));\n" + + " String str = domain.sayHello(\"jack\");\n" + + " ctx.setData(\"hi\", str);\n" + + "\n" + + " return null;\n" + + " }\n" + + " }"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.JAVA)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.GROOVY)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/resources/remove/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/resources/remove/application.properties new file mode 100644 index 000000000..21b596255 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/resources/remove/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=remove/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/resources/remove/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/resources/remove/flow.xml new file mode 100644 index 000000000..dded8d6f5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-java-springboot/src/test/resources/remove/flow.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/LiteFlowScriptGetNodesJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/LiteFlowScriptGetNodesJsELTest.java new file mode 100644 index 000000000..1bbd41bae --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/LiteFlowScriptGetNodesJsELTest.java @@ -0,0 +1,139 @@ +package com.yomahub.liteflow.test.script.javascript.getnodes; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.flow.element.Node; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 根据 chainId 获取节点测试 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/getnodes/application.properties") +@SpringBootTest(classes = LiteFlowScriptGetNodesJsELTest.class) +@EnableAutoConfiguration +@ComponentScan("com.yomahub.liteflow.test.script.javascript.getnodes.cmp") +public class LiteFlowScriptGetNodesJsELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void getNodesTest1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain1"); + // 判断数量 + Assertions.assertEquals(5, nodes.size()); + // 判断 id + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + List targetIds = Arrays.asList("a", "b", "c", "s1", "s2"); + for (String id : targetIds) { + Assertions.assertTrue(nodeIds.contains(id)); + } + } + + @Test + public void getNodesTest2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain2"); + // 判断总数量 + Assertions.assertEquals(6, nodes.size()); + // 判断 id 与数量 + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + Map map = listToMap(nodeIds); + Map targetMap = new HashMap<>(); + targetMap.put("a", 3); + targetMap.put("b", 1); + targetMap.put("s1", 2); + Assertions.assertTrue(targetMap.equals(map)); + // 判断 tag + List nodeTags = nodes.stream().map(Node::getTag) + .collect(Collectors.toList()); + List targetTags = Arrays.asList("a1", "a2", "a3", "b1", "s11", "s12"); + for (String id : targetTags) { + Assertions.assertTrue(nodeTags.contains(id)); + } + } + + @Test + public void getNodesTest3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain3"); + // 判断总数量 + Assertions.assertEquals(8, nodes.size()); + // 判断 id 与数量 + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + Map map = listToMap(nodeIds); + Map targetMap = new HashMap<>(); + targetMap.put("a", 2); + targetMap.put("b", 2); + targetMap.put("c", 1); + targetMap.put("f", 1); + targetMap.put("s1", 1); + targetMap.put("s2", 1); + Assertions.assertTrue(targetMap.equals(map)); + } + + @Test + public void getNodesTest4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain4"); + // 判断数量 + Assertions.assertEquals(5, nodes.size()); + // 判断 id + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + List targetIds = Arrays.asList("a", "b", "c", "s"); + for (String id : targetIds) { + Assertions.assertTrue(nodeIds.contains(id)); + } + } + + @Test + public void getNodesTest5() { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + List nodes = FlowBus.getNodesByChainId("chain5"); + // 判断数量 + Assertions.assertEquals(3, nodes.size()); + // 判断 id + List nodeIds = nodes.stream().map(Node::getId) + .collect(Collectors.toList()); + List targetIds = Arrays.asList("x", "y", "s1"); + for (String id : targetIds) { + Assertions.assertTrue(nodeIds.contains(id)); + } + } + + // 统计节点 id 出现的数量 + private Map listToMap(List list) { + Map map = new HashMap<>(); + for (String s : list) { + map.put(s, map.getOrDefault(s, 0) + 1); + } + return map; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/ACmp.java new file mode 100644 index 000000000..8deacaeb0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.script.javascript.getnodes.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-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/BCmp.java new file mode 100644 index 000000000..0e634e36d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/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.script.javascript.getnodes.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-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/CCmp.java new file mode 100644 index 000000000..ad7bffdee --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/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.script.javascript.getnodes.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-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/FCmp.java new file mode 100644 index 000000000..05041540d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/FCmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.javascript.getnodes.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/SCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/SCmp.java new file mode 100644 index 000000000..937a973d9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/getnodes/cmp/SCmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.script.javascript.getnodes.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import org.springframework.stereotype.Component; + +@Component("s") +public class SCmp extends NodeSwitchComponent { + @Override + public String processSwitch() throws Exception { + return "f1"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/remove/LiteFlowJsScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/remove/LiteFlowJsScriptRemoveELTest.java new file mode 100644 index 000000000..fd1740dad --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/remove/LiteFlowJsScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.javascript.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowJsScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowJsScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private final ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.JS.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Double.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Double.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "defaultContext.setData(\"s1\",\"abc\");"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/validate/ValidateJavaScriptScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/validate/ValidateJavaScriptScriptComponentTest.java new file mode 100644 index 000000000..29ef33af4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/validate/ValidateJavaScriptScriptComponentTest.java @@ -0,0 +1,55 @@ +package com.yomahub.liteflow.test.script.javascript.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.javascript.JavaScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidateJavaScriptScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateJavaScriptScriptComponentTest { + @Test + public void testJavaScriptScriptComponentValidateFunction(){ + String correctScript = "var a=3;\n" + + " var b=2;\n" + + " var c=1;\n" + + " var d=5;\n" + + "\n" + + " function addByArray(values) {\n" + + " var sum = 0;\n" + + " for (var i = 0; i < values.length; i++) {\n" + + " sum += values[i];\n" + + " }\n" + + " return sum;\n" + + " }\n" + + "\n" + + " var result = addByArray([a,b,c,d]);\n" + + "\n" + + " defaultContext.setData(\"s1\",parseInt(result));"; + // 语法错误 + String wrongScript = "var a=3;\n" + + " var b=2;\n" + + " var c=1;\n" + + " var d=5;\n" + + "\n" + + " fon addByArray(values) {\n" + + " var sum = 0;\n" + + " for (var i = 0; i < values.length; i++) {\n" + + " sum += values[i];\n" + + " }\n" + + " return sum;\n" + + " }\n" + + "\n" + + " var result = addByArray([a,b,c,d]);\n" + + "\n" + + " defaultContext.setData(\"s1\",parseInt(result));"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.JS)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.JAVA)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/getnodes/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/getnodes/application.properties new file mode 100644 index 000000000..4acf0f012 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/getnodes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=getnodes/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/getnodes/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/getnodes/flow.xml new file mode 100644 index 000000000..13e96568b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/getnodes/flow.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + THEN(a, b, c, s1, s2); + + + + + THEN(a.tag("a1"), a.tag("a2"), a.tag("a3"), b.tag("b1"), s1.tag("s11"), s1.tag("s12")); + + + + + THEN(WHEN(a, b), IF(f, WHEN(THEN(c, s2, WHEN(s1, b)), a))); + + + + SWITCH(s).to(FOR(3).DO(a).id("f1"), b, c); + + + + WHILE(x).DO(s1).BREAK(y); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/flow.xml index db5d0d591..f69385aaa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/ifelse/flow.xml @@ -1,13 +1,13 @@ - + - + diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/flow.xml index 603cf721a..b960180d1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/resources/loop/flow.xml @@ -8,14 +8,14 @@ ]]> - + 3; ]]> - + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/remove/LiteFlowLuaScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/remove/LiteFlowLuaScriptRemoveELTest.java new file mode 100644 index 000000000..395cfbd1d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/remove/LiteFlowLuaScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.lua.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowLuaScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowLuaScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.LUA.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "defaultContext:setData(\"s1\",\"abc\");"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/validate/ValidateLuaScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/validate/ValidateLuaScriptComponentTest.java new file mode 100644 index 000000000..01bd73487 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/validate/ValidateLuaScriptComponentTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.script.lua.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.lua.LuaScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidateLuaScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateLuaScriptComponentTest { + @Test + public void testLuaScriptComponentValidateFunction(){ + String correctScript = " local a=6\n" + + " local b=10\n" + + " if(a>5) then\n" + + " b=5\n" + + " else\n" + + " b=2\n" + + " end\n" + + " defaultContext:setData(\"s1\",a*b)\n" + + " defaultContext:setData(\"s2\",_meta:get(\"nodeId\"))"; + // 语法错误 + String wrongScript = " local a=6\n" + + " local b=10\n" + + " if(a>5) tn\n" + + " b=5\n" + + " else\n" + + " b=2\n" + + " end\n" + + " defaultContext:setData(\"s1\",a*b)\n" + + " defaultContext:setData(\"s2\",_meta:get(\"nodeId\"))"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.LUA)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.JS)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/resources/remove/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/resources/remove/application.properties new file mode 100644 index 000000000..21b596255 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/resources/remove/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=remove/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/resources/remove/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/resources/remove/flow.xml new file mode 100644 index 000000000..80888321f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/resources/remove/flow.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/validate/ValidateMultiLanguageScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/validate/ValidateMultiLanguageScriptComponentTest.java new file mode 100644 index 000000000..2bbee5dc0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/validate/ValidateMultiLanguageScriptComponentTest.java @@ -0,0 +1,62 @@ +package com.yomahub.liteflow.test.script.multi.language.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.HashMap; +import java.util.Map; + +@SpringBootTest(classes = ValidateMultiLanguageScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateMultiLanguageScriptComponentTest { + @Test + public void testMultiLanguageScriptComponentValidateFunction(){ + String correctGroovyScript = " class Student {\n" + + " int studentID;\n" + + " String studentName;\n" + + "\n" + + " public void setStudentID(int id){\n" + + " this.studentID = id;\n" + + " }\n" + + " }\n" + + "\n" + + " Student student = new Student()\n" + + " student.studentID = 100301\n" + + " student.studentName = \"张三\"\n" + + " defaultContext.setData(\"student\", student)\n" + + "\n" + + " def a = 3\n" + + " def b = 2\n" + + " defaultContext.setData(\"s1\", a * b)"; + String correctJavascriptScript = " var student = defaultContext.getData(\"student\");\n" + + " student.setStudentID(10032);"; + String correctPythonScript = " a = 3\n" + + " s1 = defaultContext.getData(\"s1\")\n" + + " defaultContext.setData(\"s1\",s1*a)"; + // 语法错误 缩进 + String wrongPythonScript = " a = 3\n" + + " s1 = defaultContext.getData(\"s1\")\n" + + " defaultContext.setData(\"s1\",s1*a)"; + // 在加载多脚本时使用默认验证方法会错误 + Assertions.assertFalse(ScriptValidator.validate(correctGroovyScript)); + + // 多语言脚本验证 正确样例 + Map correctData = new HashMap<>(); + correctData.put(ScriptTypeEnum.GROOVY, correctGroovyScript); + correctData.put(ScriptTypeEnum.JS, correctJavascriptScript); + correctData.put(ScriptTypeEnum.PYTHON, correctPythonScript); + Assertions.assertTrue(ScriptValidator.validate(correctData)); + + // 多语言脚本验证 错误样例 + Map wrongData = new HashMap<>(); + wrongData.put(ScriptTypeEnum.GROOVY, correctGroovyScript); + wrongData.put(ScriptTypeEnum.JS, correctJavascriptScript); + wrongData.put(ScriptTypeEnum.PYTHON, wrongPythonScript); + Assertions.assertFalse(ScriptValidator.validate(wrongData)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/ScriptPythonCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/ScriptPythonCommonELTest.java index 36f360b5b..a29b63fbe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/ScriptPythonCommonELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/ScriptPythonCommonELTest.java @@ -43,4 +43,10 @@ public class ScriptPythonCommonELTest extends BaseTest { Assertions.assertEquals("hi,jack", context.getData("td")); } + @Test + public void testCommon2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/remove/LiteFlowPythonScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/remove/LiteFlowPythonScriptRemoveELTest.java new file mode 100644 index 000000000..c4643525d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/remove/LiteFlowPythonScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.python.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowPythonScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowPythonScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.PYTHON.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "defaultContext.setData(\"s1\",\"abc\");"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/validate/ValidatePythonScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/validate/ValidatePythonScriptComponentTest.java new file mode 100644 index 000000000..77601e4f3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/validate/ValidatePythonScriptComponentTest.java @@ -0,0 +1,57 @@ +package com.yomahub.liteflow.test.script.python.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.python.PythonScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidatePythonScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidatePythonScriptComponentTest { + @Test + public void testPythonScriptComponentValidateFunction(){ + String correctScript = " import json\n" + + "\n" + + " x='{\"name\": \"杰克\", \"age\": 75, \"nationality\": \"China\"}'\n" + + " jsonData=json.loads(x)\n" + + " name=jsonData['name']\n" + + " defaultContext.setData(\"name\", name.decode('utf-8'))\n" + + "\n" + + "\n" + + " a=6\n" + + " b=10\n" + + " if a>5:\n" + + " b=5\n" + + " print '你好'.decode('UTF-8')\n" + + " else:\n" + + " print 'hi'\n" + + " defaultContext.setData(\"s1\",a*b)\n" + + " defaultContext.setData(\"td\", td.sayHi(\"jack\"))"; + // 语法错误 缩进 + String wrongScript = " import json\n" + + "\n" + + " x='{\"name\": \"杰克\", \"age\": 75, \"nationality\": \"China\"}'\n" + + " jsonData=json.loads(x)\n" + + " name=jsonData['name']\n" + + " defaultContext.setData(\"name\", name.decode('utf-8'))\n" + + "\n" + + "\n" + + " a=6\n" + + " b=10\n" + + " if a>5:\n" + + " b=5\n" + + " print '你好'.decode('UTF-8')\n" + + " else:\n" + + " print 'hi'\n" + + " defaultContext.setData(\"s1\",a*b)\n" + + " defaultContext.setData(\"td\", td.sayHi(\"jack\"))"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.PYTHON)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.LUA)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/common/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/common/flow.xml index b43fdc9ba..b226abcd7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/common/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/common/flow.xml @@ -25,9 +25,19 @@ + + + + THEN(a, b, c, s1, s2); + + + SWITCH(s3).TO(a,b); + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/remove/application.properties b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/remove/application.properties new file mode 100644 index 000000000..21b596255 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/remove/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=remove/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/remove/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/remove/flow.xml new file mode 100644 index 000000000..0ca8f80fd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/resources/remove/flow.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/remove/LiteFlowQLExpressScriptRemoveELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/remove/LiteFlowQLExpressScriptRemoveELTest.java new file mode 100644 index 000000000..99d727048 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/remove/LiteFlowQLExpressScriptRemoveELTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.script.qlexpress.remove; + +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.script.ScriptExecutor; +import com.yomahub.liteflow.script.ScriptExecutorFactory; +import com.yomahub.liteflow.script.exception.ScriptLoadException; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 测试脚本的卸载和重载功能 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/remove/application.properties") +@SpringBootTest(classes = LiteFlowQLExpressScriptRemoveELTest.class) +@EnableAutoConfiguration +public class LiteFlowQLExpressScriptRemoveELTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + private ScriptExecutor scriptExecutor = ScriptExecutorFactory.loadInstance() + .getScriptExecutor(ScriptTypeEnum.QLEXPRESS.getDisplayName()); + + // 仅卸载脚本 + @Test + public void testUnload() { + flowExecutor.reloadRule(); + + // 获取节点id + List nodeIds = scriptExecutor.getNodeIds(); + Assertions.assertEquals(2, nodeIds.size()); + Assertions.assertTrue(nodeIds.contains("s1")); + Assertions.assertTrue(nodeIds.contains("s2")); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(6), context.getData("s1")); + + // 卸载脚本 + scriptExecutor.unLoad("s1"); + response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + Assertions.assertEquals("script for node[s1] is not loaded", response.getMessage()); + + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s1")); + } + + // 卸载节点和脚本 + @Test + public void testRemove() { + flowExecutor.reloadRule(); + + // 保证脚本可以正常运行 + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(Integer.valueOf(5), context.getData("s2")); + + // 卸载节点 + FlowBus.unloadScriptNode("s2"); + + // 旧 chain 报脚本加载错误 + response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertEquals(ScriptLoadException.class, response.getCause().getClass()); + + // 新 chian 会找不到节点 + Assertions.assertThrows(ELParseException.class, + () -> LiteFlowChainELBuilder.createChain() + .setChainId("chain3") + .setEL("THEN(s2)") + .build()); + + // 节点已卸载 + Assertions.assertFalse(FlowBus.containNode("s2")); + // 脚本已卸载 + Assertions.assertFalse(scriptExecutor.getNodeIds().contains("s2")); + } + + // 重载脚本 + @Test + public void testReloadScript() { + flowExecutor.reloadRule(); + String script = "defaultContext.setData(\"s1\",\"abc\");"; + FlowBus.reloadScript("s1", script); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + // 执行结果变更 + Assertions.assertEquals("abc", context.getData("s1")); + // 脚本变更 + Assertions.assertEquals(FlowBus.getNode("s1").getScript(), script); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/validate/ValidateQLExpressScriptComponentTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/validate/ValidateQLExpressScriptComponentTest.java new file mode 100644 index 000000000..34f449357 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/validate/ValidateQLExpressScriptComponentTest.java @@ -0,0 +1,35 @@ +package com.yomahub.liteflow.test.script.qlexpress.validate; + +import com.yomahub.liteflow.enums.ScriptTypeEnum; +import com.yomahub.liteflow.script.qlexpress.QLExpressScriptExecutor; +import com.yomahub.liteflow.script.validator.ScriptValidator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = ValidateQLExpressScriptComponentTest.class) +@EnableAutoConfiguration +public class ValidateQLExpressScriptComponentTest { + @Test + public void testQLExpressScriptComponentValidateFunction(){ + String correctScript = " count = defaultContext.getData(\"count\");\n" + + " if(count > 100){\n" + + " return \"a\";\n" + + " }else{\n" + + " return \"b\";\n" + + " }"; + // 语法错误 + String wrongScript = " count = defaultContext.getData(\"count\");\n" + + " if(count > 100){\n" + + " return \"a\";\n" + + " }el{\n" + + " return \"b\";\n" + + " }"; + Assertions.assertTrue(ScriptValidator.validate(correctScript)); + Assertions.assertFalse(ScriptValidator.validate(wrongScript)); + + Assertions.assertTrue(ScriptValidator.validate(correctScript, ScriptTypeEnum.QLEXPRESS)); + Assertions.assertFalse(ScriptValidator.validate(correctScript, ScriptTypeEnum.PYTHON)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/ifelse/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/ifelse/flow.el.xml index a0a5c2418..09f97a0f1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/ifelse/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/ifelse/flow.el.xml @@ -1,13 +1,13 @@ - + - + diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/loop/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/loop/flow.xml index b775bb495..fd5cb0a6c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/loop/flow.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/resources/loop/flow.xml @@ -8,14 +8,14 @@ ]]> - + 3; ]]> - + + + + + + + + + + + + + + THEN(s1); + + + + THEN(s2); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainJsonELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainJsonELSpringBootTest.java index d2a6809ae..e419124ac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainJsonELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainJsonELSpringBootTest.java @@ -6,12 +6,12 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/abstractChain/application-json.properties") +@Import(profiles="classpath:/abstractChain/application-json.properties") public class AbstractChainJsonELSpringBootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainXMLELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainXMLELSpringBootTest.java index e4be4203c..d94db943a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainXMLELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainXMLELSpringBootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试显示调用子流程(xml) 单元测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author justin.xu */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/abstractChain/application.properties") +@Import(profiles="classpath:/abstractChain/application.properties") public class AbstractChainXMLELSpringBootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainYmlELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainYmlELSpringBootTest.java index 454011c00..2ce1b74b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainYmlELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/AbstractChainYmlELSpringBootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试显示调用子流程(yml) 单元测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author justin.xu */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/abstractChain/application-yml.properties") +@Import(profiles="classpath:/abstractChain/application-yml.properties") public class AbstractChainYmlELSpringBootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java index eccbc7d17..d42517e4e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.abstractChain.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.noear.solon.annotation.Component; @Component("c") -public class CCmp extends NodeIfComponent { +public class CCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { //do your biz return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java index 6b223f825..05ca42dc4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java @@ -9,9 +9,9 @@ import com.yomahub.liteflow.test.asyncNode.exception.TestException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试隐式调用子流程 单元测试 @@ -19,7 +19,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author ssss */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/asyncNode/application.properties") +@Import(profiles="classpath:/asyncNode/application.properties") public class AsyncNodeELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java index 4b6fbc38e..296825816 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/base/application.properties") +@Import(profiles="classpath:/base/application.properties") public class BaseELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java index 46a28ce6e..5297fed2b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java @@ -9,9 +9,9 @@ import com.yomahub.liteflow.test.cmpData.vo.User; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 @@ -19,7 +19,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/cmpData/application.properties") +@Import(profiles="classpath:/cmpData/application.properties") public class CmpDataELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java index 8e28792e9..4a28fed19 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java @@ -6,10 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.noear.snack.ONode; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试springboot下的节点执行器 @@ -18,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.10 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/cmpRetry/application.properties") +@Import(profiles="classpath:/cmpRetry/application.properties") public class LiteflowRetryELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java index 7624a3690..f7d98c0e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import java.util.*; @@ -20,7 +20,7 @@ import java.util.*; * @since 2.7.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/cmpStep/application.properties") +@Import(profiles="classpath:/cmpStep/application.properties") public class CmpStepELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java index c188d3a92..f75a91614 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java @@ -7,12 +7,12 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/comments/application.properties") +@Import(profiles="classpath:/comments/application.properties") public class LiteflowNodeELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java index adfa6d0da..08e63f399 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL复杂例子测试1 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/complex/application1.properties") +@Import(profiles="classpath:/complex/application1.properties") public class ComplexELSpringbootTest1 extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/ComplexELSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/ComplexELSpringbootTest2.java index 9d79f629c..21d3c15e4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/ComplexELSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/ComplexELSpringbootTest2.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL复杂例子测试1 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/complex/application2.properties") +@Import(profiles="classpath:/complex/application2.properties") public class ComplexELSpringbootTest2 extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java index 58450c05e..00068cd0d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,7 +18,7 @@ import org.slf4j.LoggerFactory; * @author donguo.tao */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/component/application.properties") +@Import(profiles="classpath:/component/application.properties") public class FlowExecutorELSpringbootTest extends BaseTest { private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELSpringbootTest.class); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java index be2c7cbe5..b2e80dc18 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/customNodes/application.properties") +@Import(profiles="classpath:/customNodes/application.properties") public class CustomNodesELSpringbootTest extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java index 3711f87c5..bb4caef34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/customWhenThreadPool/application.properties") +@Import(profiles="classpath:/customWhenThreadPool/application.properties") public class CustomWhenThreadPoolELSpringbootTest extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java index 8b7696891..4de9c6ee9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境事件回调测试 @@ -18,7 +18,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.7.1 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/event/application.properties") +@Import(profiles="classpath:/event/application.properties") public class EventELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java index 115f35e55..530fc24da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java @@ -2,7 +2,6 @@ package com.yomahub.liteflow.test.exception; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.exception.ChainNotFoundException; -import com.yomahub.liteflow.exception.FlowSystemException; import com.yomahub.liteflow.exception.LiteFlowException; import com.yomahub.liteflow.exception.NoSwitchTargetNodeException; import com.yomahub.liteflow.flow.LiteflowResponse; @@ -10,10 +9,10 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; -import org.noear.solon.core.AopContext; +import org.noear.solon.core.AppContext; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 流程执行异常 单元测试 @@ -21,14 +20,14 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author zendwang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/exception/application.properties") +@Import(profiles="classpath:/exception/application.properties") public class Exception2ELSpringBootTest extends BaseTest { @Inject private FlowExecutor flowExecutor; @Inject - private AopContext context; + private AppContext context; @Test public void testChainNotFoundException() throws Exception { diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java index 2cdcf6ac2..705838dc4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java @@ -7,9 +7,10 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; + import java.util.concurrent.Future; /** @@ -19,7 +20,7 @@ import java.util.concurrent.Future; * @since 2.6.13 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/execute2Future/application.properties") +@Import(profiles="classpath:/execute2Future/application.properties") public class Executor2FutureELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSolonTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSolonTest.java index db1603212..dae75cc12 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSolonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSolonTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -20,7 +20,7 @@ import java.util.concurrent.Future; * @since 2.11.1 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/fallback/application.properties") +@Import(profiles="classpath:/fallback/application.properties") public class FallbackELSolonTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java index 32813ffe3..f528524e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("bn1") -@FallbackCmp -public class BreakCmp extends NodeBreakComponent { +@FallbackCmp(BooleanTypeEnum.BREAK) +public class BreakCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java index 62b47dec1..6d999baac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("ifn1") -public class IfCmp1 extends NodeIfComponent { +public class IfCmp1 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java index c5b20fcd8..5be4620bd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("ifn2") -@FallbackCmp -public class IfCmp2 extends NodeIfComponent { +@FallbackCmp(BooleanTypeEnum.IF) +public class IfCmp2 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java index 6769480c6..f732ca792 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("wn1") -public class WhileCmp1 extends NodeWhileComponent { +public class WhileCmp1 extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java index b198faa0e..3f88484ee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("wn2") -@FallbackCmp -public class WhileCmp2 extends NodeWhileComponent { +@FallbackCmp(BooleanTypeEnum.WHILE) +public class WhileCmp2 extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java index c1ec728ed..41bba0aeb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境获取ChainName的测试 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/getChainName/application.properties") +@Import(profiles="classpath:/getChainName/application.properties") public class GetChainNameELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java index 3138f2f80..92924a969 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/ifelse/application.properties") +@Import(profiles="classpath:/ifelse/application.properties") public class IfELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java index d8af1a880..66a5eaa8f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java @@ -7,14 +7,14 @@ */ package com.yomahub.liteflow.test.ifelse.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.noear.solon.annotation.Component; @Component("x1") -public class X1Cmp extends NodeIfComponent { +public class X1Cmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return Boolean.parseBoolean(this.getTag()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringbootTest.java index 1e40ced58..5260c9dad 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试@LiteflowComponent标注 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.10 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/lfCmpAnno/application.properties") +@Import(profiles="classpath:/lfCmpAnno/application.properties") public class LiteflowComponentELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java index e70731910..00abc254e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL循环的例子测试 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/loop/application.properties") +@Import(profiles="classpath:/loop/application.properties") public class LoopELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java index c4bb114c9..449f0dfac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java @@ -1,15 +1,15 @@ package com.yomahub.liteflow.test.loop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.core.NodeForComponent; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); int count = context.getData("test"); return count > 3; diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java index c7bb40e7c..bba3dd601 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java @@ -1,15 +1,15 @@ package com.yomahub.liteflow.test.loop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); String key = "test"; if (context.hasData(key)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/MaxWaitMillisecondsSolonTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/MaxWaitMillisecondsSolonTest.java index d246c786b..3c977c1ed 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/MaxWaitMillisecondsSolonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/MaxWaitMillisecondsSolonTest.java @@ -14,9 +14,9 @@ import com.yomahub.liteflow.test.maxWaitSeconds.cmp.CCmp; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import java.util.concurrent.TimeoutException; @@ -29,7 +29,7 @@ import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY; * @since 2.11.1 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/maxWaitMilliseconds/application.properties") +@Import(profiles="classpath:/maxWaitMilliseconds/application.properties") public class MaxWaitMillisecondsSolonTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java index dbed32163..970fb121b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("f") -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java index 433c8bec5..f881557df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsSolonTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsSolonTest.java index 981d6b215..b4c40a3ad 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsSolonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsSolonTest.java @@ -14,9 +14,9 @@ import com.yomahub.liteflow.test.maxWaitSeconds.cmp.CCmp; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import java.util.concurrent.TimeoutException; @@ -29,7 +29,7 @@ import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY; * @since 2.11.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/maxWaitSeconds/application.properties") +@Import(profiles="classpath:/maxWaitSeconds/application.properties") public class MaxWaitSecondsSolonTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java index 89ef9f92d..7674a4f41 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("f") -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java index 1db12e3de..ead8b1ae9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java index 69db27030..dbdf47464 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java @@ -9,9 +9,9 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境最普通的例子测试 @@ -20,7 +20,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/monitor/application.properties") +@Import(profiles="classpath:/monitor/application.properties") public class MonitorELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java index 8c9173c28..5a718dc70 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java @@ -9,9 +9,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境最普通的例子测试 @@ -20,7 +20,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/multiContext/application.properties") +@Import(profiles="classpath:/multiContext/application.properties") public class MultiContextELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java index 5052d86a5..3a10ed4cf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试springboot下混合格式规则的场景 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.10 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/multipleType/application.properties") +@Import(profiles="classpath:/multipleType/application.properties") public class LiteflowMultipleTypeELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java index 524199bbd..063675732 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试springboot下的组件重试 @@ -18,7 +18,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.10 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/nodeExecutor/application.properties") +@Import(profiles="classpath:/nodeExecutor/application.properties") public class LiteflowNodeExecutorELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java index f2ffff350..ad15f97c7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 单元测试:传递null param导致NPE的优化代码 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.6.6 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/nullParam/application.properties") +@Import(profiles="classpath:/nullParam/application.properties") public class NullParamELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopELSpringbootTest.java index fffe2b305..e19394d65 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopELSpringbootTest.java @@ -9,11 +9,10 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; -//import javax.annotation.Resource; import java.util.List; import java.util.regex.Pattern; @@ -24,7 +23,7 @@ import java.util.regex.Pattern; * @since 2.11.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parallelLoop/application.properties") +@Import(profiles="classpath:/parallelLoop/application.properties") public class ParallelLoopELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java index 0712fd95a..61df5c759 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java @@ -1,14 +1,14 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; @Component("y") -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); int count = 0; if(context.hasData("test")) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java index 332454777..edf604ba9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java @@ -1,14 +1,14 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; @Component("z") -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); String key = "test"; if (context.hasData(key)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java index 60911af80..3ecccc553 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境的自定义json parser单元测试 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parsecustom/application-custom-json.properties") +@Import(profiles="classpath:/parsecustom/application-custom-json.properties") public class CustomParserJsonELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java index 9a6b92ab2..8fff7ff8a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.7 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parsecustom/application-custom-xml.properties") +@Import(profiles="classpath:/parsecustom/application-custom-xml.properties") public class CustomParserXmlELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java index 7a61da242..798c368de 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境的自定义yml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author junjun */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parsecustom/application-custom-yml.properties") +@Import(profiles="classpath:/parsecustom/application-custom-yml.properties") public class CustomParserYmlELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java index 13e66a5f9..f50590f02 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * spring环境的json parser单元测试 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parser/application-json.properties") +@Import(profiles="classpath:/parser/application-json.properties") public class JsonParserELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java index 0e03bbc88..b66b02b1c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java @@ -6,12 +6,12 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parser/application-springEL.properties") +@Import(profiles="classpath:/parser/application-springEL.properties") public class SpringELSupportELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java index 5df5042b7..e77846c3b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境的xml parser单元测试 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parser/application-xml.properties") +@Import(profiles="classpath:/parser/application-xml.properties") public class XmlParserELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java index ba528c532..ad2ddac0d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot下的yml parser测试用例 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/parser/application-yml.properties") +@Import(profiles="classpath:/parser/application-yml.properties") public class YmlParserELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java index b652e25ef..2e9d4841f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下pre节点和finally节点的测试 @@ -18,7 +18,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/preAndFinally/application.properties") +@Import(profiles="classpath:/preAndFinally/application.properties") public class PreAndFinallyELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java index ed0558750..2d5498757 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java @@ -8,9 +8,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下隐私投递的测试 @@ -19,7 +19,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/privateDelivery/application.properties") +@Import(profiles="classpath:/privateDelivery/application.properties") public class PrivateDeliveryELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java index 605880ee6..33a870d20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java @@ -9,9 +9,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下重新加载规则测试 @@ -20,7 +20,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/refreshRule/application.properties") +@Import(profiles="classpath:/refreshRule/application.properties") public class RefreshRuleELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java index a42a3112b..07b7666b4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下重新加载规则测试 @@ -17,7 +17,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/reload/application.properties") +@Import(profiles="classpath:/reload/application.properties") public class ReloadELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java index c9d81b0b8..38a201f96 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境最普通的例子测试 @@ -18,7 +18,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/removeChain/application.properties") +@Import(profiles="classpath:/removeChain/application.properties") public class RemoveChainELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java index 269add359..95ef6040d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java @@ -6,15 +6,15 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * @author tangkc */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/requestId/application.properties") +@Import(profiles="classpath:/requestId/application.properties") public class LiteflowRequestIdELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringbootTest.java new file mode 100644 index 000000000..ed5371230 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringbootTest.java @@ -0,0 +1,113 @@ +package com.yomahub.liteflow.test.retry; + + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonJUnit5Extension; +import org.noear.solon.test.annotation.TestPropertySource; + +@ExtendWith(SolonJUnit5Extension.class) +@TestPropertySource("classpath:/retry/application.properties") +public class RetrySpringbootTest extends BaseTest { + + @Inject + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + + // 指定异常重试测试1 + @Test + public void testException1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // 指定异常重试测试2 + @Test + public void testException2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain12", "arg"); + Assertions.assertFalse(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java new file mode 100644 index 000000000..795d8247e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.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-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java new file mode 100644 index 000000000..0eb4b1573 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.Component; + +@Component("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java new file mode 100644 index 000000000..9d135e74d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeForComponent; +import org.noear.solon.annotation.Component; + +@Component("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java new file mode 100644 index 000000000..7848456db --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import org.noear.solon.annotation.Component; + +@Component("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java new file mode 100644 index 000000000..fe2a07702 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import org.noear.solon.annotation.Component; + +@Component("f") +public class FCmp extends NodeBooleanComponent { + int flag = 0; + @Override + public boolean processBoolean() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java new file mode 100644 index 000000000..a711d5b4f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.noear.solon.annotation.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java new file mode 100644 index 000000000..37e1d9f35 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.ELParseException; +import org.noear.solon.annotation.Component; + +@Component("m") +public class MCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() throws Exception { + flag ++; + System.out.println("MCmp executed!"); + if(flag < 4) throw new ELParseException("MCmp error!"); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java new file mode 100644 index 000000000..463bc84a1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import org.noear.solon.annotation.Component; + +@Component("n") +public class NCmp extends NodeBooleanComponent { + int flag = 0; + + @Override + public boolean processBoolean() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/RollbackSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/RollbackSpringbootTest.java index fdaa63d62..464059e6f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/RollbackSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/RollbackSpringbootTest.java @@ -7,13 +7,13 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/rollback/application.properties") +@Import(profiles="classpath:/rollback/application.properties") public class RollbackSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java index f2935ff68..4918dccf6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.noear.solon.annotation.Component; @Component("h") -public class HCmp extends NodeBreakComponent { +public class HCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("HCmp executed!"); throw new RuntimeException(); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java index 6e72a9c86..b25b04ca9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.noear.solon.annotation.Component; @Component("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("WCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java index d165ba325..8a468e247 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.noear.solon.annotation.Component;; @Component("x") -public class XCmp extends NodeIfComponent { +public class XCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("XCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java index d463b70ac..dba7ce268 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import java.util.HashSet; import java.util.Set; @@ -20,7 +20,7 @@ import java.util.Set; * @author justin.xu */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/subflow/application-implicit.properties") +@Import(profiles="classpath:/subflow/application-implicit.properties") public class ImplicitSubFlowELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java index 46d611a9a..9f85741a8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java @@ -8,10 +8,10 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; -import org.noear.solon.core.AopContext; +import org.noear.solon.core.AppContext; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试主流程与子流程在不同的配置文件的场景 @@ -19,7 +19,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/subflow/application-subInDifferentConfig1.properties") +@Import(profiles = "classpath:/subflow/application-subInDifferentConfig1.properties") public class SubflowInDifferentConfigELSpringbootTest extends BaseTest { @Inject @@ -34,7 +34,7 @@ public class SubflowInDifferentConfigELSpringbootTest extends BaseTest { } @Inject - private AopContext context; + private AppContext context; // 主要测试有不同的配置类型后会不会报出既定的错误 @Test diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java index 30d2e5ee4..428d218fa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试显示调用子流程(xml) 单元测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author justin.xu */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/subflow/application-xml.properties") +@Import(profiles ="classpath:/subflow/application-xml.properties") public class SubflowXMLELSpringBootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java index a85349784..d0bffb02d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试显示调用子流程(yml) 单元测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author justin.xu */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/subflow/application-yml.properties") +@Import(profiles ="classpath:/subflow/application-yml.properties") public class SubflowYmlELSpringBootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/SubflowJsonELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/SubflowJsonELSpringBootTest.java index 512d4870f..b0bf2c19f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/SubflowJsonELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/SubflowJsonELSpringBootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 测试显示调用子流程(json) 单元测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author justin.xu */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/subflow/application-json.properties") +@Import(profiles ="classpath:/subflow/application-json.properties") public class SubflowJsonELSpringBootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java index 7d1b2c09f..54cabd667 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 @@ -16,7 +16,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @author Bryan.Zhang */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/switchcase/application.properties") +@Import(profiles ="classpath:/switchcase/application.properties") public class SwitchELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java index d5301e3f3..277096fd8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java @@ -8,9 +8,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下隐私投递的测试 @@ -19,7 +19,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/tag/application-json.properties") +@Import(profiles ="classpath:/tag/application-json.properties") public class NodeTagELSpringbootJsonTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java index a25f63b63..2d123f80c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java @@ -8,9 +8,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下隐私投递的测试 @@ -19,7 +19,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.5.0 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/tag/application-xml.properties") +@Import(profiles ="classpath:/tag/application-xml.properties") public class NodeTagELSpringbootXmlTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java index f12ece677..49b7cd5f6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; /** * 在when异步节点的情况下去拿ThreadLocal里的测试场景 @@ -18,7 +18,7 @@ import org.noear.solon.test.annotation.TestPropertySource; * @since 2.6.3 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/useTTLInWhen/application.properties") +@Import(profiles ="classpath:/useTTLInWhen/application.properties") public class UseTTLInWhenELSpringbootTest extends BaseTest { @Inject diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java index 904fbcc9b..4d109e4da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java @@ -7,9 +7,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/whenTimeOut/application1.properties") +@Import(profiles ="classpath:/whenTimeOut/application1.properties") public class WhenTimeOutELSpringbootTest1 extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java index 3612d67d3..f797525f1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java @@ -6,9 +6,9 @@ import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit5Extension; -import org.noear.solon.test.annotation.TestPropertySource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory; * @since 2.6.4 */ @ExtendWith(SolonJUnit5Extension.class) -@TestPropertySource("classpath:/whenTimeOut/application2.properties") +@Import(profiles ="classpath:/whenTimeOut/application2.properties") public class WhenTimeOutELSpringbootTest2 extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retry/application.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retry/application.properties new file mode 100644 index 000000000..4323c74b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retry/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retry/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retry/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retry/flow.el.xml new file mode 100644 index 000000000..c567d84d5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retry/flow.el.xml @@ -0,0 +1,51 @@ + + + + THEN( a, b ).retry(3); + + + + WHEN( a, b ).retry(3); + + + + THEN( a, b.retry(3) ); + + + + FOR(c).DO(a).retry(3); + + + + SWITCH(d).TO(a).retry(3); + + + + IF(f, a).retry(3); + + + + WHILE(n).DO(a).retry(3); + + + + ITERATOR(i).DO(a).retry(3); + + + + THEN( a, b ).retry(1); + + + + THEN( a, FINALLY(b, a).retry(3) ); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.ELParseException", "com.yomahub.liteflow.exception.FlowSystemException"); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.AndOrConditionException"); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java index e2c16b4ae..c89cb352a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.abstractChain.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("c") -public class CCmp extends NodeIfComponent { +public class CCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { //do your biz return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELOperatorSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELOperatorSpringbootTest.java new file mode 100644 index 000000000..d6ebc9587 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELOperatorSpringbootTest.java @@ -0,0 +1,58 @@ +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.test.BaseTest; +import com.yomahub.liteflow.test.aop.aspect.CustomOperatorAspect; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 javax.annotation.Resource; + +/** + * 切面场景单元测试 + * + * @author luo yi + */ +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = CustomAOPELOperatorSpringbootTest.class) +@EnableAutoConfiguration +@Import(CustomOperatorAspect.class) +@ComponentScan({ "com.yomahub.liteflow.test.aop.cmp1", "com.yomahub.liteflow.test.aop.cmp2" }) +public class CustomAOPELOperatorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 设置 isContinueOnError 测试全局 AOP,串行场景 + @Test + public void testGlobalAopErrorWithContinueS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("before_after", context.getData("a")); + Assertions.assertEquals("before_after", context.getData("b")); + Assertions.assertEquals("before_after", context.getData("c")); + Assertions.assertEquals("before", context.getData("f")); + } + + // 设置 isContinueOnError 测试全局 AOP,并行场景 + @Test + public void testGlobalAopErrorWithContinueP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("before_after", context.getData("a")); + Assertions.assertEquals("before_after", context.getData("b")); + Assertions.assertEquals("before_after", context.getData("c")); + Assertions.assertEquals("before_after", context.getData("e")); + Assertions.assertEquals("before", context.getData("f")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELOperatorSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELOperatorSpringbootTest.java new file mode 100644 index 000000000..8a3dd6cf1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELOperatorSpringbootTest.java @@ -0,0 +1,66 @@ +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.CmpOperatorAspect; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 javax.annotation.Resource; + +/** + * 切面场景单元测试 + * + * @author luo yi + */ +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = GlobalAOPELOperatorSpringbootTest.class) +@EnableAutoConfiguration +@Import(CmpOperatorAspect.class) +@ComponentScan({ "com.yomahub.liteflow.test.aop.cmp1", "com.yomahub.liteflow.test.aop.cmp2" }) +public class GlobalAOPELOperatorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 设置 isContinueOnError 测试全局 AOP,串行场景 + @Test + public void testGlobalAopErrorWithContinueS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("before_after", context.getData("a")); + Assertions.assertEquals("before_after", context.getData("b")); + Assertions.assertEquals("before_after", context.getData("c")); + Assertions.assertEquals("test error", context.getData("f_error")); + } + + // 设置 isContinueOnError 测试全局 AOP,并行场景 + @Test + public void testGlobalAopErrorWithContinueP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("before_after", context.getData("a")); + Assertions.assertEquals("before_after", context.getData("b")); + Assertions.assertEquals("before_after", context.getData("c")); + Assertions.assertEquals("before_after", context.getData("e")); + Assertions.assertEquals("test error", context.getData("f_error")); + } + + @AfterAll + public static void cleanScanCache() { + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpOperatorAspect.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpOperatorAspect.java new file mode 100644 index 000000000..783d92ce9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpOperatorAspect.java @@ -0,0 +1,34 @@ +package com.yomahub.liteflow.test.aop.aspect; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.aop.ICmpAroundAspect; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class CmpOperatorAspect implements ICmpAroundAspect { + + @Override + public void beforeProcess(NodeComponent cmp) { + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId(), "before"); + } + + @Override + public void afterProcess(NodeComponent cmp) { + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); + } + + @Override + public void onSuccess(NodeComponent cmp) { + + } + + @Override + public void onError(NodeComponent cmp, Exception e) { + cmp.setIsContinueOnError(true); + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId() + "_error", e.getMessage()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomOperatorAspect.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomOperatorAspect.java new file mode 100644 index 000000000..964546da2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomOperatorAspect.java @@ -0,0 +1,29 @@ +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 CustomOperatorAspect { + + @Pointcut("execution(* com.yomahub.liteflow.test.aop.*.*.process())") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + DefaultContext context = cmp.getFirstContextBean(); + cmp.setIsContinueOnError(true); + 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-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java index c2361cacb..c33792217 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java @@ -17,5 +17,4 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } - } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java index 6b6f84b41..f744fdbb8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java @@ -18,4 +18,9 @@ public class CCmp extends NodeComponent { System.out.println("CCmp executed!"); } + @Override + public boolean isAccess() { + System.out.println("hello"); + return true; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/BK.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/BK.java index 54353a351..dc0844ba2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/BK.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/BK.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.booleanOpt.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("bk") -public class BK extends NodeBreakComponent { +public class BK extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { int index = this.getLoopIndex(); return index > 2; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W1.java index 24e4d686d..e2cb66e2f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W1.java @@ -7,14 +7,14 @@ */ package com.yomahub.liteflow.test.booleanOpt.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("w1") -public class W1 extends NodeWhileComponent { +public class W1 extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W2.java index 07007d85d..7c9581d21 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/W2.java @@ -7,14 +7,14 @@ */ package com.yomahub.liteflow.test.booleanOpt.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("w2") -public class W2 extends NodeWhileComponent { +public class W2 extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X1.java index afa69979e..b6e2d7f20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X1.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.booleanOpt.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x1") -public class X1 extends NodeIfComponent { +public class X1 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X2.java index 266c7457a..1152e5c8a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X2.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.booleanOpt.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x2") -public class X2 extends NodeIfComponent { +public class X2 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X3.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X3.java index dea18a14d..6df5c4b68 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X3.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.booleanOpt.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x3") -public class X3 extends NodeIfComponent { +public class X3 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X4.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X4.java index 1de35a3b3..ecfe9f94b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X4.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/booleanOpt/cmp/X4.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.booleanOpt.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x4") -public class X4 extends NodeIfComponent { +public class X4 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/ContextBeanSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/ContextBeanSpringbootTest.java new file mode 100644 index 000000000..55567ea7e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/ContextBeanSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.contextBean; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.contextBean.context.TestContext; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 javax.annotation.Resource; + +/** + * ContextBean测试 + * + * @author Bryan.Zhang + */ +@TestPropertySource(value = "classpath:/contextBean/application.properties") +@SpringBootTest(classes = ContextBeanSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.contextBean.cmp" }) +public class ContextBeanSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 最简单的情况 + @Test + public void testContextBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", TestContext.class); + Assertions.assertTrue(response.isSuccess()); + TestContext context = response.getContextBean("skuContext"); + Assertions.assertEquals("J001", context.getSkuCode()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/cmp/ACmp.java new file mode 100644 index 000000000..45119e9d9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/cmp/ACmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.contextBean.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.test.contextBean.context.TestContext; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + TestContext context = this.getContextBean("skuContext"); + context.setSkuCode("J001"); + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/cmp/BCmp.java new file mode 100644 index 000000000..1e8c6d1b1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/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.contextBean.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-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/context/TestContext.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/context/TestContext.java new file mode 100644 index 000000000..9f83e3b39 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/contextBean/context/TestContext.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.test.contextBean.context; + +import com.yomahub.liteflow.context.ContextBean; + +@ContextBean("skuContext") +public class TestContext { + + private String skuCode; + + private String skuName; + + public TestContext(String skuCode, String skuName) { + this.skuCode = skuCode; + this.skuName = skuName; + } + + public String getSkuCode() { + return skuCode; + } + + public void setSkuCode(String skuCode) { + this.skuCode = skuCode; + } + + public String getSkuName() { + return skuName; + } + + public void setSkuName(String skuName) { + this.skuName = skuName; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java index 32813ffe3..f528524e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("bn1") -@FallbackCmp -public class BreakCmp extends NodeBreakComponent { +@FallbackCmp(BooleanTypeEnum.BREAK) +public class BreakCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java index 62b47dec1..6d999baac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("ifn1") -public class IfCmp1 extends NodeIfComponent { +public class IfCmp1 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java index c5b20fcd8..5be4620bd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("ifn2") -@FallbackCmp -public class IfCmp2 extends NodeIfComponent { +@FallbackCmp(BooleanTypeEnum.IF) +public class IfCmp2 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java index 6769480c6..f732ca792 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("wn1") -public class WhileCmp1 extends NodeWhileComponent { +public class WhileCmp1 extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java index b198faa0e..3f88484ee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("wn2") -@FallbackCmp -public class WhileCmp2 extends NodeWhileComponent { +@FallbackCmp(BooleanTypeEnum.WHILE) +public class WhileCmp2 extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java index ad0f8158d..b707e2778 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java @@ -7,14 +7,14 @@ */ package com.yomahub.liteflow.test.ifelse.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x1") -public class X1Cmp extends NodeIfComponent { +public class X1Cmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return Boolean.parseBoolean(this.getTag()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X2Cmp.java index 704532893..d74b46fb4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X2Cmp.java @@ -7,14 +7,14 @@ */ package com.yomahub.liteflow.test.ifelse.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x2") -public class X2Cmp extends NodeIfComponent { +public class X2Cmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java index c0eccdb98..172d424cf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java @@ -1,15 +1,15 @@ package com.yomahub.liteflow.test.iterator.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; @Component("b") -public class BCmp extends NodeBreakComponent { +public class BCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return this.getLoopIndex() == 1; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java index b70b16114..a4ad69cf6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java @@ -1,15 +1,15 @@ package com.yomahub.liteflow.test.loop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.core.NodeForComponent; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return this.getLoopIndex() > 2; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java index 1d464cae7..d8baa25ad 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java @@ -1,15 +1,15 @@ package com.yomahub.liteflow.test.loop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { return this.getLoopIndex()<5; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java index dbed32163..970fb121b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("f") -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java index 433c8bec5..f881557df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringbootTest.java index a71ce42e4..611e39c17 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringbootTest.java @@ -182,6 +182,16 @@ public class MaxWaitSecondsELSpringbootTest extends BaseTest { assertNotTimeout("chain2"); } + // 测试超时情况下组件还在运行的场景是否会报错 + @Test + public void testChain3() { + DefaultContext context = new DefaultContext(); + context.setData("test", "123"); + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg", context); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals(TimeoutException.class, response.getCause().getClass()); + } + private void assertTimeout(String chainId) { LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg"); Assertions.assertFalse(response.isSuccess()); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/ECmp.java new file mode 100644 index 000000000..a87f87d0f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/ECmp.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent("e") +public class ECmp extends NodeComponent { + @Override + public void process() throws Exception{ + DefaultContext context = this.getFirstContextBean(); + for (int i = 0; i < 10; i++) { + String str = context.getData("test"); + System.out.println(str); + Thread.sleep(1000); + } + + System.out.println("ECmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java index 89ef9f92d..7674a4f41 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("f") -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java index 1db12e3de..ead8b1ae9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java index 2ac455183..ea6a03591 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java @@ -2,7 +2,7 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowMethod; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @@ -10,10 +10,10 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("y") -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); int count = 0; if(context.hasData("test")) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java index d1dfaf657..cd89c8059 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java @@ -3,17 +3,17 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("z") -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); String key = "test"; if (context.hasData(key)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringbootTest.java new file mode 100644 index 000000000..da8fa7f5e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringbootTest.java @@ -0,0 +1,117 @@ +package com.yomahub.liteflow.test.retry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 javax.annotation.Resource; + + +@TestPropertySource(value = "classpath:/retry/application.properties") +@SpringBootTest(classes = RetrySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.retry.cmp"}) +public class RetrySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + + // 指定异常重试测试1 + @Test + public void testException1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // 指定异常重试测试2 + @Test + public void testException2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain12", "arg"); + Assertions.assertFalse(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java new file mode 100644 index 000000000..98bcc2379 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + @Override + public void process() { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java new file mode 100644 index 000000000..d622bed92 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java new file mode 100644 index 000000000..ecf7f1a25 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeForComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java new file mode 100644 index 000000000..34e9bb5b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java new file mode 100644 index 000000000..81704f493 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("f") +public class FCmp extends NodeBooleanComponent { + int flag = 0; + @Override + public boolean processBoolean() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java new file mode 100644 index 000000000..9ccd8457e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java new file mode 100644 index 000000000..0498cee17 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.ELParseException; + +@LiteflowComponent("m") +public class MCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() throws Exception { + flag ++; + System.out.println("MCmp executed!"); + if(flag < 4) throw new ELParseException("MCmp error!"); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java new file mode 100644 index 000000000..e72524abb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("n") +public class NCmp extends NodeBooleanComponent { + int flag = 0; + + @Override + public boolean processBoolean() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java index 19ebef9b3..a2d3ebe5f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("h") -public class HCmp extends NodeBreakComponent { +public class HCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("HCmp executed!"); throw new RuntimeException(); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java index 3f0fd80d4..81233ca78 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("WCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java index 9928246c4..7d161a2d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x") -public class XCmp extends NodeIfComponent { +public class XCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("XCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/RouteSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/RouteSpringbootTest.java new file mode 100644 index 000000000..315964999 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/RouteSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.route; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 javax.annotation.Resource; + +/** + * springboot环境EL常规的例子测试 + * + * @author Bryan.Zhang + */ +@TestPropertySource(value = "classpath:/route/application.properties") +@SpringBootTest(classes = RouteSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.route.cmp" }) +public class RouteSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 最简单的情况 + @Test + public void testRoute1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("r_chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + @Test + public void testRoute2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("r_chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/ACmp.java new file mode 100644 index 000000000..ea62ff2ab --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/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.route.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-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/BCmp.java new file mode 100644 index 000000000..2f71f619d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/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.route.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-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/R1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/R1.java new file mode 100644 index 000000000..e74b21ba7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/R1.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.route.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("r1") +public class R1 extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/R2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/R2.java new file mode 100644 index 000000000..2faee1887 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/route/cmp/R2.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.route.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; + +@LiteflowComponent("r2") +public class R2 extends NodeBooleanComponent { + @Override + public boolean processBoolean() throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java index f5778fcd9..9c3cb6bd0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -16,7 +16,7 @@ public class BCmp extends NodeComponent { @Override public void process() { try { - Thread.sleep(4000); + Thread.sleep(2000); } catch (Exception ignored) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java index e50c9689e..abdb1f12e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -14,14 +14,11 @@ import org.springframework.stereotype.Component; public class CCmp extends NodeComponent { @Override - public void process() { - try { - Thread.sleep(3500); + public void process() throws Exception{ + for (int i = 0; i < 10; i++) { + System.out.println("executing cmp c"); + Thread.sleep(500); } - catch (Exception ignored) { - - } - System.out.println("CCmp executed!"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/aop/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/aop/flow.el.xml index 8b89951a2..4937d9e5b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/aop/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/aop/flow.el.xml @@ -11,4 +11,13 @@ THEN(a,b,c,f); + + + THEN(a, f, b, c); + + + + THEN(a, b, WHEN(f, e), c); + +
\ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/base/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/base/flow.el.xml index af69a1c64..aab117311 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/base/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/base/flow.el.xml @@ -2,7 +2,7 @@ - THEN(a,b,WHEN(c,d)); + THEN(a,b,b,a); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/contextBean/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/contextBean/application.properties new file mode 100644 index 000000000..5b68813b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/contextBean/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=contextBean/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/contextBean/flow.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/contextBean/flow.xml new file mode 100644 index 000000000..84d650db4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/contextBean/flow.xml @@ -0,0 +1,7 @@ + + + + + THEN(a,b); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/flow.el.xml index 91869ae50..8fd19db05 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/flow.el.xml @@ -107,4 +107,8 @@ testChain.maxWaitSeconds(3); + + + THEN(a, b, e).maxWaitSeconds(8); + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retry/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retry/application.properties new file mode 100644 index 000000000..4323c74b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retry/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retry/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retry/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retry/flow.el.xml new file mode 100644 index 000000000..6e3410c57 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retry/flow.el.xml @@ -0,0 +1,50 @@ + + + + THEN( a, b ).retry(3); + + + + WHEN( a, b ).retry(3); + + + + THEN( a, b.retry(3) ); + + + + FOR(c).DO(a).retry(3); + + + + SWITCH(d).TO(a).retry(3); + + + + IF(f, a).retry(3); + + + + WHILE(n).DO(a).retry(3); + + + + ITERATOR(i).DO(a).retry(3); + + + + THEN( a, b ).retry(1); + + + + THEN( a, FINALLY(b, a).retry(3) ); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.ELParseException", "com.yomahub.liteflow.exception.FlowSystemException"); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.AndOrConditionException"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/route/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/route/application.properties new file mode 100644 index 000000000..0a81040f7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/route/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=route/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/route/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/route/flow.el.xml new file mode 100644 index 000000000..f752f2f1f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/route/flow.el.xml @@ -0,0 +1,21 @@ + + + + + + r1 + + + THEN(a,b); + + + + + + OR(r1,r2) + + + THEN(a,b); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java index e2c16b4ae..c89cb352a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/abstractChain/cmp/CCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.abstractChain.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("c") -public class CCmp extends NodeIfComponent { +public class CCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { //do your biz return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java index 32813ffe3..f528524e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("bn1") -@FallbackCmp -public class BreakCmp extends NodeBreakComponent { +@FallbackCmp(BooleanTypeEnum.BREAK) +public class BreakCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java index 62b47dec1..6d999baac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("ifn1") -public class IfCmp1 extends NodeIfComponent { +public class IfCmp1 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java index c5b20fcd8..5be4620bd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("ifn2") -@FallbackCmp -public class IfCmp2 extends NodeIfComponent { +@FallbackCmp(BooleanTypeEnum.IF) +public class IfCmp2 extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java index 6769480c6..f732ca792 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("wn1") -public class WhileCmp1 extends NodeWhileComponent { +public class WhileCmp1 extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java index b198faa0e..3f88484ee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -2,14 +2,15 @@ package com.yomahub.liteflow.test.fallback.cmp; import com.yomahub.liteflow.annotation.FallbackCmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.enums.BooleanTypeEnum; @LiteflowComponent("wn2") -@FallbackCmp -public class WhileCmp2 extends NodeWhileComponent { +@FallbackCmp(BooleanTypeEnum.WHILE) +public class WhileCmp2 extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { return false; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java index ad0f8158d..b707e2778 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/X1Cmp.java @@ -7,14 +7,14 @@ */ package com.yomahub.liteflow.test.ifelse.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x1") -public class X1Cmp extends NodeIfComponent { +public class X1Cmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return Boolean.parseBoolean(this.getTag()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java index e6dcd45a7..e06262e86 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/BCmp.java @@ -1,14 +1,14 @@ package com.yomahub.liteflow.test.iterator.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("b") -public class BCmp extends NodeBreakComponent { +public class BCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { return this.getLoopIndex() == 1; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java index 6a820a638..1ff92b000 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/YCmp.java @@ -1,14 +1,14 @@ package com.yomahub.liteflow.test.loop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); int count = context.getData("test"); return count > 3; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java index 78c621f2b..209bcbb46 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ZCmp.java @@ -1,14 +1,14 @@ package com.yomahub.liteflow.test.loop.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); String key = "test"; if (context.hasData(key)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java index dbed32163..970fb121b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/FCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("f") -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java index 433c8bec5..f881557df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitMilliseconds/cmp/WCmp.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.maxWaitMilliseconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java index 89ef9f92d..7674a4f41 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; @LiteflowComponent("f") -public class FCmp extends NodeIfComponent { +public class FCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { return true; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java index 1db12e3de..ead8b1ae9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java @@ -1,20 +1,20 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp; import com.yomahub.liteflow.annotation.LiteflowComponent; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import java.util.HashSet; import java.util.Set; @LiteflowComponent("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { private int count = 0; // 执行过的 chain Set executedChain = new HashSet<>(); @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { // 判断是否切换了 chain if (!executedChain.contains(this.getCurrChainId())) { count = 0; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java index 8975f7f3b..dee9e1899 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/YCmp.java @@ -1,14 +1,14 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("y") -public class YCmp extends NodeBreakComponent { +public class YCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); int count = 0; if(context.hasData("test")) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java index 844a6ff25..134489c62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/ZCmp.java @@ -1,14 +1,14 @@ package com.yomahub.liteflow.test.parallelLoop.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("z") -public class ZCmp extends NodeWhileComponent { +public class ZCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { DefaultContext context = this.getFirstContextBean(); String key = "test"; if (context.hasData(key)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringTest.java new file mode 100644 index 000000000..be03cb224 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/RetrySpringTest.java @@ -0,0 +1,114 @@ +package com.yomahub.liteflow.test.retry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + + +@ExtendWith(SpringExtension.class) +@ContextConfiguration("classpath:/retry/application.xml") +public class RetrySpringTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + + // 指定异常重试测试1 + @Test + public void testException1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // 指定异常重试测试2 + @Test + public void testException2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain12", "arg"); + Assertions.assertFalse(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java new file mode 100644 index 000000000..e56306412 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retry.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-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java new file mode 100644 index 000000000..85898c803 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java new file mode 100644 index 000000000..c3ed52c34 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeForComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java new file mode 100644 index 000000000..236546f45 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java new file mode 100644 index 000000000..5172ab902 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeBooleanComponent { + int flag = 0; + @Override + public boolean processBoolean() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java new file mode 100644 index 000000000..5c29b8d15 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retry.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.springframework.stereotype.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java new file mode 100644 index 000000000..cf7755b06 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/MCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.ELParseException; +import org.springframework.stereotype.Component; + +@Component("m") +public class MCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() throws Exception { + flag ++; + System.out.println("MCmp executed!"); + if(flag < 4) throw new ELParseException("MCmp error!"); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java new file mode 100644 index 000000000..5543be3b9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retry/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retry.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import org.springframework.stereotype.Component; + +@Component("n") +public class NCmp extends NodeBooleanComponent { + int flag = 0; + + @Override + public boolean processBoolean() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java index 19ebef9b3..a2d3ebe5f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/HCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeBreakComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("h") -public class HCmp extends NodeBreakComponent { +public class HCmp extends NodeBooleanComponent { @Override - public boolean processBreak() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("HCmp executed!"); throw new RuntimeException(); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java index 3f0fd80d4..81233ca78 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/WCmp.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeWhileComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("w") -public class WCmp extends NodeWhileComponent { +public class WCmp extends NodeBooleanComponent { @Override - public boolean processWhile() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("WCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java index 9928246c4..7d161a2d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/rollback/cmp/XCmp.java @@ -1,12 +1,12 @@ package com.yomahub.liteflow.test.rollback.cmp; -import com.yomahub.liteflow.core.NodeIfComponent; +import com.yomahub.liteflow.core.NodeBooleanComponent; import org.springframework.stereotype.Component; @Component("x") -public class XCmp extends NodeIfComponent { +public class XCmp extends NodeBooleanComponent { @Override - public boolean processIf() throws Exception { + public boolean processBoolean() throws Exception { System.out.println("XCmp executed!"); return true; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retry/application.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retry/application.xml new file mode 100644 index 000000000..441929a5c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retry/application.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retry/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retry/flow.el.xml new file mode 100644 index 000000000..c567d84d5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retry/flow.el.xml @@ -0,0 +1,51 @@ + + + + THEN( a, b ).retry(3); + + + + WHEN( a, b ).retry(3); + + + + THEN( a, b.retry(3) ); + + + + FOR(c).DO(a).retry(3); + + + + SWITCH(d).TO(a).retry(3); + + + + IF(f, a).retry(3); + + + + WHILE(n).DO(a).retry(3); + + + + ITERATOR(i).DO(a).retry(3); + + + + THEN( a, b ).retry(1); + + + + THEN( a, FINALLY(b, a).retry(3) ); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.ELParseException", "com.yomahub.liteflow.exception.FlowSystemException"); + + + + THEN( a, m ).retry(3, "com.yomahub.liteflow.exception.AndOrConditionException"); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql index dda527ee6..f6875cc64 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql @@ -8,7 +8,7 @@ INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain DELETE FROM SCRIPT_NODE_TABLE; -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','if_script','return true','groovy'); -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','if_script','return false','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','boolean_script','return true','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','boolean_script','return false','groovy'); -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','if_script','return true','js'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','boolean_script','return true','js'); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql index 35412b6a8..2b83a0685 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql @@ -17,11 +17,11 @@ FROM SCRIPT_NODE_TABLE; INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, SCRIPT_LANGUAGE) -values ('demo', 'x01', 'if 脚本', 'if_script', 'return true', 'groovy'); +values ('demo', 'x01', 'if 脚本', 'boolean_script', 'return true', 'groovy'); INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, SCRIPT_LANGUAGE) -values ('demo', 'x11', 'if 脚本', 'if_script', 'return false', 'groovy'); +values ('demo', 'x11', 'if 脚本', 'boolean_script', 'return false', 'groovy'); INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, SCRIPT_LANGUAGE) -values ('demo', 'x21', 'python脚本', 'if_script', 'return true', 'js'); +values ('demo', 'x21', 'python脚本', 'boolean_script', 'return true', 'js'); 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 index 5900dfa0a..5453c149e 100644 --- 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 @@ -8,7 +8,7 @@ INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain DELETE FROM SCRIPT_NODE_TABLE; -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','if_script','return true','groovy'); -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','if_script','return true','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','boolean_script','return true','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','boolean_script','return true','groovy'); -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','if_script','return true','js'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','boolean_script','return true','js'); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/sql-lite/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/sql-lite/data.sql index dda527ee6..f6875cc64 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/sql-lite/data.sql +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/resources/sql/sql-lite/data.sql @@ -8,7 +8,7 @@ INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain DELETE FROM SCRIPT_NODE_TABLE; -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','if_script','return true','groovy'); -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','if_script','return false','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','boolean_script','return true','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','boolean_script','return false','groovy'); -INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','if_script','return true','js'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','boolean_script','return true','js'); diff --git a/pom.xml b/pom.xml index 789f9544e..94426b9fa 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ - 2.11.4 + 2.12.0 UTF-8 UTF-8 8 @@ -64,7 +64,7 @@ 1.14.10 1.8.13 1.2.3 - 2.5.3 + 2.6.5 4.1.84.Final 4.5.13 1.9.4 diff --git a/static/img/fb-banner.png b/static/img/fb-banner.png new file mode 100644 index 000000000..12f4cdd59 Binary files /dev/null and b/static/img/fb-banner.png differ diff --git a/static/img/zsxq-gitee.png b/static/img/zsxq-gitee.png new file mode 100644 index 000000000..be9c435ea Binary files /dev/null and b/static/img/zsxq-gitee.png differ diff --git a/static/img/zsxq-github.png b/static/img/zsxq-github.png new file mode 100644 index 000000000..cf97787a6 Binary files /dev/null and b/static/img/zsxq-github.png differ