diff --git a/.springjavaformatconfig b/.springjavaformatconfig new file mode 100644 index 00000000..12643781 --- /dev/null +++ b/.springjavaformatconfig @@ -0,0 +1 @@ +java-baseline=8 \ No newline at end of file diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/AliasFor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/AliasFor.java index de149a40..3839257d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/AliasFor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/AliasFor.java @@ -1,6 +1,7 @@ package com.yomahub.liteflow.annotation; import java.lang.annotation.*; + /** * @author Bryan.Zhang */ @@ -9,5 +10,6 @@ import java.lang.annotation.*; @Documented public @interface AliasFor { - String value() default ""; + String value() default ""; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java index 65cd2c4e..6e146819 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java @@ -3,14 +3,16 @@ package com.yomahub.liteflow.annotation; import com.yomahub.liteflow.enums.NodeTypeEnum; import java.lang.annotation.*; + /** * @author Bryan.Zhang */ -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface LiteflowCmpDefine { - NodeTypeEnum value() default NodeTypeEnum.COMMON; + NodeTypeEnum value() default NodeTypeEnum.COMMON; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java index 0c36ea8e..589cf4ee 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java @@ -8,24 +8,24 @@ import java.lang.annotation.*; /** * @author Bryan.Zhang */ -@Target({ElementType.METHOD}) +@Target({ ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface LiteflowMethod { - LiteFlowMethodEnum value(); + LiteFlowMethodEnum value(); - /** - * 节点ID,用于区分节点 - * 默认为空 则按照Spring模式下BeanName为准。 - * @return - */ - String nodeId() default ""; + /** + * 节点ID,用于区分节点 默认为空 则按照Spring模式下BeanName为准。 + * @return + */ + String nodeId() default ""; + + /** + * CMP类型定义 + * @return AnnotationNodeTypeEnum + */ + NodeTypeEnum nodeType() default NodeTypeEnum.COMMON; - /** - * CMP类型定义 - * @return AnnotationNodeTypeEnum - */ - NodeTypeEnum nodeType() default NodeTypeEnum.COMMON; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java index bb49d4c5..d77c5450 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowRetry.java @@ -8,17 +8,18 @@ import java.lang.annotation.*; * @author Bryan.Zhang * @since 2.6.0 */ -@Target({ElementType.TYPE,ElementType.METHOD}) +@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface LiteflowRetry { - @AliasFor("retry") - int value() default 0; + @AliasFor("retry") + int value() default 0; - @AliasFor("value") - int retry() default 0; + @AliasFor("value") + int retry() default 0; + + Class[] forExceptions() default { Exception.class }; - Class[] forExceptions() default {Exception.class}; } 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 09fb5362..1b018939 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 @@ -11,44 +11,48 @@ import java.lang.reflect.AnnotatedElement; import java.util.Arrays; import java.util.HashMap; import java.util.Map; + /** * 注解工具类 + * * @author Bryan.Zhang */ public class AnnoUtil { - public static A getAnnotation(AnnotatedElement annotatedElement, Class annotationType) { - A annotation = AnnotationUtil.getAnnotation(annotatedElement, annotationType); - if (ObjectUtil.isNull(annotation)){ - return null; - } + public static A getAnnotation(AnnotatedElement annotatedElement, Class annotationType) { + A annotation = AnnotationUtil.getAnnotation(annotatedElement, annotationType); + if (ObjectUtil.isNull(annotation)) { + return null; + } - Map aliasMap = new HashMap<>(); - Map defaultValueMap = new HashMap<>(); - Arrays.stream(ReflectUtil.getMethods(annotationType)).forEach(method -> { - AliasFor aliasFor = AnnotationUtil.getAnnotation(method, AliasFor.class); - if (ObjectUtil.isNotNull(aliasFor)){ - aliasMap.put(method.getName(), aliasFor.value()); - defaultValueMap.put(method.getName(), getDefaultValue(annotationType, method.getName())); - } - }); + Map aliasMap = new HashMap<>(); + Map defaultValueMap = new HashMap<>(); + Arrays.stream(ReflectUtil.getMethods(annotationType)).forEach(method -> { + AliasFor aliasFor = AnnotationUtil.getAnnotation(method, AliasFor.class); + if (ObjectUtil.isNotNull(aliasFor)) { + aliasMap.put(method.getName(), aliasFor.value()); + defaultValueMap.put(method.getName(), getDefaultValue(annotationType, method.getName())); + } + }); - aliasMap.forEach((key, value1) -> { - Object value = ReflectUtil.invoke(annotation, key); - Object defaultValue = defaultValueMap.get(key); - if (ObjectUtil.notEqual(value, defaultValue)) { - AnnotationUtil.setValue(annotation, value1, value); - } - }); + aliasMap.forEach((key, value1) -> { + Object value = ReflectUtil.invoke(annotation, key); + Object defaultValue = defaultValueMap.get(key); + if (ObjectUtil.notEqual(value, defaultValue)) { + AnnotationUtil.setValue(annotation, value1, value); + } + }); - return annotation; - } + return annotation; + } + + private static Object getDefaultValue(Class annotationType, String property) { + try { + return annotationType.getMethod(property).getDefaultValue(); + } + catch (Exception e) { + return null; + } + } - private static Object getDefaultValue(Class annotationType, String property){ - try{ - return annotationType.getMethod(property).getDefaultValue(); - }catch (Exception e){ - return null; - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/aop/ICmpAroundAspect.java b/liteflow-core/src/main/java/com/yomahub/liteflow/aop/ICmpAroundAspect.java index b2ec45a4..d8bff0d2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/aop/ICmpAroundAspect.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/aop/ICmpAroundAspect.java @@ -11,23 +11,24 @@ package com.yomahub.liteflow.aop; import com.yomahub.liteflow.slot.Slot; /** - * 全局组件拦截器接口 - * 实现这个接口并注入到spring上下文即可 + * 全局组件拦截器接口 实现这个接口并注入到spring上下文即可 + * * @author Bryan.Zhang */ public interface ICmpAroundAspect { - /** - * 前置处理 - * @param nodeId 节点ID - * @param slot - */ - void beforeProcess(String nodeId, Slot slot); + /** + * 前置处理 + * @param nodeId 节点ID + * @param slot + */ + void beforeProcess(String nodeId, Slot slot); + + /** + * 后置处理 + * @param nodeId 节点ID + * @param slot + */ + void afterProcess(String nodeId, Slot slot); - /** - * 后置处理 - * @param nodeId 节点ID - * @param slot - */ - void afterProcess(String nodeId, Slot slot); } 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 3849e3a0..1168f723 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 @@ -18,170 +18,178 @@ import java.util.Objects; public class LiteFlowNodeBuilder { - private final Logger LOG = LoggerFactory.getLogger(this.getClass()); + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); - private final Node node; + private final Node node; - public static LiteFlowNodeBuilder createNode() { - return new LiteFlowNodeBuilder(); - } + public static LiteFlowNodeBuilder createNode() { + return new LiteFlowNodeBuilder(); + } - public static LiteFlowNodeBuilder createCommonNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.COMMON); - } + public static LiteFlowNodeBuilder createCommonNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.COMMON); + } - public static LiteFlowNodeBuilder createSwitchNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH); - } + public static LiteFlowNodeBuilder createSwitchNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH); + } - public static LiteFlowNodeBuilder createIfNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.IF); - } + public static LiteFlowNodeBuilder createIfNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.IF); + } - public static LiteFlowNodeBuilder createForNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.FOR); - } + public static LiteFlowNodeBuilder createForNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.FOR); + } - public static LiteFlowNodeBuilder createWhileNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE); - } + public static LiteFlowNodeBuilder createWhileNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE); + } - public static LiteFlowNodeBuilder createBreakNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK); - } + public static LiteFlowNodeBuilder createBreakNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK); + } - public static LiteFlowNodeBuilder createIteratorNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.ITERATOR); - } + public static LiteFlowNodeBuilder createIteratorNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.ITERATOR); + } - public static LiteFlowNodeBuilder createScriptNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.SCRIPT); - } + public static LiteFlowNodeBuilder createScriptNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.SCRIPT); + } - public static LiteFlowNodeBuilder createScriptSwitchNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH_SCRIPT); - } + public static LiteFlowNodeBuilder createScriptSwitchNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.SWITCH_SCRIPT); + } - public static LiteFlowNodeBuilder createScriptIfNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.IF_SCRIPT); - } + public static LiteFlowNodeBuilder createScriptIfNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.IF_SCRIPT); + } - public static LiteFlowNodeBuilder createScriptForNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.FOR_SCRIPT); - } + public static LiteFlowNodeBuilder createScriptForNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.FOR_SCRIPT); + } - public static LiteFlowNodeBuilder createScriptWhileNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE_SCRIPT); - } + public static LiteFlowNodeBuilder createScriptWhileNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.WHILE_SCRIPT); + } - public static LiteFlowNodeBuilder createScriptBreakNode() { - return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK_SCRIPT); - } + public static LiteFlowNodeBuilder createScriptBreakNode() { + return new LiteFlowNodeBuilder(NodeTypeEnum.BREAK_SCRIPT); + } - public LiteFlowNodeBuilder() { - this.node = new Node(); - } + public LiteFlowNodeBuilder() { + this.node = new Node(); + } - public LiteFlowNodeBuilder(NodeTypeEnum type) { - this.node = new Node(); - this.node.setType(type); - } + public LiteFlowNodeBuilder(NodeTypeEnum type) { + this.node = new Node(); + this.node.setType(type); + } - public LiteFlowNodeBuilder setId(String nodeId) { - if (StrUtil.isBlank(nodeId)) { - return this; - } - this.node.setId(nodeId.trim()); - return this; - } + public LiteFlowNodeBuilder setId(String nodeId) { + if (StrUtil.isBlank(nodeId)) { + return this; + } + this.node.setId(nodeId.trim()); + return this; + } - public LiteFlowNodeBuilder setName(String name) { - if (StrUtil.isBlank(name)) { - return this; - } - this.node.setName(name.trim()); - return this; - } + public LiteFlowNodeBuilder setName(String name) { + if (StrUtil.isBlank(name)) { + return this; + } + this.node.setName(name.trim()); + return this; + } - public LiteFlowNodeBuilder setClazz(String clazz) { - if (StrUtil.isBlank(clazz)) { - return this; - } - this.node.setClazz(clazz.trim()); - return this; - } + public LiteFlowNodeBuilder setClazz(String clazz) { + if (StrUtil.isBlank(clazz)) { + return this; + } + this.node.setClazz(clazz.trim()); + return this; + } - public LiteFlowNodeBuilder setClazz(Class clazz) { - assert clazz != null; - setClazz(clazz.getName()); - return this; - } + public LiteFlowNodeBuilder setClazz(Class clazz) { + assert clazz != null; + setClazz(clazz.getName()); + return this; + } - public LiteFlowNodeBuilder setType(NodeTypeEnum type) { - this.node.setType(type); - return this; - } + public LiteFlowNodeBuilder setType(NodeTypeEnum type) { + this.node.setType(type); + return this; + } - public LiteFlowNodeBuilder setScript(String script) { - this.node.setScript(script); - return this; - } + public LiteFlowNodeBuilder setScript(String script) { + this.node.setScript(script); + return this; + } - public LiteFlowNodeBuilder setFile(String filePath) { - if (StrUtil.isBlank(filePath)) { - return this; - } - try { - List scriptList = PathContentParserHolder.loadContextAware().parseContent(ListUtil.toList(filePath)); - String script = CollUtil.getFirst(scriptList); - setScript(script); + public LiteFlowNodeBuilder setFile(String filePath) { + if (StrUtil.isBlank(filePath)) { + return this; + } + try { + List scriptList = PathContentParserHolder.loadContextAware() + .parseContent(ListUtil.toList(filePath)); + String script = CollUtil.getFirst(scriptList); + setScript(script); - // 添加脚本文件监听 - List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(ListUtil.toList(filePath)); - MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); - } catch (Exception e) { - String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(), e.getMessage()); - throw new NodeBuildException(errMsg); - } - return this; - } + // 添加脚本文件监听 + List fileAbsolutePath = PathContentParserHolder.loadContextAware() + .getFileAbsolutePath(ListUtil.toList(filePath)); + MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); + } + catch (Exception e) { + String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(), + e.getMessage()); + throw new NodeBuildException(errMsg); + } + return this; + } - public LiteFlowNodeBuilder setLanguage(String language) { - this.node.setLanguage(language); - return this; - } + public LiteFlowNodeBuilder setLanguage(String language) { + this.node.setLanguage(language); + return this; + } - public void build() { - checkBuild(); - try { - // 用于处理脚本 node - if (this.node.getType().isScript()){ - FlowBus.addScriptNode(this.node.getId(), this.node.getName(), this.node.getType(), this.node.getScript(), this.node.getLanguage()); - } - // 用于处理普通 node - else{ - FlowBus.addNode(this.node.getId(), this.node.getName(), this.node.getType(), this.node.getClazz()); - } - } catch (Exception e) { - String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(), e.getMessage()); - LOG.error(errMsg, e); - throw new NodeBuildException(errMsg); - } - } + public void build() { + checkBuild(); + try { + // 用于处理脚本 node + if (this.node.getType().isScript()) { + FlowBus.addScriptNode(this.node.getId(), this.node.getName(), this.node.getType(), + this.node.getScript(), this.node.getLanguage()); + } + // 用于处理普通 node + else { + FlowBus.addNode(this.node.getId(), this.node.getName(), this.node.getType(), this.node.getClazz()); + } + } + catch (Exception e) { + String errMsg = StrUtil.format("An exception occurred while building the node[{}],{}", this.node.getId(), + e.getMessage()); + LOG.error(errMsg, e); + throw new NodeBuildException(errMsg); + } + } + + /** + * build 前简单校验 + */ + private void checkBuild() { + List errorList = new ArrayList<>(); + if (StrUtil.isBlank(this.node.getId())) { + errorList.add("id is blank"); + } + if (Objects.isNull(this.node.getType())) { + errorList.add("type is null"); + } + if (CollUtil.isNotEmpty(errorList)) { + throw new NodeBuildException(CollUtil.join(errorList, ",", "[", "]")); + } + } - /** - * build 前简单校验 - */ - private void checkBuild() { - List errorList = new ArrayList<>(); - if (StrUtil.isBlank(this.node.getId())) { - errorList.add("id is blank"); - } - if (Objects.isNull(this.node.getType())) { - errorList.add("type is null"); - } - if (CollUtil.isNotEmpty(errorList)) { - throw new NodeBuildException(CollUtil.join(errorList, ",", "[", "]")); - } - } } 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 dee70ce9..7c025be6 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 @@ -25,238 +25,245 @@ import java.util.List; import java.util.Objects; /** - * Chain基于代码形式的组装器 - * EL表达式规则专属组装器 + * Chain基于代码形式的组装器 EL表达式规则专属组装器 * * @author Bryan.Zhang * @since 2.8.0 */ public class LiteFlowChainELBuilder { - private static final Logger LOG = LoggerFactory.getLogger(LiteFlowChainELBuilder.class); + private static final Logger LOG = LoggerFactory.getLogger(LiteFlowChainELBuilder.class); + private Chain chain; - private Chain chain; + /** + * //这是主体的Condition //声明这个变量,而不是用chain.getConditionList的目的,是为了辅助平滑加载 + * //虽然FlowBus里面的map都是CopyOnWrite类型的,但是在buildCondition的时候,为了平滑加载,所以不能事先把chain.getConditionList给设为空List + * //所以在这里做一个缓存,等conditionList全部build完毕后,再去一次性替换chain里面的conditionList + */ + private final List conditionList; - /** - * //这是主体的Condition - * //声明这个变量,而不是用chain.getConditionList的目的,是为了辅助平滑加载 - * //虽然FlowBus里面的map都是CopyOnWrite类型的,但是在buildCondition的时候,为了平滑加载,所以不能事先把chain.getConditionList给设为空List - * //所以在这里做一个缓存,等conditionList全部build完毕后,再去一次性替换chain里面的conditionList - */ - private final List conditionList; + /** + * EL解析引擎 + */ + public final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner(); - /** - * EL解析引擎 - */ - public final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner(); + static { + // 初始化QLExpress的Runner + EXPRESS_RUNNER.addFunction(ChainConstant.THEN, new ThenOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.WHEN, new WhenOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.SWITCH, new SwitchOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.PRE, new PreOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.FINALLY, new FinallyOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.IF, new IfOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.NODE.toUpperCase(), new NodeOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.NODE, new NodeOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.FOR, new ForOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.WHILE, new WhileOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.ITERATOR, new IteratorOperator()); + EXPRESS_RUNNER.addFunction(ChainConstant.CATCH, new CatchOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ELSE, Object.class, new ElseOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ELIF, Object.class, new ElifOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TO, Object.class, new ToOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TO.toLowerCase(), Object.class, new ToOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DEFAULT, Object.class, new DefaultOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TAG, Object.class, new TagOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ANY, Object.class, new AnyOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ID, Object.class, new IdOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.IGNORE_ERROR, Object.class, new IgnoreErrorOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.THREAD_POOL, Object.class, new ThreadPoolOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DO, Object.class, new DoOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.BREAK, Object.class, new BreakOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DATA, Object.class, new DataOperator()); + } - static { - //初始化QLExpress的Runner - EXPRESS_RUNNER.addFunction(ChainConstant.THEN, new ThenOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.WHEN, new WhenOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.SWITCH, new SwitchOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.PRE, new PreOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.FINALLY, new FinallyOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.IF, new IfOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.NODE.toUpperCase(), new NodeOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.NODE, new NodeOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.FOR, new ForOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.WHILE, new WhileOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.ITERATOR, new IteratorOperator()); - EXPRESS_RUNNER.addFunction(ChainConstant.CATCH, new CatchOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ELSE, Object.class, new ElseOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ELIF, Object.class, new ElifOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TO, Object.class, new ToOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TO.toLowerCase(), Object.class, new ToOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DEFAULT, Object.class, new DefaultOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.TAG, Object.class, new TagOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ANY, Object.class, new AnyOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.ID, Object.class, new IdOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.IGNORE_ERROR, Object.class, new IgnoreErrorOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.THREAD_POOL, Object.class, new ThreadPoolOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DO, Object.class, new DoOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.BREAK, Object.class, new BreakOperator()); - EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DATA, Object.class, new DataOperator()); - } + public static LiteFlowChainELBuilder createChain() { + return new LiteFlowChainELBuilder(); + } - public static LiteFlowChainELBuilder createChain() { - return new LiteFlowChainELBuilder(); - } + public LiteFlowChainELBuilder() { + chain = new Chain(); + conditionList = new ArrayList<>(); + } - public LiteFlowChainELBuilder() { - chain = new Chain(); - conditionList = new ArrayList<>(); - } + // 在parser中chain的build是2段式的,因为涉及到依赖问题,以前是递归parser + // 2.6.8之后取消了递归的模式,两段式组装,先把带有chainName的chain对象放进去,第二段再组装chain里面的condition + // 所以这里setChainName的时候需要判断下 - //在parser中chain的build是2段式的,因为涉及到依赖问题,以前是递归parser - //2.6.8之后取消了递归的模式,两段式组装,先把带有chainName的chain对象放进去,第二段再组装chain里面的condition - //所以这里setChainName的时候需要判断下 + /** + * @return LiteFlowChainELBuilder + * @deprecated 请使用 {@link #setChainId(String)} + */ + public LiteFlowChainELBuilder setChainName(String chainName) { + if (FlowBus.containChain(chainName)) { + this.chain = FlowBus.getChain(chainName); + } + else { + this.chain.setChainName(chainName); + } + return this; + } - /** - * @return LiteFlowChainELBuilder - * @deprecated 请使用 {@link #setChainId(String)} - */ - public LiteFlowChainELBuilder setChainName(String chainName) { - if (FlowBus.containChain(chainName)) { - this.chain = FlowBus.getChain(chainName); - } else { - this.chain.setChainName(chainName); - } - return this; - } + public LiteFlowChainELBuilder setChainId(String chainId) { + if (FlowBus.containChain(chainId)) { + this.chain = FlowBus.getChain(chainId); + } + else { + this.chain.setChainId(chainId); + } + return this; + } - public LiteFlowChainELBuilder setChainId(String chainId) { - if (FlowBus.containChain(chainId)) { - this.chain = FlowBus.getChain(chainId); - } else { - this.chain.setChainId(chainId); - } - return this; - } + public LiteFlowChainELBuilder setEL(String elStr) { + if (StrUtil.isBlank(elStr)) { + String errMsg = StrUtil.format("no content in this chain[{}]", chain.getChainId()); + throw new FlowSystemException(errMsg); + } - public LiteFlowChainELBuilder setEL(String elStr) { - if (StrUtil.isBlank(elStr)) { - String errMsg = StrUtil.format("no content in this chain[{}]", chain.getChainId()); - throw new FlowSystemException(errMsg); - } + List errorList = new ArrayList<>(); + try { + DefaultContext context = new DefaultContext<>(); - List errorList = new ArrayList<>(); - try { - DefaultContext context = new DefaultContext<>(); + // 这里一定要先放chain,再放node,因为node优先于chain,所以当重名时,node会覆盖掉chain + // 往上下文里放入所有的chain,是的el表达式可以直接引用到chain + FlowBus.getChainMap().values().forEach(chain -> context.put(chain.getChainId(), chain)); - //这里一定要先放chain,再放node,因为node优先于chain,所以当重名时,node会覆盖掉chain - //往上下文里放入所有的chain,是的el表达式可以直接引用到chain - FlowBus.getChainMap().values().forEach(chain -> context.put(chain.getChainId(), chain)); + // 往上下文里放入所有的node,使得el表达式可以直接引用到nodeId + FlowBus.getNodeMap().keySet().forEach(nodeId -> context.put(nodeId, FlowBus.getNode(nodeId))); - //往上下文里放入所有的node,使得el表达式可以直接引用到nodeId - FlowBus.getNodeMap().keySet().forEach(nodeId -> context.put(nodeId, FlowBus.getNode(nodeId))); + // 放入当前主chain的ID + context.put(ChainConstant.CURR_CHAIN_ID, this.chain.getChainId()); - //放入当前主chain的ID - context.put(ChainConstant.CURR_CHAIN_ID, this.chain.getChainId()); + // 解析el成为一个Condition + // 为什么这里只是一个Condition,而不是一个List呢 + // 这里无论多复杂的,外面必定有一个最外层的Condition,所以这里只有一个,内部可以嵌套很多层,这点和以前的不太一样 + Condition condition = (Condition) EXPRESS_RUNNER.execute(elStr, context, errorList, true, true); - //解析el成为一个Condition - //为什么这里只是一个Condition,而不是一个List呢 - //这里无论多复杂的,外面必定有一个最外层的Condition,所以这里只有一个,内部可以嵌套很多层,这点和以前的不太一样 - Condition condition = (Condition) EXPRESS_RUNNER.execute(elStr, context, errorList, true, true); + // 从condition的第一层嵌套结构里拿出Pre和Finally节点 + // 为什么只寻找第一层,而不往下寻找了呢? + // 因为这是一个规范,如果在后面的层级中出现pre和finally,语义上也不好理解,所以pre和finally只能定义在第一层 + // 如果硬是要在后面定义,则执行的时候会忽略,相关代码已做了判断 + /* + * for (Executable executable : condition.getExecutableList()) { if + * (executable instanceof PreCondition) { + * this.preConditionList.add((PreCondition) executable); } else if (executable + * instanceof FinallyCondition) { + * this.finallyConditionList.add((FinallyCondition) executable); } } + */ - //从condition的第一层嵌套结构里拿出Pre和Finally节点 - //为什么只寻找第一层,而不往下寻找了呢? - //因为这是一个规范,如果在后面的层级中出现pre和finally,语义上也不好理解,所以pre和finally只能定义在第一层 - //如果硬是要在后面定义,则执行的时候会忽略,相关代码已做了判断 - /*for (Executable executable : condition.getExecutableList()) { - if (executable instanceof PreCondition) { - this.preConditionList.add((PreCondition) executable); - } else if (executable instanceof FinallyCondition) { - this.finallyConditionList.add((FinallyCondition) executable); - } - }*/ + // 把主要的condition加入 + this.conditionList.add(condition); + return this; + } + catch (QLException e) { + // EL 底层会包装异常,这里是曲线处理 + if (Objects.equals(e.getCause().getMessage(), DataNotFoundException.MSG)) { + // 构建错误信息 + String msg = buildDataNotFoundExceptionMsg(elStr); + throw new ELParseException(msg); + } + throw new ELParseException(e.getCause().getMessage()); + } + catch (Exception e) { + throw new ELParseException(e.getMessage()); + } + } - //把主要的condition加入 - this.conditionList.add(condition); - return this; - } catch (QLException e) { - // EL 底层会包装异常,这里是曲线处理 - if (Objects.equals(e.getCause().getMessage(), DataNotFoundException.MSG)) { - // 构建错误信息 - String msg = buildDataNotFoundExceptionMsg(elStr); - throw new ELParseException(msg); - } - throw new ELParseException(e.getCause().getMessage()); - } catch (Exception e) { - throw new ELParseException(e.getMessage()); - } - } + /** + * EL表达式校验 + * @param elStr EL表达式 + * @return true 校验成功 false 校验失败 + */ + public static boolean validate(String elStr) { + try { + LiteFlowChainELBuilder.createChain().setEL(elStr); + return Boolean.TRUE; + } + catch (ELParseException e) { + LOG.error(e.getMessage()); + } + return Boolean.FALSE; + } - /** - * EL表达式校验 - * - * @param elStr EL表达式 - * @return true 校验成功 false 校验失败 - */ - public static boolean validate(String elStr) { - try { - LiteFlowChainELBuilder.createChain().setEL(elStr); - return Boolean.TRUE; - } catch (ELParseException e) { - LOG.error(e.getMessage()); - } - return Boolean.FALSE; - } + public void build() { + this.chain.setConditionList(this.conditionList); - public void build() { - this.chain.setConditionList(this.conditionList); + checkBuild(); - checkBuild(); + FlowBus.addChain(this.chain); + } - FlowBus.addChain(this.chain); - } + // #region private method - //#region private method + /** + * build 前简单校验 + */ + private void checkBuild() { + List errorList = new ArrayList<>(); + if (StrUtil.isBlank(this.chain.getChainId())) { + errorList.add("name is blank"); + } + if (CollUtil.isNotEmpty(errorList)) { + throw new RuntimeException(CollUtil.join(errorList, ",", "[", "]")); + } + } - /** - * build 前简单校验 - */ - private void checkBuild() { - List errorList = new ArrayList<>(); - if (StrUtil.isBlank(this.chain.getChainId())) { - errorList.add("name is blank"); - } - if (CollUtil.isNotEmpty(errorList)) { - throw new RuntimeException(CollUtil.join(errorList, ",", "[", "]")); - } - } + /** + * 解析 EL 表达式,查找未定义的 id 并构建错误信息 + * @param elStr el 表达式 + */ + private String buildDataNotFoundExceptionMsg(String elStr) { + String msg = String.format("[node/chain is not exist or node/chain not register]\n EL: %s", + StrUtil.trim(elStr)); + try { + InstructionSet parseResult = EXPRESS_RUNNER.getInstructionSetFromLocalCache(elStr); + if (parseResult == null) { + return msg; + } - /** - * 解析 EL 表达式,查找未定义的 id 并构建错误信息 - * - * @param elStr el 表达式 - */ - private String buildDataNotFoundExceptionMsg(String elStr) { - String msg = String.format("[node/chain is not exist or node/chain not register]\n EL: %s", StrUtil.trim(elStr)); - try { - InstructionSet parseResult = EXPRESS_RUNNER.getInstructionSetFromLocalCache(elStr); - if (parseResult == null) { - return msg; - } + String[] outAttrNames = parseResult.getOutAttrNames(); + if (ArrayUtil.isEmpty(outAttrNames)) { + return msg; + } - String[] outAttrNames = parseResult.getOutAttrNames(); - if (ArrayUtil.isEmpty(outAttrNames)) { - return msg; - } + List chainIds = CollUtil.map(FlowBus.getChainMap().values(), Chain::getChainId, true); + List nodeIds = CollUtil.map(FlowBus.getNodeMap().values(), Node::getId, true); + for (String attrName : outAttrNames) { + if (!chainIds.contains(attrName) && !nodeIds.contains(attrName)) { + msg = String.format( + "[%s] is not exist or [%s] is not registered, you need to define a node or chain with id [%s] and register it \n EL: ", + attrName, attrName, attrName); - List chainIds = CollUtil.map(FlowBus.getChainMap().values(), Chain::getChainId, true); - List nodeIds = CollUtil.map(FlowBus.getNodeMap().values(), Node::getId, true); - for (String attrName : outAttrNames) { - if (!chainIds.contains(attrName) && !nodeIds.contains(attrName)) { - msg = String.format("[%s] is not exist or [%s] is not registered, you need to define a node or chain with id [%s] and register it \n EL: ", attrName, attrName, attrName); + // 去除 EL 表达式中的空格和换行符 + String sourceEl = StrUtil.removeAll(elStr, CharUtil.SPACE, CharUtil.LF, CharUtil.CR); + // 这里需要注意的是,nodeId 和 chainId 可能是关键字的一部分,如果直接 indexOf(attrName) 会出现误判 + // 所以需要判断 attrName 前后是否有 "," + int commaRightIndex = sourceEl.indexOf(attrName + StrUtil.COMMA); + if (commaRightIndex != -1) { + // 需要加上 "EL: " 的长度 4,再加上 "^" 的长度 1,indexOf 从 0 开始,所以还需要加 1 + return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaRightIndex + 6, true); + } + int commaLeftIndex = sourceEl.indexOf(StrUtil.COMMA + attrName); + if (commaLeftIndex != -1) { + // 需要加上 "EL: " 的长度 4,再加上 "^" 的长度 1,再加上 "," 的长度 1,indexOf 从 0 + // 开始,所以还需要加 1 + return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 7, true); + } + // 还有一种特殊情况,就是 EL 表达式中的节点使用 node("a") + int nodeIndex = sourceEl.indexOf(String.format("node(\"%s\")", attrName)); + if (nodeIndex != -1) { + // 需要加上 "EL: " 的长度 4,再加上 “node("” 长度 6,再加上 "^" 的长度 1,indexOf 从 0 + // 开始,所以还需要加 1 + return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 12, true); + } + } + } + } + catch (Exception ex) { + // ignore + } + return msg; + } + // #endregion - // 去除 EL 表达式中的空格和换行符 - String sourceEl = StrUtil.removeAll(elStr, CharUtil.SPACE, CharUtil.LF, CharUtil.CR); - // 这里需要注意的是,nodeId 和 chainId 可能是关键字的一部分,如果直接 indexOf(attrName) 会出现误判 - // 所以需要判断 attrName 前后是否有 "," - int commaRightIndex = sourceEl.indexOf(attrName + StrUtil.COMMA); - if (commaRightIndex != -1) { - // 需要加上 "EL: " 的长度 4,再加上 "^" 的长度 1,indexOf 从 0 开始,所以还需要加 1 - return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaRightIndex + 6, true); - } - int commaLeftIndex = sourceEl.indexOf(StrUtil.COMMA + attrName); - if (commaLeftIndex != -1) { - // 需要加上 "EL: " 的长度 4,再加上 "^" 的长度 1,再加上 "," 的长度 1,indexOf 从 0 开始,所以还需要加 1 - return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 7, true); - } - // 还有一种特殊情况,就是 EL 表达式中的节点使用 node("a") - int nodeIndex = sourceEl.indexOf(String.format("node(\"%s\")", attrName)); - if (nodeIndex != -1) { - // 需要加上 "EL: " 的长度 4,再加上 “node("” 长度 6,再加上 "^" 的长度 1,indexOf 从 0 开始,所以还需要加 1 - return msg + sourceEl + "\n" + StrUtil.fill("^", CharUtil.SPACE, commaLeftIndex + 12, true); - } - } - } - } catch (Exception ex) { - // ignore - } - return msg; - } - //#endregion } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java index 1da1d2ff..144f3a27 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/AnyOperator.java @@ -12,14 +12,15 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; */ public class AnyOperator extends BaseOperator { - @Override - public WhenCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEqTwo(objects); + @Override + public WhenCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); - WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class); + WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class); + + Boolean any = OperatorHelper.convert(objects[1], Boolean.class); + whenCondition.setAny(any); + return whenCondition; + } - Boolean any = OperatorHelper.convert(objects[1], Boolean.class); - whenCondition.setAny(any); - return whenCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/BreakOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/BreakOperator.java index d48ce99b..39f69586 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/BreakOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/BreakOperator.java @@ -9,30 +9,30 @@ import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.element.condition.LoopCondition; /** - * EL规则中的BREAK的操作符 - * 有两种用法 - * FOR...DO...BREAK - * WHILE...DO...BREAK + * EL规则中的BREAK的操作符 有两种用法 FOR...DO...BREAK WHILE...DO...BREAK * * @author Bryan.Zhang * @since 2.9.0 */ public class BreakOperator extends BaseOperator { - @Override - public LoopCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEqTwo(objects); - //DO关键字有可能用在FOR后面,也有可能用于WHILE后面,所以这里要进行判断是不是这两种类型的超类LoopCondition - String errorMsg = "The caller must be ForCondition or WhileCondition item"; - LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg); + @Override + public LoopCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); + + // DO关键字有可能用在FOR后面,也有可能用于WHILE后面,所以这里要进行判断是不是这两种类型的超类LoopCondition + String errorMsg = "The caller must be ForCondition or WhileCondition item"; + LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg); + + // 获得需要执行的可执行表达式 + Node breakNode = OperatorHelper.convert(objects[1], Node.class); + if (ListUtil.toList(NodeTypeEnum.BREAK, NodeTypeEnum.BREAK_SCRIPT).contains(breakNode.getType())) { + condition.setBreakNode(breakNode); + } + else { + throw new QLException("The parameter must be node-break item"); + } + return condition; + } - //获得需要执行的可执行表达式 - Node breakNode = OperatorHelper.convert(objects[1], Node.class); - if (ListUtil.toList(NodeTypeEnum.BREAK, NodeTypeEnum.BREAK_SCRIPT).contains(breakNode.getType())) { - condition.setBreakNode(breakNode); - } else { - throw new QLException("The parameter must be node-break item"); - } - return condition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java index 0b555c14..b12ba067 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/CatchOperator.java @@ -6,21 +6,23 @@ import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.flow.element.condition.CatchCondition; /** - * EL规则中的CATCH的操作符 - * 用法:CATCH...DO... + * EL规则中的CATCH的操作符 用法:CATCH...DO... + * * @author Bryan.Zhang * @since 2.10.0 */ public class CatchOperator extends BaseOperator { - @Override - public CatchCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEq(objects, 1); - Executable catchItem = OperatorHelper.convert(objects[0], Executable.class); + @Override + public CatchCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEq(objects, 1); - CatchCondition catchCondition = new CatchCondition(); - catchCondition.setCatchItem(catchItem); + Executable catchItem = OperatorHelper.convert(objects[0], Executable.class); + + CatchCondition catchCondition = new CatchCondition(); + catchCondition.setCatchItem(catchItem); + + return catchCondition; + } - return catchCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DataOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DataOperator.java index 61a25b1e..9b46a18f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DataOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DataOperator.java @@ -12,16 +12,17 @@ import com.yomahub.liteflow.flow.element.Node; */ public class DataOperator extends BaseOperator { - @Override - public Node build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEqTwo(objects); + @Override + public Node build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); - Node node = OperatorHelper.convert(objects[0], Node.class); + Node node = OperatorHelper.convert(objects[0], Node.class); - String cmpData = OperatorHelper.convert(objects[1], String.class); + String cmpData = OperatorHelper.convert(objects[1], String.class); - node.setCmpData(cmpData); + node.setCmpData(cmpData); + + return node; + } - return node; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DefaultOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DefaultOperator.java index dc1493c9..876475c2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DefaultOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DefaultOperator.java @@ -13,15 +13,16 @@ import com.yomahub.liteflow.flow.element.condition.SwitchCondition; */ public class DefaultOperator extends BaseOperator { - @Override - public SwitchCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEqTwo(objects); + @Override + public SwitchCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); - SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class); + SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class); - Executable target = OperatorHelper.convert(objects[1], Executable.class); - switchCondition.setDefaultExecutor(target); + Executable target = OperatorHelper.convert(objects[1], Executable.class); + switchCondition.setDefaultExecutor(target); + + return switchCondition; + } - return switchCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DoOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DoOperator.java index d2003dbe..f7780c19 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DoOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/DoOperator.java @@ -9,38 +9,38 @@ import com.yomahub.liteflow.flow.element.condition.Condition; import com.yomahub.liteflow.flow.element.condition.LoopCondition; /** - * EL规则中的DO的操作符 - * 有三种用法 - * FOR...DO...BREAK - * WHILE...DO...BREAK - * CATCH...DO + * EL规则中的DO的操作符 有三种用法 FOR...DO...BREAK WHILE...DO...BREAK CATCH...DO * * @author Bryan.Zhang * @since 2.9.0 */ public class DoOperator extends BaseOperator { - @Override - public Condition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEqTwo(objects); - if (objects[0] instanceof CatchCondition){ - String errorMsg = "The caller must be CatchCondition item"; - CatchCondition condition = OperatorHelper.convert(objects[0], CatchCondition.class, errorMsg); - //获得需要执行的可执行表达式 - Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class); - condition.setDoItem(doExecutableItem); - return condition; - }else if(objects[0] instanceof LoopCondition){ - String errorMsg = "The caller must be LoopCondition item"; - //DO关键字有可能用在FOR后面,也有可能用于WHILE后面,所以这里要进行判断是不是这两种类型的超类LoopCondition - LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg); - //获得需要执行的可执行表达式 - Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class); - condition.setDoExecutor(doExecutableItem); - return condition; - }else{ - String errorMsg = "The caller must be LoopCondition or CatchCondition item"; - throw new QLException(errorMsg); - } - } + @Override + public Condition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); + + if (objects[0] instanceof CatchCondition) { + String errorMsg = "The caller must be CatchCondition item"; + CatchCondition condition = OperatorHelper.convert(objects[0], CatchCondition.class, errorMsg); + // 获得需要执行的可执行表达式 + Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class); + condition.setDoItem(doExecutableItem); + return condition; + } + else if (objects[0] instanceof LoopCondition) { + String errorMsg = "The caller must be LoopCondition item"; + // DO关键字有可能用在FOR后面,也有可能用于WHILE后面,所以这里要进行判断是不是这两种类型的超类LoopCondition + LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg); + // 获得需要执行的可执行表达式 + Executable doExecutableItem = OperatorHelper.convert(objects[1], Executable.class); + condition.setDoExecutor(doExecutableItem); + return condition; + } + else { + String errorMsg = "The caller must be LoopCondition or CatchCondition item"; + throw new QLException(errorMsg); + } + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java index 35d8c197..95075c90 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElifOperator.java @@ -21,35 +21,37 @@ public class ElifOperator extends BaseOperator { public IfCondition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqThree(objects); - //解析caller + // 解析caller IfCondition ifCondition = OperatorHelper.convert(objects[0], IfCondition.class); - //解析第一个参数 + // 解析第一个参数 Node ifNode = OperatorHelper.convert(objects[1], Node.class); if (!ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(ifNode.getType())) { throw new QLException("The first parameter must be If item"); } - //解析第二个参数 + // 解析第二个参数 Executable trueCaseExecutableItem = OperatorHelper.convert(objects[2], Executable.class); - //构建一个内部的IfCondition + // 构建一个内部的IfCondition IfCondition ifConditionItem = new IfCondition(); ifConditionItem.setIfNode(ifNode); ifConditionItem.setTrueCaseExecutableItem(trueCaseExecutableItem); - //因为可能会有多个ELIF,所以每一次拿到的caller总是最开始大的if,需要遍历到没有falseCaseExecutable的地方。 - //塞进去是一个新的IfCondition + // 因为可能会有多个ELIF,所以每一次拿到的caller总是最开始大的if,需要遍历到没有falseCaseExecutable的地方。 + // 塞进去是一个新的IfCondition IfCondition loopIfCondition = ifCondition; while (true) { if (loopIfCondition.getFalseCaseExecutableItem() == null) { loopIfCondition.setFalseCaseExecutableItem(ifConditionItem); break; - } else { + } + else { loopIfCondition = (IfCondition) loopIfCondition.getFalseCaseExecutableItem(); } } return ifCondition; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java index 0221ba2f..8c6b37e0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ElseOperator.java @@ -30,11 +30,13 @@ public class ElseOperator extends BaseOperator { if (loopIfCondition.getFalseCaseExecutableItem() == null) { loopIfCondition.setFalseCaseExecutableItem(elseExecutableItem); break; - } else { + } + else { loopIfCondition = (IfCondition) loopIfCondition.getFalseCaseExecutableItem(); } } return ifCondition; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java index 0b92594a..d374b0a8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/FinallyOperator.java @@ -24,4 +24,5 @@ public class FinallyOperator extends BaseOperator { } return finallyCondition; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ForOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ForOperator.java index 93e7d85f..44bccfa9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ForOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ForOperator.java @@ -19,34 +19,38 @@ import com.yomahub.liteflow.flow.element.condition.ForCondition; * @since 2.9.0 */ public class ForOperator extends BaseOperator { - @Override - public ForCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEq(objects, 1); - Node node; - if (objects[0] instanceof Node) { - node = OperatorHelper.convert(objects[0], Node.class); - if (!ListUtil.toList(NodeTypeEnum.FOR, NodeTypeEnum.FOR_SCRIPT).contains(node.getType())) { - throw new QLException("The parameter must be for-node item"); - } - }else if(objects[0] instanceof Integer){ - Integer forCount = OperatorHelper.convert(objects[0], Integer.class); - node = new Node(); - NodeForComponent nodeForComponent = new NodeForComponent() { - @Override - public int processFor() { - return forCount; - } - }; - nodeForComponent.setSelf(nodeForComponent); - nodeForComponent.setNodeId(StrUtil.format("LOOP_{}", forCount)); - node.setInstance(nodeForComponent); - }else{ - throw new QLException("The parameter must be Node item"); - } + @Override + public ForCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEq(objects, 1); + + Node node; + if (objects[0] instanceof Node) { + node = OperatorHelper.convert(objects[0], Node.class); + if (!ListUtil.toList(NodeTypeEnum.FOR, NodeTypeEnum.FOR_SCRIPT).contains(node.getType())) { + throw new QLException("The parameter must be for-node item"); + } + } + else if (objects[0] instanceof Integer) { + Integer forCount = OperatorHelper.convert(objects[0], Integer.class); + node = new Node(); + NodeForComponent nodeForComponent = new NodeForComponent() { + @Override + public int processFor() { + return forCount; + } + }; + nodeForComponent.setSelf(nodeForComponent); + nodeForComponent.setNodeId(StrUtil.format("LOOP_{}", forCount)); + node.setInstance(nodeForComponent); + } + else { + throw new QLException("The parameter must be Node item"); + } + + ForCondition forCondition = new ForCondition(); + forCondition.setForNode(node); + return forCondition; + } - ForCondition forCondition = new ForCondition(); - forCondition.setForNode(node); - return forCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java index df34bca0..62541749 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IdOperator.java @@ -12,16 +12,17 @@ import com.yomahub.liteflow.flow.element.condition.Condition; */ public class IdOperator extends BaseOperator { - @Override - public Condition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEqTwo(objects); + @Override + public Condition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); - Condition condition = OperatorHelper.convert(objects[0], Condition.class); + Condition condition = OperatorHelper.convert(objects[0], Condition.class); - String id = OperatorHelper.convert(objects[1], String.class); + String id = OperatorHelper.convert(objects[1], String.class); - condition.setId(id); + condition.setId(id); + + return condition; + } - return condition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java index 4c7e724b..b40ced37 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IfOperator.java @@ -17,29 +17,30 @@ import com.yomahub.liteflow.flow.element.condition.IfCondition; */ public class IfOperator extends BaseOperator { - @Override - public IfCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEq(objects, 2, 3); + @Override + public IfCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEq(objects, 2, 3); - //解析第一个参数 - Node ifNode = OperatorHelper.convert(objects[0], Node.class); - if (!ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(ifNode.getType())) { - throw new QLException("The first parameter must be If item"); - } + // 解析第一个参数 + Node ifNode = OperatorHelper.convert(objects[0], Node.class); + if (!ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(ifNode.getType())) { + throw new QLException("The first parameter must be If item"); + } - //解析第二个参数 - Executable trueCaseExecutableItem = OperatorHelper.convert(objects[1], Executable.class); + // 解析第二个参数 + Executable trueCaseExecutableItem = OperatorHelper.convert(objects[1], Executable.class); - //解析第三个参数,如果有的话 - Executable falseCaseExecutableItem = null; - if (objects.length == 3) { - falseCaseExecutableItem = OperatorHelper.convert(objects[2], Executable.class); - } + // 解析第三个参数,如果有的话 + Executable falseCaseExecutableItem = null; + if (objects.length == 3) { + falseCaseExecutableItem = OperatorHelper.convert(objects[2], Executable.class); + } + + IfCondition ifCondition = new IfCondition(); + ifCondition.setIfNode(ifNode); + ifCondition.setTrueCaseExecutableItem(trueCaseExecutableItem); + ifCondition.setFalseCaseExecutableItem(falseCaseExecutableItem); + return ifCondition; + } - IfCondition ifCondition = new IfCondition(); - ifCondition.setIfNode(ifNode); - ifCondition.setTrueCaseExecutableItem(trueCaseExecutableItem); - ifCondition.setFalseCaseExecutableItem(falseCaseExecutableItem); - return ifCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java index ede076eb..8ce63b2d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IgnoreErrorOperator.java @@ -24,4 +24,5 @@ public class IgnoreErrorOperator extends BaseOperator { return condition; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IteratorOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IteratorOperator.java index 9a19bdb7..c9637980 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IteratorOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/IteratorOperator.java @@ -9,18 +9,20 @@ import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.element.condition.IteratorCondition; public class IteratorOperator extends BaseOperator { - @Override - public IteratorCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEq(objects, 1); - Node node = OperatorHelper.convert(objects[0], Node.class); - if (!ListUtil.toList(NodeTypeEnum.ITERATOR).contains(node.getType())) { - throw new QLException("The parameter must be iterator-node item"); - } + @Override + public IteratorCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEq(objects, 1); - IteratorCondition iteratorCondition = new IteratorCondition(); - iteratorCondition.setIteratorNode(node); + Node node = OperatorHelper.convert(objects[0], Node.class); + if (!ListUtil.toList(NodeTypeEnum.ITERATOR).contains(node.getType())) { + throw new QLException("The parameter must be iterator-node item"); + } + + IteratorCondition iteratorCondition = new IteratorCondition(); + iteratorCondition.setIteratorNode(node); + + return iteratorCondition; + } - return iteratorCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java index 7343ff39..8a4fd576 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java @@ -26,21 +26,33 @@ public class NodeOperator extends BaseOperator { if (FlowBus.containNode(nodeId)) { return FlowBus.getNode(nodeId); - } else { + } + else { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); if (StrUtil.isNotBlank(liteflowConfig.getSubstituteCmpClass())) { - Node substituteNode = FlowBus.getNodeMap().values().stream().filter(node - -> node.getInstance().getClass().getName().equals(liteflowConfig.getSubstituteCmpClass())).findFirst().orElse(null); + Node substituteNode = FlowBus.getNodeMap() + .values() + .stream() + .filter(node -> node.getInstance() + .getClass() + .getName() + .equals(liteflowConfig.getSubstituteCmpClass())) + .findFirst() + .orElse(null); if (ObjectUtil.isNotNull(substituteNode)) { return substituteNode; - } else { + } + else { String error = StrUtil.format("This node[{}] cannot be found", nodeId); throw new QLException(error); } - } else { - String error = StrUtil.format("This node[{}] cannot be found, or you can configure an substitute node", nodeId); + } + else { + String error = StrUtil.format("This node[{}] cannot be found, or you can configure an substitute node", + nodeId); throw new QLException(error); } } } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java index f6f62ced..27c65ad0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/PreOperator.java @@ -13,14 +13,15 @@ import com.yomahub.liteflow.flow.element.condition.PreCondition; */ public class PreOperator extends BaseOperator { - @Override - public PreCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtZero(objects); + @Override + public PreCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeGtZero(objects); + + PreCondition preCondition = new PreCondition(); + for (Object obj : objects) { + preCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); + } + return preCondition; + } - PreCondition preCondition = new PreCondition(); - for (Object obj : objects) { - preCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); - } - return preCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java index b05dd588..becb615b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/SwitchOperator.java @@ -30,4 +30,5 @@ public class SwitchOperator extends BaseOperator { return switchCondition; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java index e9a1c87e..791e61ec 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/TagOperator.java @@ -26,4 +26,5 @@ public class TagOperator extends BaseOperator { return node; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java index 7c19aa0d..619e69c7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThenOperator.java @@ -13,14 +13,15 @@ import com.yomahub.liteflow.flow.element.condition.ThenCondition; */ public class ThenOperator extends BaseOperator { - @Override - public ThenCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtZero(objects); + @Override + public ThenCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeGtZero(objects); + + ThenCondition thenCondition = new ThenCondition(); + for (Object obj : objects) { + thenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); + } + return thenCondition; + } - ThenCondition thenCondition = new ThenCondition(); - for (Object obj : objects) { - thenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); - } - return thenCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java index b3c81ef1..a5b0791c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java @@ -12,14 +12,15 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; */ public class ThreadPoolOperator extends BaseOperator { - @Override - public WhenCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEqTwo(objects); + @Override + public WhenCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); - WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class); + WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class); - whenCondition.setThreadExecutorClass(OperatorHelper.convert(objects[1], String.class)); + whenCondition.setThreadExecutorClass(OperatorHelper.convert(objects[1], String.class)); + + return whenCondition; + } - return whenCondition; - } } 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 1ce13724..806e559a 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 @@ -13,16 +13,17 @@ import com.yomahub.liteflow.flow.element.condition.SwitchCondition; */ public class ToOperator extends BaseOperator { - @Override - public SwitchCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtTwo(objects); + @Override + public SwitchCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeGtTwo(objects); - SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class); + SwitchCondition switchCondition = OperatorHelper.convert(objects[0], SwitchCondition.class); + + for (int i = 1; i < objects.length; i++) { + Executable target = OperatorHelper.convert(objects[i], Executable.class); + switchCondition.addTargetItem(target); + } + return switchCondition; + } - for (int i = 1; i < objects.length; i++) { - Executable target = OperatorHelper.convert(objects[i], Executable.class); - switchCondition.addTargetItem(target); - } - return switchCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java index b2faa3f0..011c4727 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java @@ -7,19 +7,21 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; /** * EL规则中的WHEN的操作符 + * * @author Bryan.Zhang * @since 2.8.0 */ public class WhenOperator extends BaseOperator { - @Override - public WhenCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeGtZero(objects); + @Override + public WhenCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeGtZero(objects); + + WhenCondition whenCondition = new WhenCondition(); + for (Object obj : objects) { + whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); + } + return whenCondition; + } - WhenCondition whenCondition = new WhenCondition(); - for (Object obj : objects) { - whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); - } - return whenCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhileOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhileOperator.java index 55a9c823..51513869 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhileOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhileOperator.java @@ -15,17 +15,19 @@ import com.yomahub.liteflow.flow.element.condition.WhileCondition; * @since 2.9.0 */ public class WhileOperator extends BaseOperator { - @Override - public WhileCondition build(Object[] objects) throws Exception { - OperatorHelper.checkObjectSizeEq(objects, 1); - Node node = OperatorHelper.convert(objects[0], Node.class); - if (!ListUtil.toList(NodeTypeEnum.WHILE, NodeTypeEnum.WHILE_SCRIPT).contains(node.getType())) { - throw new QLException("The parameter must be while-node item"); - } + @Override + public WhileCondition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEq(objects, 1); + + Node node = OperatorHelper.convert(objects[0], Node.class); + if (!ListUtil.toList(NodeTypeEnum.WHILE, NodeTypeEnum.WHILE_SCRIPT).contains(node.getType())) { + throw new QLException("The parameter must be while-node item"); + } + + WhileCondition whileCondition = new WhileCondition(); + whileCondition.setWhileNode(node); + return whileCondition; + } - WhileCondition whileCondition = new WhileCondition(); - whileCondition.setWhileNode(node); - return whileCondition; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java index c5410530..b51a8fc2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/BaseOperator.java @@ -13,25 +13,27 @@ import com.yomahub.liteflow.flow.element.Executable; */ public abstract class BaseOperator extends Operator { - @Override - public T executeInner(Object[] objects) throws Exception { - try { - // 检查 node 和 chain 是否已经注册 - OperatorHelper.checkNodeAndChainExist(objects); - return build(objects); - } catch (QLException e) { - throw e; - } catch (Exception e) { - throw new ELParseException("errors occurred in EL parsing"); - } - } + @Override + public T executeInner(Object[] objects) throws Exception { + try { + // 检查 node 和 chain 是否已经注册 + OperatorHelper.checkNodeAndChainExist(objects); + return build(objects); + } + catch (QLException e) { + throw e; + } + catch (Exception e) { + throw new ELParseException("errors occurred in EL parsing"); + } + } + + /** + * 构建 EL 条件 + * @param objects objects + * @return Condition + * @throws Exception Exception + */ + public abstract T build(Object[] objects) throws Exception; - /** - * 构建 EL 条件 - * - * @param objects objects - * @return Condition - * @throws Exception Exception - */ - public abstract T build(Object[] objects) throws Exception; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/OperatorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/base/OperatorHelper.java index 88f60764..0ad20c8b 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 @@ -15,149 +15,140 @@ import java.util.Objects; */ public class OperatorHelper { - /** - * 检查参数数量,不等于1 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeNeqOne(Object[] objects) throws QLException { - checkObjectSizeNeq(objects, 1); - } + /** + * 检查参数数量,不等于1 + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeNeqOne(Object[] objects) throws QLException { + checkObjectSizeNeq(objects, 1); + } - /** - * 检查参数数量,不等于 size - * - * @param objects objects - * @param size 参数数量 - * @throws QLException QLException - */ - public static void checkObjectSizeNeq(Object[] objects, int size) throws QLException { - checkObjectSizeGtZero(objects); - if (objects.length != size) { - throw new QLException("parameter error"); - } - } + /** + * 检查参数数量,不等于 size + * @param objects objects + * @param size 参数数量 + * @throws QLException QLException + */ + public static void checkObjectSizeNeq(Object[] objects, int size) throws QLException { + checkObjectSizeGtZero(objects); + if (objects.length != size) { + throw new QLException("parameter error"); + } + } - /** - * 检查参数数量,大于 0 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeGtZero(Object[] objects) throws QLException { - if (objects.length == 0) { - throw new QLException("parameter is empty"); - } - } + /** + * 检查参数数量,大于 0 + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeGtZero(Object[] objects) throws QLException { + if (objects.length == 0) { + throw new QLException("parameter is empty"); + } + } - /** - * 检查参数数量,大于 2 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeGtTwo(Object[] objects) throws QLException { - checkObjectSizeGtZero(objects); - if (objects.length <= 1) { - throw new QLException("parameter error"); - } - } + /** + * 检查参数数量,大于 2 + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeGtTwo(Object[] objects) throws QLException { + checkObjectSizeGtZero(objects); + if (objects.length <= 1) { + throw new QLException("parameter error"); + } + } - /** - * 检查参数数量,等于 2 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeEqTwo(Object[] objects) throws QLException { - checkObjectSizeEq(objects, 2); - } + /** + * 检查参数数量,等于 2 + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeEqTwo(Object[] objects) throws QLException { + checkObjectSizeEq(objects, 2); + } - /** - * 检查参数数量,等于 3 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkObjectSizeEqThree(Object[] objects) throws QLException { - checkObjectSizeEq(objects, 3); - } + /** + * 检查参数数量,等于 3 + * @param objects objects + * @throws QLException QLException + */ + public static void checkObjectSizeEqThree(Object[] objects) throws QLException { + checkObjectSizeEq(objects, 3); + } - /** - * 检查参数数量,等于 size - * - * @param objects objects - * @param size 参数数量 - * @throws QLException QLException - */ - public static void checkObjectSizeEq(Object[] objects, int size) throws QLException { - checkObjectSizeGtZero(objects); + /** + * 检查参数数量,等于 size + * @param objects objects + * @param size 参数数量 + * @throws QLException QLException + */ + public static void checkObjectSizeEq(Object[] objects, int size) throws QLException { + checkObjectSizeGtZero(objects); - if (objects.length != size) { - throw new QLException("parameter error"); - } - } + if (objects.length != size) { + throw new QLException("parameter error"); + } + } - /** - * 检查参数数量,等于 size1 或 size2 - * - * @param objects objects - * @param size1 参数数量1 - * @param size2 参数数量2 - * @throws QLException QLException - */ - public static void checkObjectSizeEq(Object[] objects, int size1, int size2) throws QLException { - checkObjectSizeGtZero(objects); + /** + * 检查参数数量,等于 size1 或 size2 + * @param objects objects + * @param size1 参数数量1 + * @param size2 参数数量2 + * @throws QLException QLException + */ + public static void checkObjectSizeEq(Object[] objects, int size1, int size2) throws QLException { + checkObjectSizeGtZero(objects); - if (objects.length != size1 && objects.length != size2) { - throw new QLException("parameter error"); - } - } + if (objects.length != size1 && objects.length != size2) { + throw new QLException("parameter error"); + } + } - /** - * 转换 object 为指定的类型 - * 如果是Node类型的则进行copy - * 为什么要进行copy呢?因为原先的Node都是存放在FlowBus的NodeMap中的。有些属性在EL中不是全局的,属于当前这个chain的。 - * 所以要进行copy动作 - */ - public static T convert(Object object, Class clazz) throws QLException { - String errorMsg = StrUtil.format("The parameter must be {} item", clazz.getSimpleName()); - return convert(object, clazz, errorMsg); - } + /** + * 转换 object 为指定的类型 如果是Node类型的则进行copy + * 为什么要进行copy呢?因为原先的Node都是存放在FlowBus的NodeMap中的。有些属性在EL中不是全局的,属于当前这个chain的。 所以要进行copy动作 + */ + public static T convert(Object object, Class clazz) throws QLException { + String errorMsg = StrUtil.format("The parameter must be {} item", clazz.getSimpleName()); + return convert(object, clazz, errorMsg); + } - /** - * 转换 object 为指定的类型,自定义错误信息 - * 如果是Node类型的则进行copy - */ - public static T convert(Object object, Class clazz, String errorMsg) throws QLException { - try { - if (clazz.isAssignableFrom(object.getClass())) { - if (clazz.equals(Node.class)) { - Node node = (Node) object; - return (T) node.copy(); - } else { - return (T) object; - } - } - } catch (Exception e) { - throw new QLException("An error occurred while copying an object"); - } + /** + * 转换 object 为指定的类型,自定义错误信息 如果是Node类型的则进行copy + */ + public static T convert(Object object, Class clazz, String errorMsg) throws QLException { + try { + if (clazz.isAssignableFrom(object.getClass())) { + if (clazz.equals(Node.class)) { + Node node = (Node) object; + return (T) node.copy(); + } + else { + return (T) object; + } + } + } + catch (Exception e) { + throw new QLException("An error occurred while copying an object"); + } - throw new QLException(errorMsg); - } + throw new QLException(errorMsg); + } + + /** + * 检查 node 和 chain 是否已经注册 + * @param objects objects + * @throws QLException QLException + */ + public static void checkNodeAndChainExist(Object[] objects) throws QLException { + for (Object object : objects) { + if (Objects.isNull(object)) { + throw new QLException(DataNotFoundException.MSG); + } + } + } - /** - * 检查 node 和 chain 是否已经注册 - * - * @param objects objects - * @throws QLException QLException - */ - public static void checkNodeAndChainExist(Object[] objects) throws QLException { - for (Object object : objects) { - if (Objects.isNull(object)) { - throw new QLException(DataNotFoundException.MSG); - } - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/ChainPropBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/ChainPropBean.java index 2d816506..817c184e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/ChainPropBean.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/ChainPropBean.java @@ -90,4 +90,5 @@ public class ChainPropBean { this.conditionType = conditionType; return this; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/NodePropBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/NodePropBean.java index 1a0741cf..13c57670 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/NodePropBean.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/prop/NodePropBean.java @@ -102,4 +102,5 @@ public class NodePropBean { this.language = language; return this; } + } 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 5d131547..f55cdf04 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 @@ -7,71 +7,72 @@ package com.yomahub.liteflow.common; */ public interface ChainConstant { - String CHAIN = "chain"; + String CHAIN = "chain"; - String FLOW = "flow"; + String FLOW = "flow"; - String NODES = "nodes"; + String NODES = "nodes"; - String NODE = "node"; + String NODE = "node"; - String ID = "id"; + String ID = "id"; - String _CLASS = "class"; + String _CLASS = "class"; - String FILE = "file"; + String FILE = "file"; - String NAME = "name"; + String NAME = "name"; - String LANGUAGE = "language"; + String LANGUAGE = "language"; - String VALUE = "value"; + String VALUE = "value"; - String ANY = "any"; + String ANY = "any"; - String TYPE = "type"; + String TYPE = "type"; - String THEN = "THEN"; + String THEN = "THEN"; - String WHEN = "WHEN"; + String WHEN = "WHEN"; - String SWITCH = "SWITCH"; + String SWITCH = "SWITCH"; - String PRE = "PRE"; + String PRE = "PRE"; - String FINALLY = "FINALLY"; + String FINALLY = "FINALLY"; - String IF = "IF"; + String IF = "IF"; - String ELSE = "ELSE"; + String ELSE = "ELSE"; - String ELIF = "ELIF"; + String ELIF = "ELIF"; - String TO = "TO"; + String TO = "TO"; - String TAG = "tag"; + String TAG = "tag"; - String IGNORE_ERROR = "ignoreError"; + String IGNORE_ERROR = "ignoreError"; - String THREAD_POOL = "threadPool"; + String THREAD_POOL = "threadPool"; - String WHILE = "WHILE"; + String WHILE = "WHILE"; - String FOR = "FOR"; + String FOR = "FOR"; - String DO = "DO"; + String DO = "DO"; - String BREAK = "BREAK"; + String BREAK = "BREAK"; - String DATA = "data"; + String DATA = "data"; - String ITERATOR = "ITERATOR"; + String ITERATOR = "ITERATOR"; - String MONITOR_BUS = "monitorBus"; + String MONITOR_BUS = "monitorBus"; - String CURR_CHAIN_ID = "currChainId"; + String CURR_CHAIN_ID = "currChainId"; - String DEFAULT = "DEFAULT"; + String DEFAULT = "DEFAULT"; + + String CATCH = "CATCH"; - String CATCH = "CATCH"; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/LocalDefaultFlowConstant.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/LocalDefaultFlowConstant.java index 2dc4f196..e6a93a01 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/common/LocalDefaultFlowConstant.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/LocalDefaultFlowConstant.java @@ -4,5 +4,7 @@ package com.yomahub.liteflow.common; * @author Yun */ public class LocalDefaultFlowConstant { - public static final String DEFAULT="default"; + + public static final String DEFAULT = "default"; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/context/ContextBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/context/ContextBean.java index 0f0beb82..f3bb15af 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/context/ContextBean.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/context/ContextBean.java @@ -6,18 +6,20 @@ import java.lang.annotation.*; /** * 用于标注上下文bean的别名,以便在脚本或者组件中通过别名来获取上下文对象 + * * @since 2.9.7 * @author Tingliang Wang */ -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface ContextBean { - @AliasFor("name") - String value() default ""; - @AliasFor("value") - String name() default ""; + @AliasFor("name") + String value() default ""; + + @AliasFor("value") + String name() default ""; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ComponentInitializer.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ComponentInitializer.java index 4aaa40c8..3dd96106 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ComponentInitializer.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ComponentInitializer.java @@ -21,57 +21,61 @@ import com.yomahub.liteflow.spi.holder.LiteflowComponentSupportHolder; */ public class ComponentInitializer { - private static ComponentInitializer instance; + private static ComponentInitializer instance; - public static ComponentInitializer loadInstance() { - if (ObjectUtil.isNull(instance)) { - instance = new ComponentInitializer(); - } - return instance; - } + public static ComponentInitializer loadInstance() { + if (ObjectUtil.isNull(instance)) { + instance = new ComponentInitializer(); + } + return instance; + } - public NodeComponent initComponent(NodeComponent nodeComponent, NodeTypeEnum type, String name, String nodeId) { - nodeComponent.setNodeId(nodeId); - nodeComponent.setSelf(nodeComponent); - nodeComponent.setType(type); + public NodeComponent initComponent(NodeComponent nodeComponent, NodeTypeEnum type, String name, String nodeId) { + nodeComponent.setNodeId(nodeId); + nodeComponent.setSelf(nodeComponent); + nodeComponent.setType(type); - //设置MonitorBus,如果没有就不注入 - if (ContextAwareHolder.loadContextAware().hasBean(ChainConstant.MONITOR_BUS)) { - MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); - if (ObjectUtil.isNotNull(monitorBus)) { - nodeComponent.setMonitorBus(monitorBus); - } - } + // 设置MonitorBus,如果没有就不注入 + if (ContextAwareHolder.loadContextAware().hasBean(ChainConstant.MONITOR_BUS)) { + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + if (ObjectUtil.isNotNull(monitorBus)) { + nodeComponent.setMonitorBus(monitorBus); + } + } - //先取传进来的name值(配置文件中配置的),再看有没有配置@LiteflowComponent标注 - //@LiteflowComponent标注只在spring体系下生效,这里用了spi机制取到相应环境下的实现类 - nodeComponent.setName(name); - if (!type.isScript() && StrUtil.isBlank(nodeComponent.getName())) { - nodeComponent.setName(LiteflowComponentSupportHolder.loadLiteflowComponentSupport().getCmpName(nodeComponent)); - } + // 先取传进来的name值(配置文件中配置的),再看有没有配置@LiteflowComponent标注 + // @LiteflowComponent标注只在spring体系下生效,这里用了spi机制取到相应环境下的实现类 + nodeComponent.setName(name); + if (!type.isScript() && StrUtil.isBlank(nodeComponent.getName())) { + nodeComponent + .setName(LiteflowComponentSupportHolder.loadLiteflowComponentSupport().getCmpName(nodeComponent)); + } - //先从组件上取@RetryCount标注,如果没有,则看全局配置,全局配置如果不配置的话,默认是0 - //默认retryForExceptions为Exception.class - LiteflowRetry liteFlowRetryAnnotation = AnnoUtil.getAnnotation(nodeComponent.getClass(), LiteflowRetry.class); - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - if (liteFlowRetryAnnotation != null) { - nodeComponent.setRetryCount(liteFlowRetryAnnotation.retry()); - nodeComponent.setRetryForExceptions(liteFlowRetryAnnotation.forExceptions()); - } else { - nodeComponent.setRetryCount(liteflowConfig.getRetryCount()); - } - nodeComponent.setNodeExecutorClass(buildNodeExecutorClass(liteflowConfig)); + // 先从组件上取@RetryCount标注,如果没有,则看全局配置,全局配置如果不配置的话,默认是0 + // 默认retryForExceptions为Exception.class + LiteflowRetry liteFlowRetryAnnotation = AnnoUtil.getAnnotation(nodeComponent.getClass(), LiteflowRetry.class); + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + if (liteFlowRetryAnnotation != null) { + nodeComponent.setRetryCount(liteFlowRetryAnnotation.retry()); + nodeComponent.setRetryForExceptions(liteFlowRetryAnnotation.forExceptions()); + } + else { + nodeComponent.setRetryCount(liteflowConfig.getRetryCount()); + } + nodeComponent.setNodeExecutorClass(buildNodeExecutorClass(liteflowConfig)); - return nodeComponent; - } + return nodeComponent; + } + + private Class buildNodeExecutorClass(LiteflowConfig liteflowConfig) { + Class nodeExecutorClass; + try { + nodeExecutorClass = Class.forName(liteflowConfig.getNodeExecutorClass()); + } + catch (ClassNotFoundException e) { + throw new RuntimeException(e.getMessage()); + } + return (Class) nodeExecutorClass; + } - private Class buildNodeExecutorClass(LiteflowConfig liteflowConfig) { - Class nodeExecutorClass; - try { - nodeExecutorClass = Class.forName(liteflowConfig.getNodeExecutorClass()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e.getMessage()); - } - return (Class) nodeExecutorClass; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 2711c753..31dba4b7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -43,379 +43,399 @@ import java.util.concurrent.Future; */ public class FlowExecutor { - private static final Logger LOG = LoggerFactory.getLogger(FlowExecutor.class); + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutor.class); - private static final String PREFIX_FORMAT_CONFIG_REGEX = "xml:|json:|yml:|el_xml:|el_json:|el_yml:"; + private static final String PREFIX_FORMAT_CONFIG_REGEX = "xml:|json:|yml:|el_xml:|el_json:|el_yml:"; - private LiteflowConfig liteflowConfig; + private LiteflowConfig liteflowConfig; - public FlowExecutor() { - //设置FlowExecutor的Holder,虽然大部分地方都可以通过Spring上下文获取到,但放入Holder,还是为了某些地方能方便的取到 - FlowExecutorHolder.setHolder(this); - //初始化DataBus - DataBus.init(); - } + public FlowExecutor() { + // 设置FlowExecutor的Holder,虽然大部分地方都可以通过Spring上下文获取到,但放入Holder,还是为了某些地方能方便的取到 + FlowExecutorHolder.setHolder(this); + // 初始化DataBus + DataBus.init(); + } - public FlowExecutor(LiteflowConfig liteflowConfig) { - this.liteflowConfig = liteflowConfig; - //把liteFlowConfig设到LiteFlowGetter中去 - LiteflowConfigGetter.setLiteflowConfig(liteflowConfig); - //设置FlowExecutor的Holder,虽然大部分地方都可以通过Spring上下文获取到,但放入Holder,还是为了某些地方能方便的取到 - FlowExecutorHolder.setHolder(this); - if (BooleanUtil.isTrue(liteflowConfig.isParseOnStart())) { - this.init(true); - } - //初始化DataBus - DataBus.init(); - } + public FlowExecutor(LiteflowConfig liteflowConfig) { + this.liteflowConfig = liteflowConfig; + // 把liteFlowConfig设到LiteFlowGetter中去 + LiteflowConfigGetter.setLiteflowConfig(liteflowConfig); + // 设置FlowExecutor的Holder,虽然大部分地方都可以通过Spring上下文获取到,但放入Holder,还是为了某些地方能方便的取到 + FlowExecutorHolder.setHolder(this); + if (BooleanUtil.isTrue(liteflowConfig.isParseOnStart())) { + this.init(true); + } + // 初始化DataBus + DataBus.init(); + } - /** - * FlowExecutor的初始化化方式,主要用于parse规则文件 - */ - public void init(boolean hook) { - if (ObjectUtil.isNull(liteflowConfig)) { - throw new ConfigErrorException("config error, please check liteflow config property"); - } + /** + * FlowExecutor的初始化化方式,主要用于parse规则文件 + */ + public void init(boolean hook) { + if (ObjectUtil.isNull(liteflowConfig)) { + throw new ConfigErrorException("config error, please check liteflow config property"); + } - //在相应的环境下进行节点的初始化工作 - //在spring体系下会获得spring扫描后的节点,接入元数据 - //在非spring体系下是一个空实现,等于不做此步骤 - ContextCmpInitHolder.loadContextCmpInit().initCmp(); + // 在相应的环境下进行节点的初始化工作 + // 在spring体系下会获得spring扫描后的节点,接入元数据 + // 在非spring体系下是一个空实现,等于不做此步骤 + ContextCmpInitHolder.loadContextCmpInit().initCmp(); - //进行id生成器的初始化 - IdGeneratorHolder.init(); + // 进行id生成器的初始化 + IdGeneratorHolder.init(); - String ruleSource = liteflowConfig.getRuleSource(); - if (StrUtil.isBlank(ruleSource)) { - //查看有没有Parser的SPI实现 - //所有的Parser的SPI实现都是以custom形式放入的,且只支持xml形式 - ServiceLoader loader = ServiceLoader.load(ParserClassNameSpi.class); - Iterator it = loader.iterator(); - if (it.hasNext()) { - ParserClassNameSpi parserClassNameSpi = it.next(); - ruleSource = "el_xml:" + parserClassNameSpi.getSpiClassName(); - liteflowConfig.setRuleSource(ruleSource); - } else { - //ruleSource为空,而且没有spi形式的扩展,那么说明真的没有ruleSource - //这种情况有可能是基于代码动态构建的 - return; - } - } + String ruleSource = liteflowConfig.getRuleSource(); + if (StrUtil.isBlank(ruleSource)) { + // 查看有没有Parser的SPI实现 + // 所有的Parser的SPI实现都是以custom形式放入的,且只支持xml形式 + ServiceLoader loader = ServiceLoader.load(ParserClassNameSpi.class); + Iterator it = loader.iterator(); + if (it.hasNext()) { + ParserClassNameSpi parserClassNameSpi = it.next(); + ruleSource = "el_xml:" + parserClassNameSpi.getSpiClassName(); + liteflowConfig.setRuleSource(ruleSource); + } + else { + // ruleSource为空,而且没有spi形式的扩展,那么说明真的没有ruleSource + // 这种情况有可能是基于代码动态构建的 + return; + } + } - //如果有前缀的,则不需要再进行分割了,说明是一个整体 - //如果没有前缀,说明是本地文件,可能配置多个,所以需要分割 - List sourceRulePathList; - if (ReUtil.contains(PREFIX_FORMAT_CONFIG_REGEX, ruleSource)) { - sourceRulePathList = ListUtil.toList(ruleSource); - } else { - String afterHandleRuleSource = ruleSource.replace(StrUtil.SPACE, StrUtil.EMPTY); - sourceRulePathList = ListUtil.toList(afterHandleRuleSource.split(",|;")); - } + // 如果有前缀的,则不需要再进行分割了,说明是一个整体 + // 如果没有前缀,说明是本地文件,可能配置多个,所以需要分割 + List sourceRulePathList; + if (ReUtil.contains(PREFIX_FORMAT_CONFIG_REGEX, ruleSource)) { + sourceRulePathList = ListUtil.toList(ruleSource); + } + else { + String afterHandleRuleSource = ruleSource.replace(StrUtil.SPACE, StrUtil.EMPTY); + sourceRulePathList = ListUtil.toList(afterHandleRuleSource.split(",|;")); + } - FlowParser parser = null; - Set parserNameSet = new HashSet<>(); - List rulePathList = new ArrayList<>(); - for (String path : sourceRulePathList) { - try { - // 查找对应的解析器 - parser = FlowParserProvider.lookup(path); - parserNameSet.add(parser.getClass().getName()); - // 替换掉前缀标识(如:xml:/json:),保留剩下的完整地址 - path = ReUtil.replaceAll(path, PREFIX_FORMAT_CONFIG_REGEX, ""); - rulePathList.add(path); + FlowParser parser = null; + Set parserNameSet = new HashSet<>(); + List rulePathList = new ArrayList<>(); + for (String path : sourceRulePathList) { + try { + // 查找对应的解析器 + parser = FlowParserProvider.lookup(path); + parserNameSet.add(parser.getClass().getName()); + // 替换掉前缀标识(如:xml:/json:),保留剩下的完整地址 + path = ReUtil.replaceAll(path, PREFIX_FORMAT_CONFIG_REGEX, ""); + rulePathList.add(path); - //支持多类型的配置文件,分别解析 - if (BooleanUtil.isTrue(liteflowConfig.isSupportMultipleType())) { - // 解析文件 - parser.parseMain(ListUtil.toList(path)); - } - } catch (CyclicDependencyException e) { - LOG.error(e.getMessage()); - throw e; - } catch (Exception e) { - String errorMsg = StrUtil.format("init flow executor cause error for path {},reason:{}", path, e.getMessage()); - LOG.error(e.getMessage(), e); - throw new FlowExecutorNotInitException(errorMsg); - } - } + // 支持多类型的配置文件,分别解析 + if (BooleanUtil.isTrue(liteflowConfig.isSupportMultipleType())) { + // 解析文件 + parser.parseMain(ListUtil.toList(path)); + } + } + catch (CyclicDependencyException e) { + LOG.error(e.getMessage()); + throw e; + } + catch (Exception e) { + String errorMsg = StrUtil.format("init flow executor cause error for path {},reason:{}", path, + e.getMessage()); + LOG.error(e.getMessage(), e); + throw new FlowExecutorNotInitException(errorMsg); + } + } - //单类型的配置文件,需要一起解析 - if (BooleanUtil.isFalse(liteflowConfig.isSupportMultipleType())) { - //检查Parser是否只有一个,因为多个不同的parser会造成子流程的混乱 - if (parserNameSet.size() > 1) { - String errorMsg = "cannot have multiple different parsers"; - LOG.error(errorMsg); - throw new MultipleParsersException(errorMsg); - } + // 单类型的配置文件,需要一起解析 + if (BooleanUtil.isFalse(liteflowConfig.isSupportMultipleType())) { + // 检查Parser是否只有一个,因为多个不同的parser会造成子流程的混乱 + if (parserNameSet.size() > 1) { + String errorMsg = "cannot have multiple different parsers"; + LOG.error(errorMsg); + throw new MultipleParsersException(errorMsg); + } - //进行多个配置文件的一起解析 - try { - if (parser != null) { - // 解析文件 - parser.parseMain(rulePathList); - } else { - throw new ConfigErrorException("parse error, please check liteflow config property"); - } - } catch (CyclicDependencyException e) { - LOG.error(e.getMessage(), e); - LOG.error(e.getMessage()); - throw e; - } catch (ChainDuplicateException e) { - LOG.error(e.getMessage(), e); - throw e; - } catch (Exception e) { - String errorMsg = StrUtil.format("init flow executor cause error for path {},reason: {}", rulePathList, e.getMessage()); - LOG.error(e.getMessage(), e); - throw new FlowExecutorNotInitException(errorMsg); - } - } + // 进行多个配置文件的一起解析 + try { + if (parser != null) { + // 解析文件 + parser.parseMain(rulePathList); + } + else { + throw new ConfigErrorException("parse error, please check liteflow config property"); + } + } + catch (CyclicDependencyException e) { + LOG.error(e.getMessage(), e); + LOG.error(e.getMessage()); + throw e; + } + catch (ChainDuplicateException e) { + LOG.error(e.getMessage(), e); + throw e; + } + catch (Exception e) { + String errorMsg = StrUtil.format("init flow executor cause error for path {},reason: {}", rulePathList, + e.getMessage()); + LOG.error(e.getMessage(), e); + throw new FlowExecutorNotInitException(errorMsg); + } + } - //如果是ruleSource方式的,最后判断下有没有解析出来,如果没有解析出来则报错 - if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData()) && MapUtil.isEmpty(liteflowConfig.getRuleSourceExtDataMap())) { - if (FlowBus.getChainMap().isEmpty()) { - String errMsg = StrUtil.format("no valid rule config found in rule path [{}]", liteflowConfig.getRuleSource()); - throw new ConfigErrorException(errMsg); - } - } + // 如果是ruleSource方式的,最后判断下有没有解析出来,如果没有解析出来则报错 + if (StrUtil.isBlank(liteflowConfig.getRuleSourceExtData()) + && MapUtil.isEmpty(liteflowConfig.getRuleSourceExtDataMap())) { + if (FlowBus.getChainMap().isEmpty()) { + String errMsg = StrUtil.format("no valid rule config found in rule path [{}]", + liteflowConfig.getRuleSource()); + throw new ConfigErrorException(errMsg); + } + } - //执行钩子 - if (hook) { - FlowInitHook.executeHook(); - } + // 执行钩子 + if (hook) { + FlowInitHook.executeHook(); + } - // 文件监听 - if (liteflowConfig.getEnableMonitorFile()) { - try{ - addMonitorFilePaths(rulePathList); - MonitorFile.getInstance().create(); - }catch (Exception e){ - String errMsg = StrUtil.format("file monitor init error for path:{}", rulePathList); - throw new MonitorFileInitErrorException(errMsg); - } + // 文件监听 + if (liteflowConfig.getEnableMonitorFile()) { + try { + addMonitorFilePaths(rulePathList); + MonitorFile.getInstance().create(); + } + catch (Exception e) { + String errMsg = StrUtil.format("file monitor init error for path:{}", rulePathList); + throw new MonitorFileInitErrorException(errMsg); + } - } - } + } + } - //此方法就是从原有的配置源主动拉取新的进行刷新 - //和FlowBus.refreshFlowMetaData的区别就是一个为主动拉取,一个为被动监听到新的内容进行刷新 - public void reloadRule() { - long start = System.currentTimeMillis(); - init(false); - LOG.info("reload rules takes {}ms", System.currentTimeMillis() - start); - } + // 此方法就是从原有的配置源主动拉取新的进行刷新 + // 和FlowBus.refreshFlowMetaData的区别就是一个为主动拉取,一个为被动监听到新的内容进行刷新 + public void reloadRule() { + long start = System.currentTimeMillis(); + init(false); + LOG.info("reload rules takes {}ms", System.currentTimeMillis() - start); + } - //隐式流程的调用方法 - @Deprecated - public void invoke(String chainId, Object param, Integer slotIndex) throws Exception { - LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC); - if (!response.isSuccess()) { - throw response.getCause(); - } - } + // 隐式流程的调用方法 + @Deprecated + public void invoke(String chainId, Object param, Integer slotIndex) throws Exception { + LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC); + if (!response.isSuccess()) { + throw response.getCause(); + } + } - @Deprecated - public void invokeInAsync(String chainId, Object param, Integer slotIndex) throws Exception { - LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC); - if (!response.isSuccess()) { - throw response.getCause(); - } - } + @Deprecated + public void invokeInAsync(String chainId, Object param, Integer slotIndex) throws Exception { + LiteflowResponse response = this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC); + if (!response.isSuccess()) { + throw response.getCause(); + } + } - public LiteflowResponse invoke2Resp(String chainId, Object param, Integer slotIndex) { - return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC); - } + public LiteflowResponse invoke2Resp(String chainId, Object param, Integer slotIndex) { + return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_SYNC); + } - public LiteflowResponse invoke2RespInAsync(String chainId, Object param, Integer slotIndex) { - return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC); - } + public LiteflowResponse invoke2RespInAsync(String chainId, Object param, Integer slotIndex) { + return this.invoke2Resp(chainId, param, slotIndex, InnerChainTypeEnum.IN_ASYNC); + } - //单独调用某一个node - @Deprecated - public void invoke(String nodeId, Integer slotIndex) throws Exception { - Node node = FlowBus.getNode(nodeId); - node.execute(slotIndex); - } + // 单独调用某一个node + @Deprecated + public void invoke(String nodeId, Integer slotIndex) throws Exception { + Node node = FlowBus.getNode(nodeId); + node.execute(slotIndex); + } - //调用一个流程并返回LiteflowResponse,上下文为默认的DefaultContext,初始参数为null - public LiteflowResponse execute2Resp(String chainId) { - return this.execute2Resp(chainId, null, DefaultContext.class); - } + // 调用一个流程并返回LiteflowResponse,上下文为默认的DefaultContext,初始参数为null + public LiteflowResponse execute2Resp(String chainId) { + return this.execute2Resp(chainId, null, DefaultContext.class); + } - //调用一个流程并返回LiteflowResponse,上下文为默认的DefaultContext - public LiteflowResponse execute2Resp(String chainId, Object param) { - return this.execute2Resp(chainId, param, DefaultContext.class); - } + // 调用一个流程并返回LiteflowResponse,上下文为默认的DefaultContext + public LiteflowResponse execute2Resp(String chainId, Object param) { + return this.execute2Resp(chainId, param, DefaultContext.class); + } - //调用一个流程并返回LiteflowResponse,允许多上下文的传入 - public LiteflowResponse execute2Resp(String chainId, Object param, Class... contextBeanClazzArray) { - return this.execute2Resp(chainId, param, contextBeanClazzArray, null); - } + // 调用一个流程并返回LiteflowResponse,允许多上下文的传入 + public LiteflowResponse execute2Resp(String chainId, Object param, Class... contextBeanClazzArray) { + return this.execute2Resp(chainId, param, contextBeanClazzArray, null); + } - public LiteflowResponse execute2Resp(String chainId, Object param, Object... contextBeanArray) { - return this.execute2Resp(chainId, param, null, contextBeanArray); - } + public LiteflowResponse execute2Resp(String chainId, Object param, Object... contextBeanArray) { + return this.execute2Resp(chainId, param, null, contextBeanArray); + } - //调用一个流程并返回Future,允许多上下文的传入 - public Future execute2Future(String chainId, Object param, Class... contextBeanClazzArray) { - return ExecutorHelper.loadInstance().buildMainExecutor(liteflowConfig.getMainExecutorClass()).submit(() - -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, contextBeanClazzArray, null)); - } + // 调用一个流程并返回Future,允许多上下文的传入 + public Future execute2Future(String chainId, Object param, Class... contextBeanClazzArray) { + return ExecutorHelper.loadInstance() + .buildMainExecutor(liteflowConfig.getMainExecutorClass()) + .submit(() -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, contextBeanClazzArray, null)); + } + public Future execute2Future(String chainId, Object param, Object... contextBeanArray) { + return ExecutorHelper.loadInstance() + .buildMainExecutor(liteflowConfig.getMainExecutorClass()) + .submit(() -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, null, contextBeanArray)); + } - public Future execute2Future(String chainId, Object param, Object... contextBeanArray) { - return ExecutorHelper.loadInstance().buildMainExecutor(liteflowConfig.getMainExecutorClass()).submit(() - -> FlowExecutorHolder.loadInstance().execute2Resp(chainId, param, null, contextBeanArray)); - } + // 调用一个流程,返回默认的上下文,适用于简单的调用 + @Deprecated + public DefaultContext execute(String chainId, Object param) throws Exception { + LiteflowResponse response = this.execute2Resp(chainId, param, DefaultContext.class); + if (!response.isSuccess()) { + throw response.getCause(); + } + else { + return response.getFirstContextBean(); + } + } - //调用一个流程,返回默认的上下文,适用于简单的调用 - @Deprecated - public DefaultContext execute(String chainId, Object param) throws Exception { - LiteflowResponse response = this.execute2Resp(chainId, param, DefaultContext.class); - if (!response.isSuccess()) { - throw response.getCause(); - } else { - return response.getFirstContextBean(); - } - } + private LiteflowResponse execute2Resp(String chainId, Object param, Class[] contextBeanClazzArray, + Object[] contextBeanArray) { + Slot slot = doExecute(chainId, param, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE); + return LiteflowResponse.newMainResponse(slot); + } - private LiteflowResponse execute2Resp(String chainId, - Object param, - Class[] contextBeanClazzArray, - Object[] contextBeanArray) { - Slot slot = doExecute(chainId, param, contextBeanClazzArray, contextBeanArray, null, InnerChainTypeEnum.NONE); - return LiteflowResponse.newMainResponse(slot); - } + private LiteflowResponse invoke2Resp(String chainId, Object param, Integer slotIndex, + InnerChainTypeEnum innerChainType) { + Slot slot = doExecute(chainId, param, null, null, slotIndex, innerChainType); + return LiteflowResponse.newInnerResponse(chainId, slot); + } - private LiteflowResponse invoke2Resp(String chainId, - Object param, - Integer slotIndex, InnerChainTypeEnum innerChainType) { - Slot slot = doExecute(chainId, param, null, null, slotIndex, innerChainType); - return LiteflowResponse.newInnerResponse(chainId, slot); - } + private Slot doExecute(String chainId, Object param, Class[] contextBeanClazzArray, Object[] contextBeanArray, + Integer slotIndex, InnerChainTypeEnum innerChainType) { + if (FlowBus.needInit()) { + init(true); + } - private Slot doExecute(String chainId, - Object param, - Class[] contextBeanClazzArray, - Object[] contextBeanArray, - Integer slotIndex, - InnerChainTypeEnum innerChainType) { - if (FlowBus.needInit()) { - init(true); - } + // 如果不是隐式流程,那么需要分配Slot + if (innerChainType.equals(InnerChainTypeEnum.NONE) && ObjectUtil.isNull(slotIndex)) { + // 这里可以根据class分配,也可以根据bean去分配 + if (ArrayUtil.isNotEmpty(contextBeanClazzArray)) { + slotIndex = DataBus.offerSlotByClass(ListUtil.toList(contextBeanClazzArray)); + } + else { + slotIndex = DataBus.offerSlotByBean(ListUtil.toList(contextBeanArray)); + } + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { + LOG.info("slot[{}] offered", slotIndex); + } + } - //如果不是隐式流程,那么需要分配Slot - if (innerChainType.equals(InnerChainTypeEnum.NONE) && ObjectUtil.isNull(slotIndex)) { - //这里可以根据class分配,也可以根据bean去分配 - if (ArrayUtil.isNotEmpty(contextBeanClazzArray)) { - slotIndex = DataBus.offerSlotByClass(ListUtil.toList(contextBeanClazzArray)); - } else { - slotIndex = DataBus.offerSlotByBean(ListUtil.toList(contextBeanArray)); - } - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { - LOG.info("slot[{}] offered", slotIndex); - } - } + if (slotIndex == -1) { + throw new NoAvailableSlotException("there is no available slot"); + } - if (slotIndex == -1) { - throw new NoAvailableSlotException("there is no available slot"); - } + Slot slot = DataBus.getSlot(slotIndex); + if (ObjectUtil.isNull(slot)) { + throw new NoAvailableSlotException(StrUtil.format("the slot[{}] is not exist", slotIndex)); + } + // 如果是隐式流程,事先把subException给置空,然后把隐式流程的chainId放入slot元数据中 + // 我知道这在多线程调用隐式流程中会有问题。但是考虑到这种场景的不会多,也有其他的转换方式。 + // 所以暂且这么做,以后再优化 + if (!innerChainType.equals(InnerChainTypeEnum.NONE)) { + slot.removeSubException(chainId); + slot.addSubChain(chainId); + } - Slot slot = DataBus.getSlot(slotIndex); - if (ObjectUtil.isNull(slot)) { - throw new NoAvailableSlotException(StrUtil.format("the slot[{}] is not exist", slotIndex)); - } + if (StrUtil.isBlank(slot.getRequestId())) { + slot.generateRequestId(); + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { + LOG.info("requestId[{}] has generated", slot.getRequestId()); + } + } - //如果是隐式流程,事先把subException给置空,然后把隐式流程的chainId放入slot元数据中 - //我知道这在多线程调用隐式流程中会有问题。但是考虑到这种场景的不会多,也有其他的转换方式。 - //所以暂且这么做,以后再优化 - if (!innerChainType.equals(InnerChainTypeEnum.NONE)) { - slot.removeSubException(chainId); - slot.addSubChain(chainId); - } + if (ObjectUtil.isNotNull(param)) { + if (innerChainType.equals(InnerChainTypeEnum.NONE)) { + slot.setRequestData(param); + } + else if (innerChainType.equals(InnerChainTypeEnum.IN_SYNC)) { + slot.setChainReqData(chainId, param); + } + else if (innerChainType.equals(InnerChainTypeEnum.IN_ASYNC)) { + slot.setChainReqData2Queue(chainId, param); + } + } - if (StrUtil.isBlank(slot.getRequestId())) { - slot.generateRequestId(); - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { - LOG.info("requestId[{}] has generated", slot.getRequestId()); - } - } + Chain chain = null; + try { + chain = FlowBus.getChain(chainId); - if (ObjectUtil.isNotNull(param)) { - if (innerChainType.equals(InnerChainTypeEnum.NONE)) { - slot.setRequestData(param); - } else if (innerChainType.equals(InnerChainTypeEnum.IN_SYNC)) { - slot.setChainReqData(chainId, param); - } else if (innerChainType.equals(InnerChainTypeEnum.IN_ASYNC)) { - slot.setChainReqData2Queue(chainId, param); - } - } + if (ObjectUtil.isNull(chain)) { + String errorMsg = StrUtil.format("[{}]:couldn't find chain with the id[{}]", slot.getRequestId(), + chainId); + throw new ChainNotFoundException(errorMsg); + } + // 执行chain + chain.execute(slotIndex); + } + catch (ChainEndException e) { + if (ObjectUtil.isNotNull(chain)) { + String warnMsg = StrUtil.format("[{}]:chain[{}] execute end on slot[{}]", slot.getRequestId(), + chain.getChainName(), slotIndex); + LOG.warn(warnMsg); + } + } + catch (Exception e) { + if (ObjectUtil.isNotNull(chain)) { + String errMsg = StrUtil.format("[{}]:chain[{}] execute error on slot[{}]", slot.getRequestId(), + chain.getChainName(), slotIndex); + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { + LOG.error(errMsg, e); + } + else { + LOG.error(errMsg); + } + } + else { + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { + LOG.error(e.getMessage(), e); + } + else { + LOG.error(e.getMessage()); + } + } - Chain chain = null; - try { - chain = FlowBus.getChain(chainId); + // 如果是正常流程需要把异常设置到slot的exception属性里 + // 如果是隐式流程,则需要设置到隐式流程的exception属性里 + if (innerChainType.equals(InnerChainTypeEnum.NONE)) { + slot.setException(e); + } + else { + slot.setSubException(chainId, e); + } + } + finally { + if (innerChainType.equals(InnerChainTypeEnum.NONE)) { + slot.printStep(); + DataBus.releaseSlot(slotIndex); + } + } + return slot; + } - if (ObjectUtil.isNull(chain)) { - String errorMsg = StrUtil.format("[{}]:couldn't find chain with the id[{}]", slot.getRequestId(), chainId); - throw new ChainNotFoundException(errorMsg); - } - // 执行chain - chain.execute(slotIndex); - } catch (ChainEndException e) { - if (ObjectUtil.isNotNull(chain)) { - String warnMsg = StrUtil.format("[{}]:chain[{}] execute end on slot[{}]", slot.getRequestId(), chain.getChainName(), slotIndex); - LOG.warn(warnMsg); - } - } catch (Exception e) { - if (ObjectUtil.isNotNull(chain)) { - String errMsg = StrUtil.format("[{}]:chain[{}] execute error on slot[{}]", slot.getRequestId(), chain.getChainName(), slotIndex); - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { - LOG.error(errMsg, e); - } else { - LOG.error(errMsg); - } - } else { - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { - LOG.error(e.getMessage(), e); - } else { - LOG.error(e.getMessage()); - } - } + public LiteflowConfig getLiteflowConfig() { + return liteflowConfig; + } - //如果是正常流程需要把异常设置到slot的exception属性里 - //如果是隐式流程,则需要设置到隐式流程的exception属性里 - if (innerChainType.equals(InnerChainTypeEnum.NONE)) { - slot.setException(e); - } else { - slot.setSubException(chainId, e); - } - } finally { - if (innerChainType.equals(InnerChainTypeEnum.NONE)) { - slot.printStep(); - DataBus.releaseSlot(slotIndex); - } - } - return slot; - } + public void setLiteflowConfig(LiteflowConfig liteflowConfig) { + this.liteflowConfig = liteflowConfig; + // 把liteFlowConfig设到LiteFlowGetter中去 + LiteflowConfigGetter.setLiteflowConfig(liteflowConfig); + } - public LiteflowConfig getLiteflowConfig() { - return liteflowConfig; - } + /** + * 添加监听文件路径 + * @param pathList 文件路径 + */ + private void addMonitorFilePaths(List pathList) throws Exception { + // 添加规则文件监听 + List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); + MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); + } - public void setLiteflowConfig(LiteflowConfig liteflowConfig) { - this.liteflowConfig = liteflowConfig; - //把liteFlowConfig设到LiteFlowGetter中去 - LiteflowConfigGetter.setLiteflowConfig(liteflowConfig); - } - - /** - * 添加监听文件路径 - * - * @param pathList 文件路径 - */ - private void addMonitorFilePaths(List pathList) throws Exception { - // 添加规则文件监听 - List fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList); - MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath); - } } \ No newline at end of file diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutorHolder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutorHolder.java index 436a9bbf..faaa95a4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutorHolder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutorHolder.java @@ -9,27 +9,28 @@ import com.yomahub.liteflow.property.LiteflowConfig; */ public class FlowExecutorHolder { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - public static FlowExecutor loadInstance(LiteflowConfig liteflowConfig){ - if (ObjectUtil.isNull(flowExecutor)){ - flowExecutor = new FlowExecutor(liteflowConfig); - } - return flowExecutor; - } + public static FlowExecutor loadInstance(LiteflowConfig liteflowConfig) { + if (ObjectUtil.isNull(flowExecutor)) { + flowExecutor = new FlowExecutor(liteflowConfig); + } + return flowExecutor; + } - public static FlowExecutor loadInstance(){ - if (ObjectUtil.isNull(flowExecutor)){ - throw new FlowExecutorNotInitException("flow executor is not initialized yet"); - } - return flowExecutor; - } + public static FlowExecutor loadInstance() { + if (ObjectUtil.isNull(flowExecutor)) { + throw new FlowExecutorNotInitException("flow executor is not initialized yet"); + } + return flowExecutor; + } - public static void setHolder(FlowExecutor flowExecutor){ - FlowExecutorHolder.flowExecutor = flowExecutor; - } + public static void setHolder(FlowExecutor flowExecutor) { + FlowExecutorHolder.flowExecutor = flowExecutor; + } + + public static void clean() { + flowExecutor = null; + } - public static void clean(){ - flowExecutor = null; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowInitHook.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowInitHook.java index 5e15e285..4e4ea12c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowInitHook.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowInitHook.java @@ -7,27 +7,27 @@ import java.util.List; import java.util.function.BooleanSupplier; /** - * 流程初始化的钩子类,所有的钩子都放在这里 - * 目前钩子主要是放一些第三方中间件的规则监听 - * 放的钩子要求都是无入参无返回的,所以这里是BooleanSupplier + * 流程初始化的钩子类,所有的钩子都放在这里 目前钩子主要是放一些第三方中间件的规则监听 放的钩子要求都是无入参无返回的,所以这里是BooleanSupplier + * * @author Bryan.Zhang * @since 2.9.4 */ public class FlowInitHook { - private static final List supplierList = new ArrayList<>(); + private static final List supplierList = new ArrayList<>(); - public static void executeHook(){ - if (CollUtil.isNotEmpty(supplierList)){ - supplierList.forEach(BooleanSupplier::getAsBoolean); - } - } + public static void executeHook() { + if (CollUtil.isNotEmpty(supplierList)) { + supplierList.forEach(BooleanSupplier::getAsBoolean); + } + } - public static void addHook(BooleanSupplier hookSupplier){ - supplierList.add(hookSupplier); - } + public static void addHook(BooleanSupplier hookSupplier) { + supplierList.add(hookSupplier); + } + + public static void cleanHook() { + supplierList.clear(); + } - public static void cleanHook(){ - supplierList.clear(); - } } 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 index 75bbcdd8..dc5cb150 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBreakComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeBreakComponent.java @@ -5,17 +5,20 @@ import com.yomahub.liteflow.util.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 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; - public abstract boolean processBreak() throws Exception; } 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 fc44f66b..6aa69417 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 @@ -32,9 +32,10 @@ import java.util.Map; /** * 普通组件抽象类 + * * @author Bryan.Zhang */ -public abstract class NodeComponent{ +public abstract class NodeComponent { private final Logger LOG = LoggerFactory.getLogger(this.getClass()); @@ -46,42 +47,41 @@ public abstract class NodeComponent{ private NodeTypeEnum type; - //这是自己的实例,取代this - //为何要设置这个,用this不行么,因为如果有aop去切的话,this在spring的aop里是切不到的。self对象有可能是代理过的对象 + // 这是自己的实例,取代this + // 为何要设置这个,用this不行么,因为如果有aop去切的话,this在spring的aop里是切不到的。self对象有可能是代理过的对象 private NodeComponent self; - //重试次数 + // 重试次数 private int retryCount = 0; - //在目标异常抛出时才重试 - private Class[] retryForExceptions = new Class[]{Exception.class}; + // 在目标异常抛出时才重试 + private Class[] retryForExceptions = new Class[] { Exception.class }; /** 节点执行器的类全名 */ private Class nodeExecutorClass = DefaultNodeExecutor.class; - /**当前对象为单例,注册进spring上下文,但是node实例不是单例,这里通过对node实例的引用来获得一些链路属性**/ + /** 当前对象为单例,注册进spring上下文,但是node实例不是单例,这里通过对node实例的引用来获得一些链路属性 **/ private final TransmittableThreadLocal refNodeTL = new TransmittableThreadLocal<>(); /** - *******************以下的属性为线程附加属性******************** - * 线程属性是指每一个request的值都是不一样的 + ******************* 以下的属性为线程附加属性******************** 线程属性是指每一个request的值都是不一样的 * 这里NodeComponent是单例,所以要用ThreadLocal来修饰 */ - //当前slot的index + // 当前slot的index private final TransmittableThreadLocal slotIndexTL = new TransmittableThreadLocal<>(); - //是否结束整个流程,这个只对串行流程有效,并行流程无效 + // 是否结束整个流程,这个只对串行流程有效,并行流程无效 private final TransmittableThreadLocal isEndTL = new TransmittableThreadLocal<>(); public NodeComponent() { } - public void execute() throws Exception{ + public void execute() throws Exception { Slot slot = this.getSlot(); - //在元数据里加入step信息 + // 在元数据里加入step信息 CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE); cmpStep.setTag(this.getTag()); slot.addStep(cmpStep); @@ -89,42 +89,46 @@ public abstract class NodeComponent{ StopWatch stopWatch = new StopWatch(); stopWatch.start(); - - try{ - //前置处理 + try { + // 前置处理 self.beforeProcess(); - //主要的处理逻辑 + // 主要的处理逻辑 self.process(); - //成功后回调方法 + // 成功后回调方法 self.onSuccess(); - //步骤状态设为true + // 步骤状态设为true cmpStep.setSuccess(true); - } catch (Exception e){ - //步骤状态设为false,并加入异常 + } + catch (Exception e) { + // 步骤状态设为false,并加入异常 cmpStep.setSuccess(false); cmpStep.setException(e); - //执行失败后回调方法 - //这里要注意,失败方法本身抛出错误,只打出堆栈,往外抛出的还是主要的异常 - try{ + // 执行失败后回调方法 + // 这里要注意,失败方法本身抛出错误,只打出堆栈,往外抛出的还是主要的异常 + try { self.onError(); - }catch (Exception ex){ - String errMsg = StrUtil.format("[{}]:component[{}] onError method happens exception",slot.getRequestId(),this.getDisplayName()); + } + catch (Exception ex) { + String errMsg = StrUtil.format("[{}]:component[{}] onError method happens exception", + slot.getRequestId(), this.getDisplayName()); LOG.error(errMsg); } throw e; - } finally { - //后置处理 + } + finally { + // 后置处理 self.afterProcess(); stopWatch.stop(); final long timeSpent = stopWatch.getTotalTimeMillis(); - LOG.debug("[{}]:component[{}] finished in {} milliseconds",slot.getRequestId(),this.getDisplayName(),timeSpent); + LOG.debug("[{}]:component[{}] finished in {} milliseconds", slot.getRequestId(), this.getDisplayName(), + timeSpent); - //往CmpStep中放入时间消耗信息 + // 往CmpStep中放入时间消耗信息 cmpStep.setTimeSpent(timeSpent); // 性能统计 @@ -135,52 +139,53 @@ public abstract class NodeComponent{ } } - public void beforeProcess(){ - //全局切面只在spring体系下生效,这里用了spi机制取到相应环境下的实现类 - //非spring环境下,全局切面为空实现 + public void beforeProcess() { + // 全局切面只在spring体系下生效,这里用了spi机制取到相应环境下的实现类 + // 非spring环境下,全局切面为空实现 CmpAroundAspectHolder.loadCmpAroundAspect().beforeProcess(nodeId, this.getSlot()); } public abstract void process() throws Exception; - public void onSuccess() throws Exception{ - //如果需要在成功后回调某一个方法,请覆盖这个方法 + public void onSuccess() throws Exception { + // 如果需要在成功后回调某一个方法,请覆盖这个方法 } - public void onError() throws Exception{ - //如果需要在抛错后回调某一段逻辑,请覆盖这个方法 + public void onError() throws Exception { + // 如果需要在抛错后回调某一段逻辑,请覆盖这个方法 } - public void afterProcess(){ + public void afterProcess() { CmpAroundAspectHolder.loadCmpAroundAspect().afterProcess(nodeId, this.getSlot()); } - //是否进入该节点 - public boolean isAccess(){ + // 是否进入该节点 + public boolean isAccess() { return true; } - //出错是否继续执行(这个只适用于并行流程,串行流程不起作用) + // 出错是否继续执行(这个只适用于并行流程,串行流程不起作用) public boolean isContinueOnError() { return false; } - //是否结束整个流程(不往下继续执行) + // 是否结束整个流程(不往下继续执行) public boolean isEnd() { Boolean isEnd = isEndTL.get(); - if(ObjectUtil.isNull(isEnd)){ + if (ObjectUtil.isNull(isEnd)) { return false; - } else { + } + else { return isEndTL.get(); } } - //设置是否结束整个流程 - public void setIsEnd(boolean isEnd){ + // 设置是否结束整个流程 + public void setIsEnd(boolean isEnd) { this.isEndTL.set(isEnd); } - public void removeIsEnd(){ + public void removeIsEnd() { this.isEndTL.remove(); } @@ -193,19 +198,19 @@ public abstract class NodeComponent{ return this.slotIndexTL.get(); } - public void removeSlotIndex(){ + public void removeSlotIndex() { this.slotIndexTL.remove(); } - public Slot getSlot(){ + public Slot getSlot() { return DataBus.getSlot(this.slotIndexTL.get()); } - public T getFirstContextBean(){ + public T getFirstContextBean() { return this.getSlot().getFirstContextBean(); } - public T getContextBean(Class contextBeanClazz){ + public T getContextBean(Class contextBeanClazz) { return this.getSlot().getContextBean(contextBeanClazz); } @@ -241,11 +246,11 @@ public abstract class NodeComponent{ this.type = type; } - public void sendPrivateDeliveryData(String nodeId, T t){ + public void sendPrivateDeliveryData(String nodeId, T t) { this.getSlot().setPrivateDeliveryData(nodeId, t); } - public T getPrivateDeliveryData(){ + public T getPrivateDeliveryData() { return this.getSlot().getPrivateDeliveryData(this.getNodeId()); } @@ -273,7 +278,7 @@ public abstract class NodeComponent{ this.nodeExecutorClass = nodeExecutorClass; } - public String getTag(){ + public String getTag() { return this.refNodeTL.get().getTag(); } @@ -285,15 +290,15 @@ public abstract class NodeComponent{ this.monitorBus = monitorBus; } - public T getRequestData(){ + public T getRequestData() { return getSlot().getRequestData(); } - public T getSubChainReqData(){ + public T getSubChainReqData() { return getSlot().getChainReqData(this.getCurrChainId()); } - public T getSubChainReqDataInAsync(){ + public T getSubChainReqDataInAsync() { return getSlot().getChainReqDataFromQueue(this.getCurrChainId()); } @@ -302,54 +307,55 @@ public abstract class NodeComponent{ * @return String */ @Deprecated - public String getChainName(){ + public String getChainName() { return getSlot().getChainName(); } - - public String getChainId(){ + + public String getChainId() { return getSlot().getChainId(); } - public String getDisplayName(){ - if(StrUtil.isEmpty(this.name)){ + public String getDisplayName() { + if (StrUtil.isEmpty(this.name)) { return this.nodeId; - }else { + } + else { return StrUtil.format("{}({})", this.nodeId, this.name); } } - public String getCurrChainId(){ + public String getCurrChainId() { return getRefNode().getCurrChainId(); } - public Node getRefNode(){ + public Node getRefNode() { return this.refNodeTL.get(); } - public void setRefNode(Node refNode){ + public void setRefNode(Node refNode) { this.refNodeTL.set(refNode); } - public void removeRefNode(){ + public void removeRefNode() { this.refNodeTL.remove(); } - public T getCmpData(Class clazz){ + public T getCmpData(Class clazz) { String cmpData = getRefNode().getCmpData(); - if (StrUtil.isBlank(cmpData)){ + if (StrUtil.isBlank(cmpData)) { return null; } - if (clazz.equals(String.class) || clazz.equals(Object.class)){ + if (clazz.equals(String.class) || clazz.equals(Object.class)) { return (T) cmpData; } return JsonUtil.parseObject(cmpData, clazz); } - public Integer getLoopIndex(){ + public Integer getLoopIndex() { return this.refNodeTL.get().getLoopIndex(); } - public T getCurrLoopObj(){ + public T getCurrLoopObj() { return this.refNodeTL.get().getCurrLoopObject(); } @@ -370,4 +376,5 @@ public abstract class NodeComponent{ public LiteflowResponse invoke2RespInAsync(String chainId, Object param) { return FlowExecutorHolder.loadInstance().invoke2RespInAsync(chainId, param, this.getSlotIndex()); } + } 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 0c8b4d45..2f530d31 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 @@ -5,18 +5,20 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; /** * FOR计数节点抽象类 + * * @author Bryan.Zhang * @since 2.9.0 */ -public abstract class NodeForComponent extends NodeComponent{ +public abstract class NodeForComponent extends NodeComponent { - @Override - public void process() throws Exception { - int forCount = processFor(); - Slot slot = this.getSlot(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - slot.setForResult(originalClass.getName(), forCount); - } + @Override + public void process() throws Exception { + int forCount = processFor(); + Slot slot = this.getSlot(); + Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); + slot.setForResult(originalClass.getName(), forCount); + } + + public abstract int processFor() throws Exception; - public abstract int processFor() throws Exception; } 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 index eed332cc..f08ae828 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIfComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeIfComponent.java @@ -4,17 +4,19 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; /** * IF节点抽象类 + * * @author Bryan.Zhang * @since 2.8.5 */ -public abstract class NodeIfComponent extends NodeComponent{ +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); - } + @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; - public abstract boolean processIf() throws Exception; } 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 03710dfc..2b49dec5 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 @@ -7,18 +7,20 @@ import java.util.Iterator; /** * ITERATOR迭代器循环组件抽象类 + * * @author Bryan.Zhang * @since 2.9.7 */ -public abstract class NodeIteratorComponent extends NodeComponent{ +public abstract class NodeIteratorComponent extends NodeComponent { - @Override - public void process() throws Exception { - Iterator it = processIterator(); - Slot slot = this.getSlot(); - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); - slot.setIteratorResult(originalClass.getName(), it); - } + @Override + public void process() throws Exception { + Iterator it = processIterator(); + Slot slot = this.getSlot(); + Class originalClass = LiteFlowProxyUtil.getUserClass(this.getClass()); + slot.setIteratorResult(originalClass.getName(), it); + } + + public abstract Iterator processIterator() throws Exception; - public abstract Iterator processIterator() throws Exception; } 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 aed00436..d94caa2e 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 @@ -11,6 +11,7 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; /** * 条件路由节点抽象类 + * * @author Bryan.Zhang */ public abstract class NodeSwitchComponent extends NodeComponent { @@ -22,7 +23,7 @@ public abstract class NodeSwitchComponent extends NodeComponent { this.getSlot().setSwitchResult(originalClass.getName(), nodeId); } - //用以返回路由节点的beanId + // 用以返回路由节点的beanId public abstract String processSwitch() throws Exception; } 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 index 1aa4216a..f04c05fe 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeWhileComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeWhileComponent.java @@ -5,17 +5,20 @@ import com.yomahub.liteflow.util.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 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; - public abstract boolean processWhile() throws Exception; } 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 index 83f8d347..dbcd61f3 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBreakComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptBreakComponent.java @@ -7,23 +7,28 @@ 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 = new ScriptExecuteWrap(); - wrap.setCurrChainId(this.getCurrChainId()); - wrap.setNodeId(this.getNodeId()); - wrap.setSlotIndex(this.getSlotIndex()); - wrap.setTag(this.getTag()); - wrap.setCmpData(this.getCmpData(Map.class)); - return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap); - } +public class ScriptBreakComponent extends NodeBreakComponent implements ScriptComponent { + + @Override + public boolean processBreak() throws Exception { + ScriptExecuteWrap wrap = new ScriptExecuteWrap(); + wrap.setCurrChainId(this.getCurrChainId()); + wrap.setNodeId(this.getNodeId()); + wrap.setSlotIndex(this.getSlotIndex()); + wrap.setTag(this.getTag()); + wrap.setCmpData(this.getCmpData(Map.class)); + 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); + } - @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/ScriptCommonComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptCommonComponent.java index 8187849f..d38e4cbb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptCommonComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptCommonComponent.java @@ -9,27 +9,29 @@ import java.util.Map; /** * 脚本组件类 + * * @author Bryan.Zhang * @since 2.6.0 */ -public class ScriptCommonComponent extends NodeComponent implements ScriptComponent{ +public class ScriptCommonComponent extends NodeComponent implements ScriptComponent { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Override - public void process() throws Exception { - ScriptExecuteWrap wrap = new ScriptExecuteWrap(); - wrap.setCurrChainId(this.getCurrChainId()); - wrap.setNodeId(this.getNodeId()); - wrap.setSlotIndex(this.getSlotIndex()); - wrap.setTag(this.getTag()); - wrap.setCmpData(this.getCmpData(Map.class)); - ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap); - } + @Override + public void process() throws Exception { + ScriptExecuteWrap wrap = new ScriptExecuteWrap(); + wrap.setCurrChainId(this.getCurrChainId()); + wrap.setNodeId(this.getNodeId()); + wrap.setSlotIndex(this.getSlotIndex()); + wrap.setTag(this.getTag()); + wrap.setCmpData(this.getCmpData(Map.class)); + ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap); + } + + @Override + public void loadScript(String script, String language) { + log.info("load script for component[{}]", getDisplayName()); + ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script); + } - @Override - public void loadScript(String script, String language) { - log.info("load script for component[{}]", getDisplayName()); - 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 efb8009f..c6d9d99e 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 @@ -7,26 +7,30 @@ import java.util.Map; /** * 脚本接口 + * * @author Bryan.Zhang * @since 2.9.0 */ public interface ScriptComponent { - /** - * 用于维护脚本类型和脚本 cmp 的映射关系 - */ - Map> ScriptComponentClassMap = new HashMap>() {{ - put(NodeTypeEnum.SCRIPT, ScriptCommonComponent.class); - put(NodeTypeEnum.SWITCH_SCRIPT, ScriptSwitchComponent.class); - put(NodeTypeEnum.IF_SCRIPT, ScriptIfComponent.class); - put(NodeTypeEnum.FOR_SCRIPT, ScriptForComponent.class); - put(NodeTypeEnum.WHILE_SCRIPT, ScriptWhileComponent.class); - put(NodeTypeEnum.BREAK_SCRIPT, ScriptBreakComponent.class); - }}; + /** + * 用于维护脚本类型和脚本 cmp 的映射关系 + */ + Map> ScriptComponentClassMap = new HashMap>() { + { + put(NodeTypeEnum.SCRIPT, ScriptCommonComponent.class); + put(NodeTypeEnum.SWITCH_SCRIPT, ScriptSwitchComponent.class); + put(NodeTypeEnum.IF_SCRIPT, ScriptIfComponent.class); + put(NodeTypeEnum.FOR_SCRIPT, ScriptForComponent.class); + put(NodeTypeEnum.WHILE_SCRIPT, ScriptWhileComponent.class); + put(NodeTypeEnum.BREAK_SCRIPT, ScriptBreakComponent.class); + } + }; + + /** + * 加载脚本 + * @param script + */ + void loadScript(String script, String language); - /** - * 加载脚本 - * @param script - */ - void loadScript(String script, String language); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptForComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptForComponent.java index bb2cf78c..5a677f2a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptForComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptForComponent.java @@ -7,23 +7,28 @@ import java.util.Map; /** * 脚本FOR节点 + * * @author Bryan.Zhang * @since 2.9.0 */ -public class ScriptForComponent extends NodeForComponent implements ScriptComponent{ - @Override - public int processFor() throws Exception { - ScriptExecuteWrap wrap = new ScriptExecuteWrap(); - wrap.setCurrChainId(this.getCurrChainId()); - wrap.setNodeId(this.getNodeId()); - wrap.setSlotIndex(this.getSlotIndex()); - wrap.setTag(this.getTag()); - wrap.setCmpData(this.getCmpData(Map.class)); - return (int) ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap); - } +public class ScriptForComponent extends NodeForComponent implements ScriptComponent { + + @Override + public int processFor() throws Exception { + ScriptExecuteWrap wrap = new ScriptExecuteWrap(); + wrap.setCurrChainId(this.getCurrChainId()); + wrap.setNodeId(this.getNodeId()); + wrap.setSlotIndex(this.getSlotIndex()); + wrap.setTag(this.getTag()); + wrap.setCmpData(this.getCmpData(Map.class)); + return (int) ScriptExecutorFactory.loadInstance() + .getScriptExecutor(this.getRefNode().getLanguage()) + .execute(wrap); + } + + @Override + public void loadScript(String script, String language) { + ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script); + } - @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/ScriptIfComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptIfComponent.java index 4e74abf9..f808b93e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptIfComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptIfComponent.java @@ -7,23 +7,28 @@ import java.util.Map; /** * 脚本IF节点 + * * @author Bryan.Zhang * @since 2.8.5 */ -public class ScriptIfComponent extends NodeIfComponent implements ScriptComponent{ - @Override - public boolean processIf() throws Exception { - ScriptExecuteWrap wrap = new ScriptExecuteWrap(); - wrap.setCurrChainId(this.getCurrChainId()); - wrap.setNodeId(this.getNodeId()); - wrap.setSlotIndex(this.getSlotIndex()); - wrap.setTag(this.getTag()); - wrap.setCmpData(this.getCmpData(Map.class)); - return (boolean)ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap); - } +public class ScriptIfComponent extends NodeIfComponent implements ScriptComponent { + + @Override + public boolean processIf() throws Exception { + ScriptExecuteWrap wrap = new ScriptExecuteWrap(); + wrap.setCurrChainId(this.getCurrChainId()); + wrap.setNodeId(this.getNodeId()); + wrap.setSlotIndex(this.getSlotIndex()); + wrap.setTag(this.getTag()); + wrap.setCmpData(this.getCmpData(Map.class)); + 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); + } - @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/ScriptSwitchComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptSwitchComponent.java index 808a3c6d..b22490b5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptSwitchComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptSwitchComponent.java @@ -7,24 +7,28 @@ import java.util.Map; /** * 脚本条件节点 + * * @author Bryan.Zhang * @since 2.6.0 */ -public class ScriptSwitchComponent extends NodeSwitchComponent implements ScriptComponent{ +public class ScriptSwitchComponent extends NodeSwitchComponent implements ScriptComponent { - @Override - public String processSwitch() throws Exception { - ScriptExecuteWrap wrap = new ScriptExecuteWrap(); - wrap.setCurrChainId(this.getCurrChainId()); - wrap.setNodeId(this.getNodeId()); - wrap.setSlotIndex(this.getSlotIndex()); - wrap.setTag(this.getTag()); - wrap.setCmpData(this.getCmpData(Map.class)); - return (String)ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap); - } + @Override + public String processSwitch() throws Exception { + ScriptExecuteWrap wrap = new ScriptExecuteWrap(); + wrap.setCurrChainId(this.getCurrChainId()); + wrap.setNodeId(this.getNodeId()); + wrap.setSlotIndex(this.getSlotIndex()); + wrap.setTag(this.getTag()); + wrap.setCmpData(this.getCmpData(Map.class)); + return (String) ScriptExecutorFactory.loadInstance() + .getScriptExecutor(this.getRefNode().getLanguage()) + .execute(wrap); + } + + @Override + public void loadScript(String script, String language) { + ScriptExecutorFactory.loadInstance().getScriptExecutor(language).load(getNodeId(), script); + } - @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/ScriptWhileComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptWhileComponent.java index 6ed65120..f86eb088 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptWhileComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/ScriptWhileComponent.java @@ -7,24 +7,28 @@ import java.util.Map; /** * 脚本WHILE节点 + * * @author Bryan.Zhang * @since 2.9.0 */ -public class ScriptWhileComponent extends NodeWhileComponent implements ScriptComponent{ +public class ScriptWhileComponent extends NodeWhileComponent implements ScriptComponent { - @Override - public boolean processWhile() throws Exception { - ScriptExecuteWrap wrap = new ScriptExecuteWrap(); - wrap.setCurrChainId(this.getCurrChainId()); - wrap.setNodeId(this.getNodeId()); - wrap.setSlotIndex(this.getSlotIndex()); - wrap.setTag(this.getTag()); - wrap.setCmpData(this.getCmpData(Map.class)); - return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor(this.getRefNode().getLanguage()).execute(wrap); - } + @Override + public boolean processWhile() throws Exception { + ScriptExecuteWrap wrap = new ScriptExecuteWrap(); + wrap.setCurrChainId(this.getCurrChainId()); + wrap.setNodeId(this.getNodeId()); + wrap.setSlotIndex(this.getSlotIndex()); + wrap.setTag(this.getTag()); + wrap.setCmpData(this.getCmpData(Map.class)); + 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); + } - @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/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java index eb54fb17..7de14644 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -34,181 +34,190 @@ import java.util.stream.Collectors; /** * 声明式组件的代理核心生成类 + * * @author Bryan.Zhang * @since 2.6.14 */ public class ComponentProxy { - private final Logger LOG = LoggerFactory.getLogger(this.getClass()); + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); - private final String nodeId; + private final String nodeId; - private final Object bean; + private final Object bean; - private final Class clazz; + private final Class clazz; - public ComponentProxy(String nodeId, Object bean, Class clazz) { - this.nodeId = nodeId; - this.bean = bean; - this.clazz = clazz; - } + public ComponentProxy(String nodeId, Object bean, Class clazz) { + this.nodeId = nodeId; + this.bean = bean; + this.clazz = clazz; + } - public List getProxyList() throws Exception{ - //这里要判断bean是否是spring代理过的bean,如果是代理过的bean需要取到原class对象 - Class beanClazz; - if (LiteFlowProxyUtil.isCglibProxyClass(bean.getClass())){ - beanClazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); - }else{ - beanClazz = bean.getClass(); - } - //得到当前bean里所覆盖的LiteflowMethod(一定是被@LiteFlowMethod修饰的),自己定义的不算 - Map> methodListMap = Arrays.stream(beanClazz.getMethods()).filter( - m -> m.getAnnotation(LiteflowMethod.class) != null - ).collect(Collectors.groupingBy( - m -> m.getAnnotation(LiteflowMethod.class).nodeId() - )); + public List getProxyList() throws Exception { + // 这里要判断bean是否是spring代理过的bean,如果是代理过的bean需要取到原class对象 + Class beanClazz; + if (LiteFlowProxyUtil.isCglibProxyClass(bean.getClass())) { + beanClazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); + } + else { + beanClazz = bean.getClass(); + } + // 得到当前bean里所覆盖的LiteflowMethod(一定是被@LiteFlowMethod修饰的),自己定义的不算 + Map> methodListMap = Arrays.stream(beanClazz.getMethods()) + .filter(m -> m.getAnnotation(LiteflowMethod.class) != null) + .collect(Collectors.groupingBy(m -> m.getAnnotation(LiteflowMethod.class).nodeId())); - return methodListMap.entrySet().stream().map(entry -> { - // 获取当前节点的原有注解,如:LiteFlowRetry 之类的规则注解 - Annotation[] beanClassAnnotation = beanClazz.getAnnotations(); - // 如果entry的key为空字符串,则是为了兼容老版本的写法,即:没有指定nodeId的情况 - // 判断是否是方法级创造节点 - boolean isMethodCreate = !StrUtil.isEmpty(entry.getKey()); - // 获取当前bean 真实的nodeId - String activeNodeId = isMethodCreate ? entry.getKey() : nodeId; - // 获取当前节点所有的@LiteflowRetry @LiteflowMethod注解对 - List tupleList = entry.getValue().stream().map(m -> - new Tuple(m.getAnnotation(LiteflowRetry.class), m.getAnnotation(LiteflowMethod.class)) - ).collect(Collectors.toList()); - // 获取当前节点的所有LiteFlowMethod注解 - List methodList = tupleList.stream().map(tuple -> ((LiteflowMethod)tuple.get(1))) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - // nodeType去重 - List> classes = methodList.stream() - .map(LiteflowMethod::nodeType) - .map(NodeTypeEnum::getMappingClazz) - .distinct() - .collect(Collectors.toList()); - // 相同nodeId里只能定义同一种的类型的NodeComponent - boolean legal = classes.size() == 1; - if (!legal){ - throw new LiteFlowException("The cmpClass of the same nodeId must be the same,you declared nodeId:" + activeNodeId + ",cmpClass:" + classes); - } - // 当前节点实际LiteflowRetry注解 - AtomicReference liteflowRetryAtomicReference = new AtomicReference<>(null); - // 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上 - boolean illegal = tupleList.stream().anyMatch( - tuple -> { - LiteflowRetry liteflowRetry = tuple.get(0); - LiteflowMethod liteflowMethod = tuple.get(1); - boolean existRetry = liteflowRetry != null; - boolean isProcess = liteflowMethod.value().isMainMethod(); - // 如果是再Process方法上的liteflowRetry注解,则默认为真实节点。 - if (isProcess && existRetry) { - liteflowRetryAtomicReference.set(liteflowRetry); - } - // 如果存在existRetry注解,但是不是在Process方法上,则为非法 - return existRetry && !isProcess; - } - ); - if (illegal){ - throw new LiteFlowException("the retry annotation (@LiteflowRetry) must be declared on the PROCESS method"); - } - // 生成nodeCmp的类型,默认为全局定义的clazz - Class cmpClazz; - cmpClazz = clazz; - // 判断是否是方法声明的组件 - if (isMethodCreate){ - cmpClazz = methodList.iterator().next().nodeType().getMappingClazz(); - LiteflowRetry liteflowRetry; - if ((liteflowRetry = liteflowRetryAtomicReference.get()) != null){ - // 增加LiteFlowRetry注解到注解数组里 - List annotations = Arrays.stream(beanClassAnnotation) - .filter(a -> !a.annotationType().equals(LiteflowRetry.class)) - .collect(Collectors.toList()); - annotations.add(liteflowRetry); - beanClassAnnotation = new Annotation[annotations.size()]; - annotations.toArray(beanClassAnnotation); - } - } - try { - //创建对象 - //这里package进行了重设,放到了被代理对象的所在目录 - //生成的对象也加了上被代理对象拥有的注解 - //被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断 - Object instance = new ByteBuddy().subclass(cmpClazz) - .name(StrUtil.format("{}.ByteBuddy${}${}", - ClassUtil.getPackage(beanClazz), - activeNodeId, - SerialsUtil.generateShortUUID())) - .method(ElementMatchers.namedOneOf(methodList.stream().map(m -> m.value().getMethodName()).toArray(String[]::new))) - .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean))) - .annotateType(beanClassAnnotation) - .make() - .load(ComponentProxy.class.getClassLoader()) - .getLoaded() - .newInstance(); - NodeComponent nodeComponent = (NodeComponent) instance; - // 重设nodeId - nodeComponent.setNodeId(activeNodeId); - return nodeComponent; - } catch (Exception e) { - throw new LiteFlowException(e); - } - }).collect(Collectors.toList()); - } + return methodListMap.entrySet().stream().map(entry -> { + // 获取当前节点的原有注解,如:LiteFlowRetry 之类的规则注解 + Annotation[] beanClassAnnotation = beanClazz.getAnnotations(); + // 如果entry的key为空字符串,则是为了兼容老版本的写法,即:没有指定nodeId的情况 + // 判断是否是方法级创造节点 + boolean isMethodCreate = !StrUtil.isEmpty(entry.getKey()); + // 获取当前bean 真实的nodeId + String activeNodeId = isMethodCreate ? entry.getKey() : nodeId; + // 获取当前节点所有的@LiteflowRetry @LiteflowMethod注解对 + List tupleList = entry.getValue() + .stream() + .map(m -> new Tuple(m.getAnnotation(LiteflowRetry.class), m.getAnnotation(LiteflowMethod.class))) + .collect(Collectors.toList()); + // 获取当前节点的所有LiteFlowMethod注解 + List methodList = tupleList.stream() + .map(tuple -> ((LiteflowMethod) tuple.get(1))) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + // nodeType去重 + List> classes = methodList.stream() + .map(LiteflowMethod::nodeType) + .map(NodeTypeEnum::getMappingClazz) + .distinct() + .collect(Collectors.toList()); + // 相同nodeId里只能定义同一种的类型的NodeComponent + boolean legal = classes.size() == 1; + if (!legal) { + throw new LiteFlowException("The cmpClass of the same nodeId must be the same,you declared nodeId:" + + activeNodeId + ",cmpClass:" + classes); + } + // 当前节点实际LiteflowRetry注解 + AtomicReference liteflowRetryAtomicReference = new AtomicReference<>(null); + // 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上 + boolean illegal = tupleList.stream().anyMatch(tuple -> { + LiteflowRetry liteflowRetry = tuple.get(0); + LiteflowMethod liteflowMethod = tuple.get(1); + boolean existRetry = liteflowRetry != null; + boolean isProcess = liteflowMethod.value().isMainMethod(); + // 如果是再Process方法上的liteflowRetry注解,则默认为真实节点。 + if (isProcess && existRetry) { + liteflowRetryAtomicReference.set(liteflowRetry); + } + // 如果存在existRetry注解,但是不是在Process方法上,则为非法 + return existRetry && !isProcess; + }); + if (illegal) { + throw new LiteFlowException( + "the retry annotation (@LiteflowRetry) must be declared on the PROCESS method"); + } + // 生成nodeCmp的类型,默认为全局定义的clazz + Class cmpClazz; + cmpClazz = clazz; + // 判断是否是方法声明的组件 + if (isMethodCreate) { + cmpClazz = methodList.iterator().next().nodeType().getMappingClazz(); + LiteflowRetry liteflowRetry; + if ((liteflowRetry = liteflowRetryAtomicReference.get()) != null) { + // 增加LiteFlowRetry注解到注解数组里 + List annotations = Arrays.stream(beanClassAnnotation) + .filter(a -> !a.annotationType().equals(LiteflowRetry.class)) + .collect(Collectors.toList()); + annotations.add(liteflowRetry); + beanClassAnnotation = new Annotation[annotations.size()]; + annotations.toArray(beanClassAnnotation); + } + } + try { + // 创建对象 + // 这里package进行了重设,放到了被代理对象的所在目录 + // 生成的对象也加了上被代理对象拥有的注解 + // 被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断 + Object instance = new ByteBuddy().subclass(cmpClazz) + .name(StrUtil.format("{}.ByteBuddy${}${}", ClassUtil.getPackage(beanClazz), activeNodeId, + SerialsUtil.generateShortUUID())) + .method(ElementMatchers + .namedOneOf(methodList.stream().map(m -> m.value().getMethodName()).toArray(String[]::new))) + .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean))) + .annotateType(beanClassAnnotation) + .make() + .load(ComponentProxy.class.getClassLoader()) + .getLoaded() + .newInstance(); + NodeComponent nodeComponent = (NodeComponent) instance; + // 重设nodeId + nodeComponent.setNodeId(activeNodeId); + return nodeComponent; + } + catch (Exception e) { + throw new LiteFlowException(e); + } + }).collect(Collectors.toList()); + } - public class AopInvocationHandler implements InvocationHandler { + public class AopInvocationHandler implements InvocationHandler { - private final Object bean; + private final Object bean; - private final Class clazz; + private final Class clazz; - public AopInvocationHandler(Object bean) { - this.bean = bean; - this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); - } + public AopInvocationHandler(Object bean) { + this.bean = bean; + this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); + } - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - //这里做了2件事情 - //先是从普通的bean里过滤出含有@LiteFlowMethod这个标注的方法 - //然后进行转换成LiteFlowMethodBean对象List,形成键值对的对象 - List liteFlowMethodBeanList = Arrays.stream(ReflectUtil.getMethods(clazz)).filter(m -> { - LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); - return ObjectUtil.isNotNull(liteFlowMethod); - }).filter(m -> { - // 过滤不属于当前NodeComponent的方法 - LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); - return StrUtil.isEmpty(liteFlowMethod.nodeId())|| Objects.equals(liteFlowMethod.nodeId(),((NodeComponent) proxy).getNodeId()); - }).map(m -> { - LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); - return new LiteFlowMethodBean(liteFlowMethod.value().getMethodName(), m); - }).collect(Collectors.toList()); + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + // 这里做了2件事情 + // 先是从普通的bean里过滤出含有@LiteFlowMethod这个标注的方法 + // 然后进行转换成LiteFlowMethodBean对象List,形成键值对的对象 + List liteFlowMethodBeanList = Arrays.stream(ReflectUtil.getMethods(clazz)).filter(m -> { + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return ObjectUtil.isNotNull(liteFlowMethod); + }).filter(m -> { + // 过滤不属于当前NodeComponent的方法 + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return StrUtil.isEmpty(liteFlowMethod.nodeId()) + || Objects.equals(liteFlowMethod.nodeId(), ((NodeComponent) proxy).getNodeId()); + }).map(m -> { + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return new LiteFlowMethodBean(liteFlowMethod.value().getMethodName(), m); + }).collect(Collectors.toList()); - //获取当前调用方法,是否在被代理的对象方法里面(根据@LiteFlowMethod这个标注去判断) - //如果在里面,则返回那个LiteFlowMethodBean,不在则返回null - LiteFlowMethodBean liteFlowMethodBean = liteFlowMethodBeanList.stream().filter( - liteFlowMethodBean1 -> liteFlowMethodBean1.getMethodName().equals(method.getName()) - ).findFirst().orElse(null); + // 获取当前调用方法,是否在被代理的对象方法里面(根据@LiteFlowMethod这个标注去判断) + // 如果在里面,则返回那个LiteFlowMethodBean,不在则返回null + LiteFlowMethodBean liteFlowMethodBean = liteFlowMethodBeanList.stream() + .filter(liteFlowMethodBean1 -> liteFlowMethodBean1.getMethodName().equals(method.getName())) + .findFirst() + .orElse(null); - //如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法 - //进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数 - boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1 - && Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class); - if (!checkFlag) { - String errMsg = StrUtil.format("Method[{}.{}] must have NodeComponent parameter(and only one parameter)", bean.getClass().getName(), liteFlowMethodBean.getMethod().getName()); - LOG.error(errMsg); - throw new ComponentMethodDefineErrorException(errMsg); - } + // 如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法 + // 进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数 + boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1 + && Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class); + if (!checkFlag) { + String errMsg = StrUtil.format( + "Method[{}.{}] must have NodeComponent parameter(and only one parameter)", + bean.getClass().getName(), liteFlowMethodBean.getMethod().getName()); + LOG.error(errMsg); + throw new ComponentMethodDefineErrorException(errMsg); + } + + try { + return liteFlowMethodBean.getMethod().invoke(bean, proxy); + } + catch (Exception e) { + InvocationTargetException targetEx = (InvocationTargetException) e; + throw targetEx.getTargetException(); + } + } + + } - try{ - return liteFlowMethodBean.getMethod().invoke(bean, proxy); - }catch (Exception e){ - InvocationTargetException targetEx = (InvocationTargetException)e; - throw targetEx.getTargetException(); - } - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java index 27388b32..83cb47fa 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java @@ -7,28 +7,29 @@ import java.lang.reflect.Method; */ public class LiteFlowMethodBean { - private String methodName; + private String methodName; - private Method method; + private Method method; - public LiteFlowMethodBean(String methodName, Method method) { - this.methodName = methodName; - this.method = method; - } + public LiteFlowMethodBean(String methodName, Method method) { + this.methodName = methodName; + this.method = method; + } - public String getMethodName() { - return methodName; - } + public String getMethodName() { + return methodName; + } - public void setMethodName(String methodName) { - this.methodName = methodName; - } + public void setMethodName(String methodName) { + this.methodName = methodName; + } - public Method getMethod() { - return method; - } + public Method getMethod() { + return method; + } + + public void setMethod(Method method) { + this.method = method; + } - public void setMethod(Method method) { - this.method = method; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/CmpStepTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/CmpStepTypeEnum.java index fdb5a03f..f01a4f18 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/CmpStepTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/CmpStepTypeEnum.java @@ -9,10 +9,11 @@ package com.yomahub.liteflow.enums; /** * 组件步骤类型 + * * @author Bryan.Zhang */ public enum CmpStepTypeEnum { - START, - END, - SINGLE; + + START, END, SINGLE; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ConditionTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ConditionTypeEnum.java index de9c0207..4ae613e8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ConditionTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ConditionTypeEnum.java @@ -4,52 +4,51 @@ package com.yomahub.liteflow.enums; * @author Yun */ public enum ConditionTypeEnum { - TYPE_THEN("then","then"), - TYPE_WHEN("when","when"), - TYPE_SWITCH("switch", "switch"), - TYPE_IF("if", "if"), - TYPE_PRE("pre","pre"), - TYPE_FINALLY("finally","finally"), + TYPE_THEN("then", "then"), TYPE_WHEN("when", "when"), TYPE_SWITCH("switch", "switch"), - TYPE_FOR("for", "for"), + TYPE_IF("if", "if"), TYPE_PRE("pre", "pre"), TYPE_FINALLY("finally", "finally"), - TYPE_WHILE("while", "while"), + TYPE_FOR("for", "for"), - TYPE_ITERATOR("iterator", "iterator"), + TYPE_WHILE("while", "while"), - TYPE_CATCH("catch", "catch") - ; - private String type; - private String name; + TYPE_ITERATOR("iterator", "iterator"), - ConditionTypeEnum(String type, String name) { - this.type = type; - this.name = name; - } + TYPE_CATCH("catch", "catch"); - public String getType() { - return type; - } + private String type; - public void setType(String type) { - this.type = type; - } + private String name; - public String getName() { - return name; - } + ConditionTypeEnum(String type, String name) { + this.type = type; + this.name = name; + } - public void setName(String name) { - this.name = name; - } + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public static ConditionTypeEnum getEnumByCode(String code) { + for (ConditionTypeEnum e : ConditionTypeEnum.values()) { + if (e.getType().equals(code)) { + return e; + } + } + return null; + } - public static ConditionTypeEnum getEnumByCode(String code) { - for (ConditionTypeEnum e : ConditionTypeEnum.values()) { - if (e.getType().equals(code)) { - return e; - } - } - return null; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ExecuteTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ExecuteTypeEnum.java index 78ca4868..4f713419 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ExecuteTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ExecuteTypeEnum.java @@ -9,8 +9,11 @@ package com.yomahub.liteflow.enums; /** * 可执行节点枚举 + * * @author Bryan.Zhang */ public enum ExecuteTypeEnum { - CHAIN,CONDITION,NODE + + CHAIN, CONDITION, NODE + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/FlowParserTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/FlowParserTypeEnum.java index 62ee1580..e8a72cd1 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/FlowParserTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/FlowParserTypeEnum.java @@ -5,35 +5,33 @@ package com.yomahub.liteflow.enums; * @since 2.5.0 */ public enum FlowParserTypeEnum { - TYPE_XML("xml", "xml"), - TYPE_YML("yml", "yml"), - TYPE_JSON("json", "json"), - TYPE_EL_XML("el_xml", "el_xml"), - TYPE_EL_JSON("el_json", "el_json"), - TYPE_EL_YML("el_yml", "el_yml") - ; - private String type; - private String name; - FlowParserTypeEnum(String type, String name) { - this.type = type; - this.name = name; - } + TYPE_XML("xml", "xml"), TYPE_YML("yml", "yml"), TYPE_JSON("json", "json"), TYPE_EL_XML("el_xml", "el_xml"), + TYPE_EL_JSON("el_json", "el_json"), TYPE_EL_YML("el_yml", "el_yml"); - public String getType() { - return type; - } + private String type; - public void setType(String type) { - this.type = type; - } + private String name; - public String getName() { - return name; - } + FlowParserTypeEnum(String type, String name) { + this.type = type; + this.name = name; + } - public void setName(String name) { - this.name = name; - } + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/InnerChainTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/InnerChainTypeEnum.java index 5039f39a..d0727471 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/InnerChainTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/InnerChainTypeEnum.java @@ -2,14 +2,17 @@ package com.yomahub.liteflow.enums; /** * 隐式流程类型 + * * @author Bryan.Zhang * @since 2.8.5 */ public enum InnerChainTypeEnum { - //不是隐式chain - NONE, - //在串行环境中执行 - IN_SYNC, - //在并行环境中执行 - IN_ASYNC + + // 不是隐式chain + NONE, + // 在串行环境中执行 + IN_SYNC, + // 在并行环境中执行 + IN_ASYNC + } 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 91ee39ba..dd49f0a8 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 @@ -1,52 +1,49 @@ package com.yomahub.liteflow.enums; public enum LiteFlowMethodEnum { - PROCESS("process", true), - PROCESS_SWITCH("processSwitch", true), - PROCESS_IF("processIf", true), - PROCESS_FOR("processFor", true), - PROCESS_WHILE("processWhile", true), - PROCESS_BREAK("processBreak", true), - PROCESS_ITERATOR("processIterator", true), + PROCESS("process", true), PROCESS_SWITCH("processSwitch", true), PROCESS_IF("processIf", true), + PROCESS_FOR("processFor", true), PROCESS_WHILE("processWhile", true), PROCESS_BREAK("processBreak", true), - IS_ACCESS("isAccess", false), + PROCESS_ITERATOR("processIterator", true), - IS_END("isEnd", false), - IS_CONTINUE_ON_ERROR("isContinueOnError", false), + IS_ACCESS("isAccess", false), - GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass", false), + IS_END("isEnd", false), IS_CONTINUE_ON_ERROR("isContinueOnError", false), - ON_SUCCESS("onSuccess", false), + GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass", false), - ON_ERROR("onError", false), + ON_SUCCESS("onSuccess", false), - BEFORE_PROCESS("beforeProcess", false), + ON_ERROR("onError", false), - AFTER_PROCESS("afterProcess", false); + BEFORE_PROCESS("beforeProcess", false), - private String methodName; + AFTER_PROCESS("afterProcess", false); - private boolean isMainMethod; + private String methodName; - LiteFlowMethodEnum(String methodName, boolean isMainMethod){ - this.methodName = methodName; - this.isMainMethod = isMainMethod; - } + private boolean isMainMethod; - public String getMethodName() { - return methodName; - } + LiteFlowMethodEnum(String methodName, boolean isMainMethod) { + this.methodName = methodName; + this.isMainMethod = isMainMethod; + } - public void setMethodName(String methodName) { - this.methodName = methodName; - } + public String getMethodName() { + return methodName; + } - public boolean isMainMethod() { - return isMainMethod; - } + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + public boolean isMainMethod() { + return isMainMethod; + } + + public void setMainMethod(boolean mainMethod) { + isMainMethod = mainMethod; + } - public void setMainMethod(boolean mainMethod) { - isMainMethod = mainMethod; - } } 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 2c0806be..1ad68650 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 @@ -52,6 +52,7 @@ public enum NodeTypeEnum { private static final Logger LOG = LoggerFactory.getLogger(NodeTypeEnum.class); private String code; + private String name; private boolean isScript; @@ -127,34 +128,35 @@ public enum NodeTypeEnum { } public static NodeTypeEnum guessType(Class clazz) { - if(LiteFlowProxyUtil.isCglibProxyClass(clazz)){ + if (LiteFlowProxyUtil.isCglibProxyClass(clazz)) { clazz = LiteFlowProxyUtil.getUserClass(clazz); } NodeTypeEnum nodeType = guessTypeBySuperClazz(clazz); if (nodeType == null) { - //尝试从类声明处进行推断 + // 尝试从类声明处进行推断 LiteflowCmpDefine liteflowCmpDefine = clazz.getAnnotation(LiteflowCmpDefine.class); if (liteflowCmpDefine != null) { - //类声明方式中@LiteflowMethod是无需设置nodeId的 - //但是如果设置了,那么核心逻辑其实是取类上定义的id的 - //这种可以运行,但是理解起来不大好理解,所以给出提示,建议不要这么做 + // 类声明方式中@LiteflowMethod是无需设置nodeId的 + // 但是如果设置了,那么核心逻辑其实是取类上定义的id的 + // 这种可以运行,但是理解起来不大好理解,所以给出提示,建议不要这么做 boolean mixDefined = Arrays.stream(clazz.getDeclaredMethods()).anyMatch(method -> { LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class); if (liteflowMethod != null) { return StrUtil.isNotBlank(liteflowMethod.nodeId()); - } else { + } + else { return false; } }); if (mixDefined) { - LOG.warn("[[[WARNING!!!]]]The @liteflowMethod in the class[{}] defined by @liteflowCmpDefine should not configure the nodeId again!", + LOG.warn( + "[[[WARNING!!!]]]The @liteflowMethod in the class[{}] defined by @liteflowCmpDefine should not configure the nodeId again!", clazz.getName()); } - - //在返回之前,还要对方法级别的@LiteflowMethod进行检查,如果存在方法上的类型与类上的不一致时,给予警告信息 + // 在返回之前,还要对方法级别的@LiteflowMethod进行检查,如果存在方法上的类型与类上的不一致时,给予警告信息 AtomicReference differenceTypeMethod = new AtomicReference<>(); boolean hasDifferenceNodeType = Arrays.stream(clazz.getDeclaredMethods()).anyMatch(method -> { LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class); @@ -162,27 +164,33 @@ public enum NodeTypeEnum { if (!liteflowMethod.nodeType().equals(liteflowCmpDefine.value())) { differenceTypeMethod.set(method); return true; - } else { + } + else { return false; } - } else { + } + else { return false; } }); - //表示存在不一样的类型 + // 表示存在不一样的类型 if (hasDifferenceNodeType) { - LOG.warn("[[[WARNING!!!]]]The nodeType in @liteflowCmpDefine declared on the class[{}] does not match the nodeType in @liteflowMethod declared on the method[{}]!", + LOG.warn( + "[[[WARNING!!!]]]The nodeType in @liteflowCmpDefine declared on the class[{}] does not match the nodeType in @liteflowMethod declared on the method[{}]!", clazz.getName(), differenceTypeMethod.get().getName()); } return liteflowCmpDefine.value(); } - //再尝试声明式组件这部分的推断 - LiteflowMethod liteflowMethod = Arrays.stream(clazz.getDeclaredMethods()).map( - method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class) - ).filter(Objects::nonNull).filter(lfMethod -> lfMethod.value().isMainMethod()).findFirst().orElse(null); + // 再尝试声明式组件这部分的推断 + LiteflowMethod liteflowMethod = Arrays.stream(clazz.getDeclaredMethods()) + .map(method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class)) + .filter(Objects::nonNull) + .filter(lfMethod -> lfMethod.value().isMainMethod()) + .findFirst() + .orElse(null); if (liteflowMethod != null) { nodeType = liteflowMethod.nodeType(); @@ -190,4 +198,5 @@ public enum NodeTypeEnum { } return nodeType; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java index 512b05cb..36081168 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/ScriptTypeEnum.java @@ -2,43 +2,41 @@ package com.yomahub.liteflow.enums; public enum ScriptTypeEnum { - GROOVY("groovy", "groovy"), - QLEXPRESS("qlexpress", "qlexpress"), - JS("javascript", "js"), - PYTHON("python", "python"), - LUA("luaj", "lua") - ; - private String engineName; + GROOVY("groovy", "groovy"), QLEXPRESS("qlexpress", "qlexpress"), JS("javascript", "js"), PYTHON("python", "python"), + LUA("luaj", "lua"); - private String displayName; + private String engineName; - ScriptTypeEnum(String engineName, String displayName) { - this.engineName = engineName; - this.displayName = displayName; - } + private String displayName; - public String getEngineName() { - return engineName; - } + ScriptTypeEnum(String engineName, String displayName) { + this.engineName = engineName; + this.displayName = displayName; + } - public void setEngineName(String engineName) { - this.engineName = engineName; - } + public String getEngineName() { + return engineName; + } - public String getDisplayName() { - return displayName; - } + public void setEngineName(String engineName) { + this.engineName = engineName; + } - public void setDisplayName(String displayName) { - this.displayName = displayName; - } + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public static ScriptTypeEnum getEnumByDisplayName(String displayName) { + for (ScriptTypeEnum e : ScriptTypeEnum.values()) { + if (e.getDisplayName().equals(displayName)) { + return e; + } + } + return null; + } - public static ScriptTypeEnum getEnumByDisplayName(String displayName) { - for (ScriptTypeEnum e : ScriptTypeEnum.values()) { - if (e.getDisplayName().equals(displayName)) { - return e; - } - } - return null; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CatchErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CatchErrorException.java index ae408183..0685b384 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CatchErrorException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CatchErrorException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 类型错误异常 + * * @author Yun */ public class CatchErrorException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public CatchErrorException(String message) { - this.message = message; - } + public CatchErrorException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainDuplicateException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainDuplicateException.java index 6cf101e0..3acbabaa 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainDuplicateException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainDuplicateException.java @@ -7,24 +7,24 @@ package com.yomahub.liteflow.exception; */ public class ChainDuplicateException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public ChainDuplicateException(String message) { - this.message = message; - } + public ChainDuplicateException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainEndException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainEndException.java index 378cbe88..3384fbdf 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainEndException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainEndException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception; /** * 链端异常 + * * @author Bryan.Zhang */ public class ChainEndException extends RuntimeException { @@ -24,4 +25,5 @@ public class ChainEndException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainNotFoundException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainNotFoundException.java index 585a6b43..a5dd8f6c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainNotFoundException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ChainNotFoundException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 链端不存在 + * * @author Bryan.Zhang */ public class ChainNotFoundException extends RuntimeException { @@ -23,4 +24,5 @@ public class ChainNotFoundException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentCannotRegisterException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentCannotRegisterException.java index b9d0e337..16259cca 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentCannotRegisterException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentCannotRegisterException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception; /** * 流程规则主要执行器类 + * * @author Bryan.Zhang * @since 2.5.3 */ @@ -25,4 +26,5 @@ public class ComponentCannotRegisterException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java index f7f98512..7b95d328 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception; /** * 组件方法定义错误异常 + * * @author Bryan.Zhang */ public class ComponentMethodDefineErrorException extends RuntimeException { @@ -24,4 +25,5 @@ public class ComponentMethodDefineErrorException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentNotAccessException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentNotAccessException.java index 7603ae08..86f5ff61 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentNotAccessException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentNotAccessException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 组件不可访问异常 + * * @author Bryan.Zhang */ public class ComponentNotAccessException extends RuntimeException { @@ -23,4 +24,5 @@ public class ComponentNotAccessException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java index 9ff85400..5ab8fb8e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception; /** * 组件代理错误异常 + * * @author Yun */ public class ComponentProxyErrorException extends RuntimeException { @@ -24,4 +25,5 @@ public class ComponentProxyErrorException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ConfigErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ConfigErrorException.java index b3807522..886db049 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ConfigErrorException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ConfigErrorException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 配置错误异常 + * * @author Yun */ public class ConfigErrorException extends RuntimeException { @@ -23,4 +24,5 @@ public class ConfigErrorException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CyclicDependencyException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CyclicDependencyException.java index 179e0ecd..8379fefb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CyclicDependencyException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/CyclicDependencyException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception; /** * 循环依赖异常 + * * @author Yun */ public class CyclicDependencyException extends RuntimeException { @@ -24,4 +25,5 @@ public class CyclicDependencyException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/DataNotFoundException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/DataNotFoundException.java index cb2f65ad..1f6d8f11 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/DataNotFoundException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/DataNotFoundException.java @@ -2,32 +2,35 @@ package com.yomahub.liteflow.exception; /** * 未找到数据异常 + * * @author tangkc */ public class DataNotFoundException extends RuntimeException { - public static final String MSG = "DataNotFoundException"; - private static final long serialVersionUID = 1L; + public static final String MSG = "DataNotFoundException"; - /** - * 异常信息 - */ - private String message; + private static final long serialVersionUID = 1L; - public DataNotFoundException() { - this.message = MSG; - } + /** + * 异常信息 + */ + private String message; - public DataNotFoundException(String message) { - this.message = message; - } + public DataNotFoundException() { + this.message = MSG; + } - @Override - public String getMessage() { - return message; - } + public DataNotFoundException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ELParseException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ELParseException.java index 871f0ac2..fa56e01d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ELParseException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ELParseException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * EL 解析异常 + * * @author Yun */ public class ELParseException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public ELParseException(String message) { - this.message = message; - } + public ELParseException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/EmptyConditionValueException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/EmptyConditionValueException.java index 821df968..c64cf19e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/EmptyConditionValueException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/EmptyConditionValueException.java @@ -1,26 +1,28 @@ package com.yomahub.liteflow.exception; - /** * 空条件值异常 + * * @author Yun */ public class EmptyConditionValueException extends RuntimeException { - private static final long serialVersionUID = 1L; - /** 异常信息 */ - private String message; + private static final long serialVersionUID = 1L; - public EmptyConditionValueException(String message) { - this.message = message; - } + /** 异常信息 */ + private String message; - @Override - public String getMessage() { - return message; - } + public EmptyConditionValueException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ErrorSupportPathException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ErrorSupportPathException.java index a3da1429..ea679e1c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ErrorSupportPathException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ErrorSupportPathException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 错误支持路径异常 + * * @author Yun */ public class ErrorSupportPathException extends RuntimeException { @@ -23,4 +24,5 @@ public class ErrorSupportPathException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ExecutableItemNotFoundException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ExecutableItemNotFoundException.java index 3cb6eba1..5c4ba212 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ExecutableItemNotFoundException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ExecutableItemNotFoundException.java @@ -29,4 +29,5 @@ public class ExecutableItemNotFoundException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowExecutorNotInitException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowExecutorNotInitException.java index bf7fbad1..374b1e17 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowExecutorNotInitException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowExecutorNotInitException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 流程执行者未初始化 + * * @author Yun */ public class FlowExecutorNotInitException extends RuntimeException { @@ -23,4 +24,5 @@ public class FlowExecutorNotInitException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowSystemException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowSystemException.java index da0fea93..77d44afe 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowSystemException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FlowSystemException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 流程系统异常 + * * @author Yun */ public class FlowSystemException extends RuntimeException { @@ -23,4 +24,5 @@ public class FlowSystemException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTargetCannotBePreOrFinallyException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTargetCannotBePreOrFinallyException.java index 0c8b7efa..4e7feacc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTargetCannotBePreOrFinallyException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTargetCannotBePreOrFinallyException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 如果目标不能是 Pre 或 Finally 异常 + * * @author Yun */ public class IfTargetCannotBePreOrFinallyException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public IfTargetCannotBePreOrFinallyException(String message) { - this.message = message; - } + public IfTargetCannotBePreOrFinallyException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTypeErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTypeErrorException.java index 1a275adf..b525fc0c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTypeErrorException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/IfTypeErrorException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 类型错误异常 + * * @author Yun */ public class IfTypeErrorException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public IfTypeErrorException(String message) { - this.message = message; - } + public IfTypeErrorException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/JsonProcessException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/JsonProcessException.java index ac2f57f6..ea495ccd 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/JsonProcessException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/JsonProcessException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * Json 进程异常 + * * @author Yun */ public class JsonProcessException extends RuntimeException { @@ -23,4 +24,5 @@ public class JsonProcessException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/LiteFlowException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/LiteFlowException.java index 7e2e865c..f1237d62 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/LiteFlowException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/LiteFlowException.java @@ -2,8 +2,8 @@ package com.yomahub.liteflow.exception; /** - * LiteFlow架内部逻辑发生错误抛出的异常 - * (自定义此异常方便开发者在做全局异常处理时分辨异常类型) + * LiteFlow架内部逻辑发生错误抛出的异常 (自定义此异常方便开发者在做全局异常处理时分辨异常类型) + * * @author zendwang * @since 2.8.3 */ @@ -16,7 +16,6 @@ public class LiteFlowException extends RuntimeException { /** * 构建一个异常 - * * @param message 异常描述信息 */ public LiteFlowException(String message) { @@ -35,7 +34,6 @@ public class LiteFlowException extends RuntimeException { /** * 构建一个异常 - * * @param cause 异常对象 */ public LiteFlowException(Throwable cause) { @@ -44,7 +42,6 @@ public class LiteFlowException extends RuntimeException { /** * 构建一个异常 - * * @param message 异常信息 * @param cause 异常对象 */ @@ -69,4 +66,5 @@ public class LiteFlowException extends RuntimeException { public String getCode() { return code; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MonitorFileInitErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MonitorFileInitErrorException.java index 5194de01..435b6417 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MonitorFileInitErrorException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MonitorFileInitErrorException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception; /** * 文件监听异常 + * * @author Bryan.Zhang * @since 2.10.0 */ @@ -25,4 +26,5 @@ public class MonitorFileInitErrorException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MultipleParsersException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MultipleParsersException.java index 4d49c411..0b642d02 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MultipleParsersException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/MultipleParsersException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 重复解析器异常 + * * @author Yun */ public class MultipleParsersException extends RuntimeException { @@ -23,4 +24,5 @@ public class MultipleParsersException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoAvailableSlotException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoAvailableSlotException.java index 2935876f..89f2fce1 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoAvailableSlotException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoAvailableSlotException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 无可用插槽异常 + * * @author Yun */ public class NoAvailableSlotException extends RuntimeException { @@ -23,4 +24,5 @@ public class NoAvailableSlotException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoForNodeException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoForNodeException.java index c61f1899..f5730a7d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoForNodeException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoForNodeException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 没有节点异常 + * * @author Yun */ public class NoForNodeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NoForNodeException(String message) { - this.message = message; - } + public NoForNodeException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIfTrueNodeException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIfTrueNodeException.java index be6bf7d5..5c023d03 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIfTrueNodeException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIfTrueNodeException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 节点不为真异常 + * * @author Yun */ public class NoIfTrueNodeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NoIfTrueNodeException(String message) { - this.message = message; - } + public NoIfTrueNodeException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIteratorNodeException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIteratorNodeException.java index 2e771aec..309c1f87 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIteratorNodeException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoIteratorNodeException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 没有节点异常 + * * @author Yun */ public class NoIteratorNodeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NoIteratorNodeException(String message) { - this.message = message; - } + public NoIteratorNodeException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSuchContextBeanException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSuchContextBeanException.java index b209a0b2..480b9a5b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSuchContextBeanException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSuchContextBeanException.java @@ -7,24 +7,24 @@ package com.yomahub.liteflow.exception; */ public class NoSuchContextBeanException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NoSuchContextBeanException(String message) { - this.message = message; - } + public NoSuchContextBeanException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSwitchTargetNodeException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSwitchTargetNodeException.java index 21daee14..aa5ae1dd 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSwitchTargetNodeException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoSwitchTargetNodeException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 无切换目标节点异常 + * * @author Yun */ public class NoSwitchTargetNodeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NoSwitchTargetNodeException(String message) { - this.message = message; - } + public NoSwitchTargetNodeException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoWhileNodeException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoWhileNodeException.java index bc860817..a3174897 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoWhileNodeException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NoWhileNodeException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 没有 While 节点异常 + * * @author Yun */ public class NoWhileNodeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NoWhileNodeException(String message) { - this.message = message; - } + public NoWhileNodeException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeBuildException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeBuildException.java index eb143cee..bc46c3a9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeBuildException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeBuildException.java @@ -1,26 +1,28 @@ package com.yomahub.liteflow.exception; - /** * 节点构建异常 + * * @author Yun */ public class NodeBuildException extends RuntimeException { - private static final long serialVersionUID = 1L; - /** 异常信息 */ - private String message; + private static final long serialVersionUID = 1L; - public NodeBuildException(String message) { - this.message = message; - } + /** 异常信息 */ + private String message; - @Override - public String getMessage() { - return message; - } + public NodeBuildException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeClassNotFoundException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeClassNotFoundException.java index ac870be3..ad4701bc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeClassNotFoundException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeClassNotFoundException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 找不到节点类异常 + * * @author Yun */ public class NodeClassNotFoundException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NodeClassNotFoundException(String message) { - this.message = message; - } + public NodeClassNotFoundException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeCanNotGuessException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeCanNotGuessException.java index a185bde6..c96bc51e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeCanNotGuessException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeCanNotGuessException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 节点类型无法猜测异常 + * * @author Yun */ public class NodeTypeCanNotGuessException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NodeTypeCanNotGuessException(String message) { - this.message = message; - } + public NodeTypeCanNotGuessException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeNotSupportException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeNotSupportException.java index 933ace6c..8578c563 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeNotSupportException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NodeTypeNotSupportException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.exception; /** * 节点类型不支持异常 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -25,4 +26,5 @@ public class NodeTypeNotSupportException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NotSupportConditionException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NotSupportConditionException.java index a0e0efbe..7ba4add5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NotSupportConditionException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NotSupportConditionException.java @@ -1,26 +1,28 @@ package com.yomahub.liteflow.exception; - /** * 不支持条件异常 + * * @author Yun */ public class NotSupportConditionException extends RuntimeException { - private static final long serialVersionUID = 1L; - /** 异常信息 */ - private String message; + private static final long serialVersionUID = 1L; - public NotSupportConditionException(String message) { - this.message = message; - } + /** 异常信息 */ + private String message; - @Override - public String getMessage() { - return message; - } + public NotSupportConditionException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullNodeTypeException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullNodeTypeException.java index ad0379a7..3f791d9d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullNodeTypeException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullNodeTypeException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 空节点异常 + * * @author Yun */ public class NullNodeTypeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public NullNodeTypeException(String message) { - this.message = message; - } + public NullNodeTypeException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullParamException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullParamException.java index 8e6e175d..551d9784 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullParamException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/NullParamException.java @@ -3,27 +3,29 @@ package com.yomahub.liteflow.exception; import java.io.Serializable; /** - * null param exception - * when param is null, dataMap (ConcurrentHashMap) cann't accept a null value + * null param exception when param is null, dataMap (ConcurrentHashMap) cann't accept a + * null value + * * @author LeoLee * @since 2.6.6 */ public class NullParamException extends RuntimeException implements Serializable { - private static final long serialVersionUID = -864259139568071245L; + private static final long serialVersionUID = -864259139568071245L; - private String message; + private String message; - public NullParamException(String message) { - this.message = message; - } + public NullParamException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParseException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParseException.java index 18c24a94..533adea9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParseException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParseException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 解析异常 + * * @author Yun */ public class ParseException extends RuntimeException { @@ -23,4 +24,5 @@ public class ParseException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParserCannotFindException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParserCannotFindException.java index c84c2189..ad212875 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParserCannotFindException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ParserCannotFindException.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.exception; /** * 解析器找不到异常 + * * @author Yun */ public class ParserCannotFindException extends RuntimeException { @@ -23,4 +24,5 @@ public class ParserCannotFindException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ScriptBeanMethodInvokeException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ScriptBeanMethodInvokeException.java index c65deb18..984e6736 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ScriptBeanMethodInvokeException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ScriptBeanMethodInvokeException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * ScriptBean的方法无法被调用异常 + * * @author Bryan.Zhang */ public class ScriptBeanMethodInvokeException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public ScriptBeanMethodInvokeException(String message) { - this.message = message; - } + public ScriptBeanMethodInvokeException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTargetCannotBePreOrFinallyException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTargetCannotBePreOrFinallyException.java index cd04d559..0904bb76 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTargetCannotBePreOrFinallyException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTargetCannotBePreOrFinallyException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 切换目标不能是 Pre 或 Finally 异常 + * * @author Yun */ public class SwitchTargetCannotBePreOrFinallyException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public SwitchTargetCannotBePreOrFinallyException(String message) { - this.message = message; - } + public SwitchTargetCannotBePreOrFinallyException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTypeErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTypeErrorException.java index f39f2d7a..f736cd52 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTypeErrorException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/SwitchTypeErrorException.java @@ -2,28 +2,29 @@ package com.yomahub.liteflow.exception; /** * 开关类型错误异常 + * * @author Yun */ public class SwitchTypeErrorException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 异常信息 - */ - private String message; + /** + * 异常信息 + */ + private String message; - public SwitchTypeErrorException(String message) { - this.message = message; - } + public SwitchTypeErrorException(String message) { + this.message = message; + } - @Override - public String getMessage() { - return message; - } + @Override + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ThreadExecutorServiceCreateException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ThreadExecutorServiceCreateException.java index 4fdba367..f2c9a29d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ThreadExecutorServiceCreateException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ThreadExecutorServiceCreateException.java @@ -2,25 +2,28 @@ package com.yomahub.liteflow.exception; /** * 并行多线程创建异常 + * * @author Bryan.Zhang * @since 2.6.6 */ public class ThreadExecutorServiceCreateException extends RuntimeException { - private static final long serialVersionUID = 1L; - /** 异常信息 */ - private String message; + private static final long serialVersionUID = 1L; - public ThreadExecutorServiceCreateException(String message) { - this.message = message; - } + /** 异常信息 */ + private String message; - @Override - public String getMessage() { - return message; - } + public ThreadExecutorServiceCreateException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenExecuteException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenExecuteException.java index bfd883b7..e5dc9c4e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenExecuteException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenExecuteException.java @@ -1,26 +1,28 @@ package com.yomahub.liteflow.exception; - /** * 执行异常时 + * * @author Yun */ public class WhenExecuteException extends RuntimeException { - private static final long serialVersionUID = 1L; - /** 异常信息 */ - private String message; + private static final long serialVersionUID = 1L; - public WhenExecuteException(String message) { - this.message = message; - } + /** 异常信息 */ + private String message; - @Override - public String getMessage() { - return message; - } + public WhenExecuteException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenTimeoutException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenTimeoutException.java index c9dcacee..df18119c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenTimeoutException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/WhenTimeoutException.java @@ -1,26 +1,28 @@ package com.yomahub.liteflow.exception; - /** * 当超时异常 + * * @author Yun */ public class WhenTimeoutException extends RuntimeException { - private static final long serialVersionUID = 1L; - /** 异常信息 */ - private String message; + private static final long serialVersionUID = 1L; - public WhenTimeoutException(String message) { - this.message = message; - } + /** 异常信息 */ + private String message; - @Override - public String getMessage() { - return message; - } + public WhenTimeoutException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } - public void setMessage(String message) { - this.message = message; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index 67b0c55b..3eca4f45 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 @@ -49,229 +49,239 @@ import java.util.stream.Collectors; */ public class FlowBus { - private static final Logger LOG = LoggerFactory.getLogger(FlowBus.class); + private static final Logger LOG = LoggerFactory.getLogger(FlowBus.class); - private static final Map chainMap = new CopyOnWriteHashMap<>(); + private static final Map chainMap = new CopyOnWriteHashMap<>(); - private static final Map nodeMap = new CopyOnWriteHashMap<>(); + private static final Map nodeMap = new CopyOnWriteHashMap<>(); - private FlowBus() { - } + private FlowBus() { + } - public static Chain getChain(String id) { - return chainMap.get(id); - } + public static Chain getChain(String id) { + return chainMap.get(id); + } - //这一方法主要用于第一阶段chain的预装载 - public static void addChain(String chainName) { - if (!chainMap.containsKey(chainName)) { - chainMap.put(chainName, new Chain(chainName)); - } - } + // 这一方法主要用于第一阶段chain的预装载 + public static void addChain(String chainName) { + if (!chainMap.containsKey(chainName)) { + chainMap.put(chainName, new Chain(chainName)); + } + } - //这个方法主要用于第二阶段的替换chain - public static void addChain(Chain chain) { - chainMap.put(chain.getChainId(), chain); - } + // 这个方法主要用于第二阶段的替换chain + public static void addChain(Chain chain) { + chainMap.put(chain.getChainId(), chain); + } - public static boolean containChain(String chainId) { - return chainMap.containsKey(chainId); - } + public static boolean containChain(String chainId) { + return chainMap.containsKey(chainId); + } - public static boolean needInit() { - return MapUtil.isEmpty(chainMap); - } + public static boolean needInit() { + return MapUtil.isEmpty(chainMap); + } - public static boolean containNode(String nodeId) { - return nodeMap.containsKey(nodeId); - } + public static boolean containNode(String nodeId) { + return nodeMap.containsKey(nodeId); + } - public static void addSpringScanNode(String nodeId, NodeComponent nodeComponent) { - //根据class来猜测类型 - NodeTypeEnum type = NodeTypeEnum.guessType(nodeComponent.getClass()); + public static void addSpringScanNode(String nodeId, NodeComponent nodeComponent) { + // 根据class来猜测类型 + NodeTypeEnum type = NodeTypeEnum.guessType(nodeComponent.getClass()); - if (type == null) { - throw new NullNodeTypeException(StrUtil.format("node type is null for node[{}]", nodeId)); - } + if (type == null) { + throw new NullNodeTypeException(StrUtil.format("node type is null for node[{}]", nodeId)); + } - nodeMap.put(nodeId, new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, null, nodeId))); - } + nodeMap.put(nodeId, + new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, null, nodeId))); + } - /** - * 添加 node - * - * @param nodeId 节点id - * @param name 节点名称 - * @param type 节点类型 - * @param cmpClazz 节点组件类 - */ - public static void addNode(String nodeId, String name, NodeTypeEnum type, Class cmpClazz) { - addNode(nodeId, name, type, cmpClazz, null, null); - } + /** + * 添加 node + * @param nodeId 节点id + * @param name 节点名称 + * @param type 节点类型 + * @param cmpClazz 节点组件类 + */ + public static void addNode(String nodeId, String name, NodeTypeEnum type, Class cmpClazz) { + addNode(nodeId, name, type, cmpClazz, null, null); + } - /** - * 添加 node - * - * @param nodeId 节点id - * @param name 节点名称 - * @param nodeType 节点类型 - * @param cmpClazzStr 节点组件类路径 - */ - public static void addNode(String nodeId, String name, NodeTypeEnum nodeType, String cmpClazzStr) { - Class cmpClazz; - try { - cmpClazz = Class.forName(cmpClazzStr); - } catch (Exception e) { - throw new ComponentCannotRegisterException(e.getMessage()); - } - addNode(nodeId, name, nodeType, cmpClazz, null, null); - } + /** + * 添加 node + * @param nodeId 节点id + * @param name 节点名称 + * @param nodeType 节点类型 + * @param cmpClazzStr 节点组件类路径 + */ + public static void addNode(String nodeId, String name, NodeTypeEnum nodeType, String cmpClazzStr) { + Class cmpClazz; + try { + cmpClazz = Class.forName(cmpClazzStr); + } + catch (Exception e) { + throw new ComponentCannotRegisterException(e.getMessage()); + } + addNode(nodeId, name, nodeType, cmpClazz, null, null); + } - /** - * 添加脚本 node - * - * @param nodeId 节点id - * @param name 节点名称 - * @param nodeType 节点类型 - * @param script 脚本 - */ - public static void addScriptNode(String nodeId, String name, NodeTypeEnum nodeType, String script, String language) { - addNode(nodeId, name, nodeType, ScriptComponent.ScriptComponentClassMap.get(nodeType), script, language); - } + /** + * 添加脚本 node + * @param nodeId 节点id + * @param name 节点名称 + * @param nodeType 节点类型 + * @param script 脚本 + */ + public static void addScriptNode(String nodeId, String name, NodeTypeEnum nodeType, String script, + String language) { + addNode(nodeId, name, nodeType, ScriptComponent.ScriptComponentClassMap.get(nodeType), script, language); + } - private static void addNode(String nodeId, String name, NodeTypeEnum type, Class cmpClazz, String script, String language) { - try { - //判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例 - //如果不是声明式的,就用传统的方式进行判断 - List cmpInstances = new ArrayList<>(); - if (LiteFlowProxyUtil.isDeclareCmp(cmpClazz)) { - //这里的逻辑要仔细看下 - //如果是spring体系,把原始的类往spring上下文中进行注册,那么会走到ComponentScanner中 - //由于ComponentScanner中已经对原始类进行了动态代理,出来的对象已经变成了动态代理类,所以这时候的bean已经是NodeComponent的子类了 - //所以spring体系下,无需再对这个bean做二次代理 - //但是在非spring体系下,这个bean依旧是原来那个bean,所以需要对这个bean做一次代理 - //这里用ContextAware的spi机制来判断是否spring体系 - ContextAware contextAware = ContextAwareHolder.loadContextAware(); - Object bean = ContextAwareHolder.loadContextAware().registerBean(nodeId, cmpClazz); - if (LocalContextAware.class.isAssignableFrom(contextAware.getClass())) { - cmpInstances = LiteFlowProxyUtil.proxy2NodeComponent(bean, nodeId); - } else { - cmpInstances = ListUtil.toList((NodeComponent) bean); - } - } else { - //以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置 - //这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了 - //如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance - if (!type.isScript()) { - cmpInstances = ListUtil.toList((NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz)); - } - // 去除null元素 - cmpInstances.remove(null); - // 如果为空 - if (cmpInstances.isEmpty()) { - NodeComponent cmpInstance = (NodeComponent) cmpClazz.newInstance(); - cmpInstances.add(cmpInstance); - } - } - //进行初始化component - cmpInstances = cmpInstances.stream() - .map(cmpInstance -> ComponentInitializer.loadInstance().initComponent( - cmpInstance, - type, - name, - cmpInstance.getNodeId() == null ? nodeId : cmpInstance.getNodeId()) - ).collect(Collectors.toList()); + private static void addNode(String nodeId, String name, NodeTypeEnum type, Class cmpClazz, String script, + String language) { + try { + // 判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例 + // 如果不是声明式的,就用传统的方式进行判断 + List cmpInstances = new ArrayList<>(); + if (LiteFlowProxyUtil.isDeclareCmp(cmpClazz)) { + // 这里的逻辑要仔细看下 + // 如果是spring体系,把原始的类往spring上下文中进行注册,那么会走到ComponentScanner中 + // 由于ComponentScanner中已经对原始类进行了动态代理,出来的对象已经变成了动态代理类,所以这时候的bean已经是NodeComponent的子类了 + // 所以spring体系下,无需再对这个bean做二次代理 + // 但是在非spring体系下,这个bean依旧是原来那个bean,所以需要对这个bean做一次代理 + // 这里用ContextAware的spi机制来判断是否spring体系 + ContextAware contextAware = ContextAwareHolder.loadContextAware(); + Object bean = ContextAwareHolder.loadContextAware().registerBean(nodeId, cmpClazz); + if (LocalContextAware.class.isAssignableFrom(contextAware.getClass())) { + cmpInstances = LiteFlowProxyUtil.proxy2NodeComponent(bean, nodeId); + } + else { + cmpInstances = ListUtil.toList((NodeComponent) bean); + } + } + else { + // 以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置 + // 这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了 + // 如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance + if (!type.isScript()) { + cmpInstances = ListUtil + .toList((NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz)); + } + // 去除null元素 + cmpInstances.remove(null); + // 如果为空 + if (cmpInstances.isEmpty()) { + NodeComponent cmpInstance = (NodeComponent) cmpClazz.newInstance(); + cmpInstances.add(cmpInstance); + } + } + // 进行初始化component + cmpInstances = cmpInstances.stream() + .map(cmpInstance -> ComponentInitializer.loadInstance() + .initComponent(cmpInstance, type, name, + cmpInstance.getNodeId() == null ? nodeId : cmpInstance.getNodeId())) + .collect(Collectors.toList()); - //初始化Node,把component放到Node里去 - List nodes = cmpInstances.stream().map(Node::new).collect(Collectors.toList()); + // 初始化Node,把component放到Node里去 + List nodes = cmpInstances.stream().map(Node::new).collect(Collectors.toList()); + for (int i = 0; i < nodes.size(); i++) { + Node node = nodes.get(i); + NodeComponent cmpInstance = cmpInstances.get(i); + // 如果是脚本节点,则还要加载script脚本 + if (type.isScript()) { + if (StrUtil.isNotBlank(script)) { + node.setScript(script); + node.setLanguage(language); + ((ScriptComponent) cmpInstance).loadScript(script, language); + } + else { + String errorMsg = StrUtil.format("script for node[{}] is empty", nodeId); + throw new ScriptLoadException(errorMsg); + } + } - for (int i = 0; i < nodes.size(); i++) { - Node node = nodes.get(i); - NodeComponent cmpInstance = cmpInstances.get(i); - //如果是脚本节点,则还要加载script脚本 - if (type.isScript()) { - if (StrUtil.isNotBlank(script)) { - node.setScript(script); - node.setLanguage(language); - ((ScriptComponent) cmpInstance).loadScript(script, language); - } else { - String errorMsg = StrUtil.format("script for node[{}] is empty", nodeId); - throw new ScriptLoadException(errorMsg); - } - } + String activeNodeId = StrUtil.isEmpty(cmpInstance.getNodeId()) ? nodeId : cmpInstance.getNodeId(); + nodeMap.put(activeNodeId, node); + } - String activeNodeId = StrUtil.isEmpty(cmpInstance.getNodeId()) ? nodeId : cmpInstance.getNodeId(); - nodeMap.put(activeNodeId, node); - } + } + catch (Exception e) { + String error = StrUtil.format("component[{}] register error", + StrUtil.isEmpty(name) ? nodeId : StrUtil.format("{}({})", nodeId, name)); + LOG.error(e.getMessage()); + throw new ComponentCannotRegisterException(StrUtil.format("{} {}", error, e.getMessage())); + } + } - } catch (Exception e) { - String error = StrUtil.format("component[{}] register error", StrUtil.isEmpty(name) ? nodeId : StrUtil.format("{}({})", nodeId, name)); - LOG.error(e.getMessage()); - throw new ComponentCannotRegisterException(StrUtil.format("{} {}", error, e.getMessage())); - } - } + public static Node getNode(String nodeId) { + return nodeMap.get(nodeId); + } - public static Node getNode(String nodeId) { - return nodeMap.get(nodeId); - } + // 虽然实现了cloneable,但是还是浅copy,因为condNodeMap这个对象还是共用的。 + // 那condNodeMap共用有关系么,原则上没有关系。但是从设计理念上,以后应该要分开 + // tag和condNodeMap这2个属性不属于全局概念,属于每个chain范围的属性 + public static Node copyNode(String nodeId) { + try { + Node node = nodeMap.get(nodeId); + return node.copy(); + } + catch (Exception e) { + return null; + } + } - //虽然实现了cloneable,但是还是浅copy,因为condNodeMap这个对象还是共用的。 - //那condNodeMap共用有关系么,原则上没有关系。但是从设计理念上,以后应该要分开 - //tag和condNodeMap这2个属性不属于全局概念,属于每个chain范围的属性 - public static Node copyNode(String nodeId) { - try { - Node node = nodeMap.get(nodeId); - return node.copy(); - } catch (Exception e) { - return null; - } - } + public static Map getNodeMap() { + return nodeMap; + } - public static Map getNodeMap() { - return nodeMap; - } + public static Map getChainMap() { + return chainMap; + } - public static Map getChainMap() { - return chainMap; - } + public static void cleanCache() { + chainMap.clear(); + nodeMap.clear(); + cleanScriptCache(); + } - public static void cleanCache() { - chainMap.clear(); - nodeMap.clear(); - cleanScriptCache(); - } + public static void cleanScriptCache() { + // 如果引入了脚本组件SPI,则还需要清理脚本的缓存 + try { + ScriptExecutorFactory.loadInstance().cleanScriptCache(); + } + catch (ScriptSpiException ignored) { + } + } - public static void cleanScriptCache() { - //如果引入了脚本组件SPI,则还需要清理脚本的缓存 - try { - ScriptExecutorFactory.loadInstance().cleanScriptCache(); - } catch (ScriptSpiException ignored) { - } - } + public static void refreshFlowMetaData(FlowParserTypeEnum type, String content) throws Exception { + if (type.equals(FlowParserTypeEnum.TYPE_EL_XML)) { + new LocalXmlFlowELParser().parse(content); + } + else if (type.equals(FlowParserTypeEnum.TYPE_EL_JSON)) { + new LocalJsonFlowELParser().parse(content); + } + else if (type.equals(FlowParserTypeEnum.TYPE_EL_YML)) { + new LocalYmlFlowELParser().parse(content); + } + } - public static void refreshFlowMetaData(FlowParserTypeEnum type, String content) throws Exception { - if (type.equals(FlowParserTypeEnum.TYPE_EL_XML)) { - new LocalXmlFlowELParser().parse(content); - } else if (type.equals(FlowParserTypeEnum.TYPE_EL_JSON)) { - new LocalJsonFlowELParser().parse(content); - } else if (type.equals(FlowParserTypeEnum.TYPE_EL_YML)) { - new LocalYmlFlowELParser().parse(content); - } - } + public static boolean removeChain(String chainId) { + if (containChain(chainId)) { + chainMap.remove(chainId); + return true; + } + else { + String errMsg = StrUtil.format("cannot find the chain[{}]", chainId); + LOG.error(errMsg); + return false; + } + } - public static boolean removeChain(String chainId) { - if (containChain(chainId)) { - chainMap.remove(chainId); - return true; - } else { - String errMsg = StrUtil.format("cannot find the chain[{}]", chainId); - LOG.error(errMsg); - return false; - } - } + public static void removeChain(String... chainIds) { + Arrays.stream(chainIds).forEach(FlowBus::removeChain); + } - public static void removeChain(String... chainIds) { - Arrays.stream(chainIds).forEach(FlowBus::removeChain); - } } 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 6930eccf..cbef4b7e 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 @@ -11,116 +11,120 @@ import java.util.Queue; /** * 执行结果封装类 + * * @author zend.wang */ -public class LiteflowResponse{ - - private boolean success; +public class LiteflowResponse { - private String code; + private boolean success; - private String message; - - private Exception cause; - - private Slot slot; - - public LiteflowResponse() { - } + private String code; - public static LiteflowResponse newMainResponse(Slot slot){ - return newResponse(slot, slot.getException()); - } + private String message; - public static LiteflowResponse newInnerResponse(String chainId, Slot slot){ - return newResponse(slot, slot.getSubException(chainId)); - } + private Exception cause; - private static LiteflowResponse newResponse(Slot slot, Exception e){ - LiteflowResponse response = new LiteflowResponse(); - if (slot != null && e != null) { - response.setSuccess(false); - response.setCause(e); - response.setMessage(response.getCause().getMessage()); - response.setCode(response.getCause() instanceof LiteFlowException ? ((LiteFlowException)response.getCause()).getCode() : null); - } else { - response.setSuccess(true); - } - response.setSlot(slot); - return response; - } + private Slot slot; - public boolean isSuccess() { - return success; - } - - public void setSuccess(final boolean success) { - this.success = success; - } - - public String getMessage() { - return message; - } - - public void setMessage(final String message) { - this.message = message; - } + public LiteflowResponse() { + } - public String getCode() { - return code; - } + public static LiteflowResponse newMainResponse(Slot slot) { + return newResponse(slot, slot.getException()); + } - public void setCode(String code) { - this.code = code; - } + public static LiteflowResponse newInnerResponse(String chainId, Slot slot) { + return newResponse(slot, slot.getSubException(chainId)); + } - public Exception getCause() { - return cause; - } - - public void setCause(final Exception cause) { - this.cause = cause; - } + private static LiteflowResponse newResponse(Slot slot, Exception e) { + LiteflowResponse response = new LiteflowResponse(); + if (slot != null && e != null) { + response.setSuccess(false); + response.setCause(e); + response.setMessage(response.getCause().getMessage()); + response.setCode(response.getCause() instanceof LiteFlowException + ? ((LiteFlowException) response.getCause()).getCode() : null); + } + else { + response.setSuccess(true); + } + response.setSlot(slot); + return response; + } - public Slot getSlot() { - return slot; - } - - public void setSlot(Slot slot) { - this.slot = slot; - } + public boolean isSuccess() { + return success; + } - public T getFirstContextBean(){ - return this.getSlot().getFirstContextBean(); - } + public void setSuccess(final boolean success) { + this.success = success; + } - public T getContextBean(Class contextBeanClazz){ - return this.getSlot().getContextBean(contextBeanClazz); - } + public String getMessage() { + return message; + } - public Map getExecuteSteps(){ - Map map = new HashMap<>(); - this.getSlot().getExecuteSteps().forEach(cmpStep -> map.put(cmpStep.getNodeId(), cmpStep)); - return map; - } + public void setMessage(final String message) { + this.message = message; + } - public Queue getExecuteStepQueue(){ - return this.getSlot().getExecuteSteps(); - } + public String getCode() { + return code; + } - public String getExecuteStepStr(){ - return getExecuteStepStrWithoutTime(); - } + public void setCode(String code) { + this.code = code; + } - public String getExecuteStepStrWithTime(){ - return this.getSlot().getExecuteStepStr(true); - } + public Exception getCause() { + return cause; + } - public String getExecuteStepStrWithoutTime(){ - return this.getSlot().getExecuteStepStr(false); - } + public void setCause(final Exception cause) { + this.cause = cause; + } + + public Slot getSlot() { + return slot; + } + + public void setSlot(Slot slot) { + this.slot = slot; + } + + public T getFirstContextBean() { + return this.getSlot().getFirstContextBean(); + } + + public T getContextBean(Class contextBeanClazz) { + return this.getSlot().getContextBean(contextBeanClazz); + } + + public Map getExecuteSteps() { + Map map = new HashMap<>(); + this.getSlot().getExecuteSteps().forEach(cmpStep -> map.put(cmpStep.getNodeId(), cmpStep)); + return map; + } + + public Queue getExecuteStepQueue() { + return this.getSlot().getExecuteSteps(); + } + + public String getExecuteStepStr() { + return getExecuteStepStrWithoutTime(); + } + + public String getExecuteStepStrWithTime() { + return this.getSlot().getExecuteStepStr(true); + } + + public String getExecuteStepStrWithoutTime() { + return this.getSlot().getExecuteStepStr(false); + } + + public String getRequestId() { + return this.getSlot().getRequestId(); + } - public String getRequestId(){ - return this.getSlot().getRequestId(); - } } 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 03204476..5fd7eca6 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 @@ -27,93 +27,97 @@ import java.util.List; */ public class Chain implements Executable { - private static final Logger LOG = LoggerFactory.getLogger(Chain.class); + private static final Logger LOG = LoggerFactory.getLogger(Chain.class); - private String chainId; + private String chainId; - private List conditionList = new ArrayList<>(); + private List conditionList = new ArrayList<>(); - public Chain(String chainName){ - this.chainId = chainName; - } + public Chain(String chainName) { + this.chainId = chainName; + } - public Chain(){} + public Chain() { + } - public Chain(String chainName, List conditionList) { - this.chainId = chainName; - this.conditionList = conditionList; - } + public Chain(String chainName, List conditionList) { + this.chainId = chainName; + this.conditionList = conditionList; + } - public List getConditionList() { - return conditionList; - } + public List getConditionList() { + return conditionList; + } - public void setConditionList(List conditionList) { - this.conditionList = conditionList; - } + public void setConditionList(List conditionList) { + this.conditionList = conditionList; + } - /** + /** * @deprecated 请使用{@link #getChainId()} */ - @Deprecated - public String getChainName() { - return chainId; - } + @Deprecated + public String getChainName() { + return chainId; + } - /** - * - * @param chainName - * @deprecated 请使用 {@link #setChainId(String)} - */ - public void setChainName(String chainName) { - this.chainId = chainName; - } - - public String getChainId() { - return chainId; - } + /** + * @param chainName + * @deprecated 请使用 {@link #setChainId(String)} + */ + public void setChainName(String chainName) { + this.chainId = chainName; + } - public void setChainId(String chainId) { - this.chainId = chainId; - } + public String getChainId() { + return chainId; + } - //执行chain的主方法 - @Override - public void execute(Integer slotIndex) throws Exception { - if (CollUtil.isEmpty(conditionList)) { - throw new FlowSystemException("no conditionList in this chain[" + chainId + "]"); - } - Slot slot = DataBus.getSlot(slotIndex); - try { - //设置主ChainName - slot.setChainId(chainId); - //执行主体Condition - for (Condition condition : conditionList) { - condition.setCurrChainId(chainId); - condition.execute(slotIndex); - } - }catch (ChainEndException e){ - //这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 - //是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 - throw e; - }catch (Exception e){ - //这里事先取到exception set到slot里,为了方便finally取到exception - if (slot.isSubChain(chainId)){ - slot.setSubException(chainId, e); - }else{ - slot.setException(e); - } - throw e; - } - } + public void setChainId(String chainId) { + this.chainId = chainId; + } - @Override - public ExecuteTypeEnum getExecuteType() { - return ExecuteTypeEnum.CHAIN; - } + // 执行chain的主方法 + @Override + public void execute(Integer slotIndex) throws Exception { + if (CollUtil.isEmpty(conditionList)) { + throw new FlowSystemException("no conditionList in this chain[" + chainId + "]"); + } + Slot slot = DataBus.getSlot(slotIndex); + try { + // 设置主ChainName + slot.setChainId(chainId); + // 执行主体Condition + for (Condition condition : conditionList) { + condition.setCurrChainId(chainId); + condition.execute(slotIndex); + } + } + catch (ChainEndException e) { + // 这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 + // 是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 + throw e; + } + catch (Exception e) { + // 这里事先取到exception set到slot里,为了方便finally取到exception + if (slot.isSubChain(chainId)) { + slot.setSubException(chainId, e); + } + else { + slot.setException(e); + } + throw e; + } + } + + @Override + public ExecuteTypeEnum getExecuteType() { + return ExecuteTypeEnum.CHAIN; + } + + @Override + public String getExecuteId() { + return chainId; + } - @Override - public String getExecuteId() { - return chainId; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Executable.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Executable.java index 5ecd3277..25746476 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Executable.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Executable.java @@ -3,43 +3,41 @@ package com.yomahub.liteflow.flow.element; import com.yomahub.liteflow.enums.ExecuteTypeEnum; /** - * 可执行器接口 - * 目前实现这个接口的有3个,Chain,Condition,Node + * 可执行器接口 目前实现这个接口的有3个,Chain,Condition,Node * * @author Bryan.Zhang */ -public interface Executable{ +public interface Executable { - void execute(Integer slotIndex) throws Exception; + void execute(Integer slotIndex) throws Exception; - default boolean isAccess(Integer slotIndex) throws Exception{ - return true; - } + default boolean isAccess(Integer slotIndex) throws Exception { + return true; + } - ExecuteTypeEnum getExecuteType(); + ExecuteTypeEnum getExecuteType(); - /** - * - * @return - * @deprecated 请使用 {@link #getExecuteId()} - */ - @Deprecated - default String getExecuteName() { - return getExecuteId(); - } + /** + * @return + * @deprecated 请使用 {@link #getExecuteId()} + */ + @Deprecated + default String getExecuteName() { + return getExecuteId(); + } - /** - * - * @param currentChainName - * @deprecated 请使用 {@link #setCurrChainId(String)} - */ - default void setCurrChainName(String currentChainName){ - setCurrChainId(currentChainName); - } - - String getExecuteId(); + /** + * @param currentChainName + * @deprecated 请使用 {@link #setCurrChainId(String)} + */ + default void setCurrChainName(String currentChainName) { + setCurrChainId(currentChainName); + } - default void setCurrChainId(String currentChainId){ + String getExecuteId(); + + default void setCurrChainId(String currentChainId) { + + } - } } 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 63937f9f..2ac0eac4 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 @@ -28,11 +28,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Node节点,实现可执行器 - * Node节点并不是单例的,每构建一次都会copy出一个新的实例 + * Node节点,实现可执行器 Node节点并不是单例的,每构建一次都会copy出一个新的实例 + * * @author Bryan.Zhang */ -public class Node implements Executable,Cloneable{ +public class Node implements Executable, Cloneable { private static final Logger LOG = LoggerFactory.getLogger(Node.class); @@ -60,7 +60,7 @@ public class Node implements Executable,Cloneable{ private TransmittableThreadLocal currLoopObject = new TransmittableThreadLocal<>(); - public Node(){ + public Node() { } @@ -104,8 +104,8 @@ public class Node implements Executable,Cloneable{ this.instance = instance; } - //node的执行主要逻辑 - //所有的可执行节点,其实最终都会落到node上来,因为chain中包含的也是node + // node的执行主要逻辑 + // 所有的可执行节点,其实最终都会落到node上来,因为chain中包含的也是node @Override public void execute(Integer slotIndex) throws Exception { if (ObjectUtil.isNull(instance)) { @@ -114,47 +114,56 @@ public class Node implements Executable,Cloneable{ Slot slot = DataBus.getSlot(slotIndex); try { - //把线程属性赋值给组件对象 + // 把线程属性赋值给组件对象 instance.setSlotIndex(slotIndex); instance.setRefNode(this); LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性 + // 判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性 if (instance.isAccess()) { - //根据配置判断是否打印执行中的日志 - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){ - LOG.info("[{}]:[O]start component[{}] execution",slot.getRequestId(), instance.getDisplayName()); + // 根据配置判断是否打印执行中的日志 + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { + LOG.info("[{}]:[O]start component[{}] execution", slot.getRequestId(), instance.getDisplayName()); } - //这里开始进行重试的逻辑和主逻辑的运行 - NodeExecutor nodeExecutor = NodeExecutorHelper.loadInstance().buildNodeExecutor(instance.getNodeExecutorClass()); + // 这里开始进行重试的逻辑和主逻辑的运行 + NodeExecutor nodeExecutor = NodeExecutorHelper.loadInstance() + .buildNodeExecutor(instance.getNodeExecutorClass()); // 调用节点执行器进行执行 nodeExecutor.execute(instance); - //如果组件覆盖了isEnd方法,或者在在逻辑中主要调用了setEnd(true)的话,流程就会立马结束 + // 如果组件覆盖了isEnd方法,或者在在逻辑中主要调用了setEnd(true)的话,流程就会立马结束 if (instance.isEnd()) { - String errorInfo = StrUtil.format("[{}]:[{}] lead the chain to end", slot.getRequestId(), instance.getDisplayName()); + String errorInfo = StrUtil.format("[{}]:[{}] lead the chain to end", slot.getRequestId(), + instance.getDisplayName()); throw new ChainEndException(errorInfo); } - } else { - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){ + } + else { + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { LOG.info("[{}]:[X]skip component[{}] execution", slot.getRequestId(), instance.getDisplayName()); } } - } catch (ChainEndException e){ + } + catch (ChainEndException e) { throw e; - } catch (Exception e) { - //如果组件覆盖了isContinueOnError方法,返回为true,那即便出了异常,也会继续流程 + } + catch (Exception e) { + // 如果组件覆盖了isContinueOnError方法,返回为true,那即便出了异常,也会继续流程 if (instance.isContinueOnError()) { - String errorMsg = MessageFormat.format("[{0}]:component[{1}] cause error,but flow is still go on", slot.getRequestId(),id); + String errorMsg = MessageFormat.format("[{0}]:component[{1}] cause error,but flow is still go on", + slot.getRequestId(), id); LOG.error(errorMsg); - } else { - String errorMsg = MessageFormat.format("[{0}]:component[{1}] cause error,error:{2}",slot.getRequestId(),id,e.getMessage()); + } + else { + String errorMsg = MessageFormat.format("[{0}]:component[{1}] cause error,error:{2}", + slot.getRequestId(), id, e.getMessage()); LOG.error(errorMsg); throw e; } - } finally { - //移除threadLocal里的信息 + } + finally { + // 移除threadLocal里的信息 instance.removeSlotIndex(); instance.removeIsEnd(); instance.removeRefNode(); @@ -162,13 +171,13 @@ public class Node implements Executable,Cloneable{ } } - //在同步场景并不会单独执行这方法,同步场景会在execute里面去判断isAccess。 - //但是在异步场景的any=true情况下,如果isAccess返回了false,那么异步的any有可能会认为这个组件先执行完。就会导致不正常 - //增加这个方法是为了在异步的时候,先去过滤掉isAccess为false的异步组件。然后再异步执行。 - //详情见这个issue:https://gitee.com/dromara/liteFlow/issues/I4XRBA + // 在同步场景并不会单独执行这方法,同步场景会在execute里面去判断isAccess。 + // 但是在异步场景的any=true情况下,如果isAccess返回了false,那么异步的any有可能会认为这个组件先执行完。就会导致不正常 + // 增加这个方法是为了在异步的时候,先去过滤掉isAccess为false的异步组件。然后再异步执行。 + // 详情见这个issue:https://gitee.com/dromara/liteFlow/issues/I4XRBA @Override public boolean isAccess(Integer slotIndex) throws Exception { - //把线程属性赋值给组件对象 + // 把线程属性赋值给组件对象 instance.setSlotIndex(slotIndex); instance.setRefNode(this); return instance.isAccess(); @@ -179,7 +188,7 @@ public class Node implements Executable,Cloneable{ return super.clone(); } - public Node copy() throws Exception{ + public Node copy() throws Exception { return (Node) this.clone(); } @@ -234,27 +243,27 @@ public class Node implements Executable,Cloneable{ return currChainId; } - public void setLoopIndex(int index){ + public void setLoopIndex(int index) { this.loopIndexTL.set(index); } - public Integer getLoopIndex(){ + public Integer getLoopIndex() { return this.loopIndexTL.get(); } - public void removeLoopIndex(){ + public void removeLoopIndex() { this.loopIndexTL.remove(); } - public void setCurrLoopObject(Object obj){ + public void setCurrLoopObject(Object obj) { this.currLoopObject.set(obj); } - public T getCurrLoopObject(){ - return (T)this.currLoopObject.get(); + public T getCurrLoopObject() { + return (T) this.currLoopObject.get(); } - public void removeCurrLoopObject(){ + public void removeCurrLoopObject() { this.currLoopObject.remove(); } @@ -265,4 +274,5 @@ public class Node implements Executable,Cloneable{ public void setLanguage(String language) { this.language = language; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java index 873bec3e..70fab7d4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java @@ -10,52 +10,55 @@ import com.yomahub.liteflow.slot.Slot; /** * Catch Condition + * * @author Bryan.Zhang * @since 2.10.0 */ -public class CatchCondition extends Condition{ +public class CatchCondition extends Condition { - @Override - public void executeCondition(Integer slotIndex) throws Exception { - Slot slot = DataBus.getSlot(slotIndex); - try{ - Executable catchExecutable = this.getCatchItem(); - if (ObjectUtil.isNull(catchExecutable)){ - String errorInfo = StrUtil.format("[{}]:no catch item find", slot.getRequestId()); - throw new CatchErrorException(errorInfo); - } - catchExecutable.setCurrChainId(this.getCurrChainId()); - catchExecutable.execute(slotIndex); - }catch (Exception e){ - Executable doExecutable = this.getDoItem(); - if (ObjectUtil.isNotNull(doExecutable)){ - doExecutable.setCurrChainId(this.getCurrChainId()); - doExecutable.execute(slotIndex); - } - //catch之后需要把exception给清除掉 - //正如同java的catch一样,异常自己处理了,属于正常流程了,整个流程状态应该是成功的 - DataBus.getSlot(slotIndex).removeException(); - } - } + @Override + public void executeCondition(Integer slotIndex) throws Exception { + Slot slot = DataBus.getSlot(slotIndex); + try { + Executable catchExecutable = this.getCatchItem(); + if (ObjectUtil.isNull(catchExecutable)) { + String errorInfo = StrUtil.format("[{}]:no catch item find", slot.getRequestId()); + throw new CatchErrorException(errorInfo); + } + catchExecutable.setCurrChainId(this.getCurrChainId()); + catchExecutable.execute(slotIndex); + } + catch (Exception e) { + Executable doExecutable = this.getDoItem(); + if (ObjectUtil.isNotNull(doExecutable)) { + doExecutable.setCurrChainId(this.getCurrChainId()); + doExecutable.execute(slotIndex); + } + // catch之后需要把exception给清除掉 + // 正如同java的catch一样,异常自己处理了,属于正常流程了,整个流程状态应该是成功的 + DataBus.getSlot(slotIndex).removeException(); + } + } - @Override - public ConditionTypeEnum getConditionType() { - return ConditionTypeEnum.TYPE_CATCH; - } + @Override + public ConditionTypeEnum getConditionType() { + return ConditionTypeEnum.TYPE_CATCH; + } - public Executable getCatchItem(){ - return this.getExecutableOne(ConditionKey.CATCH_KEY); - } + public Executable getCatchItem() { + return this.getExecutableOne(ConditionKey.CATCH_KEY); + } - public void setCatchItem(Executable executable){ - this.addExecutable(ConditionKey.CATCH_KEY, executable); - } + public void setCatchItem(Executable executable) { + this.addExecutable(ConditionKey.CATCH_KEY, executable); + } - public Executable getDoItem(){ - return this.getExecutableOne(ConditionKey.DO_KEY); - } + public Executable getDoItem() { + return this.getExecutableOne(ConditionKey.DO_KEY); + } + + public void setDoItem(Executable executable) { + this.addExecutable(ConditionKey.DO_KEY, executable); + } - public void setDoItem(Executable executable){ - this.addExecutable(ConditionKey.DO_KEY, executable); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java index a497fe0e..12e822ae 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/Condition.java @@ -24,9 +24,10 @@ import java.util.Map; /** * Condition的抽象类 + * * @author Bryan.Zhang */ -public abstract class Condition implements Executable{ +public abstract class Condition implements Executable { private String id; @@ -36,26 +37,28 @@ public abstract class Condition implements Executable{ private final Map> executableGroup = new HashMap<>(); /** - * 当前所在的ChainName - * 如果对于子流程来说,那这个就是子流程所在的Chain + * 当前所在的ChainName 如果对于子流程来说,那这个就是子流程所在的Chain */ private String currChainId; @Override public void execute(Integer slotIndex) throws Exception { - try{ + try { executeCondition(slotIndex); - }catch (ChainEndException e){ - //这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 - //是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 + } + catch (ChainEndException e) { + // 这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 + // 是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 throw e; - }catch (Exception e){ + } + catch (Exception e) { Slot slot = DataBus.getSlot(slotIndex); String chainId = this.getCurrChainId(); - //这里事先取到exception set到slot里,为了方便finally取到exception - if (slot.isSubChain(chainId)){ + // 这里事先取到exception set到slot里,为了方便finally取到exception + if (slot.isSubChain(chainId)) { slot.setSubException(chainId, e); - }else{ + } + else { slot.setException(e); } throw e; @@ -80,7 +83,7 @@ public abstract class Condition implements Executable{ public List getExecutableList(String groupKey) { List executableList = this.executableGroup.get(groupKey); - if (CollUtil.isEmpty(executableList)){ + if (CollUtil.isEmpty(executableList)) { executableList = new ArrayList<>(); } return executableList; @@ -88,9 +91,10 @@ public abstract class Condition implements Executable{ public Executable getExecutableOne(String groupKey) { List list = getExecutableList(groupKey); - if (CollUtil.isEmpty(list)){ + if (CollUtil.isEmpty(list)) { return null; - }else{ + } + else { return list.get(0); } } @@ -104,13 +108,14 @@ public abstract class Condition implements Executable{ } public void addExecutable(String groupKey, Executable executable) { - if (ObjectUtil.isNull(executable)){ + if (ObjectUtil.isNull(executable)) { return; } List executableList = this.executableGroup.get(groupKey); - if (CollUtil.isEmpty(executableList)){ + if (CollUtil.isEmpty(executableList)) { this.executableGroup.put(groupKey, ListUtil.toList(executable)); - }else{ + } + else { this.executableGroup.get(groupKey).add(executable); } } @@ -136,7 +141,7 @@ public abstract class Condition implements Executable{ public String getCurrChainId() { return currChainId; } - + @Override public void setCurrChainId(String currChainId) { this.currChainId = currChainId; @@ -145,4 +150,5 @@ public abstract class Condition implements Executable{ public Map> getExecutableGroup() { return executableGroup; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ConditionKey.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ConditionKey.java index e8c0de21..185b1b3f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ConditionKey.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ConditionKey.java @@ -2,33 +2,34 @@ package com.yomahub.liteflow.flow.element.condition; public interface ConditionKey { - String DEFAULT_KEY = "DEFAULT_KEY"; + String DEFAULT_KEY = "DEFAULT_KEY"; - String FOR_KEY = "FOR_KEY"; + String FOR_KEY = "FOR_KEY"; - String IF_KEY = "IF_KEY"; + String IF_KEY = "IF_KEY"; - String IF_TRUE_CASE_KEY = "IF_TRUE_CASE_KEY"; + String IF_TRUE_CASE_KEY = "IF_TRUE_CASE_KEY"; - String IF_FALSE_CASE_KEY = "IF_FALSE_CASE_KEY"; + String IF_FALSE_CASE_KEY = "IF_FALSE_CASE_KEY"; - String ITERATOR_KEY = "ITERATOR_KEY"; + String ITERATOR_KEY = "ITERATOR_KEY"; - String DO_KEY = "DO_KEY"; + String DO_KEY = "DO_KEY"; - String BREAK_KEY = "BREAK_KEY"; + String BREAK_KEY = "BREAK_KEY"; - String SWITCH_KEY = "SWITCH_KEY"; + String SWITCH_KEY = "SWITCH_KEY"; - String SWITCH_TARGET_KEY = "SWITCH_TARGET_KEY"; + String SWITCH_TARGET_KEY = "SWITCH_TARGET_KEY"; - String SWITCH_DEFAULT_KEY = "SWITCH_DEFAULT_KEY"; + String SWITCH_DEFAULT_KEY = "SWITCH_DEFAULT_KEY"; - String PRE_KEY = "PRE_KEY"; + String PRE_KEY = "PRE_KEY"; - String FINALLY_KEY = "FINALLY_KEY"; + String FINALLY_KEY = "FINALLY_KEY"; - String WHILE_KEY = "WHILE_KEY"; + String WHILE_KEY = "WHILE_KEY"; + + String CATCH_KEY = "CATCH_KEY"; - String CATCH_KEY = "CATCH_KEY"; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java index 7df5f430..adf69062 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/FinallyCondition.java @@ -12,6 +12,7 @@ import com.yomahub.liteflow.flow.element.Executable; /** * 后置Condition + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -19,7 +20,7 @@ public class FinallyCondition extends Condition { @Override public void executeCondition(Integer slotIndex) throws Exception { - for(Executable executableItem : this.getExecutableList()){ + for (Executable executableItem : this.getExecutableList()) { executableItem.setCurrChainId(this.getCurrChainId()); executableItem.execute(slotIndex); } @@ -29,4 +30,5 @@ public class FinallyCondition extends Condition { public ConditionTypeEnum getConditionType() { return ConditionTypeEnum.TYPE_FINALLY; } + } 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 acabb6af..1abd75a1 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 @@ -16,67 +16,68 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; * @author Bryan.Zhang * @since 2.9.0 */ -public class ForCondition extends LoopCondition{ +public class ForCondition extends LoopCondition { - @Override - public void executeCondition(Integer slotIndex) throws Exception { - Slot slot = DataBus.getSlot(slotIndex); - Node forNode = this.getForNode(); - if (ObjectUtil.isNull(forNode)){ - String errorInfo = StrUtil.format("[{}]:no for-node found", slot.getRequestId()); - throw new NoForNodeException(errorInfo); - } + @Override + public void executeCondition(Integer slotIndex) throws Exception { + Slot slot = DataBus.getSlot(slotIndex); + Node forNode = this.getForNode(); + if (ObjectUtil.isNull(forNode)) { + String errorInfo = StrUtil.format("[{}]:no for-node found", slot.getRequestId()); + throw new NoForNodeException(errorInfo); + } - //先去判断isAccess方法,如果isAccess方法都返回false,整个FOR表达式不执行 - if (!this.getForNode().isAccess(slotIndex)){ - return; - } + // 先去判断isAccess方法,如果isAccess方法都返回false,整个FOR表达式不执行 + if (!this.getForNode().isAccess(slotIndex)) { + return; + } - //执行forCount组件 - forNode.setCurrChainId(this.getCurrChainId()); - forNode.execute(slotIndex); + // 执行forCount组件 + forNode.setCurrChainId(this.getCurrChainId()); + forNode.execute(slotIndex); - //这里可能会有spring代理过的bean,所以拿到user原始的class - Class originalForCountClass = LiteFlowProxyUtil.getUserClass(forNode.getInstance().getClass()); - //获得循环次数 - int forCount = slot.getForResult(originalForCountClass.getName()); + // 这里可能会有spring代理过的bean,所以拿到user原始的class + Class originalForCountClass = LiteFlowProxyUtil.getUserClass(forNode.getInstance().getClass()); + // 获得循环次数 + int forCount = slot.getForResult(originalForCountClass.getName()); - //获得要循环的可执行对象 - Executable executableItem = this.getDoExecutor(); + // 获得要循环的可执行对象 + Executable executableItem = this.getDoExecutor(); - //获取Break节点 - Node breakNode = this.getBreakNode(); + // 获取Break节点 + Node breakNode = this.getBreakNode(); - //循环执行 - for (int i = 0; i < forCount; i++) { - executableItem.setCurrChainId(this.getCurrChainId()); - //设置循环index - setLoopIndex(executableItem, i); - executableItem.execute(slotIndex); - //如果break组件不为空,则去执行 - if (ObjectUtil.isNotNull(breakNode)){ - breakNode.setCurrChainId(this.getCurrChainId()); - setLoopIndex(breakNode, i); - breakNode.execute(slotIndex); - Class originalBreakClass = LiteFlowProxyUtil.getUserClass(breakNode.getInstance().getClass()); - boolean isBreak = slot.getBreakResult(originalBreakClass.getName()); - if (isBreak){ - break; - } - } - } - } + // 循环执行 + for (int i = 0; i < forCount; i++) { + executableItem.setCurrChainId(this.getCurrChainId()); + // 设置循环index + setLoopIndex(executableItem, i); + executableItem.execute(slotIndex); + // 如果break组件不为空,则去执行 + if (ObjectUtil.isNotNull(breakNode)) { + breakNode.setCurrChainId(this.getCurrChainId()); + setLoopIndex(breakNode, i); + breakNode.execute(slotIndex); + Class originalBreakClass = LiteFlowProxyUtil.getUserClass(breakNode.getInstance().getClass()); + boolean isBreak = slot.getBreakResult(originalBreakClass.getName()); + if (isBreak) { + break; + } + } + } + } - @Override - public ConditionTypeEnum getConditionType() { - return ConditionTypeEnum.TYPE_FOR; - } + @Override + public ConditionTypeEnum getConditionType() { + return ConditionTypeEnum.TYPE_FOR; + } - public Node getForNode() { - return (Node) this.getExecutableOne(ConditionKey.FOR_KEY); - } + public Node getForNode() { + return (Node) this.getExecutableOne(ConditionKey.FOR_KEY); + } + + public void setForNode(Node forNode) { + this.addExecutable(ConditionKey.FOR_KEY, forNode); + } - public void setForNode(Node forNode) { - this.addExecutable(ConditionKey.FOR_KEY, forNode); - } } 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 3052d039..e2593fed 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 @@ -20,88 +20,98 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; */ public class IfCondition extends Condition { - @Override - public void executeCondition(Integer slotIndex) throws Exception { - if (ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(getIfNode().getType())){ - //先去判断isAccess方法,如果isAccess方法都返回false,整个IF表达式不执行 - if (!this.getIfNode().isAccess(slotIndex)){ - return; - } + @Override + public void executeCondition(Integer slotIndex) throws Exception { + if (ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(getIfNode().getType())) { + // 先去判断isAccess方法,如果isAccess方法都返回false,整个IF表达式不执行 + if (!this.getIfNode().isAccess(slotIndex)) { + return; + } - //先执行IF节点 - this.getIfNode().setCurrChainId(this.getCurrChainId()); - this.getIfNode().execute(slotIndex); + // 先执行IF节点 + this.getIfNode().setCurrChainId(this.getCurrChainId()); + this.getIfNode().execute(slotIndex); - Slot slot = DataBus.getSlot(slotIndex); - //这里可能会有spring代理过的bean,所以拿到user原始的class - Class originalClass = LiteFlowProxyUtil.getUserClass(this.getIfNode().getInstance().getClass()); - //拿到If执行过的结果 - boolean ifResult = slot.getIfResult(originalClass.getName()); + Slot slot = DataBus.getSlot(slotIndex); + // 这里可能会有spring代理过的bean,所以拿到user原始的class + Class originalClass = LiteFlowProxyUtil.getUserClass(this.getIfNode().getInstance().getClass()); + // 拿到If执行过的结果 + boolean ifResult = slot.getIfResult(originalClass.getName()); - Executable trueCaseExecutableItem = this.getTrueCaseExecutableItem(); - Executable falseCaseExecutableItem = this.getFalseCaseExecutableItem(); + Executable trueCaseExecutableItem = this.getTrueCaseExecutableItem(); + Executable falseCaseExecutableItem = this.getFalseCaseExecutableItem(); - if (ifResult) { - //trueCaseExecutableItem这个不能为空,否则执行什么呢 - if (ObjectUtil.isNull(trueCaseExecutableItem)) { - String errorInfo = StrUtil.format("[{}]:no if-true node found for the component[{}]", slot.getRequestId(), this.getIfNode().getInstance().getDisplayName()); - throw new NoIfTrueNodeException(errorInfo); - } + if (ifResult) { + // trueCaseExecutableItem这个不能为空,否则执行什么呢 + if (ObjectUtil.isNull(trueCaseExecutableItem)) { + String errorInfo = StrUtil.format("[{}]:no if-true node found for the component[{}]", + slot.getRequestId(), this.getIfNode().getInstance().getDisplayName()); + throw new NoIfTrueNodeException(errorInfo); + } - //trueCaseExecutableItem 不能为前置或者后置组件 - if (trueCaseExecutableItem instanceof PreCondition || trueCaseExecutableItem instanceof FinallyCondition) { - String errorInfo = StrUtil.format("[{}]:if component[{}] error, if true node cannot be pre or finally", slot.getRequestId(), this.getIfNode().getInstance().getDisplayName()); - throw new IfTargetCannotBePreOrFinallyException(errorInfo); - } + // trueCaseExecutableItem 不能为前置或者后置组件 + if (trueCaseExecutableItem instanceof PreCondition + || trueCaseExecutableItem instanceof FinallyCondition) { + String errorInfo = StrUtil.format( + "[{}]:if component[{}] error, if true node cannot be pre or finally", slot.getRequestId(), + this.getIfNode().getInstance().getDisplayName()); + throw new IfTargetCannotBePreOrFinallyException(errorInfo); + } - //执行trueCaseExecutableItem - trueCaseExecutableItem.setCurrChainId(this.getCurrChainId()); - trueCaseExecutableItem.execute(slotIndex); - } else { - //falseCaseExecutableItem可以为null,但是不为null时就执行否的情况 - if (ObjectUtil.isNotNull(falseCaseExecutableItem)) { - //falseCaseExecutableItem 不能为前置或者后置组件 - if (falseCaseExecutableItem instanceof PreCondition || falseCaseExecutableItem instanceof FinallyCondition) { - String errorInfo = StrUtil.format("[{}]:if component[{}] error, if true node cannot be pre or finally", slot.getRequestId(), this.getIfNode().getInstance().getDisplayName()); - throw new IfTargetCannotBePreOrFinallyException(errorInfo); - } + // 执行trueCaseExecutableItem + trueCaseExecutableItem.setCurrChainId(this.getCurrChainId()); + trueCaseExecutableItem.execute(slotIndex); + } + else { + // falseCaseExecutableItem可以为null,但是不为null时就执行否的情况 + if (ObjectUtil.isNotNull(falseCaseExecutableItem)) { + // falseCaseExecutableItem 不能为前置或者后置组件 + if (falseCaseExecutableItem instanceof PreCondition + || falseCaseExecutableItem instanceof FinallyCondition) { + String errorInfo = StrUtil.format( + "[{}]:if component[{}] error, if true node cannot be pre or finally", + slot.getRequestId(), this.getIfNode().getInstance().getDisplayName()); + throw new IfTargetCannotBePreOrFinallyException(errorInfo); + } - //执行falseCaseExecutableItem - falseCaseExecutableItem.setCurrChainId(this.getCurrChainId()); - falseCaseExecutableItem.execute(slotIndex); - } - } - } else { - throw new IfTypeErrorException("if instance must be NodeIfComponent"); - } - } + // 执行falseCaseExecutableItem + falseCaseExecutableItem.setCurrChainId(this.getCurrChainId()); + falseCaseExecutableItem.execute(slotIndex); + } + } + } + else { + throw new IfTypeErrorException("if instance must be NodeIfComponent"); + } + } - @Override - public ConditionTypeEnum getConditionType() { - return ConditionTypeEnum.TYPE_IF; - } + @Override + public ConditionTypeEnum getConditionType() { + return ConditionTypeEnum.TYPE_IF; + } - public Executable getTrueCaseExecutableItem() { - return this.getExecutableOne(ConditionKey.IF_TRUE_CASE_KEY); - } + public Executable getTrueCaseExecutableItem() { + return this.getExecutableOne(ConditionKey.IF_TRUE_CASE_KEY); + } - public void setTrueCaseExecutableItem(Executable trueCaseExecutableItem) { - this.addExecutable(ConditionKey.IF_TRUE_CASE_KEY, trueCaseExecutableItem); - } + public void setTrueCaseExecutableItem(Executable trueCaseExecutableItem) { + this.addExecutable(ConditionKey.IF_TRUE_CASE_KEY, trueCaseExecutableItem); + } - public Executable getFalseCaseExecutableItem() { - return this.getExecutableOne(ConditionKey.IF_FALSE_CASE_KEY); - } + public Executable getFalseCaseExecutableItem() { + return this.getExecutableOne(ConditionKey.IF_FALSE_CASE_KEY); + } - public void setFalseCaseExecutableItem(Executable falseCaseExecutableItem) { - this.addExecutable(ConditionKey.IF_FALSE_CASE_KEY, falseCaseExecutableItem); - } + public void setFalseCaseExecutableItem(Executable falseCaseExecutableItem) { + this.addExecutable(ConditionKey.IF_FALSE_CASE_KEY, falseCaseExecutableItem); + } - public void setIfNode(Node ifNode){ - this.addExecutable(ConditionKey.IF_KEY, ifNode); - } + public void setIfNode(Node ifNode) { + this.addExecutable(ConditionKey.IF_KEY, ifNode); + } + + public Node getIfNode() { + return (Node) this.getExecutableOne(ConditionKey.IF_KEY); + } - public Node getIfNode() { - return (Node) this.getExecutableOne(ConditionKey.IF_KEY); - } } 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 e917dcd9..efd25f1f 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 @@ -12,75 +12,76 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; import java.util.Iterator; -public class IteratorCondition extends LoopCondition{ +public class IteratorCondition extends LoopCondition { - @Override - public void executeCondition(Integer slotIndex) throws Exception { - Slot slot = DataBus.getSlot(slotIndex); - Node iteratorNode = this.getIteratorNode(); + @Override + public void executeCondition(Integer slotIndex) throws Exception { + Slot slot = DataBus.getSlot(slotIndex); + Node iteratorNode = this.getIteratorNode(); - if (ObjectUtil.isNull(iteratorNode)){ - String errorInfo = StrUtil.format("[{}]:no iterator-node found", slot.getRequestId()); - throw new NoIteratorNodeException(errorInfo); - } + if (ObjectUtil.isNull(iteratorNode)) { + String errorInfo = StrUtil.format("[{}]:no iterator-node found", slot.getRequestId()); + throw new NoIteratorNodeException(errorInfo); + } - //先去判断isAccess方法,如果isAccess方法都返回false,整个ITERATOR表达式不执行 - if (!this.getIteratorNode().isAccess(slotIndex)){ - return; - } + // 先去判断isAccess方法,如果isAccess方法都返回false,整个ITERATOR表达式不执行 + if (!this.getIteratorNode().isAccess(slotIndex)) { + return; + } - //执行Iterator组件 - iteratorNode.setCurrChainId(this.getCurrChainId()); - iteratorNode.execute(slotIndex); + // 执行Iterator组件 + iteratorNode.setCurrChainId(this.getCurrChainId()); + iteratorNode.execute(slotIndex); - //这里可能会有spring代理过的bean,所以拿到user原始的class - Class originalForCountClass = LiteFlowProxyUtil.getUserClass(iteratorNode.getInstance().getClass()); - //获得迭代器 - Iterator it = slot.getIteratorResult(originalForCountClass.getName()); + // 这里可能会有spring代理过的bean,所以拿到user原始的class + Class originalForCountClass = LiteFlowProxyUtil.getUserClass(iteratorNode.getInstance().getClass()); + // 获得迭代器 + Iterator it = slot.getIteratorResult(originalForCountClass.getName()); - //获得要循环的可执行对象 - Executable executableItem = this.getDoExecutor(); + // 获得要循环的可执行对象 + Executable executableItem = this.getDoExecutor(); - //获取Break节点 - Node breakNode = this.getBreakNode(); + // 获取Break节点 + Node breakNode = this.getBreakNode(); - int index = 0; - while(it.hasNext()){ - Object itObj = it.next(); + int index = 0; + while (it.hasNext()) { + Object itObj = it.next(); - executableItem.setCurrChainId(this.getCurrChainId()); - //设置循环index - setLoopIndex(executableItem, index); - //设置循环迭代器对象 - setCurrLoopObject(executableItem, itObj); - //执行可执行对象 - executableItem.execute(slotIndex); - //如果break组件不为空,则去执行 - if (ObjectUtil.isNotNull(breakNode)){ - breakNode.setCurrChainId(this.getCurrChainId()); - setLoopIndex(breakNode, index); - setCurrLoopObject(breakNode, itObj); - breakNode.execute(slotIndex); - Class originalBreakClass = LiteFlowProxyUtil.getUserClass(breakNode.getInstance().getClass()); - boolean isBreak = slot.getBreakResult(originalBreakClass.getName()); - if (isBreak){ - break; - } - } - index++; - } - } + executableItem.setCurrChainId(this.getCurrChainId()); + // 设置循环index + setLoopIndex(executableItem, index); + // 设置循环迭代器对象 + setCurrLoopObject(executableItem, itObj); + // 执行可执行对象 + executableItem.execute(slotIndex); + // 如果break组件不为空,则去执行 + if (ObjectUtil.isNotNull(breakNode)) { + breakNode.setCurrChainId(this.getCurrChainId()); + setLoopIndex(breakNode, index); + setCurrLoopObject(breakNode, itObj); + breakNode.execute(slotIndex); + Class originalBreakClass = LiteFlowProxyUtil.getUserClass(breakNode.getInstance().getClass()); + boolean isBreak = slot.getBreakResult(originalBreakClass.getName()); + if (isBreak) { + break; + } + } + index++; + } + } - @Override - public ConditionTypeEnum getConditionType() { - return ConditionTypeEnum.TYPE_ITERATOR; - } + @Override + public ConditionTypeEnum getConditionType() { + return ConditionTypeEnum.TYPE_ITERATOR; + } - public Node getIteratorNode() { - return (Node) this.getExecutableOne(ConditionKey.ITERATOR_KEY); - } + public Node getIteratorNode() { + return (Node) this.getExecutableOne(ConditionKey.ITERATOR_KEY); + } + + public void setIteratorNode(Node iteratorNode) { + this.addExecutable(ConditionKey.ITERATOR_KEY, iteratorNode); + } - public void setIteratorNode(Node iteratorNode) { - this.addExecutable(ConditionKey.ITERATOR_KEY, iteratorNode); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java index b22697bb..1b405394 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java @@ -9,49 +9,53 @@ import java.util.Map; import java.util.function.Consumer; /** - * 循环Condition的抽象类 - * 主要继承对象有ForCondition和WhileCondition + * 循环Condition的抽象类 主要继承对象有ForCondition和WhileCondition * * @author Bryan.Zhang * @since 2.9.0 */ public abstract class LoopCondition extends Condition { - protected Node getBreakNode() { - return (Node) this.getExecutableOne(ConditionKey.BREAK_KEY); - } + protected Node getBreakNode() { + return (Node) this.getExecutableOne(ConditionKey.BREAK_KEY); + } - public void setBreakNode(Node breakNode) { - this.addExecutable(ConditionKey.BREAK_KEY, breakNode); - } + public void setBreakNode(Node breakNode) { + this.addExecutable(ConditionKey.BREAK_KEY, breakNode); + } - protected Executable getDoExecutor() { - return this.getExecutableOne(ConditionKey.DO_KEY); - } + protected Executable getDoExecutor() { + return this.getExecutableOne(ConditionKey.DO_KEY); + } - public void setDoExecutor(Executable executable) { - this.addExecutable(ConditionKey.DO_KEY, executable); - } + public void setDoExecutor(Executable executable) { + this.addExecutable(ConditionKey.DO_KEY, executable); + } - protected void setLoopIndex(Executable executableItem, int index){ - if (executableItem instanceof Chain){ - ((Chain)executableItem).getConditionList().forEach(condition -> setLoopIndex(condition, index)); - }else if(executableItem instanceof Condition){ - ((Condition) executableItem).getExecutableGroup().forEach((key, value) -> value.forEach(executable -> setLoopIndex(executable, index))); - }else if(executableItem instanceof Node){ - ((Node)executableItem).setLoopIndex(index); - } - } - - protected void setCurrLoopObject(Executable executableItem, Object obj){ - if (executableItem instanceof Chain){ - ((Chain)executableItem).getConditionList().forEach(condition -> setCurrLoopObject(condition, obj)); - }else if(executableItem instanceof Condition){ - ((Condition) executableItem).getExecutableGroup().forEach((key, value) -> value.forEach(executable -> setCurrLoopObject(executable, obj))); - }else if(executableItem instanceof Node){ - ((Node)executableItem).setCurrLoopObject(obj); - } - } + protected void setLoopIndex(Executable executableItem, int index) { + if (executableItem instanceof Chain) { + ((Chain) executableItem).getConditionList().forEach(condition -> setLoopIndex(condition, index)); + } + else if (executableItem instanceof Condition) { + ((Condition) executableItem).getExecutableGroup() + .forEach((key, value) -> value.forEach(executable -> setLoopIndex(executable, index))); + } + else if (executableItem instanceof Node) { + ((Node) executableItem).setLoopIndex(index); + } + } + protected void setCurrLoopObject(Executable executableItem, Object obj) { + if (executableItem instanceof Chain) { + ((Chain) executableItem).getConditionList().forEach(condition -> setCurrLoopObject(condition, obj)); + } + else if (executableItem instanceof Condition) { + ((Condition) executableItem).getExecutableGroup() + .forEach((key, value) -> value.forEach(executable -> setCurrLoopObject(executable, obj))); + } + else if (executableItem instanceof Node) { + ((Node) executableItem).setCurrLoopObject(obj); + } + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java index cf63d4f6..37187f05 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/PreCondition.java @@ -12,6 +12,7 @@ import com.yomahub.liteflow.flow.element.Executable; /** * 前置Condition + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -19,7 +20,7 @@ public class PreCondition extends Condition { @Override public void executeCondition(Integer slotIndex) throws Exception { - for(Executable executableItem : this.getExecutableList()){ + for (Executable executableItem : this.getExecutableList()) { executableItem.setCurrChainId(this.getCurrChainId()); executableItem.execute(slotIndex); } @@ -29,4 +30,5 @@ public class PreCondition extends Condition { public ConditionTypeEnum getConditionType() { return ConditionTypeEnum.TYPE_PRE; } + } 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 9ac2313c..ef41197d 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 @@ -19,108 +19,120 @@ import java.util.List; /** * 选择Condition + * * @author Bryan.Zhang * @since 2.8.0 */ -public class SwitchCondition extends Condition{ - private final String TAG_PREFIX = "tag"; - private final String TAG_FLAG = ":"; +public class SwitchCondition extends Condition { - @Override - public void executeCondition(Integer slotIndex) throws Exception { - if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())){ - //获取switch node - Node switchNode = this.getSwitchNode(); - //获取target List - List targetList = this.getTargetList(); + private final String TAG_PREFIX = "tag"; - //先去判断isAccess方法,如果isAccess方法都返回false,整个SWITCH表达式不执行 - if (!switchNode.isAccess(slotIndex)){ - return; - } + private final String TAG_FLAG = ":"; - //先执行switch节点 - switchNode.setCurrChainId(this.getCurrChainId()); - switchNode.execute(slotIndex); + @Override + public void executeCondition(Integer slotIndex) throws Exception { + if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())) { + // 获取switch node + Node switchNode = this.getSwitchNode(); + // 获取target List + List targetList = this.getTargetList(); - //根据switch节点执行出来的结果选择 - Slot slot = DataBus.getSlot(slotIndex); - //这里可能会有spring代理过的bean,所以拿到user原始的class - Class originalClass = LiteFlowProxyUtil.getUserClass(switchNode.getInstance().getClass()); - String targetId = slot.getSwitchResult(originalClass.getName()); + // 先去判断isAccess方法,如果isAccess方法都返回false,整个SWITCH表达式不执行 + if (!switchNode.isAccess(slotIndex)) { + return; + } - Executable targetExecutor = null; - if (StrUtil.isNotBlank(targetId)) { - //这里要判断是否使用tag模式跳转 - if (targetId.contains(TAG_FLAG)){ - String[] target = targetId.split(TAG_FLAG, 2); - String _targetId = target[0]; - String _targetTag = target[1]; - targetExecutor = targetList.stream().filter(executable -> { - if (executable instanceof Node){ - Node node = (Node) executable; - return (StrUtil.startWith(_targetId, TAG_PREFIX) && _targetTag.equals(node.getTag())) || ((StrUtil.isEmpty(_targetId) || _targetId.equals(node.getId())) && (StrUtil.isEmpty(_targetTag) || _targetTag.equals(node.getTag()))); - }else{ - return false; - } - }).findFirst().orElse(null); - }else{ - targetExecutor = targetList.stream().filter( - executable -> executable.getExecuteId().equals(targetId) - ).findFirst().orElse(null); - } - } + // 先执行switch节点 + switchNode.setCurrChainId(this.getCurrChainId()); + switchNode.execute(slotIndex); - if (ObjectUtil.isNull(targetExecutor)) { - //没有匹配到执行节点,则走默认的执行节点 - targetExecutor = this.getDefaultExecutor(); - } + // 根据switch节点执行出来的结果选择 + Slot slot = DataBus.getSlot(slotIndex); + // 这里可能会有spring代理过的bean,所以拿到user原始的class + Class originalClass = LiteFlowProxyUtil.getUserClass(switchNode.getInstance().getClass()); + String targetId = slot.getSwitchResult(originalClass.getName()); - if (ObjectUtil.isNotNull(targetExecutor)) { - //switch的目标不能是Pre节点或者Finally节点 - if (targetExecutor instanceof PreCondition || targetExecutor instanceof FinallyCondition){ - String errorInfo = StrUtil.format("[{}]:switch component[{}] error, switch target node cannot be pre or finally", - slot.getRequestId(), this.getSwitchNode().getInstance().getDisplayName()); - throw new SwitchTargetCannotBePreOrFinallyException(errorInfo); - } - targetExecutor.setCurrChainId(this.getCurrChainId()); - targetExecutor.execute(slotIndex); - }else{ - String errorInfo = StrUtil.format("[{}]:no target node find for the component[{}],target str is [{}]", - slot.getRequestId(), this.getSwitchNode().getInstance().getDisplayName(), targetId); - throw new NoSwitchTargetNodeException(errorInfo); - } - }else{ - throw new SwitchTypeErrorException("switch instance must be NodeSwitchComponent"); - } - } + Executable targetExecutor = null; + if (StrUtil.isNotBlank(targetId)) { + // 这里要判断是否使用tag模式跳转 + if (targetId.contains(TAG_FLAG)) { + String[] target = targetId.split(TAG_FLAG, 2); + String _targetId = target[0]; + String _targetTag = target[1]; + targetExecutor = targetList.stream().filter(executable -> { + if (executable instanceof Node) { + Node node = (Node) executable; + return (StrUtil.startWith(_targetId, TAG_PREFIX) && _targetTag.equals(node.getTag())) + || ((StrUtil.isEmpty(_targetId) || _targetId.equals(node.getId())) + && (StrUtil.isEmpty(_targetTag) || _targetTag.equals(node.getTag()))); + } + else { + return false; + } + }).findFirst().orElse(null); + } + else { + targetExecutor = targetList.stream() + .filter(executable -> executable.getExecuteId().equals(targetId)) + .findFirst() + .orElse(null); + } + } - @Override - public ConditionTypeEnum getConditionType() { - return ConditionTypeEnum.TYPE_SWITCH; - } + if (ObjectUtil.isNull(targetExecutor)) { + // 没有匹配到执行节点,则走默认的执行节点 + targetExecutor = this.getDefaultExecutor(); + } - public void addTargetItem(Executable executable){ - this.addExecutable(ConditionKey.SWITCH_TARGET_KEY, executable); - } + if (ObjectUtil.isNotNull(targetExecutor)) { + // switch的目标不能是Pre节点或者Finally节点 + if (targetExecutor instanceof PreCondition || targetExecutor instanceof FinallyCondition) { + String errorInfo = StrUtil.format( + "[{}]:switch component[{}] error, switch target node cannot be pre or finally", + slot.getRequestId(), this.getSwitchNode().getInstance().getDisplayName()); + throw new SwitchTargetCannotBePreOrFinallyException(errorInfo); + } + targetExecutor.setCurrChainId(this.getCurrChainId()); + targetExecutor.execute(slotIndex); + } + else { + String errorInfo = StrUtil.format("[{}]:no target node find for the component[{}],target str is [{}]", + slot.getRequestId(), this.getSwitchNode().getInstance().getDisplayName(), targetId); + throw new NoSwitchTargetNodeException(errorInfo); + } + } + else { + throw new SwitchTypeErrorException("switch instance must be NodeSwitchComponent"); + } + } - public List getTargetList(){ - return this.getExecutableList(ConditionKey.SWITCH_TARGET_KEY); - } + @Override + public ConditionTypeEnum getConditionType() { + return ConditionTypeEnum.TYPE_SWITCH; + } - public void setSwitchNode(Node switchNode) { - this.addExecutable(ConditionKey.SWITCH_KEY, switchNode); - } + public void addTargetItem(Executable executable) { + this.addExecutable(ConditionKey.SWITCH_TARGET_KEY, executable); + } - public Node getSwitchNode(){ - return (Node) this.getExecutableOne(ConditionKey.SWITCH_KEY); - } + public List getTargetList() { + return this.getExecutableList(ConditionKey.SWITCH_TARGET_KEY); + } - public Executable getDefaultExecutor() { - return this.getExecutableOne(ConditionKey.SWITCH_DEFAULT_KEY); - } + public void setSwitchNode(Node switchNode) { + this.addExecutable(ConditionKey.SWITCH_KEY, switchNode); + } + + public Node getSwitchNode() { + return (Node) this.getExecutableOne(ConditionKey.SWITCH_KEY); + } + + public Executable getDefaultExecutor() { + return this.getExecutableOne(ConditionKey.SWITCH_DEFAULT_KEY); + } + + public void setDefaultExecutor(Executable defaultExecutor) { + this.addExecutable(ConditionKey.SWITCH_DEFAULT_KEY, defaultExecutor); + } - public void setDefaultExecutor(Executable defaultExecutor) { - this.addExecutable(ConditionKey.SWITCH_DEFAULT_KEY, defaultExecutor); - } } 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 443d90fa..439915c7 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 @@ -17,6 +17,7 @@ import java.util.stream.Collectors; /** * 串行器 + * * @author Bryan.Zhang */ public class ThenCondition extends Condition { @@ -31,8 +32,8 @@ public class ThenCondition extends Condition { List preConditionList = this.getPreConditionList(); List finallyConditionList = this.getFinallyConditionList(); - try{ - for (PreCondition preCondition : preConditionList){ + try { + for (PreCondition preCondition : preConditionList) { preCondition.setCurrChainId(this.getCurrChainId()); preCondition.execute(slotIndex); } @@ -41,22 +42,26 @@ public class ThenCondition extends Condition { executableItem.setCurrChainId(this.getCurrChainId()); executableItem.execute(slotIndex); } - }catch (ChainEndException e){ - //这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 - //是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 + } + catch (ChainEndException e) { + // 这里单独catch ChainEndException是因为ChainEndException是用户自己setIsEnd抛出的异常 + // 是属于正常逻辑,所以会在FlowExecutor中判断。这里不作为异常处理 throw e; - }catch (Exception e){ + } + catch (Exception e) { Slot slot = DataBus.getSlot(slotIndex); String chainId = this.getCurrChainId(); - //这里事先取到exception set到slot里,为了方便finally取到exception - if (slot.isSubChain(chainId)){ + // 这里事先取到exception set到slot里,为了方便finally取到exception + if (slot.isSubChain(chainId)) { slot.setSubException(chainId, e); - }else{ + } + else { slot.setException(e); } throw e; - }finally { - for (FinallyCondition finallyCondition : finallyConditionList){ + } + finally { + for (FinallyCondition finallyCondition : finallyConditionList) { finallyCondition.setCurrChainId(this.getCurrChainId()); finallyCondition.execute(slotIndex); } @@ -65,28 +70,37 @@ public class ThenCondition extends Condition { @Override public void addExecutable(Executable executable) { - if (executable instanceof PreCondition){ + if (executable instanceof PreCondition) { this.addPreCondition((PreCondition) executable); - }else if (executable instanceof FinallyCondition){ + } + else if (executable instanceof FinallyCondition) { this.addFinallyCondition((FinallyCondition) executable); - }else{ + } + else { super.addExecutable(executable); } } public List getPreConditionList() { - return this.getExecutableList(ConditionKey.PRE_KEY).stream().map(executable -> (PreCondition) executable).collect(Collectors.toList()); + return this.getExecutableList(ConditionKey.PRE_KEY) + .stream() + .map(executable -> (PreCondition) executable) + .collect(Collectors.toList()); } - public void addPreCondition(PreCondition preCondition){ + public void addPreCondition(PreCondition preCondition) { this.addExecutable(ConditionKey.PRE_KEY, preCondition); } public List getFinallyConditionList() { - return this.getExecutableList(ConditionKey.FINALLY_KEY).stream().map(executable -> (FinallyCondition) executable).collect(Collectors.toList()); + return this.getExecutableList(ConditionKey.FINALLY_KEY) + .stream() + .map(executable -> (FinallyCondition) executable) + .collect(Collectors.toList()); } - public void addFinallyCondition(FinallyCondition finallyCondition){ + public void addFinallyCondition(FinallyCondition finallyCondition) { this.addExecutable(ConditionKey.FINALLY_KEY, finallyCondition); } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java index 68ada352..0feb87a2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java @@ -30,26 +30,26 @@ import java.util.stream.Collectors; /** * 并行器 + * * @author Bryan.Zhang */ public class WhenCondition extends Condition { private final Logger LOG = LoggerFactory.getLogger(this.getClass()); - //只在when类型下有效,以区分当when调用链调用失败时是否继续往下执行 默认false不继续执行 + // 只在when类型下有效,以区分当when调用链调用失败时是否继续往下执行 默认false不继续执行 private boolean ignoreError = false; - //只在when类型下有效,用于不同node进行同组合并,相同的组会进行合并,不同的组不会进行合并 - //此属性已弃用 + // 只在when类型下有效,用于不同node进行同组合并,相同的组会进行合并,不同的组不会进行合并 + // 此属性已弃用 private String group = LocalDefaultFlowConstant.DEFAULT; - //只在when类型下有效,为true的话说明在多个并行节点下,任意一个成功,整个when就成功 + // 只在when类型下有效,为true的话说明在多个并行节点下,任意一个成功,整个when就成功 private boolean any = false; // when单独的线程池名称 private String threadExecutorClass; - @Override public void executeCondition(Integer slotIndex) throws Exception { executeAsyncCondition(slotIndex); @@ -60,112 +60,128 @@ public class WhenCondition extends Condition { return ConditionTypeEnum.TYPE_WHEN; } - //使用线程池执行when并发流程 - //这块涉及到挺多的多线程逻辑,所以注释比较详细,看到这里的童鞋可以仔细阅读 - private void executeAsyncCondition(Integer slotIndex) throws Exception{ + // 使用线程池执行when并发流程 + // 这块涉及到挺多的多线程逻辑,所以注释比较详细,看到这里的童鞋可以仔细阅读 + private void executeAsyncCondition(Integer slotIndex) throws Exception { Slot slot = DataBus.getSlot(slotIndex); String currChainName = this.getCurrChainId(); - //此方法其实只会初始化一次Executor,不会每次都会初始化。Executor是唯一的 - ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutor(this.getThreadExecutorClass()); + // 此方法其实只会初始化一次Executor,不会每次都会初始化。Executor是唯一的 + ExecutorService parallelExecutor = ExecutorHelper.loadInstance() + .buildWhenExecutor(this.getThreadExecutorClass()); - //获得liteflow的参数 + // 获得liteflow的参数 LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //定义是否中断参数 - //这里为什么要定义成数组呢,因为后面lambda要用到,根据final不能修改引用的原则,这里用了数组对象 - final boolean[] interrupted = {false}; - - //这里主要是做了封装CompletableFuture对象,用lumbda表达式做了很多事情,这句代码要仔细理清 - //1.先进行过滤,前置和后置组件过滤掉,因为在EL Chain处理的时候已经提出来了 - //2.过滤isAccess为false的情况,因为不过滤这个的话,如果加上了any,那么isAccess为false那就是最快的了 - //3.根据condition.getNodeList()的集合进行流处理,用map进行把executable对象转换成List> - //4.在转的过程中,套入CompletableFutureTimeout方法进行超时判断,如果超时则用WhenFutureObj.timeOut返回超时的对象 - //5.第2个参数是主要的本体CompletableFuture,传入了ParallelSupplier和线程池对象 - List> completableFutureList = this.getExecutableList().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; - } - }).map(executable -> CompletableFutureTimeout.completeOnTimeout( - WhenFutureObj.timeOut(executable.getExecuteId()), - CompletableFuture.supplyAsync(new ParallelSupplier(executable, currChainName, slotIndex), parallelExecutor), - liteflowConfig.getWhenMaxWaitSeconds(), - TimeUnit.SECONDS - )).collect(Collectors.toList()); + // 定义是否中断参数 + // 这里为什么要定义成数组呢,因为后面lambda要用到,根据final不能修改引用的原则,这里用了数组对象 + final boolean[] interrupted = { false }; + // 这里主要是做了封装CompletableFuture对象,用lumbda表达式做了很多事情,这句代码要仔细理清 + // 1.先进行过滤,前置和后置组件过滤掉,因为在EL Chain处理的时候已经提出来了 + // 2.过滤isAccess为false的情况,因为不过滤这个的话,如果加上了any,那么isAccess为false那就是最快的了 + // 3.根据condition.getNodeList()的集合进行流处理,用map进行把executable对象转换成List> + // 4.在转的过程中,套入CompletableFutureTimeout方法进行超时判断,如果超时则用WhenFutureObj.timeOut返回超时的对象 + // 5.第2个参数是主要的本体CompletableFuture,传入了ParallelSupplier和线程池对象 + List> completableFutureList = this.getExecutableList() + .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; + } + }) + .map(executable -> CompletableFutureTimeout.completeOnTimeout( + WhenFutureObj.timeOut(executable.getExecuteId()), + CompletableFuture.supplyAsync(new ParallelSupplier(executable, currChainName, slotIndex), + parallelExecutor), + liteflowConfig.getWhenMaxWaitSeconds(), TimeUnit.SECONDS)) + .collect(Collectors.toList()); CompletableFuture resultCompletableFuture; - //这里判断执行方式 - //如果any为false,说明这些异步任务全部执行好或者超时,才返回 - //如果any为true,说明这些异步任务只要任意一个执行完成,就返回 - if(this.isAny()){ - //把这些CompletableFuture通过anyOf合成一个CompletableFuture - resultCompletableFuture = CompletableFuture.anyOf(completableFutureList.toArray(new CompletableFuture[]{})); - }else{ - //把这些CompletableFuture通过allOf合成一个CompletableFuture - resultCompletableFuture = CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[]{})); + // 这里判断执行方式 + // 如果any为false,说明这些异步任务全部执行好或者超时,才返回 + // 如果any为true,说明这些异步任务只要任意一个执行完成,就返回 + if (this.isAny()) { + // 把这些CompletableFuture通过anyOf合成一个CompletableFuture + resultCompletableFuture = CompletableFuture + .anyOf(completableFutureList.toArray(new CompletableFuture[] {})); + } + else { + // 把这些CompletableFuture通过allOf合成一个CompletableFuture + resultCompletableFuture = CompletableFuture + .allOf(completableFutureList.toArray(new CompletableFuture[] {})); } try { - //进行执行,这句执行完后,就意味着所有的任务要么执行完毕,要么超时返回 + // 进行执行,这句执行完后,就意味着所有的任务要么执行完毕,要么超时返回 resultCompletableFuture.get(); - } catch (InterruptedException | ExecutionException e) { - LOG.error("there was an error when executing the CompletableFuture",e); + } + catch (InterruptedException | ExecutionException e) { + LOG.error("there was an error when executing the CompletableFuture", e); interrupted[0] = true; } - //拿到已经完成的CompletableFuture - //如果any为false,那么所有任务都已经完成 - //如果any为true,那么这里拿到的是第一个完成的任务 - //这里过滤和转换一起用lumbda做了 + // 拿到已经完成的CompletableFuture + // 如果any为false,那么所有任务都已经完成 + // 如果any为true,那么这里拿到的是第一个完成的任务 + // 这里过滤和转换一起用lumbda做了 List allCompletableWhenFutureObjList = completableFutureList.stream().filter(f -> { - //过滤出已经完成的,没完成的就直接终止 - if (f.isDone()){ + // 过滤出已经完成的,没完成的就直接终止 + if (f.isDone()) { return true; - }else{ + } + else { f.cancel(true); return false; } }).map(f -> { try { return f.get(); - } catch (InterruptedException | ExecutionException e) { + } + catch (InterruptedException | ExecutionException e) { interrupted[0] = true; return null; } }).collect(Collectors.toList()); - //判断超时,上面已经拿到了所有已经完成的CompletableFuture - //那我们只要过滤出超时的CompletableFuture - List timeOutWhenFutureObjList = allCompletableWhenFutureObjList.stream().filter(WhenFutureObj::isTimeout).collect(Collectors.toList()); + // 判断超时,上面已经拿到了所有已经完成的CompletableFuture + // 那我们只要过滤出超时的CompletableFuture + List timeOutWhenFutureObjList = allCompletableWhenFutureObjList.stream() + .filter(WhenFutureObj::isTimeout) + .collect(Collectors.toList()); - //输出超时信息 - timeOutWhenFutureObjList.forEach(whenFutureObj -> - LOG.warn("requestId [{}] executing thread has reached max-wait-seconds, thread canceled.Execute-item: [{}]", slot.getRequestId(), whenFutureObj.getExecutorName())); + // 输出超时信息 + timeOutWhenFutureObjList.forEach(whenFutureObj -> LOG.warn( + "requestId [{}] executing thread has reached max-wait-seconds, thread canceled.Execute-item: [{}]", + slot.getRequestId(), whenFutureObj.getExecutorName())); - //当配置了ignoreError = false,出现interrupted或者!f.get()的情况,将抛出WhenExecuteException + // 当配置了ignoreError = false,出现interrupted或者!f.get()的情况,将抛出WhenExecuteException if (!this.isIgnoreError()) { if (interrupted[0]) { - throw new WhenExecuteException(StrUtil.format("requestId [{}] when execute interrupted. errorResume [false].", slot.getRequestId())); + throw new WhenExecuteException(StrUtil + .format("requestId [{}] when execute interrupted. errorResume [false].", slot.getRequestId())); } - //循环判断CompletableFuture的返回值,如果异步执行失败,则抛出相应的业务异常 - for(WhenFutureObj whenFutureObj : allCompletableWhenFutureObjList){ - if (!whenFutureObj.isSuccess()){ - LOG.info(StrUtil.format("requestId [{}] when-executor[{}] execute failed. errorResume [false].",slot.getRequestId(), whenFutureObj.getExecutorName())); + // 循环判断CompletableFuture的返回值,如果异步执行失败,则抛出相应的业务异常 + for (WhenFutureObj whenFutureObj : allCompletableWhenFutureObjList) { + if (!whenFutureObj.isSuccess()) { + LOG.info(StrUtil.format("requestId [{}] when-executor[{}] execute failed. errorResume [false].", + slot.getRequestId(), whenFutureObj.getExecutorName())); throw whenFutureObj.getEx(); } } - } else if (interrupted[0]) { - // 这里由于配置了ignoreError,所以只打印warn日志 - LOG.warn("requestId [{}] executing when condition timeout , but ignore with errorResume.", slot.getRequestId()); + } + else if (interrupted[0]) { + // 这里由于配置了ignoreError,所以只打印warn日志 + LOG.warn("requestId [{}] executing when condition timeout , but ignore with errorResume.", + slot.getRequestId()); } } @@ -200,4 +216,5 @@ public class WhenCondition extends Condition { public void setThreadExecutorClass(String threadExecutorClass) { this.threadExecutorClass = threadExecutorClass; } + } 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 d731d432..060d51b4 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 @@ -16,69 +16,70 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil; * @author Bryan.Zhang * @since 2.9.0 */ -public class WhileCondition extends LoopCondition{ +public class WhileCondition extends LoopCondition { - @Override - public void executeCondition(Integer slotIndex) throws Exception { - Slot slot = DataBus.getSlot(slotIndex); - Node whileNode = this.getWhileNode(); - if (ObjectUtil.isNull(whileNode)){ - String errorInfo = StrUtil.format("[{}]:no while-node found", slot.getRequestId()); - throw new NoWhileNodeException(errorInfo); - } + @Override + public void executeCondition(Integer slotIndex) throws Exception { + Slot slot = DataBus.getSlot(slotIndex); + Node whileNode = this.getWhileNode(); + if (ObjectUtil.isNull(whileNode)) { + String errorInfo = StrUtil.format("[{}]:no while-node found", slot.getRequestId()); + throw new NoWhileNodeException(errorInfo); + } - //先去判断isAccess方法,如果isAccess方法都返回false,整个WHILE表达式不执行 - if (!this.getWhileNode().isAccess(slotIndex)){ - return; - } + // 先去判断isAccess方法,如果isAccess方法都返回false,整个WHILE表达式不执行 + if (!this.getWhileNode().isAccess(slotIndex)) { + return; + } - //获得要循环的可执行对象 - Executable executableItem = this.getDoExecutor(); + // 获得要循环的可执行对象 + Executable executableItem = this.getDoExecutor(); - //获取Break节点 - Node breakNode = this.getBreakNode(); + // 获取Break节点 + Node breakNode = this.getBreakNode(); - //循环执行 - int index = 0; - while(getWhileResult(slotIndex)){ - executableItem.setCurrChainId(this.getCurrChainId()); - setLoopIndex(executableItem, index); - executableItem.execute(slotIndex); - //如果break组件不为空,则去执行 - if (ObjectUtil.isNotNull(breakNode)){ - breakNode.setCurrChainId(this.getCurrChainId()); - setLoopIndex(breakNode, index); - breakNode.execute(slotIndex); - Class originalBreakClass = LiteFlowProxyUtil.getUserClass(breakNode.getInstance().getClass()); - boolean isBreak = slot.getBreakResult(originalBreakClass.getName()); - if (isBreak){ - break; - } - } - index++; - } - } + // 循环执行 + int index = 0; + while (getWhileResult(slotIndex)) { + executableItem.setCurrChainId(this.getCurrChainId()); + setLoopIndex(executableItem, index); + executableItem.execute(slotIndex); + // 如果break组件不为空,则去执行 + if (ObjectUtil.isNotNull(breakNode)) { + breakNode.setCurrChainId(this.getCurrChainId()); + setLoopIndex(breakNode, index); + breakNode.execute(slotIndex); + Class originalBreakClass = LiteFlowProxyUtil.getUserClass(breakNode.getInstance().getClass()); + boolean isBreak = slot.getBreakResult(originalBreakClass.getName()); + if (isBreak) { + break; + } + } + index++; + } + } - private boolean getWhileResult(Integer slotIndex) throws Exception{ - Slot slot = DataBus.getSlot(slotIndex); - Node whileNode = this.getWhileNode(); - //执行while组件 - whileNode.setCurrChainId(this.getCurrChainId()); - whileNode.execute(slotIndex); - Class originalWhileClass = LiteFlowProxyUtil.getUserClass(whileNode.getInstance().getClass()); - return slot.getWhileResult(originalWhileClass.getName()); - } + private boolean getWhileResult(Integer slotIndex) throws Exception { + Slot slot = DataBus.getSlot(slotIndex); + Node whileNode = this.getWhileNode(); + // 执行while组件 + whileNode.setCurrChainId(this.getCurrChainId()); + whileNode.execute(slotIndex); + Class originalWhileClass = LiteFlowProxyUtil.getUserClass(whileNode.getInstance().getClass()); + return slot.getWhileResult(originalWhileClass.getName()); + } - @Override - public ConditionTypeEnum getConditionType() { - return ConditionTypeEnum.TYPE_WHILE; - } + @Override + public ConditionTypeEnum getConditionType() { + return ConditionTypeEnum.TYPE_WHILE; + } - public Node getWhileNode() { - return (Node) this.getExecutableOne(ConditionKey.WHILE_KEY); - } + public Node getWhileNode() { + return (Node) this.getExecutableOne(ConditionKey.WHILE_KEY); + } + + public void setWhileNode(Node whileNode) { + this.addExecutable(ConditionKey.WHILE_KEY, whileNode); + } - public void setWhileNode(Node whileNode) { - this.addExecutable(ConditionKey.WHILE_KEY, whileNode); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/entity/CmpStep.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/entity/CmpStep.java index 9173bb8b..a09277b4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/entity/CmpStep.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/entity/CmpStep.java @@ -14,138 +14,149 @@ import com.yomahub.liteflow.enums.CmpStepTypeEnum; /** * 组件步骤对象 + * * @author Bryan.Zhang */ public class CmpStep { - private String nodeId; + private String nodeId; - private String nodeName; + private String nodeName; - private String tag; + private String tag; - private CmpStepTypeEnum stepType; + private CmpStepTypeEnum stepType; - //消耗的时间,毫秒为单位 - private Long timeSpent; + // 消耗的时间,毫秒为单位 + private Long timeSpent; - //是否成功 - private boolean success; + // 是否成功 + private boolean success; - //有exception,success一定为false - //但是success为false,不一定有exception,因为有可能没执行到,或者没执行结束(any) - private Exception exception; + // 有exception,success一定为false + // 但是success为false,不一定有exception,因为有可能没执行到,或者没执行结束(any) + private Exception exception; - public CmpStep(String nodeId, String nodeName, CmpStepTypeEnum stepType) { - this.nodeId = nodeId; - this.nodeName = nodeName; - this.stepType = stepType; - } + public CmpStep(String nodeId, String nodeName, CmpStepTypeEnum stepType) { + this.nodeId = nodeId; + this.nodeName = nodeName; + this.stepType = stepType; + } - public String getNodeId() { - return nodeId; - } + public String getNodeId() { + return nodeId; + } - public void setNodeId(String nodeId) { - this.nodeId = nodeId; - } + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } - public CmpStepTypeEnum getStepType() { - return stepType; - } + public CmpStepTypeEnum getStepType() { + return stepType; + } - public void setStepType(CmpStepTypeEnum stepType) { - this.stepType = stepType; - } + public void setStepType(CmpStepTypeEnum stepType) { + this.stepType = stepType; + } - public String getNodeName() { - return nodeName; - } + public String getNodeName() { + return nodeName; + } - public void setNodeName(String nodeName) { - this.nodeName = nodeName; - } + public void setNodeName(String nodeName) { + this.nodeName = nodeName; + } - public Long getTimeSpent() { - return timeSpent; - } + public Long getTimeSpent() { + return timeSpent; + } - public void setTimeSpent(Long timeSpent) { - this.timeSpent = timeSpent; - } + public void setTimeSpent(Long timeSpent) { + this.timeSpent = timeSpent; + } - public boolean isSuccess() { - return success; - } + public boolean isSuccess() { + return success; + } - public void setSuccess(boolean success) { - this.success = success; - } + public void setSuccess(boolean success) { + this.success = success; + } - public Exception getException() { - return exception; - } + public Exception getException() { + return exception; + } - public void setException(Exception exception) { - this.exception = exception; - } + public void setException(Exception exception) { + this.exception = exception; + } - public String buildString() { - if (stepType.equals(CmpStepTypeEnum.SINGLE)) { - if (StrUtil.isBlank(nodeName)){ + public String buildString() { + if (stepType.equals(CmpStepTypeEnum.SINGLE)) { + if (StrUtil.isBlank(nodeName)) { return StrUtil.format("{}", nodeId); - }else{ + } + else { return StrUtil.format("{}[{}]", nodeId, nodeName); } - } else { - //目前没有其他的类型 - return null; - } - } + } + else { + // 目前没有其他的类型 + return null; + } + } - public String buildStringWithTime() { - if (stepType.equals(CmpStepTypeEnum.SINGLE)) { - if (StrUtil.isBlank(nodeName)){ - if (timeSpent != null){ - return StrUtil.format("{}<{}>", nodeId, timeSpent); - }else{ - return StrUtil.format("{}", nodeId); - } - }else{ - if (timeSpent != null){ - return StrUtil.format("{}[{}]<{}>", nodeId, nodeName, timeSpent); - }else{ - return StrUtil.format("{}[{}]", nodeId, nodeName); - } - } - } else { - //目前没有其他的类型 - return null; - } - } + public String buildStringWithTime() { + if (stepType.equals(CmpStepTypeEnum.SINGLE)) { + if (StrUtil.isBlank(nodeName)) { + if (timeSpent != null) { + return StrUtil.format("{}<{}>", nodeId, timeSpent); + } + else { + return StrUtil.format("{}", nodeId); + } + } + else { + if (timeSpent != null) { + return StrUtil.format("{}[{}]<{}>", nodeId, nodeName, timeSpent); + } + else { + return StrUtil.format("{}[{}]", nodeId, nodeName); + } + } + } + else { + // 目前没有其他的类型 + return null; + } + } - @Override - public boolean equals(Object obj) { - if (ObjectUtil.isNull(obj)) { - return false; - } else { - if (getClass() != obj.getClass()) { - return false; - } else { - if (((CmpStep) obj).getNodeId().equals(this.getNodeId())) { - return true; - } else { - return false; - } - } - } - } + @Override + public boolean equals(Object obj) { + if (ObjectUtil.isNull(obj)) { + return false; + } + else { + if (getClass() != obj.getClass()) { + return false; + } + else { + if (((CmpStep) obj).getNodeId().equals(this.getNodeId())) { + return true; + } + else { + return false; + } + } + } + } - public String getTag() { - return tag; - } + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } - public void setTag(String tag) { - this.tag = tag; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/DefaultNodeExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/DefaultNodeExecutor.java index 70cbc2ff..0869267a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/DefaultNodeExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/DefaultNodeExecutor.java @@ -9,8 +9,10 @@ import com.yomahub.liteflow.core.NodeComponent; * @since 2.6.9 */ public class DefaultNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + super.execute(instance); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutor.java index a421983a..094d6347 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutor.java @@ -17,45 +17,51 @@ import java.util.List; * @since 2.6.9 */ public abstract class NodeExecutor { - protected final Logger LOG = LoggerFactory.getLogger(this.getClass()); - /** - * 执行器执行入口-若需要更大维度的执行方式可以重写该方法 - */ - public void execute(NodeComponent instance) throws Exception { - int retryCount = instance.getRetryCount(); - List> forExceptions = Arrays.asList(instance.getRetryForExceptions()); - for (int i = 0; i <= retryCount; i++) { - try { - // 先执行一次 - if (i == 0) { - instance.execute(); - } else { - // 进入重试逻辑 - retry(instance, i); - } - break; - } catch (ChainEndException e) { - //如果是ChainEndException,则无需重试 - throw e; - } catch (Exception e) { - //判断抛出的异常是不是指定异常的子类 - boolean flag = forExceptions.stream().anyMatch(clazz -> clazz.isAssignableFrom(e.getClass())); - //两种情况不重试,1)抛出异常不在指定异常范围内 2)已经重试次数大于等于配置次数 - if (!flag || i >= retryCount) { - throw e; - } - } - } - } + protected final Logger LOG = LoggerFactory.getLogger(this.getClass()); + + /** + * 执行器执行入口-若需要更大维度的执行方式可以重写该方法 + */ + public void execute(NodeComponent instance) throws Exception { + int retryCount = instance.getRetryCount(); + List> forExceptions = Arrays.asList(instance.getRetryForExceptions()); + for (int i = 0; i <= retryCount; i++) { + try { + // 先执行一次 + if (i == 0) { + instance.execute(); + } + else { + // 进入重试逻辑 + retry(instance, i); + } + break; + } + catch (ChainEndException e) { + // 如果是ChainEndException,则无需重试 + throw e; + } + catch (Exception e) { + // 判断抛出的异常是不是指定异常的子类 + boolean flag = forExceptions.stream().anyMatch(clazz -> clazz.isAssignableFrom(e.getClass())); + // 两种情况不重试,1)抛出异常不在指定异常范围内 2)已经重试次数大于等于配置次数 + if (!flag || i >= retryCount) { + throw e; + } + } + } + } + + /** + * 执行重试逻辑 - 子类通过实现该方法进行重试逻辑的控制 + */ + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("[{}]:component[{}] performs {} retry", slot.getRequestId(), instance.getDisplayName(), + currentRetryCount + 1); + // 执行业务逻辑的主要入口 + instance.execute(); + } - /** - * 执行重试逻辑 - 子类通过实现该方法进行重试逻辑的控制 - */ - protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { - Slot slot = DataBus.getSlot(instance.getSlotIndex()); - LOG.info("[{}]:component[{}] performs {} retry", slot.getRequestId(),instance.getDisplayName(), currentRetryCount + 1); - //执行业务逻辑的主要入口 - instance.execute(); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutorHelper.java index 203db345..53e5b685 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/executor/NodeExecutorHelper.java @@ -13,44 +13,48 @@ import java.util.Map; * @since 2.6.9 */ public class NodeExecutorHelper { - /** - * 此处使用Map缓存线程池信息 - */ - private final Map, NodeExecutor> nodeExecutorMap; - private NodeExecutorHelper() { - nodeExecutorMap = MapUtil.newConcurrentHashMap(); - } + /** + * 此处使用Map缓存线程池信息 + */ + private final Map, NodeExecutor> nodeExecutorMap; - /** - * 使用静态内部类实现单例模式 - */ - private static class Holder { - static final NodeExecutorHelper INSTANCE = new NodeExecutorHelper(); - } + private NodeExecutorHelper() { + nodeExecutorMap = MapUtil.newConcurrentHashMap(); + } - /** - * 获取帮助者的实例 - * @return - */ - public static NodeExecutorHelper loadInstance() { - // 外围类能直接访问内部类(不管是否是静态的)的私有变量 - return Holder.INSTANCE; - } + /** + * 使用静态内部类实现单例模式 + */ + private static class Holder { + + static final NodeExecutorHelper INSTANCE = new NodeExecutorHelper(); + + } + + /** + * 获取帮助者的实例 + * @return + */ + public static NodeExecutorHelper loadInstance() { + // 外围类能直接访问内部类(不管是否是静态的)的私有变量 + return Holder.INSTANCE; + } + + public NodeExecutor buildNodeExecutor(Class nodeExecutorClass) { + if (nodeExecutorClass == null) { + // 此处使用默认的节点执行器进行执行 + nodeExecutorClass = DefaultNodeExecutor.class; + } + NodeExecutor nodeExecutor = nodeExecutorMap.get(nodeExecutorClass); + // 此处无需使用同步锁进行同步-因为即使同时创建了两个实例,但是添加到缓存中的只会存在一个且不会存在并发问题-具体是由ConcurrentMap保证 + if (ObjectUtil.isNull(nodeExecutor)) { + // 获取重试执行器实例 + nodeExecutor = ContextAwareHolder.loadContextAware().registerBean(nodeExecutorClass); + // 缓存 + nodeExecutorMap.put(nodeExecutorClass, nodeExecutor); + } + return nodeExecutorMap.get(nodeExecutorClass); + } - public NodeExecutor buildNodeExecutor(Class nodeExecutorClass) { - if (nodeExecutorClass == null) { - // 此处使用默认的节点执行器进行执行 - nodeExecutorClass = DefaultNodeExecutor.class; - } - NodeExecutor nodeExecutor = nodeExecutorMap.get(nodeExecutorClass); - // 此处无需使用同步锁进行同步-因为即使同时创建了两个实例,但是添加到缓存中的只会存在一个且不会存在并发问题-具体是由ConcurrentMap保证 - if (ObjectUtil.isNull(nodeExecutor)) { - // 获取重试执行器实例 - nodeExecutor = ContextAwareHolder.loadContextAware().registerBean(nodeExecutorClass); - // 缓存 - nodeExecutorMap.put(nodeExecutorClass, nodeExecutor); - } - return nodeExecutorMap.get(nodeExecutorClass); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/DefaultRequestIdGenerator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/DefaultRequestIdGenerator.java index 2791baad..8376279c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/DefaultRequestIdGenerator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/DefaultRequestIdGenerator.java @@ -9,8 +9,9 @@ import cn.hutool.core.util.IdUtil; */ public class DefaultRequestIdGenerator implements RequestIdGenerator { - @Override - public String generate() { - return IdUtil.fastSimpleUUID(); - } + @Override + public String generate() { + return IdUtil.fastSimpleUUID(); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/IdGeneratorHolder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/IdGeneratorHolder.java index 9899bbd5..a5ef6666 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/IdGeneratorHolder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/IdGeneratorHolder.java @@ -13,42 +13,46 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder; */ public class IdGeneratorHolder { - private RequestIdGenerator requestIdGenerator; + private RequestIdGenerator requestIdGenerator; - private static IdGeneratorHolder INSTANCE; + private static IdGeneratorHolder INSTANCE; - public static void init(){ - try{ - INSTANCE = new IdGeneratorHolder(); - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - String requestIdGeneratorClass = liteflowConfig.getRequestIdGeneratorClass(); + public static void init() { + try { + INSTANCE = new IdGeneratorHolder(); + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + String requestIdGeneratorClass = liteflowConfig.getRequestIdGeneratorClass(); - RequestIdGenerator requestIdGenerator; - if (StrUtil.isBlank(requestIdGeneratorClass)) { - requestIdGenerator = new DefaultRequestIdGenerator(); - } else { - Class idGenerateClass = (Class) Class.forName(requestIdGeneratorClass); - requestIdGenerator = ContextAwareHolder.loadContextAware().registerBean(idGenerateClass); - } - INSTANCE.setRequestIdGenerator(requestIdGenerator); - }catch (Exception e) { - throw new RequestIdGeneratorException(e.getMessage()); - } - } + RequestIdGenerator requestIdGenerator; + if (StrUtil.isBlank(requestIdGeneratorClass)) { + requestIdGenerator = new DefaultRequestIdGenerator(); + } + else { + Class idGenerateClass = (Class) Class + .forName(requestIdGeneratorClass); + requestIdGenerator = ContextAwareHolder.loadContextAware().registerBean(idGenerateClass); + } + INSTANCE.setRequestIdGenerator(requestIdGenerator); + } + catch (Exception e) { + throw new RequestIdGeneratorException(e.getMessage()); + } + } - public static IdGeneratorHolder getInstance() { - return INSTANCE; - } + public static IdGeneratorHolder getInstance() { + return INSTANCE; + } - public String generate() { - return requestIdGenerator.generate(); - } + public String generate() { + return requestIdGenerator.generate(); + } - public RequestIdGenerator getRequestIdGenerator() { - return requestIdGenerator; - } + public RequestIdGenerator getRequestIdGenerator() { + return requestIdGenerator; + } + + public void setRequestIdGenerator(RequestIdGenerator requestIdGenerator) { + this.requestIdGenerator = requestIdGenerator; + } - public void setRequestIdGenerator(RequestIdGenerator requestIdGenerator) { - this.requestIdGenerator = requestIdGenerator; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/RequestIdGenerator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/RequestIdGenerator.java index cf8fc862..49bf1d39 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/RequestIdGenerator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/id/RequestIdGenerator.java @@ -7,11 +7,10 @@ package com.yomahub.liteflow.flow.id; */ public interface RequestIdGenerator { - /** - * 获取唯一 id - * - * @return 返回唯一 id - */ - String generate(); + /** + * 获取唯一 id + * @return 返回唯一 id + */ + String generate(); } 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 541b3033..e73ec8c7 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 @@ -6,57 +6,67 @@ import java.util.function.Function; /** * java8中CompletableFuture异步处理超时的方法 * - * Java 8 的 CompletableFuture 并没有 timeout 机制,虽然可以在 get 的时候指定 timeout,是一个同步堵塞的操作。怎样让 timeout 也是异步的呢?Java 8 内有内建的机 - * 制支持,一般的实现方案是启动一个 ScheduledThreadpoolExecutor 线程在 timeout 时间后直接调用 CompletableFuture.completeExceptionally(new TimeoutException()), - * 然后用acceptEither() 或者 applyToEither 看是先计算完成还是先超时: + * Java 8 的 CompletableFuture 并没有 timeout 机制,虽然可以在 get 的时候指定 timeout,是一个同步堵塞的操作。怎样让 + * timeout 也是异步的呢?Java 8 内有内建的机 制支持,一般的实现方案是启动一个 ScheduledThreadpoolExecutor 线程在 timeout + * 时间后直接调用 CompletableFuture.completeExceptionally(new TimeoutException()), + * 然后用acceptEither() 或者 applyToEither 看是先计算完成还是先超时: * - * 在 java 9 引入了 orTimeout 和 completeOnTimeOut 两个方法支持 异步 timeout 机制: + * 在 java 9 引入了 orTimeout 和 completeOnTimeOut 两个方法支持 异步 timeout 机制: * - * public CompletableFuture orTimeout(long timeout, TimeUnit unit) : completes the CompletableFuture with a TimeoutException after the specified timeout has elapsed. - * public CompletableFuture completeOnTimeout(T value, long timeout, TimeUnit unit) : provides a default value in the case that the CompletableFuture pipeline times out. + * public CompletableFuture orTimeout(long timeout, TimeUnit unit) : completes the + * CompletableFuture with a TimeoutException after the specified timeout has elapsed. + * public CompletableFuture completeOnTimeout(T value, long timeout, TimeUnit unit) : + * provides a default value in the case that the CompletableFuture pipeline times out. * 内部实现上跟我们上面的实现方案是一模一样的,只是现在不需要自己实现了。 * * 实际上hystrix等熔断的框架,其实现线程Timeout之后就关闭线程,也是基于同样的道理,所以我们可以看到hystrix中会有一个Timer Thread * - * * @author luliang * @since 2.6.4 */ public class CompletableFutureTimeout { - static final class 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("CompletableFutureDelayScheduler"); - return t; - } - } + static final class Delayer { - static final ScheduledThreadPoolExecutor delayer; + static ScheduledFuture delay(Runnable command, long delay, TimeUnit unit) { + return delayer.schedule(command, delay, unit); + } - // 注意,这里使用一个线程就可以搞定 因为这个线程并不真的执行请求 而是仅仅抛出一个异常 - static { - delayer = new ScheduledThreadPoolExecutor(1, new CompletableFutureTimeout.Delayer.DaemonThreadFactory()); - delayer.setRemoveOnCancelPolicy(true); - } - } + static final class DaemonThreadFactory implements ThreadFactory { - public static CompletableFuture timeoutAfter(long timeout, TimeUnit unit) { - CompletableFuture result = new CompletableFuture(); - // timeout 时间后 抛出TimeoutException 类似于sentinel / watcher - CompletableFutureTimeout.Delayer.delayer.schedule(() -> result.completeExceptionally(new TimeoutException()), timeout, unit); - return result; - } + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + t.setName("CompletableFutureDelayScheduler"); + return t; + } + + } + + static final ScheduledThreadPoolExecutor delayer; + + // 注意,这里使用一个线程就可以搞定 因为这个线程并不真的执行请求 而是仅仅抛出一个异常 + static { + delayer = new ScheduledThreadPoolExecutor(1, new CompletableFutureTimeout.Delayer.DaemonThreadFactory()); + delayer.setRemoveOnCancelPolicy(true); + } + + } + + public static CompletableFuture timeoutAfter(long timeout, TimeUnit unit) { + CompletableFuture result = new CompletableFuture(); + // timeout 时间后 抛出TimeoutException 类似于sentinel / watcher + CompletableFutureTimeout.Delayer.delayer.schedule(() -> result.completeExceptionally(new TimeoutException()), + timeout, unit); + return result; + } + + // 哪个先完成 就apply哪一个结果 这是一个关键的API,exceptionally出现异常后返回默认值 + public static CompletableFuture completeOnTimeout(T t, CompletableFuture future, long timeout, + TimeUnit unit) { + final CompletableFuture timeoutFuture = timeoutAfter(timeout, unit); + return future.applyToEither(timeoutFuture, Function.identity()).exceptionally((throwable) -> t); + } - //哪个先完成 就apply哪一个结果 这是一个关键的API,exceptionally出现异常后返回默认值 - public static CompletableFuture completeOnTimeout(T t, CompletableFuture future, long timeout, TimeUnit unit) { - 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/ParallelSupplier.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/ParallelSupplier.java index d472bbe2..6493d383 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/ParallelSupplier.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/ParallelSupplier.java @@ -7,33 +7,36 @@ import java.util.function.Supplier; /** * 并行异步worker对象,提供给CompletableFuture用 + * * @author Bryan.Zhang * @since 2.6.4 */ public class ParallelSupplier implements Supplier { - private static final Logger LOG = LoggerFactory.getLogger(ParallelSupplier.class); + private static final Logger LOG = LoggerFactory.getLogger(ParallelSupplier.class); - private final Executable executableItem; + private final Executable executableItem; - private final String currChainName; - - private final Integer slotIndex; + private final String currChainName; - public ParallelSupplier(Executable executableItem, String currChainName, Integer slotIndex) { - this.executableItem = executableItem; - this.currChainName = currChainName; - this.slotIndex = slotIndex; - } + private final Integer slotIndex; + + public ParallelSupplier(Executable executableItem, String currChainName, Integer slotIndex) { + this.executableItem = executableItem; + this.currChainName = currChainName; + this.slotIndex = slotIndex; + } + + @Override + public WhenFutureObj get() { + try { + executableItem.setCurrChainId(currChainName); + executableItem.execute(slotIndex); + return WhenFutureObj.success(executableItem.getExecuteId()); + } + catch (Exception e) { + return WhenFutureObj.fail(executableItem.getExecuteId(), e); + } + } - @Override - public WhenFutureObj get() { - try { - executableItem.setCurrChainId(currChainName); - executableItem.execute(slotIndex); - return WhenFutureObj.success(executableItem.getExecuteId()); - } catch (Exception e){ - return WhenFutureObj.fail(executableItem.getExecuteId(), e); - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/WhenFutureObj.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/WhenFutureObj.java index 5114c626..ec5abd2f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/WhenFutureObj.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/WhenFutureObj.java @@ -6,78 +6,78 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter; /** * 并行异步CompletableFuture里的值对象 + * * @author Bryan.Zhang * @since 2.6.4 */ public class WhenFutureObj { - private boolean success; + private boolean success; - private boolean timeout; + private boolean timeout; - private String executorName; + private String executorName; - private Exception ex; + private Exception ex; - public static WhenFutureObj success(String executorName){ - WhenFutureObj result = new WhenFutureObj(); - result.setSuccess(true); - result.setTimeout(false); - result.setExecutorName(executorName); - return result; - } + public static WhenFutureObj success(String executorName) { + WhenFutureObj result = new WhenFutureObj(); + result.setSuccess(true); + result.setTimeout(false); + result.setExecutorName(executorName); + return result; + } - public static WhenFutureObj fail(String executorName, Exception ex){ - WhenFutureObj result = new WhenFutureObj(); - result.setSuccess(false); - result.setTimeout(false); - result.setExecutorName(executorName); - result.setEx(ex); - return result; - } + public static WhenFutureObj fail(String executorName, Exception ex) { + WhenFutureObj result = new WhenFutureObj(); + result.setSuccess(false); + result.setTimeout(false); + result.setExecutorName(executorName); + result.setEx(ex); + return result; + } - public static WhenFutureObj timeOut(String executorName){ - WhenFutureObj result = new WhenFutureObj(); - result.setSuccess(false); - result.setTimeout(true); - result.setExecutorName(executorName); - result.setEx(new WhenTimeoutException( - StrUtil.format("Timed out when executing the component[{}],when-max-timeout-seconds config is:{}(s)", - executorName, - LiteflowConfigGetter.get().getWhenMaxWaitSeconds())) - ); - return result; - } + public static WhenFutureObj timeOut(String executorName) { + WhenFutureObj result = new WhenFutureObj(); + result.setSuccess(false); + result.setTimeout(true); + result.setExecutorName(executorName); + result.setEx(new WhenTimeoutException( + StrUtil.format("Timed out when executing the component[{}],when-max-timeout-seconds config is:{}(s)", + executorName, LiteflowConfigGetter.get().getWhenMaxWaitSeconds()))); + return result; + } - public boolean isSuccess() { - return success; - } + public boolean isSuccess() { + return success; + } - public void setSuccess(boolean success) { - this.success = success; - } + public void setSuccess(boolean success) { + this.success = success; + } - public String getExecutorName() { - return executorName; - } + public String getExecutorName() { + return executorName; + } - public void setExecutorName(String executorName) { - this.executorName = executorName; - } + public void setExecutorName(String executorName) { + this.executorName = executorName; + } - public Exception getEx() { - return ex; - } + public Exception getEx() { + return ex; + } - public void setEx(Exception ex) { - this.ex = ex; - } + public void setEx(Exception ex) { + this.ex = ex; + } - public boolean isTimeout() { - return timeout; - } + public boolean isTimeout() { + return timeout; + } + + public void setTimeout(boolean timeout) { + this.timeout = timeout; + } - public void setTimeout(boolean timeout) { - this.timeout = timeout; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/CompStatistics.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/CompStatistics.java index 2077eb1d..1fdea2e5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/CompStatistics.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/CompStatistics.java @@ -9,9 +9,10 @@ package com.yomahub.liteflow.monitor; /** * 统计类 + * * @author Bryan.Zhang */ -public class CompStatistics implements Comparable{ +public class CompStatistics implements Comparable { private String componentClazzName; @@ -20,12 +21,13 @@ public class CompStatistics implements Comparable{ private long memorySpent; private long recordTime; - + public CompStatistics(String componentClazzName, long timeSpent) { this.componentClazzName = componentClazzName; this.timeSpent = timeSpent; this.recordTime = System.currentTimeMillis(); } + public String getComponentClazzName() { return componentClazzName; } @@ -49,16 +51,17 @@ public class CompStatistics implements Comparable{ public void setMemorySpent(long memorySpent) { this.memorySpent = memorySpent; } - + public long getRecordTime() { return recordTime; } - + @Override public int compareTo(CompStatistics o) { - if(o != null) { - return this.recordTime >= o.getRecordTime() ? -1 : 1; + if (o != null) { + return this.recordTime >= o.getRecordTime() ? -1 : 1; } return 1; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorBus.java index 355d4eae..3d773ada 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorBus.java @@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit; /** * 监控类元数据,打印执行器类 + * * @author Bryan.Zhang */ public class MonitorBus { @@ -41,34 +42,39 @@ public class MonitorBus { public MonitorBus(LiteflowConfig liteflowConfig) { this.liteflowConfig = liteflowConfig; - if(BooleanUtil.isTrue(liteflowConfig.getEnableLog())){ - this.printLogScheduler.scheduleAtFixedRate(new MonitorTimeTask(this), liteflowConfig.getDelay(), liteflowConfig.getPeriod(), TimeUnit.MILLISECONDS); + if (BooleanUtil.isTrue(liteflowConfig.getEnableLog())) { + this.printLogScheduler.scheduleAtFixedRate(new MonitorTimeTask(this), liteflowConfig.getDelay(), + liteflowConfig.getPeriod(), TimeUnit.MILLISECONDS); } } - public void addStatistics(CompStatistics statistics){ - if(statisticsMap.containsKey(statistics.getComponentClazzName())){ + public void addStatistics(CompStatistics statistics) { + if (statisticsMap.containsKey(statistics.getComponentClazzName())) { statisticsMap.get(statistics.getComponentClazzName()).add(statistics); - }else{ - BoundedPriorityBlockingQueue queue = new BoundedPriorityBlockingQueue<>(liteflowConfig.getQueueLimit()); + } + else { + BoundedPriorityBlockingQueue queue = new BoundedPriorityBlockingQueue<>( + liteflowConfig.getQueueLimit()); queue.offer(statistics); statisticsMap.put(statistics.getComponentClazzName(), queue); } } - public void printStatistics(){ - try{ + public void printStatistics() { + try { Map compAverageTimeSpent = new HashMap(); - - for(Entry> entry : statisticsMap.entrySet()){ + + for (Entry> entry : statisticsMap.entrySet()) { long totalTimeSpent = 0; - for(CompStatistics statistics : entry.getValue()){ + for (CompStatistics statistics : entry.getValue()) { totalTimeSpent += statistics.getTimeSpent(); } - compAverageTimeSpent.put(entry.getKey(), new BigDecimal(totalTimeSpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP)); + compAverageTimeSpent.put(entry.getKey(), new BigDecimal(totalTimeSpent) + .divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP)); } - List> compAverageTimeSpentEntryList = new ArrayList<>(compAverageTimeSpent.entrySet()); + List> compAverageTimeSpentEntryList = new ArrayList<>( + compAverageTimeSpent.entrySet()); Collections.sort(compAverageTimeSpentEntryList, (o1, o2) -> o2.getValue().compareTo(o1.getValue())); @@ -79,13 +85,15 @@ public class MonitorBus { logStr.append(MessageFormat.format("SLOT TOTAL SIZE : {0}\n", liteflowConfig.getSlotSize())); logStr.append(MessageFormat.format("SLOT OCCUPY COUNT : {0}\n", DataBus.OCCUPY_COUNT)); logStr.append("===============================TIME AVERAGE SPENT=====================================\n"); - for(Entry entry : compAverageTimeSpentEntryList){ - logStr.append(MessageFormat.format("COMPONENT[{0}] AVERAGE TIME SPENT : {1}\n", entry.getKey(), entry.getValue())); + for (Entry entry : compAverageTimeSpentEntryList) { + logStr.append(MessageFormat.format("COMPONENT[{0}] AVERAGE TIME SPENT : {1}\n", entry.getKey(), + entry.getValue())); } logStr.append("======================================================================================\n"); LOG.info(logStr.toString()); - }catch(Exception e){ - LOG.error("print statistics cause error",e); + } + catch (Exception e) { + LOG.error("print statistics cause error", e); } } @@ -97,11 +105,12 @@ public class MonitorBus { this.liteflowConfig = liteflowConfig; } - public void closeScheduler(){ + public void closeScheduler() { this.printLogScheduler.shutdown(); } public ConcurrentHashMap> getStatisticsMap() { return statisticsMap; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java index cff488e6..3fc10cb0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorFile.java @@ -34,61 +34,62 @@ import java.util.function.Consumer; */ public class MonitorFile { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final Set PATH_SET = new HashSet<>(); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); - public static MonitorFile getInstance() { - return Singleton.get(MonitorFile.class); - } + private final Set PATH_SET = new HashSet<>(); - /** - * 添加监听文件路径 - * - * @param path 文件路径 - */ - public void addMonitorFilePath(String path) { - if (FileUtil.isFile(path)){ - String parentFolder = FileUtil.getParent(path, 1); - PATH_SET.add(parentFolder); - }else{ - PATH_SET.add(path); - } - } + public static MonitorFile getInstance() { + return Singleton.get(MonitorFile.class); + } - /** - * 添加监听文件路径 - * - * @param filePaths 文件路径 - */ - public void addMonitorFilePaths(List filePaths) { - filePaths.forEach(this::addMonitorFilePath); - } + /** + * 添加监听文件路径 + * @param path 文件路径 + */ + public void addMonitorFilePath(String path) { + if (FileUtil.isFile(path)) { + String parentFolder = FileUtil.getParent(path, 1); + PATH_SET.add(parentFolder); + } + else { + PATH_SET.add(path); + } + } - /** - * 创建文件监听 - */ - public void create() throws Exception{ - for (String path : PATH_SET) { - long interval = TimeUnit.MILLISECONDS.toMillis(2); - //不使用过滤器 - FileAlterationObserver observer = new FileAlterationObserver(new File(path)); - observer.addListener(new FileAlterationListenerAdaptor() { - @Override - public void onFileChange(File file) { - logger.info("file modify,filePath={}", file.getAbsolutePath()); - FlowExecutorHolder.loadInstance().reloadRule(); - } + /** + * 添加监听文件路径 + * @param filePaths 文件路径 + */ + public void addMonitorFilePaths(List filePaths) { + filePaths.forEach(this::addMonitorFilePath); + } + + /** + * 创建文件监听 + */ + public void create() throws Exception { + for (String path : PATH_SET) { + long interval = TimeUnit.MILLISECONDS.toMillis(2); + // 不使用过滤器 + FileAlterationObserver observer = new FileAlterationObserver(new File(path)); + observer.addListener(new FileAlterationListenerAdaptor() { + @Override + public void onFileChange(File file) { + logger.info("file modify,filePath={}", file.getAbsolutePath()); + FlowExecutorHolder.loadInstance().reloadRule(); + } + + @Override + public void onFileDelete(File file) { + logger.info("file delete,filePath={}", file.getAbsolutePath()); + FlowExecutorHolder.loadInstance().reloadRule(); + } + }); + // 创建文件变化监听器 + FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer); + // 开始监控 + monitor.start(); + } + } - @Override - public void onFileDelete(File file) { - logger.info("file delete,filePath={}", file.getAbsolutePath()); - FlowExecutorHolder.loadInstance().reloadRule(); - } - }); - //创建文件变化监听器 - FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer); - // 开始监控 - monitor.start(); - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorTimeTask.java b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorTimeTask.java index 21ada681..a6ce816c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorTimeTask.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/monitor/MonitorTimeTask.java @@ -4,18 +4,20 @@ import java.util.TimerTask; /** * 监控器线程 + * * @author Bryan.Zhang */ public class MonitorTimeTask extends TimerTask { - private MonitorBus monitorBus; + private MonitorBus monitorBus; - public MonitorTimeTask(MonitorBus monitorBus) { - this.monitorBus = monitorBus; - } + public MonitorTimeTask(MonitorBus monitorBus) { + this.monitorBus = monitorBus; + } + + @Override + public void run() { + monitorBus.printStatistics(); + } - @Override - public void run() { - monitorBus.printStatistics(); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseJsonFlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseJsonFlowParser.java index a5e02dae..a41e0505 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseJsonFlowParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseJsonFlowParser.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; - /** * 基类,用于存放 JsonFlowParser 通用方法 * @@ -41,7 +40,6 @@ public abstract class BaseJsonFlowParser implements FlowParser { /** * 解析一个chain的过程 - * * @param chainObject chain 节点 */ public abstract void parseOneChain(JsonNode chainObject); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseXmlFlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseXmlFlowParser.java index 13ad9642..404f540b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseXmlFlowParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseXmlFlowParser.java @@ -12,13 +12,13 @@ import java.util.List; import java.util.Set; import java.util.function.Consumer; - /** * 基类,用于存放 XmlFlowParser 通用方法 * * @author tangkc */ public abstract class BaseXmlFlowParser implements FlowParser { + private final Set CHAIN_NAME_SET = new HashSet<>(); public void parse(String content) throws Exception { @@ -42,7 +42,6 @@ public abstract class BaseXmlFlowParser implements FlowParser { /** * 解析一个 chain 的过程 - * * @param chain chain */ public abstract void parseOneChain(Element chain); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseYmlFlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseYmlFlowParser.java index d5606c35..d55526e2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseYmlFlowParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/BaseYmlFlowParser.java @@ -22,7 +22,7 @@ public abstract class BaseYmlFlowParser implements FlowParser { private final Set CHAIN_NAME_SET = new HashSet<>(); - public void parse(String content) throws Exception{ + public void parse(String content) throws Exception { parse(ListUtil.toList(content)); } @@ -33,7 +33,7 @@ public abstract class BaseYmlFlowParser implements FlowParser { } List jsonObjectList = ListUtil.toList(); - for (String content : contentList){ + for (String content : contentList) { JsonNode ruleObject = convertToJson(content); jsonObjectList.add(ruleObject); } @@ -44,15 +44,15 @@ public abstract class BaseYmlFlowParser implements FlowParser { } protected JsonNode convertToJson(String yamlString) { - Yaml yaml= new Yaml(); + Yaml yaml = new Yaml(); Map map = yaml.load(yamlString); return JsonUtil.parseObject(JsonUtil.toJsonString(map)); } /** * 解析一个 chain 的过程 - * * @param chain chain */ public abstract void parseOneChain(JsonNode chain); + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/FlowParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/FlowParser.java index ca8fd2c5..636e0aed 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/FlowParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/base/FlowParser.java @@ -6,13 +6,14 @@ import java.util.*; /** * 虽则Parser的抽象类,所有的parser需要继承这个抽象类 + * * @author guodongqing * @since 2.5.0 */ public interface FlowParser { - void parseMain(List pathList) throws Exception; + void parseMain(List pathList) throws Exception; - void parse(List contentList) throws Exception; + void parse(List contentList) throws Exception; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassJsonFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassJsonFlowELParser.java index e84a6677..c48b57d8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassJsonFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassJsonFlowELParser.java @@ -4,10 +4,12 @@ import java.util.List; /** * 基于自定义的json方式EL表达式解析器 + * * @author Bryan.Zhang * @since 2.8.0 */ public abstract class ClassJsonFlowELParser extends JsonFlowELParser { + @Override public void parseMain(List pathList) throws Exception { String content = parseCustom(); @@ -15,4 +17,5 @@ public abstract class ClassJsonFlowELParser extends JsonFlowELParser { } public abstract String parseCustom(); + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassXmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassXmlFlowELParser.java index 4898a920..c1d42ee5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassXmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassXmlFlowELParser.java @@ -4,15 +4,18 @@ import java.util.List; /** * 基于自定义的xml方式EL表达式解析器 + * * @author Bryan.Zhang * @since 2.8.0 */ -public abstract class ClassXmlFlowELParser extends XmlFlowELParser{ - @Override - public void parseMain(List pathList) throws Exception { - String content = parseCustom(); - parse(content); - } +public abstract class ClassXmlFlowELParser extends XmlFlowELParser { + + @Override + public void parseMain(List pathList) throws Exception { + String content = parseCustom(); + parse(content); + } + + public abstract String parseCustom(); - public abstract String parseCustom(); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassYmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassYmlFlowELParser.java index ab9cd1d4..dc1c5fd4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassYmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/ClassYmlFlowELParser.java @@ -4,15 +4,18 @@ import java.util.List; /** * 基于自定义的yml方式EL表达式解析器 + * * @author Bryan.Zhang * @since 2.8.0 */ public abstract class ClassYmlFlowELParser extends YmlFlowELParser { - @Override - public void parseMain(List pathList) throws Exception { - String content = parseCustom(); - parse(content); - } - public abstract String parseCustom(); + @Override + public void parseMain(List pathList) throws Exception { + String content = parseCustom(); + parse(content); + } + + public abstract String parseCustom(); + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/JsonFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/JsonFlowELParser.java index d3da3e10..8ce292be 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/JsonFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/JsonFlowELParser.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.yomahub.liteflow.parser.base.BaseJsonFlowParser; import com.yomahub.liteflow.parser.helper.ParserHelper; - /** * JSON形式的EL表达式解析抽象引擎 * @@ -15,7 +14,6 @@ public abstract class JsonFlowELParser extends BaseJsonFlowParser { /** * 解析一个chain的过程 - * * @param chainObject chain 节点 */ @Override diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java index 6c6aa1a9..31c05b59 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalJsonFlowELParser.java @@ -12,9 +12,10 @@ import java.util.List; */ public class LocalJsonFlowELParser extends JsonFlowELParser { - @Override - public void parseMain(List pathList) throws Exception { - List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); - parse(contentList); - } + @Override + public void parseMain(List pathList) throws Exception { + List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); + parse(contentList); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java index d0769f16..aac22289 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalXmlFlowELParser.java @@ -6,13 +6,16 @@ import java.util.List; /** * 基于本地的xml方式EL表达式解析器 + * * @author Bryan.Zhang * @since 2.8.0 */ -public class LocalXmlFlowELParser extends XmlFlowELParser{ - @Override - public void parseMain(List pathList) throws Exception { - List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); - parse(contentList); - } +public class LocalXmlFlowELParser extends XmlFlowELParser { + + @Override + public void parseMain(List pathList) throws Exception { + List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); + parse(contentList); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java index 8c85abef..a36d4176 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/el/LocalYmlFlowELParser.java @@ -6,15 +6,16 @@ import java.util.List; /** * 基于本地的yml方式EL表达式解析器 + * * @author Bryan.Zhang * @since 2.8.0 */ public class LocalYmlFlowELParser extends YmlFlowELParser { - @Override - public void parseMain(List pathList) throws Exception { - List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); - parse(contentList); - } + @Override + public void parseMain(List pathList) throws Exception { + List contentList = PathContentParserHolder.loadContextAware().parseContent(pathList); + parse(contentList); + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/ClassParserFactory.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/ClassParserFactory.java index adcb7b3f..9dc4b1c0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/ClassParserFactory.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/ClassParserFactory.java @@ -16,29 +16,31 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder; */ public class ClassParserFactory implements FlowParserFactory { - @Override - public BaseJsonFlowParser createJsonELParser(String path) { - Class c = forName(path); - return (JsonFlowELParser) ContextAwareHolder.loadContextAware().registerBean(c); - } + @Override + public BaseJsonFlowParser createJsonELParser(String path) { + Class c = forName(path); + return (JsonFlowELParser) ContextAwareHolder.loadContextAware().registerBean(c); + } - @Override - public BaseXmlFlowParser createXmlELParser(String path) { - Class c = forName(path); - return (XmlFlowELParser) ContextAwareHolder.loadContextAware().registerBean(c); - } + @Override + public BaseXmlFlowParser createXmlELParser(String path) { + Class c = forName(path); + return (XmlFlowELParser) ContextAwareHolder.loadContextAware().registerBean(c); + } - @Override - public BaseYmlFlowParser createYmlELParser(String path) { - Class c = forName(path); - return (YmlFlowELParser) ContextAwareHolder.loadContextAware().registerBean(c); - } + @Override + public BaseYmlFlowParser createYmlELParser(String path) { + Class c = forName(path); + return (YmlFlowELParser) ContextAwareHolder.loadContextAware().registerBean(c); + } + + private Class forName(String path) { + try { + return Class.forName(path); + } + catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } - private Class forName(String path) { - try { - return Class.forName(path); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserFactory.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserFactory.java index 813d2a7a..c3f23231 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserFactory.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserFactory.java @@ -12,10 +12,10 @@ import com.yomahub.liteflow.parser.base.BaseYmlFlowParser; */ public interface FlowParserFactory { - BaseJsonFlowParser createJsonELParser(String path); + BaseJsonFlowParser createJsonELParser(String path); - BaseXmlFlowParser createXmlELParser(String path); + BaseXmlFlowParser createXmlELParser(String path); - BaseYmlFlowParser createYmlELParser(String path); + BaseYmlFlowParser createYmlELParser(String path); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserProvider.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserProvider.java index d028aaa4..2d7c58e0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserProvider.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/FlowParserProvider.java @@ -36,39 +36,41 @@ public class FlowParserProvider { private static final Logger LOG = LoggerFactory.getLogger(FlowExecutor.class); private static final FlowParserFactory LOCAL_PARSER_FACTORY = new LocalParserFactory(); + /** - * 使用 map 枚举不同类型的 Parser,用于解耦如下的 if 判断 - *
+	 * 使用 map 枚举不同类型的 Parser,用于解耦如下的 if 判断 
 	 * if (ReUtil.isMatch(LOCAL_XML_CONFIG_REGEX, path)) {
 	 * 	return factory.createXmlParser(path);
 	 * }
 	 * 
*/ - private static final Map, Function> LOCAL_PARSER_DICT = - new HashMap, Function>() {{ - put(path -> ReUtil.isMatch(LOCAL_XML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createXmlELParser); - put(path -> ReUtil.isMatch(LOCAL_JSON_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createJsonELParser); - put(path -> ReUtil.isMatch(LOCAL_YML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createYmlELParser); - put(path -> ReUtil.isMatch(LOCAL_EL_XML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createXmlELParser); - put(path -> ReUtil.isMatch(LOCAL_EL_JSON_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createJsonELParser); - put(path -> ReUtil.isMatch(LOCAL_EL_YML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createYmlELParser); - }}; + private static final Map, Function> LOCAL_PARSER_DICT = new HashMap, Function>() { + { + put(path -> ReUtil.isMatch(LOCAL_XML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createXmlELParser); + put(path -> ReUtil.isMatch(LOCAL_JSON_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createJsonELParser); + put(path -> ReUtil.isMatch(LOCAL_YML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createYmlELParser); + put(path -> ReUtil.isMatch(LOCAL_EL_XML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createXmlELParser); + put(path -> ReUtil.isMatch(LOCAL_EL_JSON_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createJsonELParser); + put(path -> ReUtil.isMatch(LOCAL_EL_YML_CONFIG_REGEX, path), LOCAL_PARSER_FACTORY::createYmlELParser); + } + }; private static final FlowParserFactory CLASS_PARSER_FACTORY = new ClassParserFactory(); + /** - * 使用 map 枚举不同类型的 Parser,用于解耦如下的 if 判断 - *
+	 * 使用 map 枚举不同类型的 Parser,用于解耦如下的 if 判断 
 	 * if (ClassXmlFlowParser.class.isAssignableFrom(clazz)) {
 	 *   return factory.createXmlParser(className);
 	 * }
 	 * 
*/ - private static final Map>, Function> CLASS_PARSER_DICT = - new HashMap>, Function>() {{ - put(ClassXmlFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createXmlELParser); - put(ClassJsonFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createJsonELParser); - put(ClassYmlFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createYmlELParser); - }}; + private static final Map>, Function> CLASS_PARSER_DICT = new HashMap>, Function>() { + { + put(ClassXmlFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createXmlELParser); + put(ClassJsonFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createJsonELParser); + put(ClassYmlFlowELParser.class::isAssignableFrom, CLASS_PARSER_FACTORY::createYmlELParser); + } + }; /** * 根据配置的地址找到对应的解析器 @@ -81,10 +83,10 @@ public class FlowParserProvider { if (isLocalConfig(path)) { // 遍历枚举 map 找到对应 factory Predicate dictKey = LOCAL_PARSER_DICT.keySet() - .stream() - .filter(key -> key.test(path)) - .findFirst() - .orElseThrow(() -> new ErrorSupportPathException(errorMsg)); + .stream() + .filter(key -> key.test(path)) + .findFirst() + .orElseThrow(() -> new ErrorSupportPathException(errorMsg)); LOG.info("flow info loaded from local file,path={}", path); return LOCAL_PARSER_DICT.get(dictKey).apply(path); @@ -97,10 +99,10 @@ public class FlowParserProvider { // 遍历枚举 map 找到对应 factory Predicate> dictKey = CLASS_PARSER_DICT.keySet() - .stream() - .filter(key -> key.test(clazz)) - .findFirst() - .orElseThrow(() -> new ErrorSupportPathException(errorMsg)); + .stream() + .filter(key -> key.test(clazz)) + .findFirst() + .orElseThrow(() -> new ErrorSupportPathException(errorMsg)); LOG.info("flow info loaded from class config with el,class={}", className); return CLASS_PARSER_DICT.get(dictKey).apply(className); @@ -114,12 +116,9 @@ public class FlowParserProvider { * 判定是否为本地文件 */ private static boolean isLocalConfig(String path) { - return ReUtil.isMatch(LOCAL_XML_CONFIG_REGEX, path) - || ReUtil.isMatch(LOCAL_JSON_CONFIG_REGEX, path) - || ReUtil.isMatch(LOCAL_YML_CONFIG_REGEX, path) - || ReUtil.isMatch(LOCAL_EL_XML_CONFIG_REGEX, path) - || ReUtil.isMatch(LOCAL_EL_JSON_CONFIG_REGEX, path) - || ReUtil.isMatch(LOCAL_EL_YML_CONFIG_REGEX, path); + return ReUtil.isMatch(LOCAL_XML_CONFIG_REGEX, path) || ReUtil.isMatch(LOCAL_JSON_CONFIG_REGEX, path) + || ReUtil.isMatch(LOCAL_YML_CONFIG_REGEX, path) || ReUtil.isMatch(LOCAL_EL_XML_CONFIG_REGEX, path) + || ReUtil.isMatch(LOCAL_EL_JSON_CONFIG_REGEX, path) || ReUtil.isMatch(LOCAL_EL_YML_CONFIG_REGEX, path); } /** @@ -133,13 +132,23 @@ public class FlowParserProvider { * 统一管理类的常量 */ protected static class ConfigRegexConstant { + public static final String LOCAL_XML_CONFIG_REGEX = "^[\\w\\:\\-\\.\\@\\/\\\\\\*]+\\.xml$"; + public static final String LOCAL_JSON_CONFIG_REGEX = "^[\\w\\:\\-\\.\\@\\/\\\\\\*]+\\.json$"; + public static final String LOCAL_YML_CONFIG_REGEX = "^[\\w\\:\\-\\.\\@\\/\\\\\\*]+\\.yml$"; + public static final String LOCAL_EL_XML_CONFIG_REGEX = "^[\\w\\:\\-\\.\\@\\/\\\\\\*]+\\.el\\.xml$"; + public static final String LOCAL_EL_JSON_CONFIG_REGEX = "^[\\w\\:\\-\\.\\@\\/\\\\\\*]+\\.el\\.json$"; + public static final String LOCAL_EL_YML_CONFIG_REGEX = "^[\\w\\:\\-\\.\\@\\/\\\\\\*]+\\.el\\.yml$"; + public static final String PREFIX_FORMAT_CONFIG_REGEX = "xml:|json:|yml:|el_xml:|el_json:|el_yml:"; + public static final String CLASS_CONFIG_REGEX = "^(xml:|json:|yml:|el_xml:|el_json:|el_yml:)?\\w+(\\.\\w+)*$"; + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/LocalParserFactory.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/LocalParserFactory.java index 0a46afdf..53ef7cfb 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/LocalParserFactory.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/factory/LocalParserFactory.java @@ -11,18 +11,19 @@ import com.yomahub.liteflow.parser.el.*; */ public class LocalParserFactory implements FlowParserFactory { - @Override - public JsonFlowELParser createJsonELParser(String path) { - return new LocalJsonFlowELParser(); - } + @Override + public JsonFlowELParser createJsonELParser(String path) { + return new LocalJsonFlowELParser(); + } - @Override - public XmlFlowELParser createXmlELParser(String path) { - return new LocalXmlFlowELParser(); - } + @Override + public XmlFlowELParser createXmlELParser(String path) { + return new LocalXmlFlowELParser(); + } + + @Override + public YmlFlowELParser createYmlELParser(String path) { + return new LocalYmlFlowELParser(); + } - @Override - public YmlFlowELParser createYmlELParser(String path) { - return new LocalYmlFlowELParser(); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java index 627b9a22..45a4838f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java @@ -34,7 +34,6 @@ public class ParserHelper { /** * 构建 node - * * @param nodePropBean 构建 node 的中间属性 */ public static void buildNode(NodePropBean nodePropBean) { @@ -46,52 +45,53 @@ public class ParserHelper { String file = nodePropBean.getFile(); String language = nodePropBean.getLanguage(); - //clazz有值的,基本都不是脚本节点 - //脚本节点,都必须配置type - //非脚本节点的先尝试自动推断类型 + // clazz有值的,基本都不是脚本节点 + // 脚本节点,都必须配置type + // 非脚本节点的先尝试自动推断类型 if (StrUtil.isNotBlank(clazz)) { try { - //先尝试从继承的类型中推断 + // 先尝试从继承的类型中推断 Class c = Class.forName(clazz); NodeTypeEnum nodeType = NodeTypeEnum.guessType(c); - if (nodeType != null){ + if (nodeType != null) { type = nodeType.getCode(); } - } catch (Exception e) { + } + catch (Exception e) { throw new NodeClassNotFoundException(StrUtil.format("cannot find the node[{}]", clazz)); } } - //因为脚本节点是必须设置type的,所以到这里type就全都有了,所以进行二次检查 + // 因为脚本节点是必须设置type的,所以到这里type就全都有了,所以进行二次检查 if (StrUtil.isBlank(type)) { throw new NodeTypeCanNotGuessException(StrUtil.format("cannot guess the type of node[{}]", clazz)); } - //检查nodeType是不是规定的类型 + // 检查nodeType是不是规定的类型 NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type); if (ObjectUtil.isNull(nodeTypeEnum)) { throw new NodeTypeNotSupportException(StrUtil.format("type [{}] is not support", type)); } - //进行node的build过程 + // 进行node的build过程 LiteFlowNodeBuilder.createNode() - .setId(id) - .setName(name) - .setClazz(clazz) - .setType(nodeTypeEnum) - .setScript(script) - .setFile(file) - .setLanguage(language) - .build(); + .setId(id) + .setName(name) + .setClazz(clazz) + .setType(nodeTypeEnum) + .setScript(script) + .setFile(file) + .setLanguage(language) + .build(); } /** * xml 形式的主要解析过程 - * @param documentList documentList + * @param documentList documentList */ /** * xml 形式的主要解析过程 - * @param documentList documentList + * @param documentList documentList */ public static void parseNodeDocument(List documentList) { for (Document document : documentList) { @@ -111,34 +111,34 @@ public class ParserHelper { language = e.attributeValue(LANGUAGE); // 构建 node - NodePropBean nodePropBean = new NodePropBean() - .setId(id) - .setName(name) - .setClazz(clazz) - .setScript(script) - .setType(type) - .setFile(file) - .setLanguage(language); + NodePropBean nodePropBean = new NodePropBean().setId(id) + .setName(name) + .setClazz(clazz) + .setScript(script) + .setType(type) + .setFile(file) + .setLanguage(language); ParserHelper.buildNode(nodePropBean); } } } } - - public static void parseChainDocument(List documentList, Set chainNameSet, Consumer parseOneChainConsumer){ - //先在元数据里放上chain - //先放有一个好处,可以在parse的时候先映射到FlowBus的chainMap,然后再去解析 - //这样就不用去像之前的版本那样回归调用 - //同时也解决了不能循环依赖的问题 + + public static void parseChainDocument(List documentList, Set chainNameSet, + Consumer parseOneChainConsumer) { + // 先在元数据里放上chain + // 先放有一个好处,可以在parse的时候先映射到FlowBus的chainMap,然后再去解析 + // 这样就不用去像之前的版本那样回归调用 + // 同时也解决了不能循环依赖的问题 documentList.forEach(document -> { // 解析chain节点 List chainList = document.getRootElement().elements(CHAIN); - //先在元数据里放上chain + // 先在元数据里放上chain chainList.forEach(e -> { - //校验加载的 chainName 是否有重复的 - //TODO 这里是否有个问题,当混合格式加载的时候,2个同名的Chain在不同的文件里,就不行了 + // 校验加载的 chainName 是否有重复的 + // TODO 这里是否有个问题,当混合格式加载的时候,2个同名的Chain在不同的文件里,就不行了 String chainName = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME)); if (!chainNameSet.add(chainName)) { throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName)); @@ -150,7 +150,7 @@ public class ParserHelper { // 清空 chainNameSet.clear(); - //解析每一个chain + // 解析每一个chain for (Document document : documentList) { Element rootElement = document.getRootElement(); List chainList = rootElement.elements(CHAIN); @@ -158,7 +158,7 @@ public class ParserHelper { } } - public static void parseNodeJson(List flowJsonObjectList) { + public static void parseNodeJson(List flowJsonObjectList) { for (JsonNode flowJsonNode : flowJsonObjectList) { // 当存在节点定义时,解析node节点 if (flowJsonNode.get(FLOW).has(NODES)) { @@ -168,40 +168,43 @@ public class ParserHelper { JsonNode nodeObject = nodeIterator.next(); id = nodeObject.get(ID).textValue(); name = nodeObject.hasNonNull(NAME) ? nodeObject.get(NAME).textValue() : ""; - clazz = nodeObject.hasNonNull(_CLASS) ? nodeObject.get(_CLASS).textValue() : "";; + clazz = nodeObject.hasNonNull(_CLASS) ? nodeObject.get(_CLASS).textValue() : ""; + ; type = nodeObject.hasNonNull(TYPE) ? nodeObject.get(TYPE).textValue() : null; script = nodeObject.hasNonNull(VALUE) ? nodeObject.get(VALUE).textValue() : ""; file = nodeObject.hasNonNull(FILE) ? nodeObject.get(FILE).textValue() : ""; // 构建 node - NodePropBean nodePropBean = new NodePropBean() - .setId(id) - .setName(name) - .setClazz(clazz) - .setScript(script) - .setType(type) - .setFile(file); + NodePropBean nodePropBean = new NodePropBean().setId(id) + .setName(name) + .setClazz(clazz) + .setScript(script) + .setType(type) + .setFile(file); ParserHelper.buildNode(nodePropBean); } } } - } - - public static void parseChainJson(List flowJsonObjectList, Set chainNameSet, Consumer parseOneChainConsumer){ - //先在元数据里放上chain - //先放有一个好处,可以在parse的时候先映射到FlowBus的chainMap,然后再去解析 - //这样就不用去像之前的版本那样回归调用 - //同时也解决了不能循环依赖的问题 + } + + public static void parseChainJson(List flowJsonObjectList, Set chainNameSet, + Consumer parseOneChainConsumer) { + // 先在元数据里放上chain + // 先放有一个好处,可以在parse的时候先映射到FlowBus的chainMap,然后再去解析 + // 这样就不用去像之前的版本那样回归调用 + // 同时也解决了不能循环依赖的问题 flowJsonObjectList.forEach(jsonObject -> { // 解析chain节点 Iterator iterator = jsonObject.get(FLOW).get(CHAIN).elements(); - //先在元数据里放上chain + // 先在元数据里放上chain while (iterator.hasNext()) { JsonNode innerJsonObject = iterator.next(); - //校验加载的 chainName 是否有重复的 + // 校验加载的 chainName 是否有重复的 // TODO 这里是否有个问题,当混合格式加载的时候,2个同名的Chain在不同的文件里,就不行了 - String chainName = Optional.ofNullable(innerJsonObject.get(ID)).orElse(innerJsonObject.get(NAME)).textValue(); + String chainName = Optional.ofNullable(innerJsonObject.get(ID)) + .orElse(innerJsonObject.get(NAME)) + .textValue(); if (!chainNameSet.add(chainName)) { throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName)); } @@ -213,7 +216,7 @@ public class ParserHelper { chainNameSet.clear(); for (JsonNode flowJsonNode : flowJsonObjectList) { - //解析每一个chain + // 解析每一个chain Iterator chainIterator = flowJsonNode.get(FLOW).get(CHAIN).elements(); while (chainIterator.hasNext()) { JsonNode jsonNode = chainIterator.next(); @@ -224,11 +227,10 @@ public class ParserHelper { /** * 解析一个chain的过程 - * * @param chainNode chain 节点 */ public static void parseOneChainEl(JsonNode chainNode) { - //构建chainBuilder + // 构建chainBuilder String chainId = Optional.ofNullable(chainNode.get(ID)).orElse(chainNode.get(NAME)).textValue(); String el = chainNode.get(VALUE).textValue(); LiteFlowChainELBuilder chainELBuilder = LiteFlowChainELBuilder.createChain().setChainId(chainId); @@ -237,11 +239,10 @@ public class ParserHelper { /** * 解析一个chain的过程 - * * @param e chain 节点 */ public static void parseOneChainEl(Element e) { - //构建chainBuilder + // 构建chainBuilder String chainId = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME)); String text = e.getText(); String el = RegexUtil.removeComments(text); @@ -249,14 +250,13 @@ public class ParserHelper { chainELBuilder.setEL(el).build(); } - private static class RegexUtil{ + private static class RegexUtil { + // java 注释的正则表达式 private static final String REGEX_COMMENT = "/\\*((?!\\*/).|[\\r\\n])*?\\*/|[ \\t]*//.*"; /** - * 移除 el 表达式中的注释,支持 java 的注释,包括单行注释、多行注释, - * 会压缩字符串,移除空格和换行符 - * + * 移除 el 表达式中的注释,支持 java 的注释,包括单行注释、多行注释, 会压缩字符串,移除空格和换行符 * @param elStr el 表达式 * @return 移除注释后的 el 表达式 */ @@ -266,9 +266,11 @@ public class ParserHelper { } return Pattern.compile(REGEX_COMMENT) - .matcher(elStr) - //移除注释 - .replaceAll(CharSequenceUtil.EMPTY); + .matcher(elStr) + // 移除注释 + .replaceAll(CharSequenceUtil.EMPTY); } + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/spi/ParserClassNameSpi.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/spi/ParserClassNameSpi.java index 6466ed9b..95c6b6d7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/spi/ParserClassNameSpi.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/spi/ParserClassNameSpi.java @@ -2,10 +2,12 @@ package com.yomahub.liteflow.parser.spi; /** * 解析器SPI插件接口 + * * @author Bryan.Zhang * @since 2.8.6 */ public interface ParserClassNameSpi { - String getSpiClassName(); + String getSpiClassName(); + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index 0f117920..b75f0556 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -14,8 +14,7 @@ import cn.hutool.core.util.StrUtil; import java.util.Map; /** - * liteflow的配置实体类 - * 这个类中的属性为什么不用基本类型,而用包装类型呢 + * liteflow的配置实体类 这个类中的属性为什么不用基本类型,而用包装类型呢 * 是因为这个类是springboot和spring的最终参数获取器,考虑到spring的场景,有些参数不是必须配置。基本类型就会出现默认值的情况。 * 所以为了要有null值出现,这里采用包装类型 * @@ -23,344 +22,364 @@ import java.util.Map; */ public class LiteflowConfig { - /** - * 是否启动liteflow自动装配 - */ - private Boolean enable; + /** + * 是否启动liteflow自动装配 + */ + private Boolean enable; - //流程定义资源地址 - private String ruleSource; + // 流程定义资源地址 + private String ruleSource; - //流程资源扩展数据 - private String ruleSourceExtData; + // 流程资源扩展数据 + private String ruleSourceExtData; - private Map ruleSourceExtDataMap; + private Map ruleSourceExtDataMap; - //slot的数量 - private Integer slotSize; + // slot的数量 + private Integer slotSize; - //并行线程执行器class路径 - private String threadExecutorClass; + // 并行线程执行器class路径 + private String threadExecutorClass; - //异步线程最大等待秒数 - private Integer whenMaxWaitSeconds; + // 异步线程最大等待秒数 + private Integer whenMaxWaitSeconds; - //是否打印监控log - private Boolean enableLog; + // 是否打印监控log + private Boolean enableLog; - //监控存储信息最大队列数量 - private Integer queueLimit; + // 监控存储信息最大队列数量 + private Integer queueLimit; - //延迟多少秒打印 - private Long delay; + // 延迟多少秒打印 + private Long delay; - //每隔多少秒打印 - private Long period; + // 每隔多少秒打印 + private Long period; - //异步线程池最大线程数 - private Integer whenMaxWorkers; + // 异步线程池最大线程数 + private Integer whenMaxWorkers; - //异步线程池最大队列数量 - private Integer whenQueueLimit; + // 异步线程池最大队列数量 + private Integer whenQueueLimit; + + // 是否在启动时解析规则文件 + // 这个参数主要给编码式注册元数据的场景用的,结合FlowBus.addNode一起用 + private Boolean parseOnStart; + + // 这个属性为true,则支持多种不同的类型的配置 + // 但是要注意,不能将主流程和子流程分配在不同类型配置文件中 + private Boolean supportMultipleType; + + // 重试次数 + private Integer retryCount; + + // 节点执行器的类全名 + private String nodeExecutorClass; + + // requestId 生成器 + private String requestIdGeneratorClass; + + // 是否打印liteflow banner + private Boolean printBanner; + + // FlowExecutor的execute2Future的线程数 + private Integer mainExecutorWorks; + + // FlowExecutor的execute2Future的自定义线程池 + private String mainExecutorClass; + + // 是否打印执行中的日志 + private Boolean printExecutionLog; + + // 替补组件class路径 + private String substituteCmpClass; + + // 规则文件/脚本文件变更监听 + private Boolean enableMonitorFile = Boolean.FALSE; + + public Boolean getEnableMonitorFile() { + return enableMonitorFile; + } + + public void setEnableMonitorFile(Boolean enableMonitorFile) { + this.enableMonitorFile = enableMonitorFile; + } + + public Boolean getEnable() { + if (ObjectUtil.isNull(enable)) { + return Boolean.TRUE; + } + else { + return enable; + } + } + + public void setEnable(Boolean enable) { + this.enable = enable; + } + + public String getRuleSource() { + return ruleSource; + } + + public void setRuleSource(String ruleSource) { + this.ruleSource = ruleSource; + } + + public Integer getSlotSize() { + if (ObjectUtil.isNull(slotSize)) { + return 1024; + } + else { + return slotSize; + } + } + + public void setSlotSize(Integer slotSize) { + this.slotSize = slotSize; + } + + public Integer getWhenMaxWaitSeconds() { + if (ObjectUtil.isNull(whenMaxWaitSeconds)) { + return 15; + } + else { + return whenMaxWaitSeconds; + } + } + + public void setWhenMaxWaitSeconds(Integer whenMaxWaitSeconds) { + this.whenMaxWaitSeconds = whenMaxWaitSeconds; + } + + public Integer getQueueLimit() { + if (ObjectUtil.isNull(queueLimit)) { + return 200; + } + else { + return queueLimit; + } + } + + public void setQueueLimit(Integer queueLimit) { + this.queueLimit = queueLimit; + } + + public Long getDelay() { + if (ObjectUtil.isNull(delay)) { + return 300000L; + } + else { + return delay; + } + } + + public void setDelay(Long delay) { + this.delay = delay; + } + + public Long getPeriod() { + if (ObjectUtil.isNull(period)) { + return 300000L; + } + else { + return period; + } + } + + public void setPeriod(Long period) { + this.period = period; + } + + public Boolean getEnableLog() { + if (ObjectUtil.isNull(enableLog)) { + return Boolean.FALSE; + } + else { + return enableLog; + } + } + + public void setEnableLog(Boolean enableLog) { + this.enableLog = enableLog; + } + + public Integer getWhenMaxWorkers() { + if (ObjectUtil.isNull(whenMaxWorkers)) { + return 16; + } + else { + return whenMaxWorkers; + } + } + + public void setWhenMaxWorkers(Integer whenMaxWorkers) { + this.whenMaxWorkers = whenMaxWorkers; + } + + public Integer getWhenQueueLimit() { + if (ObjectUtil.isNull(whenQueueLimit)) { + return 512; + } + else { + return whenQueueLimit; + } + } + + public void setWhenQueueLimit(Integer whenQueueLimit) { + this.whenQueueLimit = whenQueueLimit; + } + + public Boolean isParseOnStart() { + if (ObjectUtil.isNull(parseOnStart)) { + return Boolean.TRUE; + } + else { + return parseOnStart; + } + } + + public void setParseOnStart(Boolean parseOnStart) { + this.parseOnStart = parseOnStart; + } + + public Boolean isSupportMultipleType() { + if (ObjectUtil.isNull(supportMultipleType)) { + return Boolean.FALSE; + } + else { + return supportMultipleType; + } + } + + public void setSupportMultipleType(Boolean supportMultipleType) { + this.supportMultipleType = supportMultipleType; + } + + public Integer getRetryCount() { + if (ObjectUtil.isNull(retryCount) || retryCount < 0) { + return 0; + } + else { + return retryCount; + } + } + + public void setRetryCount(Integer retryCount) { + this.retryCount = retryCount; + } + + public Boolean getPrintBanner() { + if (ObjectUtil.isNull(printBanner)) { + return Boolean.TRUE; + } + else { + return printBanner; + } + } + + public void setPrintBanner(Boolean printBanner) { + this.printBanner = printBanner; + } + + public String getThreadExecutorClass() { + if (StrUtil.isBlank(threadExecutorClass)) { + return "com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder"; + } + else { + return threadExecutorClass; + } + } + + public void setThreadExecutorClass(String threadExecutorClass) { + this.threadExecutorClass = threadExecutorClass; + } + + public String getNodeExecutorClass() { + if (StrUtil.isBlank(nodeExecutorClass)) { + return "com.yomahub.liteflow.flow.executor.DefaultNodeExecutor"; + } + else { + return nodeExecutorClass; + } + } + + public void setNodeExecutorClass(String nodeExecutorClass) { + this.nodeExecutorClass = nodeExecutorClass; + } + + public String getRequestIdGeneratorClass() { + if (StrUtil.isBlank(this.requestIdGeneratorClass)) { + return "com.yomahub.liteflow.flow.id.DefaultRequestIdGenerator"; + } + return requestIdGeneratorClass; + } + + public void setRequestIdGeneratorClass(String requestIdGeneratorClass) { + this.requestIdGeneratorClass = requestIdGeneratorClass; + } + + public Integer getMainExecutorWorks() { + if (ObjectUtil.isNull(mainExecutorWorks)) { + return 64; + } + else { + return mainExecutorWorks; + } + } + + public void setMainExecutorWorks(Integer mainExecutorWorks) { + this.mainExecutorWorks = mainExecutorWorks; + } + + public String getMainExecutorClass() { + if (StrUtil.isBlank(mainExecutorClass)) { + return "com.yomahub.liteflow.thread.LiteFlowDefaultMainExecutorBuilder"; + } + else { + return mainExecutorClass; + } + } + + public void setMainExecutorClass(String mainExecutorClass) { + this.mainExecutorClass = mainExecutorClass; + } + + public Boolean getPrintExecutionLog() { + if (ObjectUtil.isNull(printExecutionLog)) { + return Boolean.TRUE; + } + else { + return printExecutionLog; + } + } + + public void setPrintExecutionLog(Boolean printExecutionLog) { + this.printExecutionLog = printExecutionLog; + } + + public String getSubstituteCmpClass() { + return substituteCmpClass; + } + + public void setSubstituteCmpClass(String substituteCmpClass) { + this.substituteCmpClass = substituteCmpClass; + } + + public String getRuleSourceExtData() { + return ruleSourceExtData; + } + + public void setRuleSourceExtData(String ruleSourceExtData) { + this.ruleSourceExtData = ruleSourceExtData; + } + + public Map getRuleSourceExtDataMap() { + return ruleSourceExtDataMap; + } + + public void setRuleSourceExtDataMap(Map ruleSourceExtDataMap) { + this.ruleSourceExtDataMap = ruleSourceExtDataMap; + } - //是否在启动时解析规则文件 - //这个参数主要给编码式注册元数据的场景用的,结合FlowBus.addNode一起用 - private Boolean parseOnStart; - - //这个属性为true,则支持多种不同的类型的配置 - //但是要注意,不能将主流程和子流程分配在不同类型配置文件中 - private Boolean supportMultipleType; - - //重试次数 - private Integer retryCount; - // 节点执行器的类全名 - private String nodeExecutorClass; - - // requestId 生成器 - private String requestIdGeneratorClass; - - //是否打印liteflow banner - private Boolean printBanner; - - //FlowExecutor的execute2Future的线程数 - private Integer mainExecutorWorks; - - //FlowExecutor的execute2Future的自定义线程池 - private String mainExecutorClass; - - //是否打印执行中的日志 - private Boolean printExecutionLog; - - //替补组件class路径 - private String substituteCmpClass; - - // 规则文件/脚本文件变更监听 - private Boolean enableMonitorFile = Boolean.FALSE; - - public Boolean getEnableMonitorFile() { - return enableMonitorFile; - } - - public void setEnableMonitorFile(Boolean enableMonitorFile) { - this.enableMonitorFile = enableMonitorFile; - } - - public Boolean getEnable() { - if (ObjectUtil.isNull(enable)) { - return Boolean.TRUE; - } else { - return enable; - } - } - - public void setEnable(Boolean enable) { - this.enable = enable; - } - - public String getRuleSource() { - return ruleSource; - } - - public void setRuleSource(String ruleSource) { - this.ruleSource = ruleSource; - } - - public Integer getSlotSize() { - if (ObjectUtil.isNull(slotSize)) { - return 1024; - } else { - return slotSize; - } - } - - public void setSlotSize(Integer slotSize) { - this.slotSize = slotSize; - } - - public Integer getWhenMaxWaitSeconds() { - if (ObjectUtil.isNull(whenMaxWaitSeconds)) { - return 15; - } else { - return whenMaxWaitSeconds; - } - } - - public void setWhenMaxWaitSeconds(Integer whenMaxWaitSeconds) { - this.whenMaxWaitSeconds = whenMaxWaitSeconds; - } - - public Integer getQueueLimit() { - if (ObjectUtil.isNull(queueLimit)) { - return 200; - } else { - return queueLimit; - } - } - - public void setQueueLimit(Integer queueLimit) { - this.queueLimit = queueLimit; - } - - public Long getDelay() { - if (ObjectUtil.isNull(delay)) { - return 300000L; - } else { - return delay; - } - } - - public void setDelay(Long delay) { - this.delay = delay; - } - - public Long getPeriod() { - if (ObjectUtil.isNull(period)) { - return 300000L; - } else { - return period; - } - } - - public void setPeriod(Long period) { - this.period = period; - } - - public Boolean getEnableLog() { - if (ObjectUtil.isNull(enableLog)) { - return Boolean.FALSE; - } else { - return enableLog; - } - } - - public void setEnableLog(Boolean enableLog) { - this.enableLog = enableLog; - } - - public Integer getWhenMaxWorkers() { - if (ObjectUtil.isNull(whenMaxWorkers)) { - return 16; - } else { - return whenMaxWorkers; - } - } - - public void setWhenMaxWorkers(Integer whenMaxWorkers) { - this.whenMaxWorkers = whenMaxWorkers; - } - - public Integer getWhenQueueLimit() { - if (ObjectUtil.isNull(whenQueueLimit)) { - return 512; - } else { - return whenQueueLimit; - } - } - - public void setWhenQueueLimit(Integer whenQueueLimit) { - this.whenQueueLimit = whenQueueLimit; - } - - public Boolean isParseOnStart() { - if (ObjectUtil.isNull(parseOnStart)) { - return Boolean.TRUE; - } else { - return parseOnStart; - } - } - - public void setParseOnStart(Boolean parseOnStart) { - this.parseOnStart = parseOnStart; - } - - public Boolean isSupportMultipleType() { - if (ObjectUtil.isNull(supportMultipleType)) { - return Boolean.FALSE; - } else { - return supportMultipleType; - } - } - - public void setSupportMultipleType(Boolean supportMultipleType) { - this.supportMultipleType = supportMultipleType; - } - - public Integer getRetryCount() { - if (ObjectUtil.isNull(retryCount) || retryCount < 0) { - return 0; - } else { - return retryCount; - } - } - - public void setRetryCount(Integer retryCount) { - this.retryCount = retryCount; - } - - public Boolean getPrintBanner() { - if (ObjectUtil.isNull(printBanner)) { - return Boolean.TRUE; - } else { - return printBanner; - } - } - - public void setPrintBanner(Boolean printBanner) { - this.printBanner = printBanner; - } - - public String getThreadExecutorClass() { - if (StrUtil.isBlank(threadExecutorClass)){ - return "com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder"; - }else{ - return threadExecutorClass; - } - } - - public void setThreadExecutorClass(String threadExecutorClass) { - this.threadExecutorClass = threadExecutorClass; - } - - public String getNodeExecutorClass() { - if (StrUtil.isBlank(nodeExecutorClass)){ - return "com.yomahub.liteflow.flow.executor.DefaultNodeExecutor"; - }else{ - return nodeExecutorClass; - } - } - - public void setNodeExecutorClass(String nodeExecutorClass) { - this.nodeExecutorClass = nodeExecutorClass; - } - - public String getRequestIdGeneratorClass() { - if(StrUtil.isBlank(this.requestIdGeneratorClass)){ - return "com.yomahub.liteflow.flow.id.DefaultRequestIdGenerator"; - } - return requestIdGeneratorClass; - } - - public void setRequestIdGeneratorClass(String requestIdGeneratorClass) { - this.requestIdGeneratorClass = requestIdGeneratorClass; - } - - public Integer getMainExecutorWorks() { - if (ObjectUtil.isNull(mainExecutorWorks)){ - return 64; - }else{ - return mainExecutorWorks; - } - } - - public void setMainExecutorWorks(Integer mainExecutorWorks) { - this.mainExecutorWorks = mainExecutorWorks; - } - - public String getMainExecutorClass() { - if (StrUtil.isBlank(mainExecutorClass)){ - return "com.yomahub.liteflow.thread.LiteFlowDefaultMainExecutorBuilder"; - }else{ - return mainExecutorClass; - } - } - - public void setMainExecutorClass(String mainExecutorClass) { - this.mainExecutorClass = mainExecutorClass; - } - - public Boolean getPrintExecutionLog() { - if (ObjectUtil.isNull(printExecutionLog)){ - return Boolean.TRUE; - }else{ - return printExecutionLog; - } - } - - public void setPrintExecutionLog(Boolean printExecutionLog) { - this.printExecutionLog = printExecutionLog; - } - - public String getSubstituteCmpClass() { - return substituteCmpClass; - } - - public void setSubstituteCmpClass(String substituteCmpClass) { - this.substituteCmpClass = substituteCmpClass; - } - - public String getRuleSourceExtData() { - return ruleSourceExtData; - } - - public void setRuleSourceExtData(String ruleSourceExtData) { - this.ruleSourceExtData = ruleSourceExtData; - } - - public Map getRuleSourceExtDataMap() { - return ruleSourceExtDataMap; - } - - public void setRuleSourceExtDataMap(Map ruleSourceExtDataMap) { - this.ruleSourceExtDataMap = ruleSourceExtDataMap; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfigGetter.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfigGetter.java index c5951338..4ac723a7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfigGetter.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfigGetter.java @@ -8,28 +8,29 @@ import com.yomahub.liteflow.spi.holder.ContextAwareHolder; */ public class LiteflowConfigGetter { - private static LiteflowConfig liteflowConfig; + private static LiteflowConfig liteflowConfig; - public static LiteflowConfig get(){ - if (ObjectUtil.isNull(liteflowConfig)){ - liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); - //这里liteflowConfig不可能为null - //如果在springboot环境,由于自动装配,所以不可能为null - //在spring环境,如果xml没配置,在FlowExecutor的init时候就已经报错了 - //非spring环境下,FlowExecutorHolder.loadInstance(config)的时候,会把config放入这个类的静态属性中 - if (ObjectUtil.isNull(liteflowConfig)){ - liteflowConfig = new LiteflowConfig(); - } - } + public static LiteflowConfig get() { + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); + // 这里liteflowConfig不可能为null + // 如果在springboot环境,由于自动装配,所以不可能为null + // 在spring环境,如果xml没配置,在FlowExecutor的init时候就已经报错了 + // 非spring环境下,FlowExecutorHolder.loadInstance(config)的时候,会把config放入这个类的静态属性中 + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + } - return liteflowConfig; - } + return liteflowConfig; + } - public static void clean(){ - liteflowConfig = null; - } + public static void clean() { + liteflowConfig = null; + } + + public static void setLiteflowConfig(LiteflowConfig liteflowConfig) { + LiteflowConfigGetter.liteflowConfig = liteflowConfig; + } - public static void setLiteflowConfig(LiteflowConfig liteflowConfig){ - LiteflowConfigGetter.liteflowConfig = liteflowConfig; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptBeanManager.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptBeanManager.java index a0de3919..122f3a22 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptBeanManager.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptBeanManager.java @@ -5,18 +5,20 @@ import java.util.Map; /** * Script中可使用的java bean管理类 + * * @author Bryan.Zhang * @since 2.9.0 */ public class ScriptBeanManager { - private static final Map scriptBeanMap = new HashMap<>(); + private static final Map scriptBeanMap = new HashMap<>(); - public static void addScriptBean(String key, Object bean){ - scriptBeanMap.put(key, bean); - } + public static void addScriptBean(String key, Object bean) { + scriptBeanMap.put(key, bean); + } + + public static Map getScriptBeanMap() { + return scriptBeanMap; + } - public static Map getScriptBeanMap(){ - return scriptBeanMap; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecuteWrap.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecuteWrap.java index 55f03cc4..00fdf7b2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecuteWrap.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecuteWrap.java @@ -2,75 +2,76 @@ package com.yomahub.liteflow.script; /** * script执行前的包装元参数 + * * @author Bryan.Zhang * @since 2.9.0 */ public class ScriptExecuteWrap { - private int slotIndex; + private int slotIndex; - private String currChainId; + private String currChainId; - private String nodeId; + private String nodeId; - private String tag; + private String tag; - private Object cmpData; + private Object cmpData; - public int getSlotIndex() { - return slotIndex; - } + public int getSlotIndex() { + return slotIndex; + } - public void setSlotIndex(int slotIndex) { - this.slotIndex = slotIndex; - } + public void setSlotIndex(int slotIndex) { + this.slotIndex = slotIndex; + } - /** - * @deprecated 请使用 {@link #getCurrChainId()} - * @return String - */ - @Deprecated - public String getCurrChainName() { - return currChainId; - } + /** + * @deprecated 请使用 {@link #getCurrChainId()} + * @return String + */ + @Deprecated + public String getCurrChainName() { + return currChainId; + } - /** - * - * @deprecated 请使用{@link #setCurrChainId(String)} - */ - public void setCurrChainName(String currChainName) { - this.currChainId = currChainName; - } - - public String getCurrChainId() { - return currChainId; - } + /** + * @deprecated 请使用{@link #setCurrChainId(String)} + */ + public void setCurrChainName(String currChainName) { + this.currChainId = currChainName; + } - public void setCurrChainId(String currChainId) { - this.currChainId = currChainId; - } + public String getCurrChainId() { + return currChainId; + } - public String getNodeId() { - return nodeId; - } + public void setCurrChainId(String currChainId) { + this.currChainId = currChainId; + } - public void setNodeId(String nodeId) { - this.nodeId = nodeId; - } + public String getNodeId() { + return nodeId; + } - public String getTag() { - return tag; - } + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } - public void setTag(String tag) { - this.tag = tag; - } + public String getTag() { + return tag; + } - public Object getCmpData() { - return cmpData; - } + public void setTag(String tag) { + this.tag = tag; + } + + public Object getCmpData() { + return cmpData; + } + + public void setCmpData(Object cmpData) { + this.cmpData = cmpData; + } - public void setCmpData(Object cmpData) { - this.cmpData = cmpData; - } } 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 49c9910a..10de81bb 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 @@ -4,18 +4,20 @@ import com.yomahub.liteflow.enums.ScriptTypeEnum; /** * 脚本执行器接口 + * * @author Bryan.Zhang * @since 2.6.0 */ public interface ScriptExecutor { - ScriptExecutor init(); + ScriptExecutor init(); - void load(String nodeId, String script); + void load(String nodeId, String script); - Object execute(ScriptExecuteWrap wrap) throws Exception; + Object execute(ScriptExecuteWrap wrap) throws Exception; - void cleanCache(); + void cleanCache(); + + ScriptTypeEnum scriptType(); - ScriptTypeEnum scriptType(); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutorFactory.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutorFactory.java index 5f0729c3..1b2b5616 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutorFactory.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutorFactory.java @@ -13,61 +13,64 @@ import java.util.function.Consumer; /** * 脚本执行器工厂类 + * * @author Bryan.Zhang * @since 2.6.0 */ public class ScriptExecutorFactory { - private static ScriptExecutorFactory scriptExecutorFactory; + private static ScriptExecutorFactory scriptExecutorFactory; - private final Map scriptExecutorMap = new HashMap<>(); + private final Map scriptExecutorMap = new HashMap<>(); - private final String NONE_LANGUAGE = "none"; + private final String NONE_LANGUAGE = "none"; - public static ScriptExecutorFactory loadInstance(){ - if (ObjectUtil.isNull(scriptExecutorFactory)){ - scriptExecutorFactory = new ScriptExecutorFactory(); - } - return scriptExecutorFactory; - } + public static ScriptExecutorFactory loadInstance() { + if (ObjectUtil.isNull(scriptExecutorFactory)) { + scriptExecutorFactory = new ScriptExecutorFactory(); + } + return scriptExecutorFactory; + } - public ScriptExecutor getScriptExecutor(String language){ - if (StrUtil.isBlank(language)){ - language = NONE_LANGUAGE; - } + public ScriptExecutor getScriptExecutor(String language) { + if (StrUtil.isBlank(language)) { + language = NONE_LANGUAGE; + } + if (!scriptExecutorMap.containsKey(language)) { + ServiceLoader loader = ServiceLoader.load(ScriptExecutor.class); - if (!scriptExecutorMap.containsKey(language)){ - ServiceLoader loader = ServiceLoader.load(ScriptExecutor.class); + ScriptExecutor scriptExecutor; + Iterator it = loader.iterator(); + while (it.hasNext()) { + scriptExecutor = it.next().init(); + if (language.equals(NONE_LANGUAGE)) { + scriptExecutorMap.put(language, scriptExecutor); + break; + } + else { + ScriptTypeEnum scriptType = ScriptTypeEnum.getEnumByDisplayName(language); + if (ObjectUtil.isNull(scriptType)) { + throw new ScriptSpiException("script language config error"); + } + if (scriptType.equals(scriptExecutor.scriptType())) { + scriptExecutorMap.put(language, scriptExecutor); + break; + } + } + } + } - ScriptExecutor scriptExecutor; - Iterator it = loader.iterator(); - while(it.hasNext()){ - scriptExecutor = it.next().init(); - if (language.equals(NONE_LANGUAGE)){ - scriptExecutorMap.put(language, scriptExecutor); - break; - }else{ - ScriptTypeEnum scriptType = ScriptTypeEnum.getEnumByDisplayName(language); - if (ObjectUtil.isNull(scriptType)){ - throw new ScriptSpiException("script language config error"); - } - if (scriptType.equals(scriptExecutor.scriptType())){ - scriptExecutorMap.put(language, scriptExecutor); - break; - } - } - } - } + if (scriptExecutorMap.containsKey(language)) { + return scriptExecutorMap.get(language); + } + else { + throw new ScriptSpiException("script spi component failed to load"); + } + } - if (scriptExecutorMap.containsKey(language)){ - return scriptExecutorMap.get(language); - }else{ - throw new ScriptSpiException("script spi component failed to load"); - } - } + public void cleanScriptCache() { + this.scriptExecutorMap.forEach((key, value) -> value.cleanCache()); + } - public void cleanScriptCache(){ - this.scriptExecutorMap.forEach((key, value) -> value.cleanCache()); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptBean.java index e99b9aa3..6667749a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptBean.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptBean.java @@ -6,22 +6,24 @@ import java.lang.annotation.*; /** * 用于标注在Script中可使用的java bean + * * @author Bryan.Zhang * @since 2.9.0 */ -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface ScriptBean { - @AliasFor("name") - String value() default ""; + @AliasFor("name") + String value() default ""; - @AliasFor("value") - String name() default ""; + @AliasFor("value") + String name() default ""; - String[] includeMethodName() default {}; + String[] includeMethodName() default {}; + + String[] excludeMethodName() default {}; - String[] excludeMethodName() default {}; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptMethod.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptMethod.java index 3ee929b4..73b945cf 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptMethod.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/annotation/ScriptMethod.java @@ -14,12 +14,13 @@ import java.lang.annotation.Target; * * @author tangkc */ -@Target({ElementType.METHOD}) +@Target({ ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface ScriptMethod { - @AliasFor("name") - String value() default ""; + @AliasFor("name") + String value() default ""; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptLoadException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptLoadException.java index be0df6bc..033c80cf 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptLoadException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptLoadException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.script.exception; /** * 脚本加载异常 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -24,4 +25,5 @@ public class ScriptLoadException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptSpiException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptSpiException.java index e7b6ec54..73dc43a8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptSpiException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/exception/ScriptSpiException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.script.exception; /** * 脚本SPI插件加载异常 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -24,4 +25,5 @@ public class ScriptSpiException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } 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 72b8b95a..53536b28 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 @@ -22,99 +22,106 @@ import java.util.Optional; /** * JSR223 script engine的统一实现抽象类 + * * @author Bryan.Zhang * @since 2.9.5 */ public abstract class JSR223ScriptExecutor implements ScriptExecutor { - protected final Logger log = LoggerFactory.getLogger(this.getClass()); + protected final Logger log = LoggerFactory.getLogger(this.getClass()); - private ScriptEngine scriptEngine; + private ScriptEngine scriptEngine; - private final Map compiledScriptMap = new CopyOnWriteHashMap<>(); + private final Map compiledScriptMap = new CopyOnWriteHashMap<>(); - @Override - public ScriptExecutor init() { - ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); - scriptEngine = scriptEngineManager.getEngineByName(this.scriptType().getEngineName()); - return this; - } + @Override + public ScriptExecutor init() { + ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); + scriptEngine = scriptEngineManager.getEngineByName(this.scriptType().getEngineName()); + return this; + } - protected String convertScript(String script){ - return script; - } + protected String convertScript(String script) { + return script; + } - @Override - public void load(String nodeId, String script) { - try{ - CompiledScript compiledScript = ((Compilable) scriptEngine).compile(convertScript(script)); - compiledScriptMap.put(nodeId, compiledScript); - }catch (Exception e){ - String errorMsg = StrUtil.format("script loading error for node[{}], error msg:{}", nodeId, e.getMessage()); - throw new ScriptLoadException(errorMsg); - } + @Override + public void load(String nodeId, String script) { + try { + CompiledScript compiledScript = ((Compilable) scriptEngine).compile(convertScript(script)); + compiledScriptMap.put(nodeId, compiledScript); + } + catch (Exception e) { + String errorMsg = StrUtil.format("script loading error for node[{}], error msg:{}", nodeId, e.getMessage()); + throw new ScriptLoadException(errorMsg); + } - } + } - @Override - public Object execute(ScriptExecuteWrap wrap) throws Exception{ - try{ - if (!compiledScriptMap.containsKey(wrap.getNodeId())){ - String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId()); - throw new ScriptLoadException(errorMsg); - } + @Override + public Object execute(ScriptExecuteWrap wrap) throws Exception { + try { + if (!compiledScriptMap.containsKey(wrap.getNodeId())) { + String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId()); + throw new ScriptLoadException(errorMsg); + } - CompiledScript compiledScript = compiledScriptMap.get(wrap.getNodeId()); - Bindings bindings = new SimpleBindings(); + CompiledScript compiledScript = compiledScriptMap.get(wrap.getNodeId()); + Bindings bindings = new SimpleBindings(); - //往脚本语言绑定表里循环增加绑定上下文的key - //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()); - } - bindings.put(key, o); - }); + // 往脚本语言绑定表里循环增加绑定上下文的key + // 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()); + } + bindings.put(key, o); + }); - //把wrap对象转换成元数据map - Map metaMap = BeanUtil.beanToMap(wrap); + // 把wrap对象转换成元数据map + Map metaMap = BeanUtil.beanToMap(wrap); - //在元数据里放入主Chain的流程参数 - Slot slot = DataBus.getSlot(wrap.getSlotIndex()); - metaMap.put("requestData", slot.getRequestData()); + // 在元数据里放入主Chain的流程参数 + Slot slot = DataBus.getSlot(wrap.getSlotIndex()); + metaMap.put("requestData", slot.getRequestData()); - //如果有隐式流程,则放入隐式流程的流程参数 - Object subRequestData = slot.getChainReqData(wrap.getCurrChainId()); - if (ObjectUtil.isNotNull(subRequestData)){ - metaMap.put("subRequestData", subRequestData); - } + // 如果有隐式流程,则放入隐式流程的流程参数 + Object subRequestData = slot.getChainReqData(wrap.getCurrChainId()); + if (ObjectUtil.isNotNull(subRequestData)) { + metaMap.put("subRequestData", subRequestData); + } - //往脚本上下文里放入元数据 - bindings.put("_meta", metaMap); + // 往脚本上下文里放入元数据 + bindings.put("_meta", metaMap); - //放入用户自己定义的bean - ScriptBeanManager.getScriptBeanMap().forEach(bindings::putIfAbsent); + // 放入用户自己定义的bean + ScriptBeanManager.getScriptBeanMap().forEach(bindings::putIfAbsent); - return compiledScript.eval(bindings); - }catch (Exception e){ - if (ObjectUtil.isNotNull(e.getCause()) && e.getCause() instanceof LiteFlowException){ - throw (LiteFlowException)e.getCause(); - } else if (ObjectUtil.isNotNull(e.getCause()) && e.getCause() instanceof RuntimeException) { - throw (RuntimeException)e.getCause(); - } else{ - throw e; - } - } - } + return compiledScript.eval(bindings); + } + catch (Exception e) { + if (ObjectUtil.isNotNull(e.getCause()) && e.getCause() instanceof LiteFlowException) { + throw (LiteFlowException) e.getCause(); + } + else if (ObjectUtil.isNotNull(e.getCause()) && e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } + else { + throw e; + } + } + } + + @Override + public void cleanCache() { + compiledScriptMap.clear(); + } - @Override - public void cleanCache() { - compiledScriptMap.clear(); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java index f5a5512b..85a866a7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptBeanProxy.java @@ -20,88 +20,95 @@ import java.util.stream.Collectors; public class ScriptBeanProxy { - private final Logger LOG = LoggerFactory.getLogger(this.getClass()); + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); - private final Object bean; + private final Object bean; - private final Class orignalClass; + private final Class orignalClass; - private final ScriptBean scriptBeanAnno; + private final ScriptBean scriptBeanAnno; - public ScriptBeanProxy(Object bean, Class orignalClass, ScriptBean scriptBeanAnno) { - this.bean = bean; - this.orignalClass = orignalClass; - this.scriptBeanAnno = scriptBeanAnno; - } + public ScriptBeanProxy(Object bean, Class orignalClass, ScriptBean scriptBeanAnno) { + this.bean = bean; + this.orignalClass = orignalClass; + this.scriptBeanAnno = scriptBeanAnno; + } - public Object getProxyScriptBean(){ - //获取bean里所有的method,包括超类里的 - List methodNameList = Arrays.stream(orignalClass.getMethods()).map(Method::getName).collect(Collectors.toList()); + public Object getProxyScriptBean() { + // 获取bean里所有的method,包括超类里的 + List methodNameList = Arrays.stream(orignalClass.getMethods()) + .map(Method::getName) + .collect(Collectors.toList()); - //首先看@ScriptBean标注里的includeMethodName属性 - //如果没有配置,则认为是全部的method,如果有配置,就取配置的method - if (ArrayUtil.isNotEmpty(scriptBeanAnno.includeMethodName())){ - methodNameList = methodNameList.stream().filter( - methodName -> ListUtil.toList(scriptBeanAnno.includeMethodName()).contains(methodName) - ).collect(Collectors.toList()); - } + // 首先看@ScriptBean标注里的includeMethodName属性 + // 如果没有配置,则认为是全部的method,如果有配置,就取配置的method + if (ArrayUtil.isNotEmpty(scriptBeanAnno.includeMethodName())) { + methodNameList = methodNameList.stream() + .filter(methodName -> ListUtil.toList(scriptBeanAnno.includeMethodName()).contains(methodName)) + .collect(Collectors.toList()); + } - //其次看excludeMethodName的配置 - if (ArrayUtil.isNotEmpty(scriptBeanAnno.excludeMethodName())){ - methodNameList = methodNameList.stream().filter( - methodName -> !ListUtil.toList(scriptBeanAnno.excludeMethodName()).contains(methodName) - ).collect(Collectors.toList()); - } + // 其次看excludeMethodName的配置 + if (ArrayUtil.isNotEmpty(scriptBeanAnno.excludeMethodName())) { + methodNameList = methodNameList.stream() + .filter(methodName -> !ListUtil.toList(scriptBeanAnno.excludeMethodName()).contains(methodName)) + .collect(Collectors.toList()); + } - try{ - return new ByteBuddy().subclass(orignalClass) - .name(StrUtil.format("{}.ByteBuddy${}", - ClassUtil.getPackage(orignalClass), - SerialsUtil.generateShortUUID())) - .method(ElementMatchers.any()) - .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean, methodNameList))) - .annotateType(orignalClass.getAnnotations()) - .make() - .load(ScriptBeanProxy.class.getClassLoader()) - .getLoaded() - .newInstance(); - }catch (Exception e){ - throw new LiteFlowException(e); - } + try { + return new ByteBuddy().subclass(orignalClass) + .name(StrUtil.format("{}.ByteBuddy${}", ClassUtil.getPackage(orignalClass), + SerialsUtil.generateShortUUID())) + .method(ElementMatchers.any()) + .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean, methodNameList))) + .annotateType(orignalClass.getAnnotations()) + .make() + .load(ScriptBeanProxy.class.getClassLoader()) + .getLoaded() + .newInstance(); + } + catch (Exception e) { + throw new LiteFlowException(e); + } - } + } - public class AopInvocationHandler implements InvocationHandler { + public class AopInvocationHandler implements InvocationHandler { - private final Object bean; + private final Object bean; - private final Class clazz; + private final Class clazz; - private final List canExecuteMethodNameList; + private final List canExecuteMethodNameList; - public AopInvocationHandler(Object bean, List canExecuteMethodNameList) { - this.bean = bean; - this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); - this.canExecuteMethodNameList = canExecuteMethodNameList; - } + public AopInvocationHandler(Object bean, List canExecuteMethodNameList) { + this.bean = bean; + this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); + this.canExecuteMethodNameList = canExecuteMethodNameList; + } - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - Method invokeMethod = Arrays.stream(clazz.getMethods()).filter( - m -> m.getName().equals(method.getName()) && m.getParameterCount() == method.getParameterCount() - ).findFirst().orElse(null); - - if (invokeMethod == null){ - String errorMsg = StrUtil.format("cannot find method[{}]", clazz.getName(), method.getName()); - throw new ScriptBeanMethodInvokeException(errorMsg); - } + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Method invokeMethod = Arrays.stream(clazz.getMethods()) + .filter(m -> m.getName().equals(method.getName()) + && m.getParameterCount() == method.getParameterCount()) + .findFirst() + .orElse(null); - if (!canExecuteMethodNameList.contains(method.getName())){ - String errorMsg = StrUtil.format("script bean method[{}.{}] cannot be executed", clazz.getName(), method.getName()); - throw new ScriptBeanMethodInvokeException(errorMsg); - } + if (invokeMethod == null) { + String errorMsg = StrUtil.format("cannot find method[{}]", clazz.getName(), method.getName()); + throw new ScriptBeanMethodInvokeException(errorMsg); + } + + if (!canExecuteMethodNameList.contains(method.getName())) { + String errorMsg = StrUtil.format("script bean method[{}.{}] cannot be executed", clazz.getName(), + method.getName()); + throw new ScriptBeanMethodInvokeException(errorMsg); + } + + return invokeMethod.invoke(bean, args); + } + + } - return invokeMethod.invoke(bean, args); - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptMethodProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptMethodProxy.java index 75af5094..50ca2937 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptMethodProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/script/proxy/ScriptMethodProxy.java @@ -22,77 +22,79 @@ import java.util.Set; * 脚本方法代理 */ public class ScriptMethodProxy { - /** - * 被代理的 bean - */ - private final Object bean; - /** - * 原始的类 - */ - private final Class orignalClass; + /** + * 被代理的 bean + */ + private final Object bean; - private final List scriptMethods; + /** + * 原始的类 + */ + private final Class orignalClass; - public ScriptMethodProxy(Object bean, Class orignalClass, List scriptMethods) { - this.bean = bean; - this.orignalClass = orignalClass; - this.scriptMethods = scriptMethods; - } + private final List scriptMethods; - public Object getProxyScriptMethod() { + public ScriptMethodProxy(Object bean, Class orignalClass, List scriptMethods) { + this.bean = bean; + this.orignalClass = orignalClass; + this.scriptMethods = scriptMethods; + } - try { - return new ByteBuddy().subclass(orignalClass) - .name(buildClassName()) // 设置生成的类名 - .method(ElementMatchers.any()) - .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean, scriptMethods))) - .annotateType(orignalClass.getAnnotations()) - .make() - .load(ScriptBeanProxy.class.getClassLoader()) - .getLoaded() - .newInstance(); - } catch (Exception e) { - throw new LiteFlowException(e); - } - } + public Object getProxyScriptMethod() { - private String buildClassName() { - return StrUtil.format("{}.ByteBuddy${}", - ClassUtil.getPackage(orignalClass), - SerialsUtil.generateShortUUID()); - } + try { + return new ByteBuddy().subclass(orignalClass) + .name(buildClassName()) // 设置生成的类名 + .method(ElementMatchers.any()) + .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean, scriptMethods))) + .annotateType(orignalClass.getAnnotations()) + .make() + .load(ScriptBeanProxy.class.getClassLoader()) + .getLoaded() + .newInstance(); + } + catch (Exception e) { + throw new LiteFlowException(e); + } + } - public static class AopInvocationHandler implements InvocationHandler { - private final Object bean; + private String buildClassName() { + return StrUtil.format("{}.ByteBuddy${}", ClassUtil.getPackage(orignalClass), SerialsUtil.generateShortUUID()); + } - private final Class clazz; + public static class AopInvocationHandler implements InvocationHandler { - private final Set methodSet; + private final Object bean; - public AopInvocationHandler(Object bean, List methods) { - this.bean = bean; - this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); - this.methodSet = new HashSet<>(methods); - } + private final Class clazz; - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - Optional invokeMethodOp = Arrays.stream(clazz.getMethods()) - .filter(method::equals) - .findFirst(); + private final Set methodSet; - if (!invokeMethodOp.isPresent()) { - String errorMsg = StrUtil.format("cannot find method[{}]", clazz.getName(), method.getName()); - throw new ScriptBeanMethodInvokeException(errorMsg); - } + public AopInvocationHandler(Object bean, List methods) { + this.bean = bean; + this.clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); + this.methodSet = new HashSet<>(methods); + } - if (!methodSet.contains(method)) { - String errorMsg = StrUtil.format("script method[{}.{}] cannot be executed", clazz.getName(), method.getName()); - throw new ScriptBeanMethodInvokeException(errorMsg); - } + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Optional invokeMethodOp = Arrays.stream(clazz.getMethods()).filter(method::equals).findFirst(); + + if (!invokeMethodOp.isPresent()) { + String errorMsg = StrUtil.format("cannot find method[{}]", clazz.getName(), method.getName()); + throw new ScriptBeanMethodInvokeException(errorMsg); + } + + if (!methodSet.contains(method)) { + String errorMsg = StrUtil.format("script method[{}.{}] cannot be executed", clazz.getName(), + method.getName()); + throw new ScriptBeanMethodInvokeException(errorMsg); + } + + return invokeMethodOp.get().invoke(bean, args); + } + + } - return invokeMethodOp.get().invoke(bean, args); - } - } } 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 dfb89543..d9ead199 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 @@ -26,6 +26,7 @@ import java.util.stream.IntStream; /** * 数据BUS,主要用来管理Slot,用以分配和回收 + * * @author Bryan.Zhang */ public class DataBus { @@ -37,7 +38,7 @@ public class DataBus { /** * 这里为什么采用ConcurrentHashMap作为slot存放的容器? * 因为ConcurrentHashMap的随机取值复杂度也和数组一样为O(1),并且没有并发问题,还有自动扩容的功能 - * 用数组的话,扩容涉及copy,线程安全问题还要自己处理 + * 用数组的话,扩容涉及copy,线程安全问题还要自己处理 */ private static ConcurrentHashMap SLOTS; @@ -50,56 +51,61 @@ public class DataBus { /** * 这里原先版本中是static块,现在改成init静态方法,由FlowExecutor中的init去调用 - * 这样的改动对项目来说没有什么实际意义,但是在单元测试中,却有意义。 - * 因为单元测试中所有的一起跑,jvm是不退出的,所以如果是static块的话,跑多个testsuite只会执行一次。 + * 这样的改动对项目来说没有什么实际意义,但是在单元测试中,却有意义。 + * 因为单元测试中所有的一起跑,jvm是不退出的,所以如果是static块的话,跑多个testsuite只会执行一次。 * 而由FlowExecutor中的init去调用,是会被执行多次的。保证了每个单元测试都能初始化一遍 */ public static void init() { - if (MapUtil.isEmpty(SLOTS)){ + if (MapUtil.isEmpty(SLOTS)) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); currentIndexMaxValue = liteflowConfig.getSlotSize(); SLOTS = new ConcurrentHashMap<>(); - QUEUE = IntStream.range(0, currentIndexMaxValue).boxed().collect(Collectors.toCollection(ConcurrentLinkedQueue::new)); + QUEUE = IntStream.range(0, currentIndexMaxValue) + .boxed() + .collect(Collectors.toCollection(ConcurrentLinkedQueue::new)); } } public static int offerSlotByClass(List> contextClazzList) { - //把classList通过反射初始化成对象列表 - //这里用newInstanceIfPossible这个方法,是为了兼容当没有无参构造方法所报的错 + // 把classList通过反射初始化成对象列表 + // 这里用newInstanceIfPossible这个方法,是为了兼容当没有无参构造方法所报的错 List contextBeanList = contextClazzList.stream() - .map((Function, Object>) ReflectUtil::newInstanceIfPossible).collect(Collectors.toList()); + .map((Function, Object>) ReflectUtil::newInstanceIfPossible) + .collect(Collectors.toList()); Slot slot = new Slot(contextBeanList); return offerIndex(slot); } - public static int offerSlotByBean(List contextList){ + public static int offerSlotByBean(List contextList) { Slot slot = new Slot(contextList); return offerIndex(slot); } - private static int offerIndex(Slot slot){ + private static int offerIndex(Slot slot) { try { - //这里有没有并发问题? - //没有,因为QUEUE的类型为ConcurrentLinkedQueue,并发情况下,每次取到的index不会相同 - //当然前提是QUEUE里面的值不会重复,但是这个是由其他机制来保证的 + // 这里有没有并发问题? + // 没有,因为QUEUE的类型为ConcurrentLinkedQueue,并发情况下,每次取到的index不会相同 + // 当然前提是QUEUE里面的值不会重复,但是这个是由其他机制来保证的 Integer slotIndex = QUEUE.poll(); - if (ObjectUtil.isNull(slotIndex)){ - //只有在扩容的时候需要用到synchronized重量级锁 - //扩一次容,增强原来size的0.75,因为初始slot容量为1024,从某种层面来说,即便并发很大。但是扩容的次数不会很多。 - //因为单个机器的tps上限总归是有一个极限的,不可能无限制的增长。 - synchronized (DataBus.class){ - //在扩容的一刹那,去竞争这个锁的线程还是有一些,所以获得这个锁的线程这里要再次取一次。如果为null,再真正扩容 + if (ObjectUtil.isNull(slotIndex)) { + // 只有在扩容的时候需要用到synchronized重量级锁 + // 扩一次容,增强原来size的0.75,因为初始slot容量为1024,从某种层面来说,即便并发很大。但是扩容的次数不会很多。 + // 因为单个机器的tps上限总归是有一个极限的,不可能无限制的增长。 + synchronized (DataBus.class) { + // 在扩容的一刹那,去竞争这个锁的线程还是有一些,所以获得这个锁的线程这里要再次取一次。如果为null,再真正扩容 slotIndex = QUEUE.poll(); - if (ObjectUtil.isNull(slotIndex)){ + if (ObjectUtil.isNull(slotIndex)) { int nextMaxIndex = (int) Math.round(currentIndexMaxValue * 1.75); - QUEUE.addAll(IntStream.range(currentIndexMaxValue, nextMaxIndex).boxed().collect(Collectors.toCollection(ConcurrentLinkedQueue::new))); + QUEUE.addAll(IntStream.range(currentIndexMaxValue, nextMaxIndex) + .boxed() + .collect(Collectors.toCollection(ConcurrentLinkedQueue::new))); currentIndexMaxValue = nextMaxIndex; - //扩容好,从队列里再取出扩容好的index + // 扩容好,从队列里再取出扩容好的index slotIndex = QUEUE.poll(); } } @@ -110,33 +116,36 @@ public class DataBus { OCCUPY_COUNT.incrementAndGet(); return slotIndex; } - } catch (Exception e) { + } + catch (Exception e) { LOG.error("offer slot error", e); return -1; } return -1; } - public static Slot getSlot(int slotIndex){ + public static Slot getSlot(int slotIndex) { return SLOTS.get(slotIndex); } - public static List getContextBeanList(int slotIndex){ + public static List getContextBeanList(int slotIndex) { Slot slot = getSlot(slotIndex); return slot.getContextBeanList(); } - public static void releaseSlot(int slotIndex){ + public static void releaseSlot(int slotIndex) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - if(ObjectUtil.isNotNull(SLOTS.get(slotIndex))){ - if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())){ - LOG.info("[{}]:slot[{}] released",SLOTS.get(slotIndex).getRequestId(),slotIndex); + if (ObjectUtil.isNotNull(SLOTS.get(slotIndex))) { + if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) { + LOG.info("[{}]:slot[{}] released", SLOTS.get(slotIndex).getRequestId(), slotIndex); } SLOTS.remove(slotIndex); QUEUE.add(slotIndex); OCCUPY_COUNT.decrementAndGet(); - }else{ - LOG.warn("slot[{}] already has been released",slotIndex); + } + else { + LOG.warn("slot[{}] already has been released", slotIndex); } } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java index 8827c327..04fb8f05 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java @@ -6,31 +6,32 @@ import com.yomahub.liteflow.exception.NullParamException; import java.util.concurrent.ConcurrentHashMap; /** - * Liteflow的默认上下文Bean - * 这个建议自己去实现一个强类型的bean,正式业务不建议用这个 + * Liteflow的默认上下文Bean 这个建议自己去实现一个强类型的bean,正式业务不建议用这个 + * * @author Bryan.Zhang * @since 2.7.0 */ public class DefaultContext { - private final ConcurrentHashMap dataMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap dataMap = new ConcurrentHashMap<>(); - private void putDataMap(String key, T t) { - if (ObjectUtil.isNull(t)) { - throw new NullParamException("data can't accept null param"); - } - dataMap.put(key, t); - } + private void putDataMap(String key, T t) { + if (ObjectUtil.isNull(t)) { + throw new NullParamException("data can't accept null param"); + } + dataMap.put(key, t); + } - public boolean hasData(String key){ - return dataMap.containsKey(key); - } + public boolean hasData(String key) { + return dataMap.containsKey(key); + } - public T getData(String key){ - return (T) dataMap.get(key); - } + public T getData(String key) { + return (T) dataMap.get(key); + } + + public void setData(String key, T t) { + putDataMap(key, t); + } - public void setData(String key, T t){ - putDataMap(key, t); - } } 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 ec809684..19c90e3e 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 @@ -31,11 +31,12 @@ import java.util.concurrent.ConcurrentLinkedQueue; /** * Slot的抽象类实现 + * * @author Bryan.Zhang * @author LeoLee */ @SuppressWarnings("unchecked") -public class Slot{ +public class Slot { private static final Logger LOG = LoggerFactory.getLogger(Slot.class); @@ -88,65 +89,67 @@ public class Slot{ this.contextBeanList = contextBeanList; } - private boolean hasMetaData(String key){ + private boolean hasMetaData(String key) { return metaDataMap.containsKey(key); } - private void putThreadMetaDataMap(String key, T t){ + private void putThreadMetaDataMap(String key, T t) { String threadKey = StrUtil.format("{}_{}", key, Thread.currentThread().getName()); putMetaDataMap(threadKey, t); } - private T getThreadMetaData(String key){ + private T getThreadMetaData(String key) { String threadKey = StrUtil.format("{}_{}", key, Thread.currentThread().getName()); - return (T)metaDataMap.get(threadKey); + return (T) metaDataMap.get(threadKey); } private void putMetaDataMap(String key, T t) { if (ObjectUtil.isNull(t)) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException + // data slot is a ConcurrentHashMap, so null value will trigger + // NullPointerException throw new NullParamException("data slot can't accept null param"); } metaDataMap.put(key, t); } - public T getInput(String nodeId){ + public T getInput(String nodeId) { return (T) metaDataMap.get(NODE_INPUT_PREFIX + nodeId); } - public T getOutput(String nodeId){ + public T getOutput(String nodeId) { return (T) metaDataMap.get(NODE_OUTPUT_PREFIX + nodeId); } - public void setInput(String nodeId,T t){ + public void setInput(String nodeId, T t) { putMetaDataMap(NODE_INPUT_PREFIX + nodeId, t); } - public void setOutput(String nodeId,T t){ + public void setOutput(String nodeId, T t) { putMetaDataMap(NODE_OUTPUT_PREFIX + nodeId, t); } - public T getRequestData(){ + public T getRequestData() { return (T) metaDataMap.get(REQUEST); } - public void setRequestData(T t){ + public void setRequestData(T t) { putMetaDataMap(REQUEST, t); } - public T getResponseData(){ + public T getResponseData() { return (T) metaDataMap.get(RESPONSE); } - public void setResponseData(T t){ + public void setResponseData(T t) { putMetaDataMap(RESPONSE, t); } public T getChainReqData(String chainId) { String key = CHAIN_REQ_PREFIX + chainId; - if (hasMetaData(key)){ + if (hasMetaData(key)) { return (T) metaDataMap.get(key); - }else{ + } + else { return null; } } @@ -158,31 +161,34 @@ public class Slot{ public T getChainReqDataFromQueue(String chainId) { String key = CHAIN_REQ_PREFIX + chainId; - if (hasMetaData(key)){ + if (hasMetaData(key)) { Queue queue = (Queue) metaDataMap.get(key); - return (T)queue.poll(); - }else{ + return (T) queue.poll(); + } + else { return null; } } public synchronized void setChainReqData2Queue(String chainId, T t) { String key = CHAIN_REQ_PREFIX + chainId; - if (hasMetaData(key)){ + if (hasMetaData(key)) { Queue queue = (Queue) metaDataMap.get(key); queue.offer(t); - }else{ + } + else { putMetaDataMap(key, new ConcurrentLinkedQueue<>(ListUtil.toList(t))); } } - public void setPrivateDeliveryData(String nodeId, T t){ + public void setPrivateDeliveryData(String nodeId, T t) { String privateDKey = PRIVATE_DELIVERY_PREFIX + nodeId; - synchronized (this){ - if (metaDataMap.containsKey(privateDKey)){ + synchronized (this) { + if (metaDataMap.containsKey(privateDKey)) { Queue queue = (Queue) metaDataMap.get(privateDKey); queue.add(t); - }else{ + } + else { Queue queue = new ConcurrentLinkedQueue<>(); queue.add(t); this.putMetaDataMap(privateDKey, queue); @@ -190,76 +196,77 @@ public class Slot{ } } - public Queue getPrivateDeliveryQueue(String nodeId){ + public Queue getPrivateDeliveryQueue(String nodeId) { String privateDKey = PRIVATE_DELIVERY_PREFIX + nodeId; - if(metaDataMap.containsKey(privateDKey)){ + if (metaDataMap.containsKey(privateDKey)) { return (Queue) metaDataMap.get(privateDKey); - }else{ + } + else { return null; } } - public T getPrivateDeliveryData(String nodeId){ + public T getPrivateDeliveryData(String nodeId) { String privateDKey = PRIVATE_DELIVERY_PREFIX + nodeId; - if(metaDataMap.containsKey(privateDKey)){ + if (metaDataMap.containsKey(privateDKey)) { Queue queue = (Queue) metaDataMap.get(privateDKey); return queue.poll(); - }else{ + } + else { return null; } } - public void setSwitchResult(String key, T t){ + public void setSwitchResult(String key, T t) { putThreadMetaDataMap(SWITCH_NODE_PREFIX + key, t); } - public T getSwitchResult(String key){ + public T getSwitchResult(String key) { return getThreadMetaData(SWITCH_NODE_PREFIX + key); } - public void setIfResult(String key, boolean result){ + public void setIfResult(String key, boolean result) { putThreadMetaDataMap(IF_NODE_PREFIX + key, result); } - public boolean getIfResult(String key){ + public boolean getIfResult(String key) { return getThreadMetaData(IF_NODE_PREFIX + key); } - public void setForResult(String key, int forCount){ + public void setForResult(String key, int forCount) { putThreadMetaDataMap(FOR_PREFIX + key, forCount); } - public int getForResult(String key){ + public int getForResult(String key) { return getThreadMetaData(FOR_PREFIX + key); } - public void setWhileResult(String key, boolean whileFlag){ + public void setWhileResult(String key, boolean whileFlag) { putThreadMetaDataMap(WHILE_PREFIX + key, whileFlag); } - public boolean getWhileResult(String key){ + public boolean getWhileResult(String key) { return getThreadMetaData(WHILE_PREFIX + key); } - public void setBreakResult(String key, boolean breakFlag){ + public void setBreakResult(String key, boolean breakFlag) { putThreadMetaDataMap(BREAK_PREFIX + key, breakFlag); } - public boolean getBreakResult(String key){ + public boolean getBreakResult(String key) { return getThreadMetaData(BREAK_PREFIX + key); } - public void setIteratorResult(String key, Iterator it){ + public void setIteratorResult(String key, Iterator it) { putThreadMetaDataMap(ITERATOR_PREFIX + key, it); } - public Iterator getIteratorResult(String key){ + public Iterator getIteratorResult(String key) { return getThreadMetaData(ITERATOR_PREFIX + key); } /** - * - * @deprecated 请使用 {@link #setChainId(String)} + * @deprecated 请使用 {@link #setChainId(String)} */ @Deprecated public void setChainName(String chainName) { @@ -267,15 +274,15 @@ public class Slot{ } /** - * @deprecated 请使用 {@link #getChainId()} + * @deprecated 请使用 {@link #getChainId()} */ @Deprecated public String getChainName() { return getChainId(); } - + public void setChainId(String chainId) { - if (!hasMetaData(CHAIN_NAME)){ + if (!hasMetaData(CHAIN_NAME)) { this.putMetaDataMap(CHAIN_NAME, chainId); } } @@ -284,21 +291,22 @@ public class Slot{ return (String) metaDataMap.get(CHAIN_NAME); } - public void addStep(CmpStep step){ + public void addStep(CmpStep step) { this.executeSteps.add(step); } - public String getExecuteStepStr(boolean withTimeSpent){ + public String getExecuteStepStr(boolean withTimeSpent) { StringBuilder str = new StringBuilder(); CmpStep cmpStep; for (Iterator it = executeSteps.iterator(); it.hasNext();) { cmpStep = it.next(); - if (withTimeSpent){ + if (withTimeSpent) { str.append(cmpStep.buildStringWithTime()); - }else{ + } + else { str.append(cmpStep.buildString()); } - if(it.hasNext()){ + if (it.hasNext()) { str.append("==>"); } } @@ -306,16 +314,16 @@ public class Slot{ return this.executeStepsStr; } - public String getExecuteStepStr(){ + public String getExecuteStepStr() { return getExecuteStepStr(false); } - public void printStep(){ - if (ObjectUtil.isNull(this.executeStepsStr)){ + public void printStep() { + if (ObjectUtil.isNull(this.executeStepsStr)) { this.executeStepsStr = getExecuteStepStr(true); } - if (LiteflowConfigGetter.get().getPrintExecutionLog()){ - LOG.info("[{}]:CHAIN_NAME[{}]\n{}",getRequestId(),this.getChainName(), this.executeStepsStr); + if (LiteflowConfigGetter.get().getPrintExecutionLog()) { + LOG.info("[{}]:CHAIN_NAME[{}]\n{}", getRequestId(), this.getChainName(), this.executeStepsStr); } } @@ -339,7 +347,7 @@ public class Slot{ putMetaDataMap(EXCEPTION, e); } - public void removeException(){ + public void removeException() { metaDataMap.remove(EXCEPTION); } @@ -351,39 +359,41 @@ public class Slot{ putMetaDataMap(SUB_EXCEPTION_PREFIX + chainId, e); } - public void removeSubException(String chainId){ + public void removeSubException(String chainId) { 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().equals(contextBeanClazz)).findFirst().orElse(null); - if (t == null){ + T t = (T) contextBeanList.stream().filter(o -> o.getClass().equals(contextBeanClazz)).findFirst().orElse(null); + if (t == null) { throw new NoSuchContextBeanException("this type is not in the context type passed in"); } return t; } - public T getFirstContextBean(){ + public T getFirstContextBean() { Class firstContextBeanClazz = (Class) this.getContextBeanList().get(0).getClass(); return this.getContextBean(firstContextBeanClazz); } - public void addSubChain(String chainId){ + public void addSubChain(String chainId) { Set subChainSet = (Set) metaDataMap.getOrDefault(SUB_CHAIN, new ConcurrentHashSet<>()); subChainSet.add(chainId); metaDataMap.putIfAbsent(SUB_CHAIN, subChainSet); } - public boolean isSubChain(String chainId){ - if (metaDataMap.containsKey(SUB_CHAIN)){ + public boolean isSubChain(String chainId) { + if (metaDataMap.containsKey(SUB_CHAIN)) { Set subChainSet = (Set) metaDataMap.get(SUB_CHAIN); return subChainSet.contains(chainId); - }else{ + } + else { return false; } } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/CmpAroundAspect.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/CmpAroundAspect.java index 5b8d1fa4..a89664d8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/CmpAroundAspect.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/CmpAroundAspect.java @@ -4,12 +4,14 @@ import com.yomahub.liteflow.slot.Slot; /** * 组件全局切面spi接口 + * * @author Bryan.Zhang * @since 2.6.11 */ public interface CmpAroundAspect extends SpiPriority { - void beforeProcess(String nodeId, Slot slot); + void beforeProcess(String nodeId, Slot slot); + + void afterProcess(String nodeId, Slot slot); - void afterProcess(String nodeId, Slot slot); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java index aec429f5..ea819742 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java @@ -8,17 +8,18 @@ package com.yomahub.liteflow.spi; */ public interface ContextAware extends SpiPriority { - T getBean(String name); + T getBean(String name); - T getBean(Class clazz); + T getBean(Class clazz); - T registerBean(String beanName, Class clazz); + T registerBean(String beanName, Class clazz); - T registerBean(Class clazz); + T registerBean(Class clazz); - T registerBean(String beanName, Object bean); + T registerBean(String beanName, Object bean); - T registerOrGet(String beanName, Class clazz); + T registerOrGet(String beanName, Class clazz); + + boolean hasBean(String beanName); - boolean hasBean(String beanName); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextCmpInit.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextCmpInit.java index 0c82bb8d..ba27b427 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextCmpInit.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextCmpInit.java @@ -1,13 +1,13 @@ package com.yomahub.liteflow.spi; /** - * 环境容器中组件初始化SPI接口 - * 分2个,非spring环境下的实现和spring体系下的实现 + * 环境容器中组件初始化SPI接口 分2个,非spring环境下的实现和spring体系下的实现 * * @author Bryan.Zhang * @since 2.6.11 */ public interface ContextCmpInit extends SpiPriority { - void initCmp(); + void initCmp(); + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java index da379025..da659f12 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/LiteflowComponentSupport.java @@ -10,6 +10,6 @@ import com.yomahub.liteflow.core.NodeComponent; */ public interface LiteflowComponentSupport extends SpiPriority { - String getCmpName(NodeComponent nodeComponent); + String getCmpName(NodeComponent nodeComponent); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java index c39b4f74..f5ab6ee7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/PathContentParser.java @@ -4,21 +4,22 @@ import java.util.List; public interface PathContentParser extends SpiPriority { - /** - * 解析路径下的文件内容 - * - * @param pathList 文件路径(支持 classpath 路径和 file 绝对路径,spring 环境支持 PathMatchingResourcePatternResolver 规则) - * @return 返回文件内容 - * @throws Exception ex - */ - List parseContent(List pathList) throws Exception; + /** + * 解析路径下的文件内容 + * @param pathList 文件路径(支持 classpath 路径和 file 绝对路径,spring 环境支持 + * PathMatchingResourcePatternResolver 规则) + * @return 返回文件内容 + * @throws Exception ex + */ + List parseContent(List pathList) throws Exception; + + /** + * 获取文件路径的绝对路径 + * @param pathList 文件路径(支持 classpath 路径和 file 绝对路径,spring 环境支持 + * PathMatchingResourcePatternResolver 规则) + * @return 返回文件绝对路径 + * @throws Exception ex + */ + List getFileAbsolutePath(List pathList) throws Exception; - /** - * 获取文件路径的绝对路径 - * - * @param pathList 文件路径(支持 classpath 路径和 file 绝对路径,spring 环境支持 PathMatchingResourcePatternResolver 规则) - * @return 返回文件绝对路径 - * @throws Exception ex - */ - List getFileAbsolutePath(List pathList) throws Exception; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/SpiPriority.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/SpiPriority.java index 5a165d26..c822aef9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/SpiPriority.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/SpiPriority.java @@ -1,12 +1,13 @@ package com.yomahub.liteflow.spi; /** - * Spi实现的优先级接口 - * 数字越小优先级越高 + * Spi实现的优先级接口 数字越小优先级越高 + * * @author Bryan.Zhang * @since 2.6.11 */ public interface SpiPriority { - int priority(); + int priority(); + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/CmpAroundAspectHolder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/CmpAroundAspectHolder.java index 47cb549c..e19a6eaa 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/CmpAroundAspectHolder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/CmpAroundAspectHolder.java @@ -10,24 +10,26 @@ import java.util.ServiceLoader; /** * 组件全局拦截器SPI工厂类 + * * @author Bryan.Zhang * @since 2.6.11 */ public class CmpAroundAspectHolder { - private static CmpAroundAspect cmpAroundAspect; + private static CmpAroundAspect cmpAroundAspect; - public static CmpAroundAspect loadCmpAroundAspect(){ - if (ObjectUtil.isNull(cmpAroundAspect)){ - List list = new ArrayList<>(); - ServiceLoader.load(CmpAroundAspect.class).forEach(list::add); - list.sort(Comparator.comparingInt(CmpAroundAspect::priority)); - cmpAroundAspect = list.get(0); - } - return cmpAroundAspect; - } + public static CmpAroundAspect loadCmpAroundAspect() { + if (ObjectUtil.isNull(cmpAroundAspect)) { + List list = new ArrayList<>(); + ServiceLoader.load(CmpAroundAspect.class).forEach(list::add); + list.sort(Comparator.comparingInt(CmpAroundAspect::priority)); + cmpAroundAspect = list.get(0); + } + return cmpAroundAspect; + } + + public static void clean() { + cmpAroundAspect = null; + } - public static void clean(){ - cmpAroundAspect = null; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextAwareHolder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextAwareHolder.java index 85258ebc..d7f9498c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextAwareHolder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextAwareHolder.java @@ -9,26 +9,27 @@ import java.util.List; import java.util.ServiceLoader; /** - * 环境容器SPI工厂类 - * 在spring体系下会获得spring的上下文包装实现 + * 环境容器SPI工厂类 在spring体系下会获得spring的上下文包装实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class ContextAwareHolder { - private static ContextAware contextAware; + private static ContextAware contextAware; - public static ContextAware loadContextAware(){ - if (ObjectUtil.isNull(contextAware)){ - List list = new ArrayList<>(); - ServiceLoader.load(ContextAware.class).forEach(list::add); - list.sort(Comparator.comparingInt(ContextAware::priority)); - contextAware = list.get(0); - } - return contextAware; - } + public static ContextAware loadContextAware() { + if (ObjectUtil.isNull(contextAware)) { + List list = new ArrayList<>(); + ServiceLoader.load(ContextAware.class).forEach(list::add); + list.sort(Comparator.comparingInt(ContextAware::priority)); + contextAware = list.get(0); + } + return contextAware; + } + + public static void clean() { + contextAware = null; + } - public static void clean(){ - contextAware = null; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextCmpInitHolder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextCmpInitHolder.java index ec10eab1..c386099a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextCmpInitHolder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/ContextCmpInitHolder.java @@ -8,26 +8,27 @@ import java.util.List; import java.util.ServiceLoader; /** - * 环境组件初始化SPI工厂类 - * 在spring体系下会获得基于spring扫描的组件初始化实现器 + * 环境组件初始化SPI工厂类 在spring体系下会获得基于spring扫描的组件初始化实现器 + * * @author Bryan.Zhang * @since 2.6.11 */ public class ContextCmpInitHolder { - private static ContextCmpInit contextCmpInit; + private static ContextCmpInit contextCmpInit; - public static ContextCmpInit loadContextCmpInit(){ - if (ObjectUtil.isNull(contextCmpInit)){ - List list = new ArrayList<>(); - ServiceLoader.load(ContextCmpInit.class).forEach(list::add); - list.sort(Comparator.comparingInt(ContextCmpInit::priority)); - contextCmpInit = list.get(0); - } - return contextCmpInit; - } + public static ContextCmpInit loadContextCmpInit() { + if (ObjectUtil.isNull(contextCmpInit)) { + List list = new ArrayList<>(); + ServiceLoader.load(ContextCmpInit.class).forEach(list::add); + list.sort(Comparator.comparingInt(ContextCmpInit::priority)); + contextCmpInit = list.get(0); + } + return contextCmpInit; + } + + public static void clean() { + contextCmpInit = null; + } - public static void clean(){ - contextCmpInit = null; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/LiteflowComponentSupportHolder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/LiteflowComponentSupportHolder.java index 7bcd4b73..e6c0d7a4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/LiteflowComponentSupportHolder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/LiteflowComponentSupportHolder.java @@ -9,24 +9,26 @@ import java.util.ServiceLoader; /** * liteflowComponent的支持扩展SPI工厂类 + * * @author Bryan.Zhang * @since 2.6.11 */ public class LiteflowComponentSupportHolder { - private static LiteflowComponentSupport liteflowComponentSupport; + private static LiteflowComponentSupport liteflowComponentSupport; - public static LiteflowComponentSupport loadLiteflowComponentSupport(){ - if (ObjectUtil.isNull(liteflowComponentSupport)){ - List list = new ArrayList<>(); - ServiceLoader.load(LiteflowComponentSupport.class).forEach(list::add); - list.sort(Comparator.comparingInt(LiteflowComponentSupport::priority)); - liteflowComponentSupport = list.get(0); - } - return liteflowComponentSupport; - } + public static LiteflowComponentSupport loadLiteflowComponentSupport() { + if (ObjectUtil.isNull(liteflowComponentSupport)) { + List list = new ArrayList<>(); + ServiceLoader.load(LiteflowComponentSupport.class).forEach(list::add); + list.sort(Comparator.comparingInt(LiteflowComponentSupport::priority)); + liteflowComponentSupport = list.get(0); + } + return liteflowComponentSupport; + } + + public static void clean() { + liteflowComponentSupport = null; + } - public static void clean(){ - liteflowComponentSupport = null; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/PathContentParserHolder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/PathContentParserHolder.java index 1b89d2dc..4c2fcc86 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/PathContentParserHolder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/PathContentParserHolder.java @@ -10,21 +10,20 @@ import java.util.ServiceLoader; public class PathContentParserHolder { - private static PathContentParser pathContentParser; + private static PathContentParser pathContentParser; - public static PathContentParser loadContextAware(){ - if (ObjectUtil.isNull(pathContentParser)){ - List list = new ArrayList<>(); - ServiceLoader.load(PathContentParser.class).forEach(list::add); - list.sort(Comparator.comparingInt(PathContentParser::priority)); - pathContentParser = list.get(0); - } - return pathContentParser; - } + public static PathContentParser loadContextAware() { + if (ObjectUtil.isNull(pathContentParser)) { + List list = new ArrayList<>(); + ServiceLoader.load(PathContentParser.class).forEach(list::add); + list.sort(Comparator.comparingInt(PathContentParser::priority)); + pathContentParser = list.get(0); + } + return pathContentParser; + } + + public static void clean() { + pathContentParser = null; + } - public static void clean(){ - pathContentParser = null; - } } - - diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/SpiFactoryCleaner.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/SpiFactoryCleaner.java index 2ab921a3..585f5a63 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/SpiFactoryCleaner.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/holder/SpiFactoryCleaner.java @@ -2,11 +2,12 @@ package com.yomahub.liteflow.spi.holder; public class SpiFactoryCleaner { - public static void clean(){ - CmpAroundAspectHolder.clean(); - ContextAwareHolder.clean(); - ContextCmpInitHolder.clean(); - LiteflowComponentSupportHolder.clean(); - PathContentParserHolder.clean(); - } + public static void clean() { + CmpAroundAspectHolder.clean(); + ContextAwareHolder.clean(); + ContextCmpInitHolder.clean(); + LiteflowComponentSupportHolder.clean(); + PathContentParserHolder.clean(); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalCmpAroundAspect.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalCmpAroundAspect.java index cdc879bb..598c971d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalCmpAroundAspect.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalCmpAroundAspect.java @@ -4,24 +4,26 @@ import com.yomahub.liteflow.slot.Slot; import com.yomahub.liteflow.spi.CmpAroundAspect; /** - * 非Spring环境全局组件切面实现 - * 其实非Spring不支持全局组件切面,所以这个是个空实现 + * 非Spring环境全局组件切面实现 其实非Spring不支持全局组件切面,所以这个是个空实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class LocalCmpAroundAspect implements CmpAroundAspect { - @Override - public void beforeProcess(String nodeId, Slot slot) { - //无spring环境下为空实现 - } - @Override - public void afterProcess(String nodeId, Slot slot) { - //无spring环境下为空实现 - } + @Override + public void beforeProcess(String nodeId, Slot slot) { + // 无spring环境下为空实现 + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + // 无spring环境下为空实现 + } + + @Override + public int priority() { + return 2; + } - @Override - public int priority() { - return 2; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java index d6d53077..63d3cc80 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java @@ -4,49 +4,51 @@ import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.spi.ContextAware; /** - * 非Spring环境容器实现 - * 其实非Spring没有环境容器,所以这是个空实现 + * 非Spring环境容器实现 其实非Spring没有环境容器,所以这是个空实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class LocalContextAware implements ContextAware { - @Override - public T getBean(String name) { - return null; - } - @Override - public T getBean(Class clazz) { - return null; - } + @Override + public T getBean(String name) { + return null; + } - @Override - public T registerBean(String beanName, Class clazz) { - return ReflectUtil.newInstance(clazz); - } + @Override + public T getBean(Class clazz) { + return null; + } - @Override - public T registerBean(Class clazz) { - return registerBean(null, clazz); - } + @Override + public T registerBean(String beanName, Class clazz) { + return ReflectUtil.newInstance(clazz); + } - @Override - public T registerBean(String beanName, Object bean) { - return (T)bean; - } + @Override + public T registerBean(Class clazz) { + return registerBean(null, clazz); + } - @Override - public T registerOrGet(String beanName, Class clazz) { - return registerBean(beanName, clazz); - } + @Override + public T registerBean(String beanName, Object bean) { + return (T) bean; + } - @Override - public boolean hasBean(String beanName) { - return false; - } + @Override + public T registerOrGet(String beanName, Class clazz) { + return registerBean(beanName, clazz); + } + + @Override + public boolean hasBean(String beanName) { + return false; + } + + @Override + public int priority() { + return 2; + } - @Override - public int priority() { - return 2; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextCmpInit.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextCmpInit.java index e7337fd9..6380a86e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextCmpInit.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextCmpInit.java @@ -3,19 +3,21 @@ package com.yomahub.liteflow.spi.local; import com.yomahub.liteflow.spi.ContextCmpInit; /** - * 非Spring环境容器上下文组件初始化实现 - * 其实非Spring没有环境容器,所以这是个空实现 + * 非Spring环境容器上下文组件初始化实现 其实非Spring没有环境容器,所以这是个空实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class LocalContextCmpInit implements ContextCmpInit { - @Override - public void initCmp() { - //非spring环境不用实现 - } - @Override - public int priority() { - return 2; - } + @Override + public void initCmp() { + // 非spring环境不用实现 + } + + @Override + public int priority() { + return 2; + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java index 30e65324..74426e82 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalLiteflowComponentSupport.java @@ -4,19 +4,21 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.spi.LiteflowComponentSupport; /** - * 非spring环境LiteflowComponent注解的处理器 - * 非spring环境不支持@LiteflowComponent注解,所以返回null + * 非spring环境LiteflowComponent注解的处理器 非spring环境不支持@LiteflowComponent注解,所以返回null + * * @author Bryan.Zhang * @since 2.6.11 */ public class LocalLiteflowComponentSupport implements LiteflowComponentSupport { - @Override - public String getCmpName(NodeComponent nodeComponent) { - return null; - } - @Override - public int priority() { - return 2; - } + @Override + public String getCmpName(NodeComponent nodeComponent) { + return null; + } + + @Override + public int priority() { + return 2; + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java index d8d34d5a..e750468d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalPathContentParser.java @@ -15,64 +15,67 @@ import java.util.List; public class LocalPathContentParser implements PathContentParser { - private final static String FILE_URL_PREFIX = "file:"; + private final static String FILE_URL_PREFIX = "file:"; - private final static String CLASSPATH_URL_PREFIX = "classpath:"; + private final static String CLASSPATH_URL_PREFIX = "classpath:"; - @Override - public List parseContent(List pathList) throws Exception { - if (CollectionUtil.isEmpty(pathList)) { - throw new ConfigErrorException("rule source must not be null"); - } + @Override + public List parseContent(List pathList) throws Exception { + if (CollectionUtil.isEmpty(pathList)) { + throw new ConfigErrorException("rule source must not be null"); + } - List contentList = new ArrayList<>(); + List contentList = new ArrayList<>(); - for (String path : pathList) { - if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { - path = FILE_URL_PREFIX + path; - } else { - if (!path.startsWith(CLASSPATH_URL_PREFIX)) { - path = CLASSPATH_URL_PREFIX + path; - } - } - String content = ResourceUtil.readUtf8Str(path); - if (StrUtil.isNotBlank(content)) { - contentList.add(content); - } - } + for (String path : pathList) { + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { + path = FILE_URL_PREFIX + path; + } + else { + if (!path.startsWith(CLASSPATH_URL_PREFIX)) { + path = CLASSPATH_URL_PREFIX + path; + } + } + String content = ResourceUtil.readUtf8Str(path); + if (StrUtil.isNotBlank(content)) { + contentList.add(content); + } + } - return contentList; - } + return contentList; + } - @Override - public List getFileAbsolutePath(List pathList) throws Exception { - if (CollectionUtil.isEmpty(pathList)) { - throw new ConfigErrorException("rule source must not be null"); - } + @Override + public List getFileAbsolutePath(List pathList) throws Exception { + if (CollectionUtil.isEmpty(pathList)) { + throw new ConfigErrorException("rule source must not be null"); + } - List result = new ArrayList<>(); + List result = new ArrayList<>(); - for (String path : pathList) { - if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { - path = FILE_URL_PREFIX + path; - result.add(new FileResource(path).getFile().getAbsolutePath()); - } else { - if (!path.startsWith(CLASSPATH_URL_PREFIX)) { - path = CLASSPATH_URL_PREFIX + path; + for (String path : pathList) { + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { + path = FILE_URL_PREFIX + path; + result.add(new FileResource(path).getFile().getAbsolutePath()); + } + else { + if (!path.startsWith(CLASSPATH_URL_PREFIX)) { + path = CLASSPATH_URL_PREFIX + path; - // 这里会有自定义解析器 - if(ClassLoaderUtil.isPresent(path)){ - result.add(new ClassPathResource(path).getAbsolutePath()); - } - } - } - } + // 这里会有自定义解析器 + if (ClassLoaderUtil.isPresent(path)) { + result.add(new ClassPathResource(path).getAbsolutePath()); + } + } + } + } - return result; - } + return result; + } + + @Override + public int priority() { + return 2; + } - @Override - public int priority() { - return 2; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java index 6349f7b0..0fa98c01 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorBuilder.java @@ -13,25 +13,23 @@ import java.util.concurrent.atomic.AtomicLong; */ public interface ExecutorBuilder { - ExecutorService buildExecutor(); + ExecutorService buildExecutor(); - //构建默认的线程池对象 - default ExecutorService buildDefaultExecutor(int corePoolSize, int maximumPoolSize, int queueCapacity, String threadName) { - return TtlExecutors.getTtlExecutorService(new ThreadPoolExecutor(corePoolSize, - maximumPoolSize, - 0L, TimeUnit.MILLISECONDS, - new ArrayBlockingQueue<>(queueCapacity), - new ThreadFactory() { - private final AtomicLong number = new AtomicLong(); + // 构建默认的线程池对象 + default ExecutorService buildDefaultExecutor(int corePoolSize, int maximumPoolSize, int queueCapacity, + String threadName) { + return TtlExecutors.getTtlExecutorService(new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 0L, + TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(queueCapacity), new ThreadFactory() { + private final AtomicLong number = new AtomicLong(); + + @Override + public Thread newThread(Runnable r) { + Thread newThread = Executors.defaultThreadFactory().newThread(r); + newThread.setName(threadName + number.getAndIncrement()); + newThread.setDaemon(false); + return newThread; + } + }, new ThreadPoolExecutor.AbortPolicy())); + } - @Override - public Thread newThread(Runnable r) { - Thread newThread = Executors.defaultThreadFactory().newThread(r); - newThread.setName(threadName + number.getAndIncrement()); - newThread.setDaemon(false); - return newThread; - } - }, - new ThreadPoolExecutor.AbortPolicy())); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index 78e90582..f168b794 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory; import java.util.Map; import java.util.concurrent.*; - /** * 线程池工具类 * @@ -29,115 +28,116 @@ import java.util.concurrent.*; */ public class ExecutorHelper { - private final Logger LOG = LoggerFactory.getLogger(ExecutorHelper.class); + private final Logger LOG = LoggerFactory.getLogger(ExecutorHelper.class); - /** - * 此处使用Map缓存线程池信息 - * key - 线程池构建者的Class全类名 - * value - 线程池对象 - */ - private final Map executorServiceMap; + /** + * 此处使用Map缓存线程池信息 key - 线程池构建者的Class全类名 value - 线程池对象 + */ + private final Map executorServiceMap; - private ExecutorHelper() { - executorServiceMap = MapUtil.newConcurrentHashMap(); - } + private ExecutorHelper() { + executorServiceMap = MapUtil.newConcurrentHashMap(); + } - /** - * 使用静态内部类实现单例模式 - */ - private static class Holder { - static final ExecutorHelper INSTANCE = new ExecutorHelper(); - } + /** + * 使用静态内部类实现单例模式 + */ + private static class Holder { - public static ExecutorHelper loadInstance() { - return Holder.INSTANCE; - } + static final ExecutorHelper INSTANCE = new ExecutorHelper(); - /** - * - *

- * - * @param pool 需要关闭的线程组. - */ - public void shutdownAwaitTermination(ExecutorService pool) { - shutdownAwaitTermination(pool, 60L); - } + } - /** - *

- * 关闭ExecutorService的线程管理者 - *

- * - * @param pool 需要关闭的管理者 - * @param timeout 等待时间 - */ - public void shutdownAwaitTermination(ExecutorService pool, - long timeout) { - pool.shutdown(); - try { - if (!pool.awaitTermination(timeout, TimeUnit.SECONDS)) { - pool.shutdownNow(); - if (!pool.awaitTermination(timeout, TimeUnit.SECONDS)) { - LOG.error("Pool did not terminate."); - } - } - } catch (InterruptedException ie) { - pool.shutdownNow(); - Thread.currentThread().interrupt(); - } - } + public static ExecutorHelper loadInstance() { + return Holder.INSTANCE; + } - //构建默认when线程池 - public ExecutorService buildWhenExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildWhenExecutor(liteflowConfig.getThreadExecutorClass()); - } + /** + * + *

+ * @param pool 需要关闭的线程组. + */ + public void shutdownAwaitTermination(ExecutorService pool) { + shutdownAwaitTermination(pool, 60L); + } - //构建when线程池 - 支持多个when公用一个线程池 - public ExecutorService buildWhenExecutor(String clazz) { - if (StrUtil.isBlank(clazz)) { - return buildWhenExecutor(); - } - return getExecutorService(clazz); - } + /** + *

+ * 关闭ExecutorService的线程管理者 + *

+ * @param pool 需要关闭的管理者 + * @param timeout 等待时间 + */ + public void shutdownAwaitTermination(ExecutorService pool, long timeout) { + pool.shutdown(); + try { + if (!pool.awaitTermination(timeout, TimeUnit.SECONDS)) { + pool.shutdownNow(); + if (!pool.awaitTermination(timeout, TimeUnit.SECONDS)) { + LOG.error("Pool did not terminate."); + } + } + } + catch (InterruptedException ie) { + pool.shutdownNow(); + Thread.currentThread().interrupt(); + } + } - //构建默认的FlowExecutor线程池,用于execute2Future方法 - public ExecutorService buildMainExecutor(){ - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildMainExecutor(liteflowConfig.getMainExecutorClass()); - } + // 构建默认when线程池 + public ExecutorService buildWhenExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + return buildWhenExecutor(liteflowConfig.getThreadExecutorClass()); + } - public ExecutorService buildMainExecutor(String clazz){ - if (StrUtil.isBlank(clazz)) { - return buildMainExecutor(); - } - return getExecutorService(clazz); - } + // 构建when线程池 - 支持多个when公用一个线程池 + public ExecutorService buildWhenExecutor(String clazz) { + if (StrUtil.isBlank(clazz)) { + return buildWhenExecutor(); + } + return getExecutorService(clazz); + } - /** - * 根据线程执行构建者Class类名获取ExecutorService实例 - */ - private ExecutorService getExecutorService(String clazz) { - try{ - ExecutorService executorServiceFromCache = executorServiceMap.get(clazz); - if (ObjectUtil.isNotNull(executorServiceFromCache)) { - return executorServiceFromCache; - } else { - Class executorClass = (Class) Class.forName(clazz); - ExecutorBuilder executorBuilder = ContextAwareHolder.loadContextAware().registerBean(executorClass); - ExecutorService executorService = executorBuilder.buildExecutor(); - executorServiceMap.put(clazz, executorService); - return executorService; - } - }catch (Exception e){ - LOG.error(e.getMessage()); - throw new ThreadExecutorServiceCreateException(e.getMessage()); - } - } + // 构建默认的FlowExecutor线程池,用于execute2Future方法 + public ExecutorService buildMainExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + return buildMainExecutor(liteflowConfig.getMainExecutorClass()); + } + + public ExecutorService buildMainExecutor(String clazz) { + if (StrUtil.isBlank(clazz)) { + return buildMainExecutor(); + } + return getExecutorService(clazz); + } + + /** + * 根据线程执行构建者Class类名获取ExecutorService实例 + */ + private ExecutorService getExecutorService(String clazz) { + try { + ExecutorService executorServiceFromCache = executorServiceMap.get(clazz); + if (ObjectUtil.isNotNull(executorServiceFromCache)) { + return executorServiceFromCache; + } + else { + Class executorClass = (Class) Class.forName(clazz); + ExecutorBuilder executorBuilder = ContextAwareHolder.loadContextAware().registerBean(executorClass); + ExecutorService executorService = executorBuilder.buildExecutor(); + executorServiceMap.put(clazz, executorService); + return executorService; + } + } + catch (Exception e) { + LOG.error(e.getMessage()); + throw new ThreadExecutorServiceCreateException(e.getMessage()); + } + } + + public void clearExecutorServiceMap() { + if (MapUtil.isNotEmpty(executorServiceMap)) { + executorServiceMap.clear(); + } + } - public void clearExecutorServiceMap(){ - if (MapUtil.isNotEmpty(executorServiceMap)){ - executorServiceMap.clear(); - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultMainExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultMainExecutorBuilder.java index 80d75c44..0ce216ce 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultMainExecutorBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultMainExecutorBuilder.java @@ -8,20 +8,20 @@ import java.util.concurrent.ExecutorService; /** * LiteFlow 默认主执行器生成器 + * * @author Yun */ -public class LiteFlowDefaultMainExecutorBuilder implements ExecutorBuilder{ - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)){ - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getMainExecutorWorks(), - liteflowConfig.getMainExecutorWorks(), - 200, - "lf-main-thead-"); - } +public class LiteFlowDefaultMainExecutorBuilder implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getMainExecutorWorks(), liteflowConfig.getMainExecutorWorks(), 200, + "lf-main-thead-"); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java index 1cf54642..8ae444c0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java @@ -8,21 +8,21 @@ import java.util.concurrent.*; /** * LiteFlow默认的并行多线程执行器实现 + * * @author Bryan.Zhang * @since 2.6.6 */ -public class LiteFlowDefaultWhenExecutorBuilder implements ExecutorBuilder{ - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)){ - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "lf-when-thead-"); - } +public class LiteFlowDefaultWhenExecutorBuilder implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "lf-when-thead-"); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/BoundedPriorityBlockingQueue.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/BoundedPriorityBlockingQueue.java index ff624e62..62e89afc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/BoundedPriorityBlockingQueue.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/BoundedPriorityBlockingQueue.java @@ -5,77 +5,80 @@ import java.util.concurrent.PriorityBlockingQueue; public class BoundedPriorityBlockingQueue extends PriorityBlockingQueue { - private static final long serialVersionUID = -1; + private static final long serialVersionUID = -1; - //容量 - private final int capacity; - private final Comparator comparator; + // 容量 + private final int capacity; - public BoundedPriorityBlockingQueue(int capacity) { - this(capacity, null); - } + private final Comparator comparator; - /** - * 构造 - * @param capacity 容量 - * @param comparator 比较器 - */ - public BoundedPriorityBlockingQueue(int capacity, final Comparator comparator) { - super(capacity, (o1, o2) -> { - int cResult; - if(comparator != null) { - cResult = comparator.compare(o1, o2); - }else { - @SuppressWarnings("unchecked") - Comparable o1c = (Comparable)o1; - cResult = o1c.compareTo(o2); - } + public BoundedPriorityBlockingQueue(int capacity) { + this(capacity, null); + } - return - cResult; - }); - this.capacity = capacity; - this.comparator = comparator; - } + /** + * 构造 + * @param capacity 容量 + * @param comparator 比较器 + */ + public BoundedPriorityBlockingQueue(int capacity, final Comparator comparator) { + super(capacity, (o1, o2) -> { + int cResult; + if (comparator != null) { + cResult = comparator.compare(o1, o2); + } + else { + @SuppressWarnings("unchecked") + Comparable o1c = (Comparable) o1; + cResult = o1c.compareTo(o2); + } - /** - * 加入元素,当队列满时,淘汰末尾元素 - * @param e 元素 - * @return 加入成功与否 - */ - @Override - public boolean offer(E e) { - if(size() >= capacity) { - E head = peek(); - if (this.comparator().compare(e, head) <= 0){ - return true; - } - //当队列满时,就要淘汰顶端队列 - poll(); - } - return super.offer(e); - } + return -cResult; + }); + this.capacity = capacity; + this.comparator = comparator; + } - /** - * 添加多个元素
- * 参数为集合的情况请使用{@link PriorityQueue#addAll} - * @param c 元素数组 - * @return 是否发生改变 - */ - public boolean addAll(E[] c) { - return this.addAll(Arrays.asList(c)); - } + /** + * 加入元素,当队列满时,淘汰末尾元素 + * @param e 元素 + * @return 加入成功与否 + */ + @Override + public boolean offer(E e) { + if (size() >= capacity) { + E head = peek(); + if (this.comparator().compare(e, head) <= 0) { + return true; + } + // 当队列满时,就要淘汰顶端队列 + poll(); + } + return super.offer(e); + } - /** - * @return 返回排序后的列表 - */ - public ArrayList toList() { - final ArrayList list = new ArrayList<>(this); - list.sort(comparator); - return list; - } + /** + * 添加多个元素
+ * 参数为集合的情况请使用{@link PriorityQueue#addAll} + * @param c 元素数组 + * @return 是否发生改变 + */ + public boolean addAll(E[] c) { + return this.addAll(Arrays.asList(c)); + } + + /** + * @return 返回排序后的列表 + */ + public ArrayList toList() { + final ArrayList list = new ArrayList<>(this); + list.sort(comparator); + return list; + } + + @Override + public Iterator iterator() { + return toList().iterator(); + } - @Override - public Iterator iterator() { - return toList().iterator(); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/CopyOnWriteHashMap.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/CopyOnWriteHashMap.java index e24dc4bf..afc34b6e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/CopyOnWriteHashMap.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/CopyOnWriteHashMap.java @@ -52,133 +52,134 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * A basic copy on write HashMap. *

- * If an instance is cloned then any methods invoked on the instance or clone - * that result in state modification will result in copying of the state - * before modification. + * If an instance is cloned then any methods invoked on the instance or clone that result + * in state modification will result in copying of the state before modification. * * @author Paul.Sandoz@Oracle.Com * @author pavel.bucek@oracle.com * @author Bryan.Zhang */ -public class CopyOnWriteHashMap extends ConcurrentHashMap { +public class CopyOnWriteHashMap extends ConcurrentHashMap { - volatile ConcurrentHashMap view; + volatile ConcurrentHashMap view; - private ConcurrentHashMap duplicate(ConcurrentHashMap original) { - // SUBTLETY: note that original.entrySet() grabs the entire contents of the original Map in a - // single call. This means that if the original map is Thread-safe or another CopyOnWriteHashMap, - // we can safely iterate over the list of entries. - return new ConcurrentHashMap<>(original); - } + private ConcurrentHashMap duplicate(ConcurrentHashMap original) { + // SUBTLETY: note that original.entrySet() grabs the entire contents of the + // original Map in a + // single call. This means that if the original map is Thread-safe or another + // CopyOnWriteHashMap, + // we can safely iterate over the list of entries. + return new ConcurrentHashMap<>(original); + } - public CopyOnWriteHashMap(ConcurrentHashMap that) { - this.view = duplicate(that); - } + public CopyOnWriteHashMap(ConcurrentHashMap that) { + this.view = duplicate(that); + } - public CopyOnWriteHashMap() { - this(new ConcurrentHashMap<>()); - } + public CopyOnWriteHashMap() { + this(new ConcurrentHashMap<>()); + } - @Override - public CopyOnWriteHashMap clone() { - return new CopyOnWriteHashMap(view); - } + @Override + public CopyOnWriteHashMap clone() { + return new CopyOnWriteHashMap(view); + } - /* ********************** - * READ-ONLY OPERATIONS - * **********************/ + /* + * ********************** READ-ONLY OPERATIONS + **********************/ - @Override - public int size() { - return view.size(); - } + @Override + public int size() { + return view.size(); + } - @Override - public boolean isEmpty() { - return view.isEmpty(); - } + @Override + public boolean isEmpty() { + return view.isEmpty(); + } - @Override - public boolean containsKey(Object key) { - return view.containsKey(key); - } + @Override + public boolean containsKey(Object key) { + return view.containsKey(key); + } - @Override - public boolean containsValue(Object value) { - return view.containsValue(value); - } + @Override + public boolean containsValue(Object value) { + return view.containsValue(value); + } - @Override - public V get(Object key) { - return view.get(key); - } + @Override + public V get(Object key) { + return view.get(key); + } - @Override - public KeySetView keySet() { - return view.keySet(); - } + @Override + public KeySetView keySet() { + return view.keySet(); + } - @Override - public Collection values() { - return view.values(); - } + @Override + public Collection values() { + return view.values(); + } - @Override - public Set> entrySet() { - return view.entrySet(); - } + @Override + public Set> entrySet() { + return view.entrySet(); + } - @Override - public String toString() { - return view.toString(); - } + @Override + public String toString() { + return view.toString(); + } - /* ********************** - * UPDATING OPERATIONS - * - * These operations all follow a common pattern: - * - * 1. Create a copy of the existing view. - * 2. Update the copy. - * 3. Perform a volatile write to replace the existing view. - * - * Note that if you are not concerned about lost updates, you could dispense with the synchronization - * entirely. - * **********************/ + /* + * ********************** UPDATING OPERATIONS + * + * These operations all follow a common pattern: + * + * 1. Create a copy of the existing view. 2. Update the copy. 3. Perform a volatile + * write to replace the existing view. + * + * Note that if you are not concerned about lost updates, you could dispense with the + * synchronization entirely. + **********************/ - @Override - public V put(K key, V value) { - synchronized (this) { - ConcurrentHashMap newCore = duplicate(view); - V result = newCore.put(key, value); - view = newCore; // volatile write - return result; - } - } + @Override + public V put(K key, V value) { + synchronized (this) { + ConcurrentHashMap newCore = duplicate(view); + V result = newCore.put(key, value); + view = newCore; // volatile write + return result; + } + } - @Override - public V remove(Object key) { - synchronized (this) { - ConcurrentHashMap newCore = duplicate(view); - V result = newCore.remove(key); - view = newCore; // volatile write - return result; - } - } + @Override + public V remove(Object key) { + synchronized (this) { + ConcurrentHashMap newCore = duplicate(view); + V result = newCore.remove(key); + view = newCore; // volatile write + return result; + } + } - @Override - public void putAll(Map t) { - synchronized (this) { - ConcurrentHashMap newCore = duplicate(view); - newCore.putAll(t); - view = newCore; // volatile write - } - } + @Override + public void putAll(Map t) { + synchronized (this) { + ConcurrentHashMap newCore = duplicate(view); + newCore.putAll(t); + view = newCore; // volatile write + } + } + + @Override + public void clear() { + synchronized (this) { + view = new ConcurrentHashMap<>(); // volatile write + } + } - @Override - public void clear() { - synchronized (this) { - view = new ConcurrentHashMap<>(); // volatile write - } - } } \ No newline at end of file diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java index fddcfa1f..53f71f48 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/JsonUtil.java @@ -25,53 +25,58 @@ import java.util.TimeZone; */ public class JsonUtil { - private static final Logger LOG = LoggerFactory.getLogger(JsonUtil.class); + private static final Logger LOG = LoggerFactory.getLogger(JsonUtil.class); - private static final ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper objectMapper = new ObjectMapper(); - private JsonUtil() { - } + private JsonUtil() { + } - static { - objectMapper.setTimeZone(TimeZone.getDefault()); - } + static { + objectMapper.setTimeZone(TimeZone.getDefault()); + } - public static String toJsonString(Object object) { - if (ObjectUtil.isNull(object)) { - return null; - } - try { - return objectMapper.writeValueAsString(object); - } catch (JsonProcessingException e) { - String errMsg = StrUtil.format("Error while writing value as string[{}],reason: {}", object.getClass().getName(), e.getMessage()); - LOG.error(e.getMessage(), e); - throw new JsonProcessException(errMsg); - } - } + public static String toJsonString(Object object) { + if (ObjectUtil.isNull(object)) { + return null; + } + try { + return objectMapper.writeValueAsString(object); + } + catch (JsonProcessingException e) { + String errMsg = StrUtil.format("Error while writing value as string[{}],reason: {}", + object.getClass().getName(), e.getMessage()); + LOG.error(e.getMessage(), e); + throw new JsonProcessException(errMsg); + } + } - public static JsonNode parseObject(String text) { - if (StrUtil.isEmpty(text)) { - return null; - } - try { - return objectMapper.readTree(text); - } catch (IOException e) { - String errMsg = StrUtil.format("Error while parsing text [{}],reason: {}", text, e.getMessage()); - LOG.error(e.getMessage(), e); - throw new JsonProcessException(errMsg); - } - } + public static JsonNode parseObject(String text) { + if (StrUtil.isEmpty(text)) { + return null; + } + try { + return objectMapper.readTree(text); + } + catch (IOException e) { + String errMsg = StrUtil.format("Error while parsing text [{}],reason: {}", text, e.getMessage()); + LOG.error(e.getMessage(), e); + throw new JsonProcessException(errMsg); + } + } + + public static T parseObject(String json, Class clazz) { + if (StrUtil.isEmpty(json)) { + return null; + } + try { + return objectMapper.readValue(json, clazz); + } + catch (IOException e) { + String errMsg = StrUtil.format("Error while parsing text [{}],reason: {}", json, e.getMessage()); + LOG.error(e.getMessage(), e); + throw new JsonProcessException(errMsg); + } + } - public static T parseObject(String json, Class clazz){ - if (StrUtil.isEmpty(json)) { - return null; - } - try { - return objectMapper.readValue(json, clazz); - } catch (IOException e) { - String errMsg = StrUtil.format("Error while parsing text [{}],reason: {}", json, e.getMessage()); - LOG.error(e.getMessage(), e); - throw new JsonProcessException(errMsg); - } - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java index 947fa7f2..826784fe 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LOGOPrinter.java @@ -7,11 +7,13 @@ import java.util.Optional; /** * logo打印器 + * * @author Bryan.Zhang */ public class LOGOPrinter { private static final Logger LOG = LoggerFactory.getLogger(LOGOPrinter.class); + /** * LiteFlow 当前版本号 */ @@ -19,7 +21,8 @@ public class LOGOPrinter { public static void print() { StringBuilder str = new StringBuilder("\n"); - str.append("================================================================================================\n"); + str.append( + "================================================================================================\n"); str.append(" _ ___ _____ _____ _____ _ _____ __\n"); str.append(" | | |_ _|_ _| ____| | ___| | / _ \\ \\ / /\n"); str.append(" | | | | | | | _| _____| |_ | | | | | \\ \\ /\\ / / \n"); @@ -31,13 +34,13 @@ public class LOGOPrinter { str.append(" Small but powerful rules engine.\n"); str.append(" 官网地址:https://liteflow.yomahub.com/\n"); str.append(" wechat:bryan_31\n"); - str.append("================================================================================================\n"); + str.append( + "================================================================================================\n"); LOG.info(str.toString()); } - private static String getVersion(){ - return Optional.ofNullable(LOGOPrinter.class.getPackage()) - .map(Package::getImplementationVersion) - .orElse("DEV"); + private static String getVersion() { + return Optional.ofNullable(LOGOPrinter.class.getPackage()).map(Package::getImplementationVersion).orElse("DEV"); } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LimitQueue.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LimitQueue.java index 78c4993e..8086e9c4 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LimitQueue.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LimitQueue.java @@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; /** * 有限队列集合 + * * @author Bryan.Zhang */ public class LimitQueue implements Queue { @@ -130,4 +131,5 @@ public class LimitQueue implements Queue { public T[] toArray(T[] a) { return queue.toArray(a); } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowExecutorPoolShutdown.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowExecutorPoolShutdown.java index 6174bfb8..2915b944 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowExecutorPoolShutdown.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowExecutorPoolShutdown.java @@ -9,20 +9,21 @@ import javax.annotation.PreDestroy; import java.util.concurrent.ExecutorService; /** - * 关闭shutdown类 - * 执行清理工作 + * 关闭shutdown类 执行清理工作 + * * @author Bryan.Zhang */ public class LiteFlowExecutorPoolShutdown { - private static final Logger LOG = LoggerFactory.getLogger(LiteFlowExecutorPoolShutdown.class); + private static final Logger LOG = LoggerFactory.getLogger(LiteFlowExecutorPoolShutdown.class); - @PreDestroy - public void destroy() throws Exception { - ExecutorService executorService = ContextAwareHolder.loadContextAware().getBean("whenExecutors"); + @PreDestroy + public void destroy() throws Exception { + ExecutorService executorService = ContextAwareHolder.loadContextAware().getBean("whenExecutors"); + + LOG.info("Start closing the liteflow-when-calls..."); + ExecutorHelper.loadInstance().shutdownAwaitTermination(executorService); + LOG.info("Succeed closing the liteflow-when-calls ok..."); + } - LOG.info("Start closing the liteflow-when-calls..."); - ExecutorHelper.loadInstance().shutdownAwaitTermination(executorService); - LOG.info("Succeed closing the liteflow-when-calls ok..."); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java index 9f1af85c..9980aa5f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java @@ -14,61 +14,62 @@ import java.util.Arrays; import java.util.List; /** - * 组件代理类通用方法 - * 主要用于声明式组件 + * 组件代理类通用方法 主要用于声明式组件 * * @author Bryan.Zhang * @since 2.6.14 */ public class LiteFlowProxyUtil { - private static final Logger LOG = LoggerFactory.getLogger(LiteFlowProxyUtil.class); + private static final Logger LOG = LoggerFactory.getLogger(LiteFlowProxyUtil.class); - /** - * 判断一个bean是否是声明式组件 - */ - public static boolean isDeclareCmp(Class clazz) { - //查看bean里的method是否有方法标记了@LiteflowMethod标注 - //这里的bean有可能是cglib加强过的class,所以要先进行个判断 - Class targetClass = getUserClass(clazz); - // 判断是否有方法标记了@LiteflowMethod标注,有则为声明式组件 - return Arrays.stream(targetClass.getMethods()).anyMatch( - method -> method.getAnnotation(LiteflowMethod.class) != null - ); - } + /** + * 判断一个bean是否是声明式组件 + */ + public static boolean isDeclareCmp(Class clazz) { + // 查看bean里的method是否有方法标记了@LiteflowMethod标注 + // 这里的bean有可能是cglib加强过的class,所以要先进行个判断 + Class targetClass = getUserClass(clazz); + // 判断是否有方法标记了@LiteflowMethod标注,有则为声明式组件 + return Arrays.stream(targetClass.getMethods()) + .anyMatch(method -> method.getAnnotation(LiteflowMethod.class) != null); + } - /** - * 对一个满足声明式的bean进行代理,生成代理类数组 - */ - public static List proxy2NodeComponent(Object bean, String nodeId) { - try { - NodeTypeEnum nodeType = NodeTypeEnum.guessType(bean.getClass()); - ComponentProxy proxy = new ComponentProxy(nodeId, bean, nodeType.getMappingClazz()); - return proxy.getProxyList(); - } catch (LiteFlowException liteFlowException) { - throw liteFlowException; - } catch (Exception e) { - String errMsg = StrUtil.format("Error while proxying bean[{}]", bean.getClass().getName()); - LOG.error(errMsg); - throw new ComponentProxyErrorException(errMsg); - } - } + /** + * 对一个满足声明式的bean进行代理,生成代理类数组 + */ + public static List proxy2NodeComponent(Object bean, String nodeId) { + try { + NodeTypeEnum nodeType = NodeTypeEnum.guessType(bean.getClass()); + ComponentProxy proxy = new ComponentProxy(nodeId, bean, nodeType.getMappingClazz()); + return proxy.getProxyList(); + } + catch (LiteFlowException liteFlowException) { + throw liteFlowException; + } + catch (Exception e) { + String errMsg = StrUtil.format("Error while proxying bean[{}]", bean.getClass().getName()); + LOG.error(errMsg); + throw new ComponentProxyErrorException(errMsg); + } + } - public static boolean isCglibProxyClass(Class clazz) { - return (clazz != null && isCglibProxyClassName(clazz.getName())); - } + public static boolean isCglibProxyClass(Class clazz) { + return (clazz != null && isCglibProxyClassName(clazz.getName())); + } - public static Class getUserClass(Class clazz) { - if (clazz.getName().contains("$$")) { - Class superclass = clazz.getSuperclass(); - if (superclass != null && superclass != Object.class) { - return superclass; - } - } - return clazz; - } + public static Class getUserClass(Class clazz) { + if (clazz.getName().contains("$$")) { + Class superclass = clazz.getSuperclass(); + if (superclass != null && superclass != Object.class) { + return superclass; + } + } + return clazz; + } + + private static boolean isCglibProxyClassName(String className) { + return (className != null && className.contains("$$")); + } - private static boolean isCglibProxyClassName(String className) { - return (className != null && className.contains("$$")); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java index acf0e7fa..4c56c436 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java @@ -11,179 +11,323 @@ import java.util.*; */ public class SerialsUtil { - public static int serialInt = 1; + public static int serialInt = 1; - private static final DecimalFormat format8 = new DecimalFormat("00000000"); - private static final DecimalFormat format12 = new DecimalFormat("000000000000"); - private static final BigInteger divisor; - private static final BigInteger divisor12; + private static final DecimalFormat format8 = new DecimalFormat("00000000"); - static { - divisor = BigInteger.valueOf(19999999L).multiply(BigInteger.valueOf(5)); - divisor12 = BigInteger.valueOf(190000000097L).multiply(BigInteger.valueOf(5)); - } + private static final DecimalFormat format12 = new DecimalFormat("000000000000"); - public static String genSerialNo(){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); - String strNow = sdf.format(new Date()); + private static final BigInteger divisor; - // 生成3位随机数 - Random random = new Random(); - int intRandom = random.nextInt(999); + private static final BigInteger divisor12; - String strRandom = String.valueOf(intRandom); - int len = strRandom.length(); - for (int i = 0; i < (3-len); i++) { - strRandom = "0" + strRandom; - } - String serialStr = SerialsUtil.nextSerial(); - return (strNow + strRandom + serialStr) ; - } + static { + divisor = BigInteger.valueOf(19999999L).multiply(BigInteger.valueOf(5)); + divisor12 = BigInteger.valueOf(190000000097L).multiply(BigInteger.valueOf(5)); + } - public static synchronized String nextSerial(){ - int serial = serialInt++; - if (serial > 999){ - serialInt = 1; - serial=1; - } - String serialStr = serial + ""; - int len = serialStr.length(); - for (int i = 0; i < (3-len); i++) { - serialStr = "0" + serialStr; - } + public static String genSerialNo() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String strNow = sdf.format(new Date()); - return serialStr; - } + // 生成3位随机数 + Random random = new Random(); + int intRandom = random.nextInt(999); + String strRandom = String.valueOf(intRandom); + int len = strRandom.length(); + for (int i = 0; i < (3 - len); i++) { + strRandom = "0" + strRandom; + } + String serialStr = SerialsUtil.nextSerial(); + return (strNow + strRandom + serialStr); + } - /** - * 生成一个12位随机数 - * @param seed 种子值 - * @return String 随机数 - */ - public static String randomNum12(long seed) { - // 被除数 - BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); - return format12.format(dividend.remainder(divisor12)); - } + public static synchronized String nextSerial() { + int serial = serialInt++; + if (serial > 999) { + serialInt = 1; + serial = 1; + } + String serialStr = serial + ""; + int len = serialStr.length(); + for (int i = 0; i < (3 - len); i++) { + serialStr = "0" + serialStr; + } - /** - * 生成一个8位随机数 - * @param seed 种子值 - * @return String 随机数 - */ - public static String randomNum8(long seed) { - // 被除数 - BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); - return format8.format(dividend.remainder(divisor)); - } + return serialStr; + } - /* - * 10进制转32进制(去除0,O,1,I) - */ - public static String from10To32(String numStr, int size){ - long to=32; - long num = Long.parseLong(numStr); - String jg=""; - while(num!=0){ - switch (new Long(num%to).intValue()) { - case 0:jg="B"+jg;break; case 1:jg="R"+jg;break; case 2:jg="6"+jg;break; case 3:jg="U"+jg;break; - case 4:jg="M"+jg;break; case 5:jg="E"+jg;break; case 6:jg="H"+jg;break; case 7:jg="C"+jg;break; - case 8:jg="G"+jg;break; case 9:jg="Q"+jg;break; case 10:jg="A"+jg;break; case 11:jg="8"+jg;break; - case 12:jg="3"+jg;break; case 13:jg="S"+jg;break; case 14:jg="J"+jg;break; case 15:jg="Y"+jg;break; - case 16:jg="7"+jg;break; case 17:jg="5"+jg;break; case 18:jg="W"+jg;break; case 19:jg="9"+jg;break; - case 20:jg="F"+jg;break; case 21:jg="T"+jg;break; case 22:jg="D"+jg;break; case 23:jg="2"+jg;break; - case 24:jg="P"+jg;break; case 25:jg="Z"+jg;break; case 26:jg="N"+jg;break; case 27:jg="K"+jg;break; - case 28:jg="V"+jg;break; case 29:jg="X"+jg;break; case 30:jg="L"+jg;break; case 31:jg="4"+jg;break; - default: jg=String.valueOf(num%to)+jg;break; - } - num=num/to; - } - if (jg.length() < size){ - int loop = size - jg.length(); - for (int i = 0; i < loop; i++){ - jg = "2" + jg; - } - } - return jg; - } + /** + * 生成一个12位随机数 + * @param seed 种子值 + * @return String 随机数 + */ + public static String randomNum12(long seed) { + // 被除数 + BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); + return format12.format(dividend.remainder(divisor12)); + } - /* - * 10进制转32进制(去除0,O,1,I) - */ - public static String from10To24(String numStr, int size){ - long to=24; - long num = Long.parseLong(numStr); - String jg=""; - while(num!=0){ - switch (new Long(num%to).intValue()) { - case 0:jg="B"+jg;break; - case 1:jg="R"+jg;break; - case 2:jg="U"+jg;break; - case 3:jg="M"+jg;break; - case 4:jg="E"+jg;break; - case 5:jg="H"+jg;break; - case 6:jg="C"+jg;break; - case 7:jg="G"+jg;break; - case 8:jg="Q"+jg;break; - case 9:jg="A"+jg;break; - case 10:jg="S"+jg;break; - case 11:jg="J"+jg;break; - case 12:jg="Y"+jg;break; - case 13:jg="W"+jg;break; - case 14:jg="F"+jg;break; - case 15:jg="T"+jg;break; - case 16:jg="D"+jg;break; - case 17:jg="P"+jg;break; - case 18:jg="Z"+jg;break; - case 19:jg="N"+jg;break; - case 20:jg="K"+jg;break; - case 21:jg="V"+jg;break; - case 22:jg="X"+jg;break; - case 23:jg="L"+jg;break; - default: jg=String.valueOf(num%to)+jg;break; - } - num=num/to; - } - if (jg.length() < size){ - int loop = size - jg.length(); - for (int i = 0; i < loop; i++){ - jg = "B" + jg; - } - } - return jg; - } + /** + * 生成一个8位随机数 + * @param seed 种子值 + * @return String 随机数 + */ + public static String randomNum8(long seed) { + // 被除数 + BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); + return format8.format(dividend.remainder(divisor)); + } - public static String getUUID() { - UUID uuid = UUID.randomUUID(); - String str = uuid.toString(); - // 去掉"-"符号 - String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24); - return temp; - } + /* + * 10进制转32进制(去除0,O,1,I) + */ + public static String from10To32(String numStr, int size) { + long to = 32; + long num = Long.parseLong(numStr); + String jg = ""; + while (num != 0) { + switch (new Long(num % to).intValue()) { + case 0: + jg = "B" + jg; + break; + case 1: + jg = "R" + jg; + break; + case 2: + jg = "6" + jg; + break; + case 3: + jg = "U" + jg; + break; + case 4: + jg = "M" + jg; + break; + case 5: + jg = "E" + jg; + break; + case 6: + jg = "H" + jg; + break; + case 7: + jg = "C" + jg; + break; + case 8: + jg = "G" + jg; + break; + case 9: + jg = "Q" + jg; + break; + case 10: + jg = "A" + jg; + break; + case 11: + jg = "8" + jg; + break; + case 12: + jg = "3" + jg; + break; + case 13: + jg = "S" + jg; + break; + case 14: + jg = "J" + jg; + break; + case 15: + jg = "Y" + jg; + break; + case 16: + jg = "7" + jg; + break; + case 17: + jg = "5" + jg; + break; + case 18: + jg = "W" + jg; + break; + case 19: + jg = "9" + jg; + break; + case 20: + jg = "F" + jg; + break; + case 21: + jg = "T" + jg; + break; + case 22: + jg = "D" + jg; + break; + case 23: + jg = "2" + jg; + break; + case 24: + jg = "P" + jg; + break; + case 25: + jg = "Z" + jg; + break; + case 26: + jg = "N" + jg; + break; + case 27: + jg = "K" + jg; + break; + case 28: + jg = "V" + jg; + break; + case 29: + jg = "X" + jg; + break; + case 30: + jg = "L" + jg; + break; + case 31: + jg = "4" + jg; + break; + default: + jg = String.valueOf(num % to) + jg; + break; + } + num = num / to; + } + if (jg.length() < size) { + int loop = size - jg.length(); + for (int i = 0; i < loop; i++) { + jg = "2" + jg; + } + } + return jg; + } - public static String generateShortUUID() { - String str = randomNum8(System.nanoTime()); - return from10To24(str, 6); - } + /* + * 10进制转32进制(去除0,O,1,I) + */ + public static String from10To24(String numStr, int size) { + long to = 24; + long num = Long.parseLong(numStr); + String jg = ""; + while (num != 0) { + switch (new Long(num % to).intValue()) { + case 0: + jg = "B" + jg; + break; + case 1: + jg = "R" + jg; + break; + case 2: + jg = "U" + jg; + break; + case 3: + jg = "M" + jg; + break; + case 4: + jg = "E" + jg; + break; + case 5: + jg = "H" + jg; + break; + case 6: + jg = "C" + jg; + break; + case 7: + jg = "G" + jg; + break; + case 8: + jg = "Q" + jg; + break; + case 9: + jg = "A" + jg; + break; + case 10: + jg = "S" + jg; + break; + case 11: + jg = "J" + jg; + break; + case 12: + jg = "Y" + jg; + break; + case 13: + jg = "W" + jg; + break; + case 14: + jg = "F" + jg; + break; + case 15: + jg = "T" + jg; + break; + case 16: + jg = "D" + jg; + break; + case 17: + jg = "P" + jg; + break; + case 18: + jg = "Z" + jg; + break; + case 19: + jg = "N" + jg; + break; + case 20: + jg = "K" + jg; + break; + case 21: + jg = "V" + jg; + break; + case 22: + jg = "X" + jg; + break; + case 23: + jg = "L" + jg; + break; + default: + jg = String.valueOf(num % to) + jg; + break; + } + num = num / to; + } + if (jg.length() < size) { + int loop = size - jg.length(); + for (int i = 0; i < loop; i++) { + jg = "B" + jg; + } + } + return jg; + } - public static String generateFileUUID() { - String str = randomNum12(System.nanoTime()); - return from10To32(str, 8); - } + public static String getUUID() { + UUID uuid = UUID.randomUUID(); + String str = uuid.toString(); + // 去掉"-"符号 + String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + + str.substring(24); + return temp; + } - public static String genToken(){ - return from10To32(randomNum12(System.currentTimeMillis()),8) + from10To32(randomNum12(System.nanoTime()),8); - } + public static String generateShortUUID() { + String str = randomNum8(System.nanoTime()); + return from10To24(str, 6); + } + + public static String generateFileUUID() { + String str = randomNum12(System.nanoTime()); + return from10To32(str, 8); + } + + public static String genToken() { + return from10To32(randomNum12(System.currentTimeMillis()), 8) + from10To32(randomNum12(System.nanoTime()), 8); + } + + public static void main(String[] args) { + Set set = new HashSet(); + String str; + for (int i = 0; i < 300; i++) { + str = generateShortUUID(); + System.out.println(str); + set.add(str); + } + System.out.println(set.size()); + } - public static void main(String[] args) { - Set set = new HashSet(); - String str; - for (int i = 0; i < 300; i++) { - str = generateShortUUID(); - System.out.println(str); - set.add(str); - } - System.out.println(set.size()); - } } \ No newline at end of file diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java index db302270..b0a443c9 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/ApolloXmlELParser.java @@ -28,9 +28,12 @@ public class ApolloXmlELParser extends ClassXmlFlowELParser { try { ApolloParserConfigVO apolloParserConfigVO = null; if (MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))) { - apolloParserConfigVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), ApolloParserConfigVO.class, CopyOptions.create()); - } else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { - apolloParserConfigVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), ApolloParserConfigVO.class); + apolloParserConfigVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), + ApolloParserConfigVO.class, CopyOptions.create()); + } + else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { + apolloParserConfigVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), + ApolloParserConfigVO.class); } // check config @@ -43,12 +46,12 @@ public class ApolloXmlELParser extends ClassXmlFlowELParser { } apolloParseHelper = new ApolloParseHelper(apolloParserConfigVO); - } catch (Exception e) { + } + catch (Exception e) { throw new ApolloException(e.getMessage()); } } - @Override public String parseCustom() { @@ -60,8 +63,10 @@ public class ApolloXmlELParser extends ClassXmlFlowELParser { }); return content; - } catch (Exception e) { + } + catch (Exception e) { throw new ApolloException(e.getMessage()); } } + } diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java index 94203efe..d11333ce 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/exception/ApolloException.java @@ -17,4 +17,5 @@ public class ApolloException extends RuntimeException { public String getMessage() { return message; } + } diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java index ea904f3e..468704be 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/util/ApolloParseHelper.java @@ -30,7 +30,6 @@ import java.util.stream.Collectors; */ public class ApolloParseHelper { - private static final Logger LOG = LoggerFactory.getLogger(ApolloParseHelper.class); private final String CHAIN_XML_PATTERN = "{}"; @@ -47,20 +46,21 @@ public class ApolloParseHelper { private Config scriptConfig; - public ApolloParseHelper(ApolloParserConfigVO apolloParserConfigVO) { this.apolloParserConfigVO = apolloParserConfigVO; try { - try{ - //这里本身对于程序运行来说没有什么意义,拿到的永远是null - //其实config对象也没有注入到spring容器中 - //这里这样写的目的是为了单测中的mockito,当有@MockBean的时候,这里就能拿到了 + try { + // 这里本身对于程序运行来说没有什么意义,拿到的永远是null + // 其实config对象也没有注入到spring容器中 + // 这里这样写的目的是为了单测中的mockito,当有@MockBean的时候,这里就能拿到了 this.chainConfig = ContextAwareHolder.loadContextAware().getBean("chainConfig"); this.scriptConfig = ContextAwareHolder.loadContextAware().getBean("scriptConfig"); - }catch (Exception ignored){} + } + catch (Exception ignored) { + } - if (ObjectUtil.isNull(chainConfig)){ + if (ObjectUtil.isNull(chainConfig)) { chainConfig = ConfigService.getConfig(apolloParserConfigVO.getChainNamespace()); String scriptNamespace; // scriptConfig is optional @@ -68,7 +68,8 @@ public class ApolloParseHelper { scriptConfig = ConfigService.getConfig(scriptNamespace); } } - } catch (Exception e) { + } + catch (Exception e) { throw new ApolloException(e.getMessage()); } } @@ -79,96 +80,96 @@ public class ApolloParseHelper { // 1. handle chain Set propertyNames = chainConfig.getPropertyNames(); if (CollectionUtil.isEmpty(propertyNames)) { - throw new ApolloException(StrUtil.format("There are no chains in namespace : {}", apolloParserConfigVO.getChainNamespace())); + throw new ApolloException(StrUtil.format("There are no chains in namespace : {}", + apolloParserConfigVO.getChainNamespace())); } List chainItemContentList = propertyNames.stream() - .map(item -> StrUtil.format(CHAIN_XML_PATTERN, item, chainConfig.getProperty(item, StrUtil.EMPTY))) - .collect(Collectors.toList()); + .map(item -> StrUtil.format(CHAIN_XML_PATTERN, item, chainConfig.getProperty(item, StrUtil.EMPTY))) + .collect(Collectors.toList()); // merge all chain content String chainAllContent = CollUtil.join(chainItemContentList, StrUtil.EMPTY); // 2. handle script if needed String scriptAllContent = StrUtil.EMPTY; Set scriptNamespaces; - if (Objects.nonNull(scriptConfig) && CollectionUtil.isNotEmpty(scriptNamespaces = scriptConfig.getPropertyNames())) { + if (Objects.nonNull(scriptConfig) + && CollectionUtil.isNotEmpty(scriptNamespaces = scriptConfig.getPropertyNames())) { List scriptItemContentList = scriptNamespaces.stream() - .map(item -> convert(item, scriptConfig.getProperty(item, StrUtil.EMPTY))) - .filter(Objects::nonNull) - .map(item -> StrUtil.format(NODE_ITEM_XML_PATTERN, item.getNodeId(), item.getName(), item.getType(), item.getScript())) - .collect(Collectors.toList()); + .map(item -> convert(item, scriptConfig.getProperty(item, StrUtil.EMPTY))) + .filter(Objects::nonNull) + .map(item -> StrUtil.format(NODE_ITEM_XML_PATTERN, item.getNodeId(), item.getName(), item.getType(), + item.getScript())) + .collect(Collectors.toList()); - scriptAllContent = StrUtil.format(NODE_XML_PATTERN, CollUtil.join(scriptItemContentList, StrUtil.EMPTY)); + scriptAllContent = StrUtil.format(NODE_XML_PATTERN, + CollUtil.join(scriptItemContentList, StrUtil.EMPTY)); } return StrUtil.format(XML_PATTERN, scriptAllContent, chainAllContent); - } catch (Exception e) { + } + catch (Exception e) { throw new ApolloException(e.getMessage()); } } - /** * listen apollo config change */ public void listenApollo() { // chain - chainConfig.addChangeListener(changeEvent -> - changeEvent.changedKeys().forEach(changeKey -> { - ConfigChange configChange = changeEvent.getChange(changeKey); - String newValue = configChange.getNewValue(); - PropertyChangeType changeType = configChange.getChangeType(); - switch (changeType) { - case ADDED: - case MODIFIED: - LOG.info("starting reload flow config... {} key={} value={},", changeType.name(), changeKey, newValue); - LiteFlowChainELBuilder.createChain() - .setChainId(changeKey) - .setEL(newValue) - .build(); - break; - case DELETED: - LOG.info("starting reload flow config... delete key={}", changeKey); - FlowBus.removeChain(changeKey); + chainConfig.addChangeListener(changeEvent -> changeEvent.changedKeys().forEach(changeKey -> { + ConfigChange configChange = changeEvent.getChange(changeKey); + String newValue = configChange.getNewValue(); + PropertyChangeType changeType = configChange.getChangeType(); + switch (changeType) { + case ADDED: + case MODIFIED: + LOG.info("starting reload flow config... {} key={} value={},", changeType.name(), changeKey, + newValue); + LiteFlowChainELBuilder.createChain().setChainId(changeKey).setEL(newValue).build(); + break; + case DELETED: + LOG.info("starting reload flow config... delete key={}", changeKey); + FlowBus.removeChain(changeKey); - } - })); + } + })); - if (StrUtil.isNotBlank(apolloParserConfigVO.getScriptNamespace())){ - scriptConfig.addChangeListener(changeEvent -> - changeEvent.changedKeys().forEach(changeKey -> { - ConfigChange configChange = changeEvent.getChange(changeKey); - String newValue = configChange.getNewValue(); + if (StrUtil.isNotBlank(apolloParserConfigVO.getScriptNamespace())) { + scriptConfig.addChangeListener(changeEvent -> changeEvent.changedKeys().forEach(changeKey -> { + ConfigChange configChange = changeEvent.getChange(changeKey); + String newValue = configChange.getNewValue(); - PropertyChangeType changeType = configChange.getChangeType(); + PropertyChangeType changeType = configChange.getChangeType(); - NodeSimpleVO nodeSimpleVO; - switch (changeType) { - case ADDED: - case MODIFIED: - LOG.info("starting reload flow config... {} key={} value={},", changeType.name(), changeKey, newValue); - nodeSimpleVO = convert(changeKey, newValue); - LiteFlowNodeBuilder.createScriptNode() - .setId(nodeSimpleVO.getNodeId()) - .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.getType())) - .setName(nodeSimpleVO.getName()) - .setScript(nodeSimpleVO.getScript()) - .build(); - break; - case DELETED: - LOG.info("starting reload flow config... delete key={}", changeKey); - nodeSimpleVO = convert(changeKey, null); - FlowBus.getNodeMap().remove(nodeSimpleVO.getNodeId()); - } - }) - ); + NodeSimpleVO nodeSimpleVO; + switch (changeType) { + case ADDED: + case MODIFIED: + LOG.info("starting reload flow config... {} key={} value={},", changeType.name(), changeKey, + newValue); + nodeSimpleVO = convert(changeKey, newValue); + LiteFlowNodeBuilder.createScriptNode() + .setId(nodeSimpleVO.getNodeId()) + .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.getType())) + .setName(nodeSimpleVO.getName()) + .setScript(nodeSimpleVO.getScript()) + .build(); + break; + case DELETED: + LOG.info("starting reload flow config... delete key={}", changeKey); + nodeSimpleVO = convert(changeKey, null); + FlowBus.getNodeMap().remove(nodeSimpleVO.getNodeId()); + } + })); } } private NodeSimpleVO convert(String key, String value) { - //不需要去理解这串正则,就是一个匹配冒号的 - //一定得是a:b,或是a:b:c...这种完整类型的字符串的 + // 不需要去理解这串正则,就是一个匹配冒号的 + // 一定得是a:b,或是a:b:c...这种完整类型的字符串的 List matchItemList = ReUtil.findAllGroup0("(?<=[^:]:)[^:]+|[^:]+(?=:[^:])", key); if (CollUtil.isEmpty(matchItemList)) { return null; @@ -190,7 +191,6 @@ public class ApolloParseHelper { return nodeSimpleVO; } - private static class NodeSimpleVO { private String nodeId; @@ -232,7 +232,7 @@ public class ApolloParseHelper { public void setScript(String script) { this.script = script; } + } - } diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java index 86090246..c332fca7 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/apollo/vo/ApolloParserConfigVO.java @@ -10,7 +10,6 @@ public class ApolloParserConfigVO { private String scriptNamespace; - public ApolloParserConfigVO() { } @@ -37,9 +36,8 @@ public class ApolloParserConfigVO { @Override public String toString() { - return "ApolloParserConfigVO{" + - "chainNamespace='" + chainNamespace + '\'' + - ", scriptNamespace='" + scriptNamespace + '\'' + - '}'; + return "ApolloParserConfigVO{" + "chainNamespace='" + chainNamespace + '\'' + ", scriptNamespace='" + + scriptNamespace + '\'' + '}'; } + } diff --git a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java index 8864f46b..f03f2eaf 100644 --- a/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java +++ b/liteflow-rule-plugin/liteflow-rule-apollo/src/main/java/com/yomahub/liteflow/parser/spi/apollo/ApolloParserClassNameSpi.java @@ -13,4 +13,5 @@ public class ApolloParserClassNameSpi implements ParserClassNameSpi { public String getSpiClassName() { return ApolloXmlELParser.class.getName(); } + } diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdClient.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdClient.java index 54c151e1..b737d5d7 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdClient.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdClient.java @@ -23,6 +23,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; /** * Etcd 客户端封装类. + * * @author zendwang * @since 2.9.0 */ @@ -47,7 +48,6 @@ public class EtcdClient { /** * get node value. - * * @param key node name * @return string */ @@ -55,7 +55,8 @@ public class EtcdClient { List keyValues = null; try { keyValues = client.getKVClient().get(bytesOf(key)).get().getKvs(); - } catch (InterruptedException | ExecutionException e) { + } + catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); } @@ -67,7 +68,7 @@ public class EtcdClient { } /** - * put a key-value pair into etcd. + * put a key-value pair into etcd. * @param key node name * @param value node value * @return @@ -78,41 +79,37 @@ public class EtcdClient { ByteSequence valueByteSequence = bytesOf(value); try { prevKv = client.getKVClient().put(keyByteSequence, valueByteSequence).get().getPrevKv(); - } catch (InterruptedException | ExecutionException e) { + } + catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); } return prevKv; } - - /** * get node sub nodes. - * - * @param prefix node prefix. + * @param prefix node prefix. * @param separator separator char * @return sub nodes - * @throws ExecutionException the exception + * @throws ExecutionException the exception * @throws InterruptedException the exception */ - public List getChildrenKeys(final String prefix, final String separator) throws ExecutionException, InterruptedException { + public List getChildrenKeys(final String prefix, final String separator) + throws ExecutionException, InterruptedException { ByteSequence prefixByteSequence = bytesOf(prefix); GetOption getOption = GetOption.newBuilder() - .withPrefix(prefixByteSequence) - .withSortField(GetOption.SortTarget.KEY) - .withSortOrder(GetOption.SortOrder.ASCEND) - .build(); + .withPrefix(prefixByteSequence) + .withSortField(GetOption.SortTarget.KEY) + .withSortOrder(GetOption.SortOrder.ASCEND) + .build(); - List keyValues = client.getKVClient() - .get(prefixByteSequence, getOption) - .get() - .getKvs(); + List keyValues = client.getKVClient().get(prefixByteSequence, getOption).get().getKvs(); return keyValues.stream() - .map(e -> getSubNodeKeyName(prefix, e.getKey().toString(UTF_8), separator)) - .distinct() - .filter(e -> Objects.nonNull(e)) - .collect(Collectors.toList()); + .map(e -> getSubNodeKeyName(prefix, e.getKey().toString(UTF_8), separator)) + .distinct() + .filter(e -> Objects.nonNull(e)) + .collect(Collectors.toList()); } private String getSubNodeKeyName(final String prefix, final String fullPath, final String separator) { @@ -122,16 +119,15 @@ public class EtcdClient { String pathWithoutPrefix = fullPath.substring(prefix.length()); return pathWithoutPrefix.contains(separator) ? pathWithoutPrefix.substring(1) : pathWithoutPrefix; } + /** * subscribe data change. - * - * @param key node name + * @param key node name * @param updateHandler node value handler of update * @param deleteHandler node value handler of delete */ - public void watchDataChange(final String key, - final BiConsumer updateHandler, - final Consumer deleteHandler) { + public void watchDataChange(final String key, final BiConsumer updateHandler, + final Consumer deleteHandler) { Watch.Listener listener = watch(updateHandler, deleteHandler); Watch.Watcher watch = client.getWatchClient().watch(bytesOf(key), listener); watchCache.put(key, watch); @@ -139,23 +135,18 @@ public class EtcdClient { /** * subscribe sub node change. - * - * @param key param node name. + * @param key param node name. * @param updateHandler sub node handler of update * @param deleteHandler sub node delete of delete */ - public void watchChildChange(final String key, - final BiConsumer updateHandler, - final Consumer deleteHandler) { + public void watchChildChange(final String key, final BiConsumer updateHandler, + final Consumer deleteHandler) { Watch.Listener listener = watch(updateHandler, deleteHandler); - WatchOption option = WatchOption.newBuilder() - .withPrefix(bytesOf(key)) - .build(); + WatchOption option = WatchOption.newBuilder().withPrefix(bytesOf(key)).build(); Watch.Watcher watch = client.getWatchClient().watch(bytesOf(key), option, listener); watchCache.put(key, watch); } - /** * bytesOf string. * @param val val. @@ -165,8 +156,7 @@ public class EtcdClient { return ByteSequence.from(val, UTF_8); } - private Watch.Listener watch(final BiConsumer updateHandler, - final Consumer deleteHandler) { + private Watch.Listener watch(final BiConsumer updateHandler, final Consumer deleteHandler) { return Watch.listener(response -> { for (WatchEvent event : response.getEvents()) { String path = event.getKeyValue().getKey().toString(UTF_8); @@ -186,7 +176,6 @@ public class EtcdClient { /** * cancel subscribe. - * * @param key node name */ public void watchClose(final String key) { @@ -195,4 +184,5 @@ public class EtcdClient { watchCache.remove(key); } } + } \ No newline at end of file diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdXmlELParser.java index f1982131..4e074a67 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdXmlELParser.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/EtcdXmlELParser.java @@ -18,6 +18,7 @@ import java.util.function.BooleanSupplier; /** * Etcd解析器实现,只支持EL形式的XML,不支持其他的形式 + * * @author zendwang * @since 2.9.0 */ @@ -28,11 +29,13 @@ public class EtcdXmlELParser extends ClassXmlFlowELParser { public EtcdXmlELParser() { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - try{ + try { EtcdParserVO etcdParserVO = null; - if(MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))){ - etcdParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), EtcdParserVO.class, CopyOptions.create()); - }else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())){ + if (MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))) { + etcdParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), EtcdParserVO.class, + CopyOptions.create()); + } + else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { etcdParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), EtcdParserVO.class); } @@ -40,15 +43,16 @@ public class EtcdXmlELParser extends ClassXmlFlowELParser { throw new EtcdException("rule-source-ext-data is empty"); } - if (StrUtil.isBlank(etcdParserVO.getChainPath())){ + if (StrUtil.isBlank(etcdParserVO.getChainPath())) { throw new EtcdException("You must configure the chainPath property"); } - if (StrUtil.isBlank(etcdParserVO.getEndpoints())){ + if (StrUtil.isBlank(etcdParserVO.getEndpoints())) { throw new EtcdException("etcd endpoints is empty"); } etcdParserHelper = new EtcdParserHelper(etcdParserVO); - }catch (Exception e){ + } + catch (Exception e) { throw new EtcdException(e.getMessage()); } } @@ -65,8 +69,10 @@ public class EtcdXmlELParser extends ClassXmlFlowELParser { }); return content; - } catch (Exception e){ + } + catch (Exception e) { throw new EtcdException(e.getMessage()); } } + } diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/exception/EtcdException.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/exception/EtcdException.java index fb2f1d40..40a51b64 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/exception/EtcdException.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/exception/EtcdException.java @@ -3,6 +3,7 @@ package com.yomahub.liteflow.parser.etcd.exception; /** * Etcd解析异常 + * * @author zendwang * @since 2.9.0 */ @@ -25,4 +26,5 @@ public class EtcdException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java index c41efa7a..1b234e03 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/util/EtcdParserHelper.java @@ -50,13 +50,14 @@ public class EtcdParserHelper { public EtcdParserHelper(EtcdParserVO etcdParserVO) { this.etcdParserVO = etcdParserVO; - try{ - try{ - this.client = ContextAwareHolder.loadContextAware().getBean(EtcdClient.class); - }catch (Exception ignored){} + try { + try { + this.client = ContextAwareHolder.loadContextAware().getBean(EtcdClient.class); + } + catch (Exception ignored) { + } if (this.client == null) { - ClientBuilder clientBuilder = Client.builder() - .endpoints(etcdParserVO.getEndpoints().split(",")); + ClientBuilder clientBuilder = Client.builder().endpoints(etcdParserVO.getEndpoints().split(",")); if (StrUtil.isNotBlank(etcdParserVO.getNamespace())) { clientBuilder.namespace(ByteSequence.from(etcdParserVO.getNamespace(), CharsetUtil.CHARSET_UTF_8)); } @@ -66,143 +67,143 @@ public class EtcdParserHelper { } this.client = new EtcdClient(clientBuilder.build()); } - }catch (Exception e){ + } + catch (Exception e) { throw new EtcdException(e.getMessage()); } } - public String getContent(){ - try{ - //检查chainPath路径下有没有子节点 + public String getContent() { + try { + // 检查chainPath路径下有没有子节点 List chainNameList = client.getChildrenKeys(etcdParserVO.getChainPath(), SEPARATOR); - if (CollectionUtil.isEmpty(chainNameList)){ - throw new EtcdException(StrUtil.format("There are no chains in path [{}]", etcdParserVO.getChainPath())); + if (CollectionUtil.isEmpty(chainNameList)) { + throw new EtcdException( + StrUtil.format("There are no chains in path [{}]", etcdParserVO.getChainPath())); } - //获取chainPath路径下的所有子节点内容List + // 获取chainPath路径下的所有子节点内容List List chainItemContentList = new ArrayList<>(); - for (String chainName : chainNameList){ + for (String chainName : chainNameList) { String chainData = client.get(StrUtil.format("{}/{}", etcdParserVO.getChainPath(), chainName)); if (StrUtil.isNotBlank(chainData)) { chainItemContentList.add(StrUtil.format(CHAIN_XML_PATTERN, chainName, chainData)); } } - //合并成所有chain的xml内容 + // 合并成所有chain的xml内容 String chainAllContent = CollUtil.join(chainItemContentList, StrUtil.EMPTY); - //检查是否有脚本内容,如果有,进行脚本内容的获取 + // 检查是否有脚本内容,如果有,进行脚本内容的获取 String scriptAllContent = StrUtil.EMPTY; - if (hasScript()){ - List scriptNodeValueList = client.getChildrenKeys(etcdParserVO.getScriptPath(), SEPARATOR).stream().filter(StrUtil::isNotBlank).collect(Collectors.toList()); + if (hasScript()) { + List scriptNodeValueList = client.getChildrenKeys(etcdParserVO.getScriptPath(), SEPARATOR) + .stream() + .filter(StrUtil::isNotBlank) + .collect(Collectors.toList()); List scriptItemContentList = new ArrayList<>(); - for (String scriptNodeValue: scriptNodeValueList){ + for (String scriptNodeValue : scriptNodeValueList) { NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); - if (Objects.isNull(nodeSimpleVO)){ - throw new EtcdException(StrUtil.format("The name of the etcd node is invalid:{}", scriptNodeValue)); + if (Objects.isNull(nodeSimpleVO)) { + throw new EtcdException( + StrUtil.format("The name of the etcd node is invalid:{}", scriptNodeValue)); } - String scriptData = client.get(StrUtil.format("{}/{}", etcdParserVO.getScriptPath(), scriptNodeValue)); + String scriptData = client + .get(StrUtil.format("{}/{}", etcdParserVO.getScriptPath(), scriptNodeValue)); - scriptItemContentList.add( - StrUtil.format(NODE_ITEM_XML_PATTERN, - nodeSimpleVO.getNodeId(), - nodeSimpleVO.getName(), - nodeSimpleVO.getType(), - scriptData) - ); + scriptItemContentList.add(StrUtil.format(NODE_ITEM_XML_PATTERN, nodeSimpleVO.getNodeId(), + nodeSimpleVO.getName(), nodeSimpleVO.getType(), scriptData)); } - scriptAllContent = StrUtil.format(NODE_XML_PATTERN, CollUtil.join(scriptItemContentList, StrUtil.EMPTY)); + scriptAllContent = StrUtil.format(NODE_XML_PATTERN, + CollUtil.join(scriptItemContentList, StrUtil.EMPTY)); } return StrUtil.format(XML_PATTERN, scriptAllContent, chainAllContent); - }catch (Exception e){ + } + catch (Exception e) { throw new EtcdException(e.getMessage()); } } - public boolean hasScript(){ - //没有配置scriptPath - if (StrUtil.isBlank(etcdParserVO.getScriptPath())){ + public boolean hasScript() { + // 没有配置scriptPath + if (StrUtil.isBlank(etcdParserVO.getScriptPath())) { return false; } - try{ - //存在这个节点,但是子节点不存在 + try { + // 存在这个节点,但是子节点不存在 List chainNameList = client.getChildrenKeys(etcdParserVO.getScriptPath(), SEPARATOR); return !CollUtil.isEmpty(chainNameList); - }catch (Exception e){ + } + catch (Exception e) { return false; } } - /** * 监听 etcd 节点 */ public void listen() { - this.client.watchChildChange(this.etcdParserVO.getChainPath(), - (updatePath, updateValue) -> { - LOG.info("starting reload flow config... update path={} value={},", updatePath, updateValue); - String chainName = FileNameUtil.getName(updatePath); - LiteFlowChainELBuilder.createChain().setChainId(chainName).setEL(updateValue).build(); - }, - (deletePath) -> { - LOG.info("starting reload flow config... delete path={}", deletePath); - String chainName = FileNameUtil.getName(deletePath); - FlowBus.removeChain(chainName); - } - ); + this.client.watchChildChange(this.etcdParserVO.getChainPath(), (updatePath, updateValue) -> { + LOG.info("starting reload flow config... update path={} value={},", updatePath, updateValue); + String chainName = FileNameUtil.getName(updatePath); + LiteFlowChainELBuilder.createChain().setChainId(chainName).setEL(updateValue).build(); + }, (deletePath) -> { + LOG.info("starting reload flow config... delete path={}", deletePath); + String chainName = FileNameUtil.getName(deletePath); + FlowBus.removeChain(chainName); + }); - if (StrUtil.isNotBlank(this.etcdParserVO.getScriptPath())){ - this.client.watchChildChange(this.etcdParserVO.getScriptPath(), - (updatePath, updateValue) -> { - LOG.info("starting reload flow config... update path={} value={}", updatePath, updateValue); - String scriptNodeValue = FileNameUtil.getName(updatePath); - NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); - LiteFlowNodeBuilder.createScriptNode().setId(nodeSimpleVO.getNodeId()) - .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type)) - .setName(nodeSimpleVO.getName()) - .setScript(updateValue).build(); - }, - (deletePath) -> { - LOG.info("starting reload flow config... delete path={}", deletePath); - String scriptNodeValue = FileNameUtil.getName(deletePath); - NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); - FlowBus.getNodeMap().remove(nodeSimpleVO.getNodeId()); - } - ); + if (StrUtil.isNotBlank(this.etcdParserVO.getScriptPath())) { + this.client.watchChildChange(this.etcdParserVO.getScriptPath(), (updatePath, updateValue) -> { + LOG.info("starting reload flow config... update path={} value={}", updatePath, updateValue); + String scriptNodeValue = FileNameUtil.getName(updatePath); + NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); + LiteFlowNodeBuilder.createScriptNode() + .setId(nodeSimpleVO.getNodeId()) + .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type)) + .setName(nodeSimpleVO.getName()) + .setScript(updateValue) + .build(); + }, (deletePath) -> { + LOG.info("starting reload flow config... delete path={}", deletePath); + String scriptNodeValue = FileNameUtil.getName(deletePath); + NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); + FlowBus.getNodeMap().remove(nodeSimpleVO.getNodeId()); + }); } } - public NodeSimpleVO convert(String str){ - //不需要去理解这串正则,就是一个匹配冒号的 - //一定得是a:b,或是a:b:c...这种完整类型的字符串的 + public NodeSimpleVO convert(String str) { + // 不需要去理解这串正则,就是一个匹配冒号的 + // 一定得是a:b,或是a:b:c...这种完整类型的字符串的 List matchItemList = ReUtil.findAllGroup0("(?<=[^:]:)[^:]+|[^:]+(?=:[^:])", str); - if (CollUtil.isEmpty(matchItemList)){ + if (CollUtil.isEmpty(matchItemList)) { return null; } NodeSimpleVO nodeSimpleVO = new NodeSimpleVO(); - if (matchItemList.size() > 1){ + if (matchItemList.size() > 1) { nodeSimpleVO.setNodeId(matchItemList.get(0)); nodeSimpleVO.setType(matchItemList.get(1)); } - if (matchItemList.size() > 2){ + if (matchItemList.size() > 2) { nodeSimpleVO.setName(matchItemList.get(2)); } return nodeSimpleVO; } - private static class NodeSimpleVO{ + private static class NodeSimpleVO { private String nodeId; private String type; - private String name=""; + private String name = ""; public String getNodeId() { return nodeId; @@ -227,5 +228,7 @@ public class EtcdParserHelper { public void setName(String name) { this.name = name; } + } + } diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/vo/EtcdParserVO.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/vo/EtcdParserVO.java index 4bb32a9d..726104d2 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/vo/EtcdParserVO.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/etcd/vo/EtcdParserVO.java @@ -2,68 +2,70 @@ package com.yomahub.liteflow.parser.etcd.vo; /** * 用于解析RuleSourceExtData的vo类,用于etcd模式中 + * * @author zendwang * @since 2.9.0 */ public class EtcdParserVO { - private String endpoints; + private String endpoints; - private String user; + private String user; - private String password; + private String password; - private String namespace; + private String namespace; - private String chainPath; + private String chainPath; - private String scriptPath; + private String scriptPath; - public String getEndpoints() { - return endpoints; - } + public String getEndpoints() { + return endpoints; + } - public void setEndpoints(String endpoints) { - this.endpoints = endpoints; - } + public void setEndpoints(String endpoints) { + this.endpoints = endpoints; + } - public String getUser() { - return user; - } + public String getUser() { + return user; + } - public void setUser(String user) { - this.user = user; - } + public void setUser(String user) { + this.user = user; + } - public String getPassword() { - return password; - } + public String getPassword() { + return password; + } - public void setPassword(String password) { - this.password = password; - } + public void setPassword(String password) { + this.password = password; + } - public String getNamespace() { - return namespace; - } + public String getNamespace() { + return namespace; + } - public void setNamespace(String namespace) { - this.namespace = namespace; - } + public void setNamespace(String namespace) { + this.namespace = namespace; + } - public String getChainPath() { - return chainPath; - } + public String getChainPath() { + return chainPath; + } - public void setChainPath(String chainPath) { - this.chainPath = chainPath; - } + public void setChainPath(String chainPath) { + this.chainPath = chainPath; + } - public String getScriptPath() { - return scriptPath; - } + public String getScriptPath() { + return scriptPath; + } + + public void setScriptPath(String scriptPath) { + this.scriptPath = scriptPath; + } - public void setScriptPath(String scriptPath) { - this.scriptPath = scriptPath; - } } diff --git a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/spi/etcd/EtcdParserClassNameSpi.java b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/spi/etcd/EtcdParserClassNameSpi.java index 72c6b7f6..e64e8ea9 100644 --- a/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/spi/etcd/EtcdParserClassNameSpi.java +++ b/liteflow-rule-plugin/liteflow-rule-etcd/src/main/java/com/yomahub/liteflow/parser/spi/etcd/EtcdParserClassNameSpi.java @@ -1,18 +1,19 @@ package com.yomahub.liteflow.parser.spi.etcd; - import com.yomahub.liteflow.parser.etcd.EtcdXmlELParser; import com.yomahub.liteflow.parser.spi.ParserClassNameSpi; - /** * Etcd解析器SPI实现 + * * @author zendwang * @since 2.9.0 */ public class EtcdParserClassNameSpi implements ParserClassNameSpi { - @Override - public String getSpiClassName() { - return EtcdXmlELParser.class.getName(); - } + + @Override + public String getSpiClassName() { + return EtcdXmlELParser.class.getName(); + } + } diff --git a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/NacosXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/NacosXmlELParser.java index a6c7064f..0633bd65 100644 --- a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/NacosXmlELParser.java +++ b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/NacosXmlELParser.java @@ -17,68 +17,75 @@ import java.util.function.Consumer; /** * Nacos 解析器实现,只支持EL形式的XML,不支持其他的形式 + * * @author mll * @since 2.9.0 */ public class NacosXmlELParser extends ClassXmlFlowELParser { - private final NacosParserHelper helper; + private final NacosParserHelper helper; - public NacosXmlELParser() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + public NacosXmlELParser() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - try{ - NacosParserVO nacosParserVO = null; - if(MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))){ - nacosParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), NacosParserVO.class, CopyOptions.create()); - }else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())){ - nacosParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), NacosParserVO.class); - } + try { + NacosParserVO nacosParserVO = null; + if (MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))) { + nacosParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), NacosParserVO.class, + CopyOptions.create()); + } + else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { + nacosParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), NacosParserVO.class); + } - if (Objects.isNull(nacosParserVO)) { - throw new NacosException("rule-source-ext-data is empty"); - } + if (Objects.isNull(nacosParserVO)) { + throw new NacosException("rule-source-ext-data is empty"); + } - if (StrUtil.isBlank(nacosParserVO.getServerAddr())){ - nacosParserVO.setServerAddr("127.0.0.1:8848"); - } - if (StrUtil.isBlank(nacosParserVO.getNamespace())){ - nacosParserVO.setNamespace(""); - } - if (StrUtil.isBlank(nacosParserVO.getDataId())){ - nacosParserVO.setDataId("LiteFlow"); - } - if (StrUtil.isBlank(nacosParserVO.getGroup())){ - nacosParserVO.setGroup("LITE_FLOW_GROUP"); - } - if (StrUtil.isBlank(nacosParserVO.getUsername())){ - nacosParserVO.setUsername(""); - } - if (StrUtil.isBlank(nacosParserVO.getPassword())){ - nacosParserVO.setPassword(""); - } - helper = new NacosParserHelper(nacosParserVO); - }catch (Exception e){ - throw new NacosException(e.getMessage()); - } - } + if (StrUtil.isBlank(nacosParserVO.getServerAddr())) { + nacosParserVO.setServerAddr("127.0.0.1:8848"); + } + if (StrUtil.isBlank(nacosParserVO.getNamespace())) { + nacosParserVO.setNamespace(""); + } + if (StrUtil.isBlank(nacosParserVO.getDataId())) { + nacosParserVO.setDataId("LiteFlow"); + } + if (StrUtil.isBlank(nacosParserVO.getGroup())) { + nacosParserVO.setGroup("LITE_FLOW_GROUP"); + } + if (StrUtil.isBlank(nacosParserVO.getUsername())) { + nacosParserVO.setUsername(""); + } + if (StrUtil.isBlank(nacosParserVO.getPassword())) { + nacosParserVO.setPassword(""); + } + helper = new NacosParserHelper(nacosParserVO); + } + catch (Exception e) { + throw new NacosException(e.getMessage()); + } + } + + @Override + public String parseCustom() { + Consumer parseConsumer = t -> { + try { + parse(t); + } + catch (Exception e) { + throw new RuntimeException(e); + } + }; + try { + String content = helper.getContent(); + helper.checkContent(content); + helper.listener(parseConsumer); + return content; + } + catch (Exception e) { + throw new NacosException(e.getMessage()); + } + } - @Override - public String parseCustom() { - Consumer parseConsumer = t -> { - try { - parse(t); - } catch (Exception e) { - throw new RuntimeException(e); - } - }; - try{ - String content = helper.getContent(); - helper.checkContent(content); - helper.listener(parseConsumer); - return content; - }catch (Exception e){ - throw new NacosException(e.getMessage()); - } - } } diff --git a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/exception/NacosException.java b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/exception/NacosException.java index 7b59de8b..f256fb52 100644 --- a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/exception/NacosException.java +++ b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/exception/NacosException.java @@ -20,4 +20,5 @@ public class NacosException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java index 3bb5ed3a..3765ccb4 100644 --- a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/util/NacosParserHelper.java @@ -19,39 +19,45 @@ import java.util.function.Consumer; /** * Nacos client for http api * OpenAPI + * * @author mll * @since 2.9.0 */ public class NacosParserHelper { + private static final Logger LOG = LoggerFactory.getLogger(NacosParserHelper.class); - private final NacosParserVO nacosParserVO; + private final NacosParserVO nacosParserVO; private NacosConfigService configService; public NacosParserHelper(NacosParserVO nacosParserVO) { this.nacosParserVO = nacosParserVO; - try{ - try{ + try { + try { this.configService = ContextAwareHolder.loadContextAware().getBean(NacosConfigService.class); - }catch (Exception ignored){} - if (this.configService == null){ + } + catch (Exception ignored) { + } + if (this.configService == null) { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, nacosParserVO.getServerAddr()); - properties.put(PropertyKeyConst.NAMESPACE,nacosParserVO.getNamespace()); - properties.put(PropertyKeyConst.USERNAME,nacosParserVO.getUsername()); - properties.put(PropertyKeyConst.PASSWORD,nacosParserVO.getPassword()); + properties.put(PropertyKeyConst.NAMESPACE, nacosParserVO.getNamespace()); + properties.put(PropertyKeyConst.USERNAME, nacosParserVO.getUsername()); + properties.put(PropertyKeyConst.PASSWORD, nacosParserVO.getPassword()); this.configService = new NacosConfigService(properties); } - }catch (Exception e){ + } + catch (Exception e) { throw new NacosException(e.getMessage()); } } - public String getContent(){ - try{ + public String getContent() { + try { return configService.getConfig(nacosParserVO.getDataId(), nacosParserVO.getGroup(), 3000L); - }catch (Exception e){ + } + catch (Exception e) { throw new NacosException(e.getMessage()); } } @@ -74,15 +80,17 @@ public class NacosParserHelper { this.configService.addListener(nacosParserVO.getDataId(), nacosParserVO.getGroup(), new Listener() { @Override public void receiveConfigInfo(String configInfo) { - LOG.info("stating load flow config.... {} " , configInfo); + LOG.info("stating load flow config.... {} ", configInfo); parseConsumer.accept(configInfo); } + @Override public Executor getExecutor() { return null; } }); - }catch (Exception ex){ + } + catch (Exception ex) { throw new NacosException(ex.getMessage()); } } diff --git a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/vo/NacosParserVO.java b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/vo/NacosParserVO.java index 9a3be530..010a240b 100644 --- a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/vo/NacosParserVO.java +++ b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/nacos/vo/NacosParserVO.java @@ -2,68 +2,77 @@ package com.yomahub.liteflow.parser.nacos.vo; /** * 用于解析 RuleSourceExtData 的vo类,用于nacos模式中 + * * @author mll * @since 2.9.0 */ public class NacosParserVO { - private String serverAddr; - private String namespace; - private String dataId; - private String group; - private String username; - private String password; - public String getServerAddr() { - return serverAddr; - } + private String serverAddr; - public void setServerAddr(String serverAddr) { - this.serverAddr = serverAddr; - } + private String namespace; - public String getNamespace() { - return namespace; - } + private String dataId; - public void setNamespace(String namespace) { - this.namespace = namespace; - } + private String group; - public String getDataId() { - return dataId; - } + private String username; - public void setDataId(String dataId) { - this.dataId = dataId; - } + private String password; - public String getGroup() { - return group; - } + public String getServerAddr() { + return serverAddr; + } - public void setGroup(String group) { - this.group = group; - } + public void setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + } - public String getUsername() { - return username; - } + public String getNamespace() { + return namespace; + } - public void setUsername(String username) { - this.username = username; - } + public void setNamespace(String namespace) { + this.namespace = namespace; + } - public String getPassword() { - return password; - } + public String getDataId() { + return dataId; + } - public void setPassword(String password) { - this.password = password; - } + public void setDataId(String dataId) { + this.dataId = dataId; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + return "NacosParserVO{" + "serverAddr='" + serverAddr + '\'' + ", namespace='" + namespace + '\'' + ", dataId='" + + dataId + '\'' + ", group='" + group + '\'' + ", username='" + username + '\'' + ", password='" + + password + '\'' + '}'; + } - @Override - public String toString() { - return "NacosParserVO{" + "serverAddr='" + serverAddr + '\'' + ", namespace='" + namespace + '\'' + ", dataId='" + dataId + '\'' + ", group='" + group + '\'' - + ", username='" + username + '\'' + ", password='" + password + '\'' + '}'; - } } diff --git a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/spi/nacos/NacosParserClassNameSpi.java b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/spi/nacos/NacosParserClassNameSpi.java index 95a25ed5..602cbee5 100644 --- a/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/spi/nacos/NacosParserClassNameSpi.java +++ b/liteflow-rule-plugin/liteflow-rule-nacos/src/main/java/com/yomahub/liteflow/parser/spi/nacos/NacosParserClassNameSpi.java @@ -5,13 +5,15 @@ import com.yomahub.liteflow.parser.spi.ParserClassNameSpi; /** * Nacos 解析器SPI实现 + * * @author mll * @since 2.9.0 */ public class NacosParserClassNameSpi implements ParserClassNameSpi { - @Override - public String getSpiClassName() { - return NacosXmlELParser.class.getName(); - } + @Override + public String getSpiClassName() { + return NacosXmlELParser.class.getName(); + } + } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java index 41271acd..90781805 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/SQLXmlELParser.java @@ -24,6 +24,7 @@ import java.util.Objects; public class SQLXmlELParser extends ClassXmlFlowELParser { private static final String ERROR_MSG_PATTERN = "rule-source-ext-data {} is blank"; + private static final String ERROR_COMMON_MSG = "rule-source-ext-data is empty"; /** @@ -35,8 +36,10 @@ public class SQLXmlELParser extends ClassXmlFlowELParser { try { SQLParserVO sqlParserVO = null; if (MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))) { - sqlParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), SQLParserVO.class, CopyOptions.create()); - } else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { + sqlParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), SQLParserVO.class, + CopyOptions.create()); + } + else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); } if (Objects.isNull(sqlParserVO)) { @@ -48,9 +51,11 @@ public class SQLXmlELParser extends ClassXmlFlowELParser { // 初始化 JDBCHelper JDBCHelper.init(sqlParserVO); - } catch (ELSQLException elsqlException) { + } + catch (ELSQLException elsqlException) { throw elsqlException; - } catch (Exception ex) { + } + catch (Exception ex) { throw new ELSQLException(ex.getMessage()); } @@ -63,7 +68,6 @@ public class SQLXmlELParser extends ClassXmlFlowELParser { /** * 检查配置文件并设置默认值 - * * @param sqlParserVO sqlParserVO */ private void checkParserVO(SQLParserVO sqlParserVO) { @@ -80,4 +84,5 @@ public class SQLXmlELParser extends ClassXmlFlowELParser { throw new ELSQLException(StrFormatter.format(ERROR_MSG_PATTERN, "password")); } } + } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/exception/ELSQLException.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/exception/ELSQLException.java index e0a4a24a..875f6d6d 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/exception/ELSQLException.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/exception/ELSQLException.java @@ -27,4 +27,5 @@ public class ELSQLException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java index 8bce369a..e07f96bb 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/util/JDBCHelper.java @@ -24,250 +24,258 @@ import java.util.Objects; */ public class JDBCHelper { - private static final String SQL_PATTERN = "SELECT {},{} FROM {} WHERE {}=?"; + private static final String SQL_PATTERN = "SELECT {},{} FROM {} WHERE {}=?"; - private static final String SCRIPT_SQL_CHECK_PATTERN = "SELECT 1 FROM {} WHERE {}=?"; + private static final String SCRIPT_SQL_CHECK_PATTERN = "SELECT 1 FROM {} WHERE {}=?"; - private static final String SCRIPT_SQL_PATTERN = "SELECT {},{},{},{} FROM {} WHERE {}=?"; + private static final String SCRIPT_SQL_PATTERN = "SELECT {},{},{},{} FROM {} WHERE {}=?"; - private static final String CHAIN_XML_PATTERN = "{}"; - private static final String NODE_XML_PATTERN = "{}"; + private static final String CHAIN_XML_PATTERN = "{}"; - private static final String NODE_ITEM_XML_PATTERN = ""; - private static final String XML_PATTERN = "{}{}"; - private static final Integer FETCH_SIZE_MAX = 1000; + private static final String NODE_XML_PATTERN = "{}"; - private SQLParserVO sqlParserVO; + private static final String NODE_ITEM_XML_PATTERN = ""; - private static JDBCHelper INSTANCE; + private static final String XML_PATTERN = "{}{}"; - /** - * 初始化 INSTANCE - */ - public static void init(SQLParserVO sqlParserVO) { - try { - INSTANCE = new JDBCHelper(); - Class.forName(sqlParserVO.getDriverClassName()); - INSTANCE.setSqlParserVO(sqlParserVO); - } catch (ClassNotFoundException e) { - throw new ELSQLException(e.getMessage()); - } - } + private static final Integer FETCH_SIZE_MAX = 1000; - /** - * 获取 INSTANCE - */ - public static JDBCHelper getInstance() { - return INSTANCE; - } + private SQLParserVO sqlParserVO; - /** - * 获取链接 - */ - public Connection getConn() { - Connection connection; - try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), sqlParserVO.getPassword()); - } catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - return connection; - } + private static JDBCHelper INSTANCE; - /** - * 获取 ElData 数据内容 - */ - public String getContent() { - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; + /** + * 初始化 INSTANCE + */ + public static void init(SQLParserVO sqlParserVO) { + try { + INSTANCE = new JDBCHelper(); + Class.forName(sqlParserVO.getDriverClassName()); + INSTANCE.setSqlParserVO(sqlParserVO); + } + catch (ClassNotFoundException e) { + throw new ELSQLException(e.getMessage()); + } + } - String chainTableName = sqlParserVO.getChainTableName(); - String elDataField = sqlParserVO.getElDataField(); - String chainNameField = sqlParserVO.getChainNameField(); - String chainApplicationNameField = sqlParserVO.getChainApplicationNameField(); - String applicationName = sqlParserVO.getApplicationName(); + /** + * 获取 INSTANCE + */ + public static JDBCHelper getInstance() { + return INSTANCE; + } - if (StrUtil.isBlank(chainTableName)) { - throw new ELSQLException("You did not define the chainTableName property"); - } + /** + * 获取链接 + */ + public Connection getConn() { + Connection connection; + try { + connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), + sqlParserVO.getPassword()); + } + catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + return connection; + } - if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(chainApplicationNameField)) { - throw new ELSQLException("You did not define the applicationName or chainApplicationNameField property"); - } + /** + * 获取 ElData 数据内容 + */ + public String getContent() { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; - String sqlCmd = StrUtil.format(SQL_PATTERN, chainNameField, elDataField, chainTableName, chainApplicationNameField); + String chainTableName = sqlParserVO.getChainTableName(); + String elDataField = sqlParserVO.getElDataField(); + String chainNameField = sqlParserVO.getChainNameField(); + String chainApplicationNameField = sqlParserVO.getChainApplicationNameField(); + String applicationName = sqlParserVO.getApplicationName(); - List result = new ArrayList<>(); - try { - conn = getConn(); - stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - // 设置游标拉取数量 - stmt.setFetchSize(FETCH_SIZE_MAX); - stmt.setString(1, applicationName); - rs = stmt.executeQuery(); + if (StrUtil.isBlank(chainTableName)) { + throw new ELSQLException("You did not define the chainTableName property"); + } - while (rs.next()) { - String elData = getStringFromResultSet(rs, elDataField); - String chainName = getStringFromResultSet(rs, chainNameField); + if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(chainApplicationNameField)) { + throw new ELSQLException("You did not define the applicationName or chainApplicationNameField property"); + } - result.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(chainName), elData)); - } - } catch (Exception e) { - throw new ELSQLException(e.getMessage()); - } finally { - // 关闭连接 - close(conn, stmt, rs); - } + String sqlCmd = StrUtil.format(SQL_PATTERN, chainNameField, elDataField, chainTableName, + chainApplicationNameField); - String chainsContent = CollUtil.join(result, StrUtil.EMPTY); + List result = new ArrayList<>(); + try { + conn = getConn(); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + // 设置游标拉取数量 + stmt.setFetchSize(FETCH_SIZE_MAX); + stmt.setString(1, applicationName); + rs = stmt.executeQuery(); - String nodesContent; - if (hasScriptData()) { - nodesContent = getScriptNodes(); - } else { - nodesContent = StrUtil.EMPTY; - } + while (rs.next()) { + String elData = getStringFromResultSet(rs, elDataField); + String chainName = getStringFromResultSet(rs, chainNameField); - return StrUtil.format(XML_PATTERN, nodesContent, chainsContent); - } + result.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(chainName), elData)); + } + } + catch (Exception e) { + throw new ELSQLException(e.getMessage()); + } + finally { + // 关闭连接 + close(conn, stmt, rs); + } - public String getScriptNodes() { - List result = new ArrayList<>(); - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; + String chainsContent = CollUtil.join(result, StrUtil.EMPTY); - String scriptTableName = sqlParserVO.getScriptTableName(); - String scriptIdField = sqlParserVO.getScriptIdField(); - String scriptDataField = sqlParserVO.getScriptDataField(); - String scriptNameField = sqlParserVO.getScriptNameField(); - String scriptTypeField = sqlParserVO.getScriptTypeField(); - String scriptApplicationNameField = sqlParserVO.getScriptApplicationNameField(); - String applicationName = sqlParserVO.getApplicationName(); + String nodesContent; + if (hasScriptData()) { + nodesContent = getScriptNodes(); + } + else { + nodesContent = StrUtil.EMPTY; + } - if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) { - throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property"); - } + return StrUtil.format(XML_PATTERN, nodesContent, chainsContent); + } - String sqlCmd = StrUtil.format( - SCRIPT_SQL_PATTERN, - scriptIdField, - scriptDataField, - scriptNameField, - scriptTypeField, - scriptTableName, - scriptApplicationNameField - ); - try { - conn = getConn(); - stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - // 设置游标拉取数量 - stmt.setFetchSize(FETCH_SIZE_MAX); - stmt.setString(1, applicationName); - rs = stmt.executeQuery(); + public String getScriptNodes() { + List result = new ArrayList<>(); + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; - while (rs.next()) { - String id = getStringFromResultSet(rs, scriptIdField); - String data = getStringFromResultSet(rs, scriptDataField); - String name = getStringFromResultSet(rs, scriptNameField); - String type = getStringFromResultSet(rs, scriptTypeField); + String scriptTableName = sqlParserVO.getScriptTableName(); + String scriptIdField = sqlParserVO.getScriptIdField(); + String scriptDataField = sqlParserVO.getScriptDataField(); + String scriptNameField = sqlParserVO.getScriptNameField(); + String scriptTypeField = sqlParserVO.getScriptTypeField(); + String scriptApplicationNameField = sqlParserVO.getScriptApplicationNameField(); + String applicationName = sqlParserVO.getApplicationName(); - NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type); - if (Objects.isNull(nodeTypeEnum)) { - throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type)); - } + if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) { + throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property"); + } - if (!nodeTypeEnum.isScript()) { - throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type)); - } + String sqlCmd = StrUtil.format(SCRIPT_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField, + scriptTypeField, scriptTableName, scriptApplicationNameField); + try { + conn = getConn(); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + // 设置游标拉取数量 + stmt.setFetchSize(FETCH_SIZE_MAX); + stmt.setString(1, applicationName); + rs = stmt.executeQuery(); - result.add(StrUtil.format(NODE_ITEM_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), type, data)); - } - } catch (Exception e) { - throw new ELSQLException(e.getMessage()); - } finally { - // 关闭连接 - close(conn, stmt, rs); - } - return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY)); - } + while (rs.next()) { + String id = getStringFromResultSet(rs, scriptIdField); + String data = getStringFromResultSet(rs, scriptDataField); + String name = getStringFromResultSet(rs, scriptNameField); + String type = getStringFromResultSet(rs, scriptTypeField); - /** - * 关闭连接 - * - * @param conn conn - * @param stmt stmt - * @param rs rs - */ - private void close(Connection conn, PreparedStatement stmt, ResultSet rs) { - // 关闭连接 - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - } - // 关闭 statement - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - } - //关闭结果集 - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - throw new ELSQLException(e.getMessage()); - } - } - } + NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type); + if (Objects.isNull(nodeTypeEnum)) { + throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type)); + } - private boolean hasScriptData() { - if (StrUtil.isBlank(sqlParserVO.getScriptTableName())) { - return false; - } + if (!nodeTypeEnum.isScript()) { + throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type)); + } - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; - String sqlCmd = StrUtil.format(SCRIPT_SQL_CHECK_PATTERN, - sqlParserVO.getScriptTableName(), - sqlParserVO.getScriptApplicationNameField()); - try { - conn = getConn(); - stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - stmt.setFetchSize(1); - stmt.setString(1, sqlParserVO.getApplicationName()); - rs = stmt.executeQuery(); - return rs.next(); - } catch (Exception e) { - return false; - } finally { - // 关闭连接 - close(conn, stmt, rs); - } - } + result.add(StrUtil.format(NODE_ITEM_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name), type, data)); + } + } + catch (Exception e) { + throw new ELSQLException(e.getMessage()); + } + finally { + // 关闭连接 + close(conn, stmt, rs); + } + return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY)); + } + /** + * 关闭连接 + * @param conn conn + * @param stmt stmt + * @param rs rs + */ + private void close(Connection conn, PreparedStatement stmt, ResultSet rs) { + // 关闭连接 + if (conn != null) { + try { + conn.close(); + } + catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + // 关闭 statement + if (stmt != null) { + try { + stmt.close(); + } + catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + // 关闭结果集 + if (rs != null) { + try { + rs.close(); + } + catch (SQLException e) { + throw new ELSQLException(e.getMessage()); + } + } + } - //#region get set method - private String getStringFromResultSet(ResultSet rs, String field) throws SQLException { - String data = rs.getString(field); - if (StrUtil.isBlank(data)) { - throw new ELSQLException(StrUtil.format("exist {} field value is empty", field)); - } - return data; - } + private boolean hasScriptData() { + if (StrUtil.isBlank(sqlParserVO.getScriptTableName())) { + return false; + } - private SQLParserVO getSqlParserVO() { - return sqlParserVO; - } + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + String sqlCmd = StrUtil.format(SCRIPT_SQL_CHECK_PATTERN, sqlParserVO.getScriptTableName(), + sqlParserVO.getScriptApplicationNameField()); + try { + conn = getConn(); + stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + stmt.setFetchSize(1); + stmt.setString(1, sqlParserVO.getApplicationName()); + rs = stmt.executeQuery(); + return rs.next(); + } + catch (Exception e) { + return false; + } + finally { + // 关闭连接 + close(conn, stmt, rs); + } + } + + // #region get set method + private String getStringFromResultSet(ResultSet rs, String field) throws SQLException { + String data = rs.getString(field); + if (StrUtil.isBlank(data)) { + throw new ELSQLException(StrUtil.format("exist {} field value is empty", field)); + } + return data; + } + + private SQLParserVO getSqlParserVO() { + return sqlParserVO; + } + + private void setSqlParserVO(SQLParserVO sqlParserVO) { + this.sqlParserVO = sqlParserVO; + } - private void setSqlParserVO(SQLParserVO sqlParserVO) { - this.sqlParserVO = sqlParserVO; - } } diff --git a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java index 9065af69..982a7125 100644 --- a/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java +++ b/liteflow-rule-plugin/liteflow-rule-sql/src/main/java/com/yomahub/liteflow/parser/sql/vo/SQLParserVO.java @@ -202,4 +202,5 @@ public class SQLParserVO { public void setScriptTypeField(String scriptTypeField) { this.scriptTypeField = scriptTypeField; } + } diff --git a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/spi/zk/ZkParserClassNameSpi.java b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/spi/zk/ZkParserClassNameSpi.java index 694ae1c6..9e5c5ba8 100644 --- a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/spi/zk/ZkParserClassNameSpi.java +++ b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/spi/zk/ZkParserClassNameSpi.java @@ -1,17 +1,19 @@ package com.yomahub.liteflow.parser.spi.zk; - import com.yomahub.liteflow.parser.spi.ParserClassNameSpi; import com.yomahub.liteflow.parser.zk.ZkXmlELParser; /** * ZK解析器SPI实现 + * * @author Bryan.Zhang * @since 2.8.6 */ public class ZkParserClassNameSpi implements ParserClassNameSpi { - @Override - public String getSpiClassName() { - return ZkXmlELParser.class.getName(); - } + + @Override + public String getSpiClassName() { + return ZkXmlELParser.class.getName(); + } + } diff --git a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/ZkXmlELParser.java b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/ZkXmlELParser.java index 2bbc82cc..7c9ed0b4 100644 --- a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/ZkXmlELParser.java +++ b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/ZkXmlELParser.java @@ -17,54 +17,60 @@ import java.util.Objects; /** * ZK解析器实现,只支持EL形式的XML,不支持其他的形式 + * * @author Bryan.Zhang * @since 2.8.6 */ public class ZkXmlELParser extends ClassXmlFlowELParser { - private final ZkParserHelper zkParserHelper; + private final ZkParserHelper zkParserHelper; - public ZkXmlELParser() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + public ZkXmlELParser() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - try{ - ZkParserVO zkParserVO = null; - if(MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))){ - zkParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), ZkParserVO.class, CopyOptions.create()); - }else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())){ - zkParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), ZkParserVO.class); - } + try { + ZkParserVO zkParserVO = null; + if (MapUtil.isNotEmpty((liteflowConfig.getRuleSourceExtDataMap()))) { + zkParserVO = BeanUtil.toBean(liteflowConfig.getRuleSourceExtDataMap(), ZkParserVO.class, + CopyOptions.create()); + } + else if (StrUtil.isNotBlank(liteflowConfig.getRuleSourceExtData())) { + zkParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), ZkParserVO.class); + } - if (Objects.isNull(zkParserVO)) { - throw new ZkException("rule-source-ext-data is empty"); - } + if (Objects.isNull(zkParserVO)) { + throw new ZkException("rule-source-ext-data is empty"); + } - if (StrUtil.isBlank(zkParserVO.getChainPath())){ - throw new ZkException("You must configure the chainPath property"); - } - if (StrUtil.isBlank(zkParserVO.getConnectStr())){ - throw new ZkException("zk connect string is empty"); - } + if (StrUtil.isBlank(zkParserVO.getChainPath())) { + throw new ZkException("You must configure the chainPath property"); + } + if (StrUtil.isBlank(zkParserVO.getConnectStr())) { + throw new ZkException("zk connect string is empty"); + } - zkParserHelper = new ZkParserHelper(zkParserVO); - }catch (Exception e){ - throw new ZkException(e.getMessage()); - } - } + zkParserHelper = new ZkParserHelper(zkParserVO); + } + catch (Exception e) { + throw new ZkException(e.getMessage()); + } + } - @Override - public String parseCustom() { - try{ - String content = zkParserHelper.getContent(); + @Override + public String parseCustom() { + try { + String content = zkParserHelper.getContent(); - FlowInitHook.addHook(() -> { - zkParserHelper.listenZkNode(); - return true; - }); + FlowInitHook.addHook(() -> { + zkParserHelper.listenZkNode(); + return true; + }); + + return content; + } + catch (Exception e) { + throw new ZkException(e.getMessage()); + } + } - return content; - }catch (Exception e){ - throw new ZkException(e.getMessage()); - } - } } diff --git a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/exception/ZkException.java b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/exception/ZkException.java index a7b315fe..70ac5b83 100644 --- a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/exception/ZkException.java +++ b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/exception/ZkException.java @@ -20,4 +20,5 @@ public class ZkException extends RuntimeException { public void setMessage(String message) { this.message = message; } + } diff --git a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java index 3b658a8d..00874a01 100644 --- a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java +++ b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/util/ZkParserHelper.java @@ -28,6 +28,7 @@ public class ZkParserHelper { private static final Logger LOG = LoggerFactory.getLogger(ZkParserHelper.class); private final ZkParserVO zkParserVO; + private final CuratorFramework client; private final String CHAIN_XML_PATTERN = "{}"; @@ -41,90 +42,87 @@ public class ZkParserHelper { public ZkParserHelper(ZkParserVO zkParserVO) { this.zkParserVO = zkParserVO; - try{ - CuratorFramework client = CuratorFrameworkFactory.newClient( - zkParserVO.getConnectStr(), - new RetryNTimes(10, 5000) - ); + try { + CuratorFramework client = CuratorFrameworkFactory.newClient(zkParserVO.getConnectStr(), + new RetryNTimes(10, 5000)); client.start(); this.client = client; - }catch (Exception e){ + } + catch (Exception e) { throw new ZkException(e.getMessage()); } } - public String getContent(){ - try{ - //检查zk上有没有chainPath节点 + public String getContent() { + try { + // 检查zk上有没有chainPath节点 if (client.checkExists().forPath(zkParserVO.getChainPath()) == null) { throw new ZkException(StrUtil.format("zk node[{}] is not exist", zkParserVO.getChainPath())); } - //检查chainPath路径下有没有子节点 + // 检查chainPath路径下有没有子节点 List chainNameList = client.getChildren().forPath(zkParserVO.getChainPath()); - if (CollectionUtil.isEmpty(chainNameList)){ + if (CollectionUtil.isEmpty(chainNameList)) { throw new ZkException(StrUtil.format("There are no chains in path [{}]", zkParserVO.getChainPath())); } - //获取chainPath路径下的所有子节点内容List + // 获取chainPath路径下的所有子节点内容List List chainItemContentList = new ArrayList<>(); - for (String chainName : chainNameList){ - String chainData = new String(client.getData().forPath(StrUtil.format("{}/{}", zkParserVO.getChainPath(), chainName))); + for (String chainName : chainNameList) { + String chainData = new String( + client.getData().forPath(StrUtil.format("{}/{}", zkParserVO.getChainPath(), chainName))); chainItemContentList.add(StrUtil.format(CHAIN_XML_PATTERN, chainName, chainData)); } - //合并成所有chain的xml内容 + // 合并成所有chain的xml内容 String chainAllContent = CollUtil.join(chainItemContentList, StrUtil.EMPTY); - //检查是否有脚本内容,如果有,进行脚本内容的获取 + // 检查是否有脚本内容,如果有,进行脚本内容的获取 String scriptAllContent = StrUtil.EMPTY; - if (hasScript()){ + if (hasScript()) { List scriptNodeValueList = client.getChildren().forPath(zkParserVO.getScriptPath()); List scriptItemContentList = new ArrayList<>(); - for (String scriptNodeValue: scriptNodeValueList){ + for (String scriptNodeValue : scriptNodeValueList) { NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); - if (Objects.isNull(nodeSimpleVO)){ + if (Objects.isNull(nodeSimpleVO)) { throw new ZkException(StrUtil.format("The name of the zk node is invalid:{}", scriptNodeValue)); } - String scriptData = new String( - client.getData().forPath(StrUtil.format("{}/{}", zkParserVO.getScriptPath(), scriptNodeValue)) - ); + String scriptData = new String(client.getData() + .forPath(StrUtil.format("{}/{}", zkParserVO.getScriptPath(), scriptNodeValue))); - scriptItemContentList.add( - StrUtil.format(NODE_ITEM_XML_PATTERN, - nodeSimpleVO.getNodeId(), - nodeSimpleVO.getName(), - nodeSimpleVO.getType(), - scriptData) - ); + scriptItemContentList.add(StrUtil.format(NODE_ITEM_XML_PATTERN, nodeSimpleVO.getNodeId(), + nodeSimpleVO.getName(), nodeSimpleVO.getType(), scriptData)); } - scriptAllContent = StrUtil.format(NODE_XML_PATTERN, CollUtil.join(scriptItemContentList, StrUtil.EMPTY)); + scriptAllContent = StrUtil.format(NODE_XML_PATTERN, + CollUtil.join(scriptItemContentList, StrUtil.EMPTY)); } return StrUtil.format(XML_PATTERN, scriptAllContent, chainAllContent); - }catch (Exception e){ + } + catch (Exception e) { throw new ZkException(e.getMessage()); } } - public boolean hasScript(){ - //没有配置scriptPath - if (StrUtil.isBlank(zkParserVO.getScriptPath())){ + public boolean hasScript() { + // 没有配置scriptPath + if (StrUtil.isBlank(zkParserVO.getScriptPath())) { return false; } - try{ - //配置了,但是不存在这个节点 - if (client.checkExists().forPath(zkParserVO.getScriptPath()) == null){ + try { + // 配置了,但是不存在这个节点 + if (client.checkExists().forPath(zkParserVO.getScriptPath()) == null) { return false; } - //存在这个节点,但是子节点不存在 + // 存在这个节点,但是子节点不存在 List chainNameList = client.getChildren().forPath(zkParserVO.getScriptPath()); return !CollUtil.isEmpty(chainNameList); - }catch (Exception e){ + } + catch (Exception e) { return false; } } @@ -132,46 +130,52 @@ public class ZkParserHelper { /** * 监听 zk 节点 */ - public void listenZkNode(){ - //监听chain + public void listenZkNode() { + // 监听chain CuratorCache cache1 = CuratorCache.build(client, zkParserVO.getChainPath()); cache1.start(); cache1.listenable().addListener((type, oldData, data) -> { String path = data.getPath(); String value = new String(data.getData()); - if (StrUtil.isBlank(value)){ + if (StrUtil.isBlank(value)) { return; } - if (ListUtil.toList(CuratorCacheListener.Type.NODE_CREATED, CuratorCacheListener.Type.NODE_CHANGED).contains(type)){ + if (ListUtil.toList(CuratorCacheListener.Type.NODE_CREATED, CuratorCacheListener.Type.NODE_CHANGED) + .contains(type)) { LOG.info("starting reload flow config... {} path={} value={},", type.name(), path, value); String chainName = FileNameUtil.getName(path); LiteFlowChainELBuilder.createChain().setChainId(chainName).setEL(value).build(); - }else if(CuratorCacheListener.Type.NODE_DELETED.equals(type)){ + } + else if (CuratorCacheListener.Type.NODE_DELETED.equals(type)) { LOG.info("starting reload flow config... delete path={}", path); String chainName = FileNameUtil.getName(path); FlowBus.removeChain(chainName); } }); - if (StrUtil.isNotBlank(zkParserVO.getScriptPath())){ - //监听script + if (StrUtil.isNotBlank(zkParserVO.getScriptPath())) { + // 监听script CuratorCache cache2 = CuratorCache.build(client, zkParserVO.getScriptPath()); cache2.start(); cache2.listenable().addListener((type, oldData, data) -> { String path = data.getPath(); String value = new String(data.getData()); - if (StrUtil.isBlank(value)){ + if (StrUtil.isBlank(value)) { return; } - if (ListUtil.toList(CuratorCacheListener.Type.NODE_CREATED, CuratorCacheListener.Type.NODE_CHANGED).contains(type)){ + if (ListUtil.toList(CuratorCacheListener.Type.NODE_CREATED, CuratorCacheListener.Type.NODE_CHANGED) + .contains(type)) { LOG.info("starting reload flow config... {} path={} value={},", type.name(), path, value); String scriptNodeValue = FileNameUtil.getName(path); NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); - LiteFlowNodeBuilder.createScriptNode().setId(nodeSimpleVO.getNodeId()) - .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type)) - .setName(nodeSimpleVO.getName()) - .setScript(value).build(); - } else if (CuratorCacheListener.Type.NODE_DELETED.equals(type)) { + LiteFlowNodeBuilder.createScriptNode() + .setId(nodeSimpleVO.getNodeId()) + .setType(NodeTypeEnum.getEnumByCode(nodeSimpleVO.type)) + .setName(nodeSimpleVO.getName()) + .setScript(value) + .build(); + } + else if (CuratorCacheListener.Type.NODE_DELETED.equals(type)) { LOG.info("starting reload flow config... delete path={}", path); String scriptNodeValue = FileNameUtil.getName(path); NodeSimpleVO nodeSimpleVO = convert(scriptNodeValue); @@ -181,34 +185,34 @@ public class ZkParserHelper { } } - public NodeSimpleVO convert(String str){ - //不需要去理解这串正则,就是一个匹配冒号的 - //一定得是a:b,或是a:b:c...这种完整类型的字符串的 + public NodeSimpleVO convert(String str) { + // 不需要去理解这串正则,就是一个匹配冒号的 + // 一定得是a:b,或是a:b:c...这种完整类型的字符串的 List matchItemList = ReUtil.findAllGroup0("(?<=[^:]:)[^:]+|[^:]+(?=:[^:])", str); - if (CollUtil.isEmpty(matchItemList)){ + if (CollUtil.isEmpty(matchItemList)) { return null; } NodeSimpleVO nodeSimpleVO = new NodeSimpleVO(); - if (matchItemList.size() > 1){ + if (matchItemList.size() > 1) { nodeSimpleVO.setNodeId(matchItemList.get(0)); nodeSimpleVO.setType(matchItemList.get(1)); } - if (matchItemList.size() > 2){ + if (matchItemList.size() > 2) { nodeSimpleVO.setName(matchItemList.get(2)); } return nodeSimpleVO; } - private static class NodeSimpleVO{ + private static class NodeSimpleVO { private String nodeId; private String type; - private String name=""; + private String name = ""; public String getNodeId() { return nodeId; @@ -233,5 +237,7 @@ public class ZkParserHelper { public void setName(String name) { this.name = name; } + } + } diff --git a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/vo/ZkParserVO.java b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/vo/ZkParserVO.java index 5d99ea44..dde939c4 100644 --- a/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/vo/ZkParserVO.java +++ b/liteflow-rule-plugin/liteflow-rule-zk/src/main/java/com/yomahub/liteflow/parser/zk/vo/ZkParserVO.java @@ -2,38 +2,40 @@ package com.yomahub.liteflow.parser.zk.vo; /** * 用于解析RuleSourceExtData的vo类,用于zk模式中 + * * @author Bryan.Zhang * @since 2.8.6 */ public class ZkParserVO { - private String connectStr; + private String connectStr; - private String chainPath; + private String chainPath; - private String scriptPath; + private String scriptPath; - public String getConnectStr() { - return connectStr; - } + public String getConnectStr() { + return connectStr; + } - public void setConnectStr(String connectStr) { - this.connectStr = connectStr; - } + public void setConnectStr(String connectStr) { + this.connectStr = connectStr; + } - public String getChainPath() { - return chainPath; - } + public String getChainPath() { + return chainPath; + } - public void setChainPath(String chainPath) { - this.chainPath = chainPath; - } + public void setChainPath(String chainPath) { + this.chainPath = chainPath; + } - public String getScriptPath() { - return scriptPath; - } + public String getScriptPath() { + return scriptPath; + } + + public void setScriptPath(String scriptPath) { + this.scriptPath = scriptPath; + } - public void setScriptPath(String scriptPath) { - this.scriptPath = scriptPath; - } } diff --git a/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java b/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java index c6350fa5..f2563e76 100644 --- a/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-graaljs/src/main/java/com/yomahub/liteflow/script/graaljs/GraalJavaScriptExecutor.java @@ -21,100 +21,106 @@ import java.util.Map; /** * GraalVM JavaScript脚本语言的执行器实现 + * * @author zendwang * @since 2.9.4 */ public class GraalJavaScriptExecutor implements ScriptExecutor { - private final Map scriptMap = new CopyOnWriteHashMap<>(); + private final Map scriptMap = new CopyOnWriteHashMap<>(); - private Engine engine; + private Engine engine; - @Override - public ScriptExecutor init() { - engine = Engine.create(); - return this; - } + @Override + public ScriptExecutor init() { + engine = Engine.create(); + return this; + } - @Override - public void load(String nodeId, String script) { - try{ - String wrapScript = StrUtil.format("function process(){{}} process();",script); - scriptMap.put(nodeId, Source.create("js", wrapScript)); - }catch (Exception e){ - String errorMsg = StrUtil.format("script loading error for node[{}], error msg:{}", nodeId, e.getMessage()); - throw new ScriptLoadException(errorMsg); - } - } + @Override + public void load(String nodeId, String script) { + try { + String wrapScript = StrUtil.format("function process(){{}} process();", script); + scriptMap.put(nodeId, Source.create("js", wrapScript)); + } + catch (Exception e) { + String errorMsg = StrUtil.format("script loading error for node[{}], error msg:{}", nodeId, e.getMessage()); + throw new ScriptLoadException(errorMsg); + } + } - @Override - public Object execute(ScriptExecuteWrap wrap) throws Exception{ - if (!scriptMap.containsKey(wrap.getNodeId())){ - String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId()); - throw new ScriptLoadException(errorMsg); - } - try (Context context = Context.newBuilder().allowAllAccess(true).engine(this.engine).build()) { - Value bindings = context.getBindings("js"); - //往脚本语言绑定表里循环增加绑定上下文的key - //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()); - } - bindings.putMember(key, o); - }); + @Override + public Object execute(ScriptExecuteWrap wrap) throws Exception { + if (!scriptMap.containsKey(wrap.getNodeId())) { + String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId()); + throw new ScriptLoadException(errorMsg); + } + try (Context context = Context.newBuilder().allowAllAccess(true).engine(this.engine).build()) { + Value bindings = context.getBindings("js"); + // 往脚本语言绑定表里循环增加绑定上下文的key + // 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()); + } + bindings.putMember(key, o); + }); - //把wrap对象转换成元数据map - Map metaMap = BeanUtil.beanToMap(wrap); + // 把wrap对象转换成元数据map + Map metaMap = BeanUtil.beanToMap(wrap); - //在元数据里放入主Chain的流程参数 - Slot slot = DataBus.getSlot(wrap.getSlotIndex()); - metaMap.put("requestData", slot.getRequestData()); + // 在元数据里放入主Chain的流程参数 + Slot slot = DataBus.getSlot(wrap.getSlotIndex()); + metaMap.put("requestData", slot.getRequestData()); - //如果有隐式流程,则放入隐式流程的流程参数 - Object subRequestData = slot.getChainReqData(wrap.getCurrChainId()); - if (ObjectUtil.isNotNull(subRequestData)){ - metaMap.put("subRequestData", subRequestData); - } + // 如果有隐式流程,则放入隐式流程的流程参数 + Object subRequestData = slot.getChainReqData(wrap.getCurrChainId()); + if (ObjectUtil.isNotNull(subRequestData)) { + metaMap.put("subRequestData", subRequestData); + } - //往脚本上下文里放入元数据 - bindings.putMember("_meta", metaMap); + // 往脚本上下文里放入元数据 + bindings.putMember("_meta", metaMap); - //放入用户自己定义的bean - ScriptBeanManager.getScriptBeanMap().forEach((key, value) -> { - if (!bindings.hasMember(key)) { - bindings.putMember(key, value); - } - }); + // 放入用户自己定义的bean + ScriptBeanManager.getScriptBeanMap().forEach((key, value) -> { + if (!bindings.hasMember(key)) { + bindings.putMember(key, value); + } + }); + Value value = context.eval(scriptMap.get(wrap.getNodeId())); + if (value.isBoolean()) { + return value.asBoolean(); + } + else if (value.isNumber()) { + return value.asInt(); + } + else if (value.isString()) { + return value.asString(); + } + return value; + } + catch (Exception e) { + throw e; + } + } - Value value = context.eval( scriptMap.get(wrap.getNodeId())); - if (value.isBoolean()) { - return value.asBoolean(); - } else if (value.isNumber()) { - return value.asInt(); - } else if (value.isString()) { - return value.asString(); - } - return value; - } catch (Exception e){ - throw e; - } - } + @Override + public void cleanCache() { + scriptMap.clear(); + } - @Override - public void cleanCache() { - scriptMap.clear(); - } + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.JS; + } - @Override - public ScriptTypeEnum scriptType() { - return ScriptTypeEnum.JS; - } } diff --git a/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java b/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java index 64549539..7a1a5666 100644 --- a/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-groovy/src/main/java/com/yomahub/liteflow/script/groovy/GroovyScriptExecutor.java @@ -5,13 +5,15 @@ import com.yomahub.liteflow.script.jsr223.JSR223ScriptExecutor; /** * Groovy脚本语言的执行器实现 + * * @author Bryan.Zhang * @since 2.6.0 */ public class GroovyScriptExecutor extends JSR223ScriptExecutor { - @Override - public ScriptTypeEnum scriptType() { - return ScriptTypeEnum.GROOVY; - } + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.GROOVY; + } + } diff --git a/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java b/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java index 13c387b2..27480802 100644 --- a/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-javascript/src/main/java/com/yomahub/liteflow/script/javascript/JavaScriptExecutor.java @@ -3,20 +3,23 @@ package com.yomahub.liteflow.script.javascript; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ScriptTypeEnum; import com.yomahub.liteflow.script.jsr223.JSR223ScriptExecutor; + /** * JavaScript脚本语言的执行器实现 + * * @author Bryan.Zhang * @since 2.9.1 */ public class JavaScriptExecutor extends JSR223ScriptExecutor { - @Override - protected String convertScript(String script) { - return StrUtil.format("function process(){{}} process();",script); - } + @Override + protected String convertScript(String script) { + return StrUtil.format("function process(){{}} process();", script); + } + + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.JS; + } - @Override - public ScriptTypeEnum scriptType() { - return ScriptTypeEnum.JS; - } } diff --git a/liteflow-script-plugin/liteflow-script-lua/src/main/java/com/yomahub/liteflow/script/lua/LuaScriptExecutor.java b/liteflow-script-plugin/liteflow-script-lua/src/main/java/com/yomahub/liteflow/script/lua/LuaScriptExecutor.java index 1aff1228..f9c2055d 100644 --- a/liteflow-script-plugin/liteflow-script-lua/src/main/java/com/yomahub/liteflow/script/lua/LuaScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-lua/src/main/java/com/yomahub/liteflow/script/lua/LuaScriptExecutor.java @@ -11,30 +11,33 @@ import java.util.stream.Collectors; /** * Lua脚本语言的执行器实现 + * * @author Bryan.Zhang * @since 2.9.5 */ public class LuaScriptExecutor extends JSR223ScriptExecutor { - @Override - public ScriptTypeEnum scriptType() { - return ScriptTypeEnum.LUA; - } - @Override - protected String convertScript(String script) { - String[] lineArray = script.split("\\n"); - List noBlankLineList = Arrays.stream(lineArray).filter( - s -> !StrUtil.isBlank(s) - ).collect(Collectors.toList()); + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.LUA; + } - //用第一行的缩进的空格数作为整个代码的缩进量 - String blankStr = ReUtil.getGroup0("^[ ]*", noBlankLineList.get(0)); + @Override + protected String convertScript(String script) { + String[] lineArray = script.split("\\n"); + List noBlankLineList = Arrays.stream(lineArray) + .filter(s -> !StrUtil.isBlank(s)) + .collect(Collectors.toList()); + + // 用第一行的缩进的空格数作为整个代码的缩进量 + String blankStr = ReUtil.getGroup0("^[ ]*", noBlankLineList.get(0)); + + // 重新构建脚本 + StringBuilder scriptSB = new StringBuilder(); + noBlankLineList.forEach(s -> scriptSB.append(StrUtil.format("{}\n", s.replaceFirst(blankStr, StrUtil.EMPTY)))); + return scriptSB.toString(); + // return StrUtil.format("function + // process()\n{}\nend\nprocess()\n",scriptSB.toString()); + } - //重新构建脚本 - StringBuilder scriptSB = new StringBuilder(); - noBlankLineList.forEach(s - -> scriptSB.append(StrUtil.format("{}\n", s.replaceFirst(blankStr, StrUtil.EMPTY)))); - return scriptSB.toString(); - //return StrUtil.format("function process()\n{}\nend\nprocess()\n",scriptSB.toString()); - } } diff --git a/liteflow-script-plugin/liteflow-script-python/src/main/java/com/yomahub/liteflow/script/python/PythonScriptExecutor.java b/liteflow-script-plugin/liteflow-script-python/src/main/java/com/yomahub/liteflow/script/python/PythonScriptExecutor.java index 6968040b..b6fc46a9 100644 --- a/liteflow-script-plugin/liteflow-script-python/src/main/java/com/yomahub/liteflow/script/python/PythonScriptExecutor.java +++ b/liteflow-script-plugin/liteflow-script-python/src/main/java/com/yomahub/liteflow/script/python/PythonScriptExecutor.java @@ -10,31 +10,32 @@ import java.util.stream.Collectors; /** * Python脚本语言的执行器实现 + * * @author Bryan.Zhang * @since 2.9.5 */ public class PythonScriptExecutor extends JSR223ScriptExecutor { - @Override - public ScriptTypeEnum scriptType() { - return ScriptTypeEnum.PYTHON; - } + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.PYTHON; + } - @Override - protected String convertScript(String script) { - String[] lineArray = script.split("\\n"); - List noBlankLineList = Arrays.stream(lineArray).filter( - s -> !StrUtil.isBlank(s) - ).collect(Collectors.toList()); + @Override + protected String convertScript(String script) { + String[] lineArray = script.split("\\n"); + List noBlankLineList = Arrays.stream(lineArray) + .filter(s -> !StrUtil.isBlank(s)) + .collect(Collectors.toList()); - //用第一行的缩进的空格数作为整个代码的缩进量 - String blankStr = ReUtil.getGroup0("^[ ]*", noBlankLineList.get(0)); + // 用第一行的缩进的空格数作为整个代码的缩进量 + String blankStr = ReUtil.getGroup0("^[ ]*", noBlankLineList.get(0)); - //重新构建脚本 - StringBuilder scriptSB = new StringBuilder(); - noBlankLineList.forEach(s - -> scriptSB.append(StrUtil.format("{}\n", s.replaceFirst(blankStr, StrUtil.EMPTY)))); + // 重新构建脚本 + StringBuilder scriptSB = new StringBuilder(); + noBlankLineList.forEach(s -> scriptSB.append(StrUtil.format("{}\n", s.replaceFirst(blankStr, StrUtil.EMPTY)))); + + return scriptSB.toString(); + } - return scriptSB.toString(); - } } 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 db77dae4..67b17eda 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 @@ -27,99 +27,104 @@ import java.util.Map; /** * 阿里QLExpress脚本语言的执行器实现 + * * @author Bryan.Zhang * @since 2.6.0 */ public class QLExpressScriptExecutor implements ScriptExecutor { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - private ExpressRunner expressRunner; + private ExpressRunner expressRunner; - private final Map compiledScriptMap = new CopyOnWriteHashMap<>(); + private final Map compiledScriptMap = new CopyOnWriteHashMap<>(); - @Override - public ScriptExecutor init() { - expressRunner = new ExpressRunner(); - return this; - } + @Override + public ScriptExecutor init() { + expressRunner = new ExpressRunner(); + return this; + } - @Override - public void load(String nodeId, String script) { - try{ - InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(script); - compiledScriptMap.put(nodeId, instructionSet); - }catch (Exception e){ - String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getMessage()); - throw new ScriptLoadException(errorMsg); - } - } + @Override + public void load(String nodeId, String script) { + try { + InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(script); + compiledScriptMap.put(nodeId, instructionSet); + } + catch (Exception e) { + String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getMessage()); + throw new ScriptLoadException(errorMsg); + } + } - @Override - public Object execute(ScriptExecuteWrap wrap) throws Exception{ - List errorList = new ArrayList<>(); - try{ - if (!compiledScriptMap.containsKey(wrap.getNodeId())){ - String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId()); - throw new ScriptLoadException(errorMsg); - } + @Override + public Object execute(ScriptExecuteWrap wrap) throws Exception { + List errorList = new ArrayList<>(); + try { + if (!compiledScriptMap.containsKey(wrap.getNodeId())) { + String errorMsg = StrUtil.format("script for node[{}] is not loaded", wrap.getNodeId()); + throw new ScriptLoadException(errorMsg); + } - InstructionSet instructionSet = compiledScriptMap.get(wrap.getNodeId()); - DefaultContext context = new DefaultContext<>(); + InstructionSet instructionSet = compiledScriptMap.get(wrap.getNodeId()); + DefaultContext context = new DefaultContext<>(); - //往脚本语言绑定表里循环增加绑定上下文的key - //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()); - } - context.put(key, o); - }); + // 往脚本语言绑定表里循环增加绑定上下文的key + // 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()); + } + context.put(key, o); + }); - //把wrap对象转换成元数据map - Map metaMap = BeanUtil.beanToMap(wrap); + // 把wrap对象转换成元数据map + Map metaMap = BeanUtil.beanToMap(wrap); - //在元数据里放入主Chain的流程参数 - Slot slot = DataBus.getSlot(wrap.getSlotIndex()); - metaMap.put("requestData", slot.getRequestData()); + // 在元数据里放入主Chain的流程参数 + Slot slot = DataBus.getSlot(wrap.getSlotIndex()); + metaMap.put("requestData", slot.getRequestData()); - //如果有隐式流程,则放入隐式流程的流程参数 - Object subRequestData = slot.getChainReqData(wrap.getCurrChainName()); - if (ObjectUtil.isNotNull(subRequestData)){ - metaMap.put("subRequestData", subRequestData); - } + // 如果有隐式流程,则放入隐式流程的流程参数 + Object subRequestData = slot.getChainReqData(wrap.getCurrChainName()); + if (ObjectUtil.isNotNull(subRequestData)) { + metaMap.put("subRequestData", subRequestData); + } - //往脚本上下文里放入元数据 - context.put("_meta", metaMap); + // 往脚本上下文里放入元数据 + context.put("_meta", metaMap); - //放入用户自己定义的bean - //放入用户自己定义的bean - ScriptBeanManager.getScriptBeanMap().forEach(context::putIfAbsent); + // 放入用户自己定义的bean + // 放入用户自己定义的bean + ScriptBeanManager.getScriptBeanMap().forEach(context::putIfAbsent); - return expressRunner.execute(instructionSet, context, errorList, true, false, null); - }catch (Exception e){ - for (String scriptErrorMsg : errorList){ - log.error("\n{}", scriptErrorMsg); - } - throw e; - } - } + return expressRunner.execute(instructionSet, context, errorList, true, false, null); + } + catch (Exception e) { + for (String scriptErrorMsg : errorList) { + log.error("\n{}", scriptErrorMsg); + } + throw e; + } + } - @Override - public void cleanCache() { - compiledScriptMap.clear(); - expressRunner.clearExpressCache(); - ReflectUtil.setFieldValue(expressRunner,"loader",new ExpressLoader(expressRunner)); - } + @Override + public void cleanCache() { + compiledScriptMap.clear(); + expressRunner.clearExpressCache(); + ReflectUtil.setFieldValue(expressRunner, "loader", new ExpressLoader(expressRunner)); + } + + @Override + public ScriptTypeEnum scriptType() { + return ScriptTypeEnum.QLEXPRESS; + } - @Override - public ScriptTypeEnum scriptType() { - return ScriptTypeEnum.QLEXPRESS; - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java index ff50724f..8095a59f 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.annotation; - import java.lang.annotation.*; /** @@ -9,17 +8,18 @@ import java.lang.annotation.*; * @author Bryan.Zhang * @since 2.6.0 */ -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface LiteflowComponent { - @AliasFor("id") - String value() default ""; + @AliasFor("id") + String value() default ""; - @AliasFor("value") - String id() default ""; + @AliasFor("value") + String id() default ""; + + String name() default ""; - String name() default ""; } 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 index 3692deac..9b16e8be 100644 --- 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 @@ -12,37 +12,42 @@ import java.lang.reflect.Method; * @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; + final BeanWrap beanWrap; - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeBreakComponent method parameter cannot be more than one: " + methodFullName); - } + final Method method; - 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); - } - } + final LiteFlowMethodEnum methodEnum; - private Object exec() throws Exception { - if (method.getParameterCount() == 0) { - return method.invoke(beanWrap.get()); - } else { - return method.invoke(beanWrap.get(), this); - } - } + 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(); + } - @Override - public boolean processBreak() throws Exception { - return (boolean) exec(); - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java index c2665b9d..96f9fce7 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java @@ -13,92 +13,97 @@ import java.lang.reflect.Method; * @since 1.11 */ public class NodeComponentOfMethod extends NodeComponent { - final BeanWrap beanWrap; - final Method method; - final LiteFlowMethodEnum methodEnum; - public NodeComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { - this.beanWrap = beanWrap; - this.method = method; - this.methodEnum = methodEnum; + final BeanWrap beanWrap; - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeComponent method parameter cannot be more than one: " + methodFullName); - } + final Method method; - if (method.getReturnType() != Void.class - && method.getReturnType() != void.class) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeComponent method returnType can only be void: " + methodFullName); - } - } + final LiteFlowMethodEnum methodEnum; - private void exec() throws Exception { - if (method.getParameterCount() == 0) { - method.invoke(beanWrap.get()); - } else { - method.invoke(beanWrap.get(), this); - } - } + public NodeComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { + this.beanWrap = beanWrap; + this.method = method; + this.methodEnum = methodEnum; - @Override - public void process() throws Exception { - if(methodEnum != LiteFlowMethodEnum.PROCESS){ - return; - } + if (method.getParameterCount() > 1) { + String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); + throw new LiteFlowException("NodeComponent method parameter cannot be more than one: " + methodFullName); + } - exec(); - } + if (method.getReturnType() != Void.class && method.getReturnType() != void.class) { + String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); + throw new LiteFlowException("NodeComponent method returnType can only be void: " + methodFullName); + } + } + private void exec() throws Exception { + if (method.getParameterCount() == 0) { + method.invoke(beanWrap.get()); + } + else { + method.invoke(beanWrap.get(), this); + } + } - @Override - public void beforeProcess() { - if(methodEnum != LiteFlowMethodEnum.BEFORE_PROCESS){ - return; - } + @Override + public void process() throws Exception { + if (methodEnum != LiteFlowMethodEnum.PROCESS) { + return; + } - try { - exec(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); - } - } + exec(); + } - @Override - public void afterProcess() { - if (methodEnum != LiteFlowMethodEnum.AFTER_PROCESS) { - return; - } + @Override + public void beforeProcess() { + if (methodEnum != LiteFlowMethodEnum.BEFORE_PROCESS) { + return; + } - try { - exec(); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); - } - } + try { + exec(); + } + catch (RuntimeException e) { + throw e; + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + @Override + public void afterProcess() { + if (methodEnum != LiteFlowMethodEnum.AFTER_PROCESS) { + return; + } - @Override - public void onError() throws Exception { - if(methodEnum != LiteFlowMethodEnum.ON_ERROR){ - return; - } + try { + exec(); + } + catch (RuntimeException e) { + throw e; + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + @Override + public void onError() throws Exception { + if (methodEnum != LiteFlowMethodEnum.ON_ERROR) { + return; + } - exec(); - } + exec(); + } - @Override - public void onSuccess() throws Exception { - if(methodEnum != LiteFlowMethodEnum.ON_SUCCESS){ - return; - } + @Override + public void onSuccess() throws Exception { + if (methodEnum != LiteFlowMethodEnum.ON_SUCCESS) { + return; + } + + exec(); + } - exec(); - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeForComponentOfMethod.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeForComponentOfMethod.java index 587c62eb..51883f04 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeForComponentOfMethod.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeForComponentOfMethod.java @@ -12,37 +12,41 @@ import java.lang.reflect.Method; * @since 1.11 */ public class NodeForComponentOfMethod extends NodeForComponent { - final BeanWrap beanWrap; - final Method method; - final LiteFlowMethodEnum methodEnum; - public NodeForComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { - this.beanWrap = beanWrap; - this.method = method; - this.methodEnum = methodEnum; + final BeanWrap beanWrap; - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeForComponent method parameter cannot be more than one: " + methodFullName); - } + final Method method; - if (method.getReturnType() != Integer.class - && method.getReturnType() != int.class) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeForComponent method returnType can only be int: " + methodFullName); - } - } + final LiteFlowMethodEnum methodEnum; - private Object exec() throws Exception { - if (method.getParameterCount() == 0) { - return method.invoke(beanWrap.get()); - } else { - return method.invoke(beanWrap.get(), this); - } - } + public NodeForComponentOfMethod(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("NodeForComponent method parameter cannot be more than one: " + methodFullName); + } + + if (method.getReturnType() != Integer.class && method.getReturnType() != int.class) { + String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); + throw new LiteFlowException("NodeForComponent method returnType can only be int: " + methodFullName); + } + } + + private Object exec() throws Exception { + if (method.getParameterCount() == 0) { + return method.invoke(beanWrap.get()); + } + else { + return method.invoke(beanWrap.get(), this); + } + } + + @Override + public int processFor() throws Exception { + return (int) exec(); + } - @Override - public int processFor() throws Exception { - return (int)exec(); - } } 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/NodeIfComponentOfMethod.java index da1e9744..ac25d7c7 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/NodeIfComponentOfMethod.java @@ -12,37 +12,41 @@ import java.lang.reflect.Method; * @since 1.11 */ public class NodeIfComponentOfMethod extends NodeIfComponent { - final BeanWrap beanWrap; - final Method method; - final LiteFlowMethodEnum methodEnum; - public NodeIfComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { - this.beanWrap = beanWrap; - this.method = method; - this.methodEnum = methodEnum; + final BeanWrap beanWrap; - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeIfComponent method parameter cannot be more than one: " + methodFullName); - } + final Method method; - if (method.getReturnType() != Boolean.class - && method.getReturnType() != boolean.class) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeIfComponent method returnType can only be boolean: " + methodFullName); - } - } + final LiteFlowMethodEnum methodEnum; - private Object exec() throws Exception { - if (method.getParameterCount() == 0) { - return method.invoke(beanWrap.get()); - } else { - return method.invoke(beanWrap.get(), this); - } - } + public NodeIfComponentOfMethod(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("NodeIfComponent 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("NodeIfComponent 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 processIf() throws Exception { + return (boolean) exec(); + } - @Override - public boolean processIf() throws Exception { - return (boolean) exec(); - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeSwitchComponentOfMethod.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeSwitchComponentOfMethod.java index 18d184a6..a39825f4 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeSwitchComponentOfMethod.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeSwitchComponentOfMethod.java @@ -12,36 +12,42 @@ import java.lang.reflect.Method; * @since 1.11 */ public class NodeSwitchComponentOfMethod extends NodeSwitchComponent { - final BeanWrap beanWrap; - final Method method; - final LiteFlowMethodEnum methodEnum; - public NodeSwitchComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) { - this.beanWrap = beanWrap; - this.method = method; - this.methodEnum = methodEnum; + final BeanWrap beanWrap; - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeSwitchComponent method parameter cannot be more than one: " + methodFullName); - } + final Method method; - if (method.getReturnType() != String.class) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeSwitchComponent method returnType can only be string: " + methodFullName); - } - } + final LiteFlowMethodEnum methodEnum; - private Object exec() throws Exception { - if (method.getParameterCount() == 0) { - return method.invoke(beanWrap.get()); - } else { - return method.invoke(beanWrap.get(), this); - } - } + public NodeSwitchComponentOfMethod(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( + "NodeSwitchComponent method parameter cannot be more than one: " + methodFullName); + } + + if (method.getReturnType() != String.class) { + String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); + throw new LiteFlowException("NodeSwitchComponent method returnType can only be string: " + methodFullName); + } + } + + private Object exec() throws Exception { + if (method.getParameterCount() == 0) { + return method.invoke(beanWrap.get()); + } + else { + return method.invoke(beanWrap.get(), this); + } + } + + @Override + public String processSwitch() throws Exception { + return (String) exec(); + } - @Override - public String processSwitch() throws Exception { - return (String) 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 index c0138ee0..cf99791e 100644 --- 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 @@ -12,37 +12,42 @@ import java.lang.reflect.Method; * @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; + final BeanWrap beanWrap; - if (method.getParameterCount() > 1) { - String methodFullName = beanWrap.clz().getName() + "::" + method.getName(); - throw new LiteFlowException("NodeWhileComponent method parameter cannot be more than one: " + methodFullName); - } + final Method method; - 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); - } - } + final LiteFlowMethodEnum methodEnum; - private Object exec() throws Exception { - if (method.getParameterCount() == 0) { - return method.invoke(beanWrap.get()); - } else { - return method.invoke(beanWrap.get(), this); - } - } + 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(); + } - @Override - public boolean processWhile() throws Exception { - return (boolean) exec(); - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java index b088cafc..e9eab764 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java @@ -9,8 +9,9 @@ import org.noear.solon.annotation.Inject; /** * LiteflowConfig的装配类 * - * 这个装配类主要是把监控器的配置参数类和流程配置参数类作一个合并,转换成统一的配置参数类。 - * 同时这里设置了默认的参数路径,如果在 solon 的 app.properties/yml 里没取到的话,就取默认值 + * 这个装配类主要是把监控器的配置参数类和流程配置参数类作一个合并,转换成统一的配置参数类。 同时这里设置了默认的参数路径,如果在 solon 的 + * app.properties/yml 里没取到的话,就取默认值 + * * @author Bryan.Zhang * @author noear * @since 2.9 @@ -18,43 +19,45 @@ import org.noear.solon.annotation.Inject; @Configuration public class LiteflowAutoConfiguration { - @Inject(value = "${liteflow.monitor.enableLog}", required = false) - boolean enableLog; + @Inject(value = "${liteflow.monitor.enableLog}", required = false) + boolean enableLog; - @Bean - public LiteflowConfig liteflowConfig(LiteflowProperty property, LiteflowMonitorProperty liteflowMonitorProperty){ - LiteflowConfig liteflowConfig = new LiteflowConfig(); - liteflowConfig.setRuleSource(property.getRuleSource()); - liteflowConfig.setRuleSourceExtData(property.getRuleSourceExtData()); - liteflowConfig.setSlotSize(property.getSlotSize()); - liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); - liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); - liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); - liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); - liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); - liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); - liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); - liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); - liteflowConfig.setParseOnStart(property.isParseOnStart()); - liteflowConfig.setEnable(property.isEnable()); - liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); - liteflowConfig.setRetryCount(property.getRetryCount()); - liteflowConfig.setPrintBanner(property.isPrintBanner()); - liteflowConfig.setNodeExecutorClass(property.getNodeExecutorClass()); - liteflowConfig.setRequestIdGeneratorClass(property.getRequestIdGeneratorClass()); - liteflowConfig.setMainExecutorWorks(property.getMainExecutorWorks()); - liteflowConfig.setMainExecutorClass(property.getMainExecutorClass()); - liteflowConfig.setPrintExecutionLog(property.isPrintExecutionLog()); - liteflowConfig.setSubstituteCmpClass(property.getSubstituteCmpClass()); - return liteflowConfig; - } + @Bean + public LiteflowConfig liteflowConfig(LiteflowProperty property, LiteflowMonitorProperty liteflowMonitorProperty) { + LiteflowConfig liteflowConfig = new LiteflowConfig(); + liteflowConfig.setRuleSource(property.getRuleSource()); + liteflowConfig.setRuleSourceExtData(property.getRuleSourceExtData()); + liteflowConfig.setSlotSize(property.getSlotSize()); + liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); + liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); + liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); + liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); + liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); + liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); + liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); + liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); + liteflowConfig.setParseOnStart(property.isParseOnStart()); + liteflowConfig.setEnable(property.isEnable()); + liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); + liteflowConfig.setRetryCount(property.getRetryCount()); + liteflowConfig.setPrintBanner(property.isPrintBanner()); + liteflowConfig.setNodeExecutorClass(property.getNodeExecutorClass()); + liteflowConfig.setRequestIdGeneratorClass(property.getRequestIdGeneratorClass()); + liteflowConfig.setMainExecutorWorks(property.getMainExecutorWorks()); + liteflowConfig.setMainExecutorClass(property.getMainExecutorClass()); + liteflowConfig.setPrintExecutionLog(property.isPrintExecutionLog()); + liteflowConfig.setSubstituteCmpClass(property.getSubstituteCmpClass()); + return liteflowConfig; + } + + @Bean + public MonitorBus monitorBus(LiteflowConfig liteflowConfig) { + if (enableLog) { + return new MonitorBus(liteflowConfig); + } + else { + return null; // null 即是没创建 + } + } - @Bean - public MonitorBus monitorBus(LiteflowConfig liteflowConfig) { - if (enableLog) { - return new MonitorBus(liteflowConfig); - } else { - return null; //null 即是没创建 - } - } } 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 d12b45e4..e40faa39 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 @@ -8,8 +8,7 @@ import org.noear.solon.annotation.Inject; import org.noear.solon.core.AopContext; /** - * 主要的业务装配器 - * 在这个装配器里装配了执行器,执行器初始化类,监控器 + * 主要的业务装配器 在这个装配器里装配了执行器,执行器初始化类,监控器 * 这个装配前置条件是需要LiteflowConfig,LiteflowPropertyAutoConfiguration以及SpringAware * * @author Bryan.Zhang @@ -19,27 +18,28 @@ import org.noear.solon.core.AopContext; @Configuration public class LiteflowMainAutoConfiguration { - @Inject(value = "${liteflow.parseOnStart}", required = false) - boolean parseOnStart; + @Inject(value = "${liteflow.parseOnStart}", required = false) + boolean parseOnStart; - @Inject - AopContext aopContext; + @Inject + AopContext aopContext; - @Inject - LiteflowConfig liteflowConfig; + @Inject + LiteflowConfig liteflowConfig; - @Init - public void flowExecutor() { - // - //实例化FlowExecutor - // - FlowExecutor flowExecutor = new FlowExecutor(); - flowExecutor.setLiteflowConfig(liteflowConfig); + @Init + public void flowExecutor() { + // + // 实例化FlowExecutor + // + FlowExecutor flowExecutor = new FlowExecutor(); + flowExecutor.setLiteflowConfig(liteflowConfig); - if (parseOnStart) { - flowExecutor.init(true); - } + if (parseOnStart) { + flowExecutor.init(true); + } + + aopContext.wrapAndPut(FlowExecutor.class, flowExecutor); + } - aopContext.wrapAndPut(FlowExecutor.class, flowExecutor); - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMonitorProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMonitorProperty.java index 4cc2f1b5..44ecc4e4 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMonitorProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowMonitorProperty.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.solon.config; - import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; @@ -15,47 +14,48 @@ import org.noear.solon.annotation.Inject; @Configuration public class LiteflowMonitorProperty { - //是否打印监控日志 - private boolean enableLog; + // 是否打印监控日志 + private boolean enableLog; - //监控队列存储的最大数量 - private int queueLimit; + // 监控队列存储的最大数量 + private int queueLimit; - //延迟多少毫秒打印 - private long delay; + // 延迟多少毫秒打印 + private long delay; - //每隔多少毫秒打印 - private long period; + // 每隔多少毫秒打印 + private long period; - public boolean isEnableLog() { - return enableLog; - } + public boolean isEnableLog() { + return enableLog; + } - public void setEnableLog(boolean enableLog) { - this.enableLog = enableLog; - } + public void setEnableLog(boolean enableLog) { + this.enableLog = enableLog; + } - public int getQueueLimit() { - return queueLimit; - } + public int getQueueLimit() { + return queueLimit; + } - public void setQueueLimit(int queueLimit) { - this.queueLimit = queueLimit; - } + public void setQueueLimit(int queueLimit) { + this.queueLimit = queueLimit; + } - public long getDelay() { - return delay; - } + public long getDelay() { + return delay; + } - public void setDelay(long delay) { - this.delay = delay; - } + public void setDelay(long delay) { + this.delay = delay; + } - public long getPeriod() { - return period; - } + public long getPeriod() { + return period; + } + + public void setPeriod(long period) { + this.period = period; + } - public void setPeriod(long period) { - this.period = period; - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java index 5bde0a62..26b0c9f0 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.solon.config; - import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; @@ -15,207 +14,209 @@ import org.noear.solon.annotation.Inject; @Configuration public class LiteflowProperty { - //是否装配liteflow - private boolean enable; + // 是否装配liteflow + private boolean enable; - //流程定义资源地址 - private String ruleSource; + // 流程定义资源地址 + private String ruleSource; - //流程资源扩展数据 - private String ruleSourceExtData; + // 流程资源扩展数据 + private String ruleSourceExtData; - //slot的数量 - private int slotSize; + // slot的数量 + private int slotSize; - //FlowExecutor的execute2Future的线程数 - private int mainExecutorWorks; + // FlowExecutor的execute2Future的线程数 + private int mainExecutorWorks; - //FlowExecutor的execute2Future的自定义线程池 - private String mainExecutorClass; + // FlowExecutor的execute2Future的自定义线程池 + private String mainExecutorClass; - //并行线程执行器class路径 - private String threadExecutorClass; + // 并行线程执行器class路径 + private String threadExecutorClass; - //异步线程最大等待描述 - private int whenMaxWaitSeconds; + // 异步线程最大等待描述 + private int whenMaxWaitSeconds; - //异步线程池最大线程数 - private int whenMaxWorkers; + // 异步线程池最大线程数 + private int whenMaxWorkers; - //异步线程池最大队列数量 - private int whenQueueLimit; + // 异步线程池最大队列数量 + private int whenQueueLimit; - //是否在启动时解析规则文件 - //这个参数主要给编码式注册元数据的场景用的,结合FlowBus.addNode一起用 - private boolean parseOnStart; + // 是否在启动时解析规则文件 + // 这个参数主要给编码式注册元数据的场景用的,结合FlowBus.addNode一起用 + private boolean parseOnStart; - //这个属性为true,则支持多种不同的类型的配置 - //但是要注意,不能将主流程和子流程分配在不同类型配置文件中 - private boolean supportMultipleType; + // 这个属性为true,则支持多种不同的类型的配置 + // 但是要注意,不能将主流程和子流程分配在不同类型配置文件中 + private boolean supportMultipleType; - //重试次数 - private int retryCount; + // 重试次数 + private int retryCount; - //是否打印liteflow banner - private boolean printBanner; + // 是否打印liteflow banner + private boolean printBanner; - // 节点执行器class全名 - private String nodeExecutorClass; + // 节点执行器class全名 + private String nodeExecutorClass; - // requestId 生成器 - private String requestIdGeneratorClass; + // requestId 生成器 + private String requestIdGeneratorClass; - //是否打印执行过程中的日志 - private boolean printExecutionLog; + // 是否打印执行过程中的日志 + private boolean printExecutionLog; - //替补组件的class路径 - private String substituteCmpClass; + // 替补组件的class路径 + private String substituteCmpClass; - public boolean isEnable() { - return enable; - } + public boolean isEnable() { + return enable; + } - public void setEnable(boolean enable) { - this.enable = enable; - } + public void setEnable(boolean enable) { + this.enable = enable; + } - public String getRuleSource() { - return ruleSource; - } + public String getRuleSource() { + return ruleSource; + } - public void setRuleSource(String ruleSource) { - if (ruleSource.contains("*")) { - this.ruleSource = String.join(",", PathsUtils.resolvePaths(ruleSource)); - } else { - this.ruleSource = ruleSource; - } - } + public void setRuleSource(String ruleSource) { + if (ruleSource.contains("*")) { + this.ruleSource = String.join(",", PathsUtils.resolvePaths(ruleSource)); + } + else { + this.ruleSource = ruleSource; + } + } - public int getSlotSize() { - return slotSize; - } + public int getSlotSize() { + return slotSize; + } - public void setSlotSize(int slotSize) { - this.slotSize = slotSize; - } + public void setSlotSize(int slotSize) { + this.slotSize = slotSize; + } - public int getWhenMaxWaitSeconds() { - return whenMaxWaitSeconds; - } + public int getWhenMaxWaitSeconds() { + return whenMaxWaitSeconds; + } - public void setWhenMaxWaitSeconds(int whenMaxWaitSeconds) { - this.whenMaxWaitSeconds = whenMaxWaitSeconds; - } + public void setWhenMaxWaitSeconds(int whenMaxWaitSeconds) { + this.whenMaxWaitSeconds = whenMaxWaitSeconds; + } - public int getWhenMaxWorkers() { - return whenMaxWorkers; - } + public int getWhenMaxWorkers() { + return whenMaxWorkers; + } - public void setWhenMaxWorkers(int whenMaxWorkers) { - this.whenMaxWorkers = whenMaxWorkers; - } + public void setWhenMaxWorkers(int whenMaxWorkers) { + this.whenMaxWorkers = whenMaxWorkers; + } - public int getWhenQueueLimit() { - return whenQueueLimit; - } + public int getWhenQueueLimit() { + return whenQueueLimit; + } - public void setWhenQueueLimit(int whenQueueLimit) { - this.whenQueueLimit = whenQueueLimit; - } + public void setWhenQueueLimit(int whenQueueLimit) { + this.whenQueueLimit = whenQueueLimit; + } - public boolean isParseOnStart() { - return parseOnStart; - } + public boolean isParseOnStart() { + return parseOnStart; + } - public void setParseOnStart(boolean parseOnStart) { - this.parseOnStart = parseOnStart; - } + public void setParseOnStart(boolean parseOnStart) { + this.parseOnStart = parseOnStart; + } - public boolean isSupportMultipleType() { - return supportMultipleType; - } + public boolean isSupportMultipleType() { + return supportMultipleType; + } - public void setSupportMultipleType(boolean supportMultipleType) { - this.supportMultipleType = supportMultipleType; - } + public void setSupportMultipleType(boolean supportMultipleType) { + this.supportMultipleType = supportMultipleType; + } - public int getRetryCount() { - return retryCount; - } + public int getRetryCount() { + return retryCount; + } - public void setRetryCount(int retryCount) { - this.retryCount = retryCount; - } + public void setRetryCount(int retryCount) { + this.retryCount = retryCount; + } - public boolean isPrintBanner() { - return printBanner; - } + public boolean isPrintBanner() { + return printBanner; + } - public void setPrintBanner(boolean printBanner) { - this.printBanner = printBanner; - } + public void setPrintBanner(boolean printBanner) { + this.printBanner = printBanner; + } - public String getThreadExecutorClass() { - return threadExecutorClass; - } + public String getThreadExecutorClass() { + return threadExecutorClass; + } - public void setThreadExecutorClass(String threadExecutorClass) { - this.threadExecutorClass = threadExecutorClass; - } + public void setThreadExecutorClass(String threadExecutorClass) { + this.threadExecutorClass = threadExecutorClass; + } - public String getNodeExecutorClass() { - return nodeExecutorClass; - } + public String getNodeExecutorClass() { + return nodeExecutorClass; + } - public void setNodeExecutorClass(String nodeExecutorClass) { - this.nodeExecutorClass = nodeExecutorClass; - } + public void setNodeExecutorClass(String nodeExecutorClass) { + this.nodeExecutorClass = nodeExecutorClass; + } - public int getMainExecutorWorks() { - return mainExecutorWorks; - } + public int getMainExecutorWorks() { + return mainExecutorWorks; + } - public void setMainExecutorWorks(int mainExecutorWorks) { - this.mainExecutorWorks = mainExecutorWorks; - } + public void setMainExecutorWorks(int mainExecutorWorks) { + this.mainExecutorWorks = mainExecutorWorks; + } - public String getMainExecutorClass() { - return mainExecutorClass; - } + public String getMainExecutorClass() { + return mainExecutorClass; + } - public void setMainExecutorClass(String mainExecutorClass) { - this.mainExecutorClass = mainExecutorClass; - } + public void setMainExecutorClass(String mainExecutorClass) { + this.mainExecutorClass = mainExecutorClass; + } - public boolean isPrintExecutionLog() { - return printExecutionLog; - } + public boolean isPrintExecutionLog() { + return printExecutionLog; + } - public void setPrintExecutionLog(boolean printExecutionLog) { - this.printExecutionLog = printExecutionLog; - } + public void setPrintExecutionLog(boolean printExecutionLog) { + this.printExecutionLog = printExecutionLog; + } - public String getRequestIdGeneratorClass() { - return requestIdGeneratorClass; - } + public String getRequestIdGeneratorClass() { + return requestIdGeneratorClass; + } - public void setRequestIdGeneratorClass(String requestIdGeneratorClass) { - this.requestIdGeneratorClass = requestIdGeneratorClass; - } + public void setRequestIdGeneratorClass(String requestIdGeneratorClass) { + this.requestIdGeneratorClass = requestIdGeneratorClass; + } - public String getSubstituteCmpClass() { - return substituteCmpClass; - } + public String getSubstituteCmpClass() { + return substituteCmpClass; + } - public void setSubstituteCmpClass(String substituteCmpClass) { - this.substituteCmpClass = substituteCmpClass; - } + public void setSubstituteCmpClass(String substituteCmpClass) { + this.substituteCmpClass = substituteCmpClass; + } - public String getRuleSourceExtData() { - return ruleSourceExtData; - } + public String getRuleSourceExtData() { + return ruleSourceExtData; + } + + public void setRuleSourceExtData(String ruleSourceExtData) { + this.ruleSourceExtData = ruleSourceExtData; + } - public void setRuleSourceExtData(String ruleSourceExtData) { - this.ruleSourceExtData = ruleSourceExtData; - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/PathsUtils.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/PathsUtils.java index 5381220a..08e9d9fb 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/PathsUtils.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/PathsUtils.java @@ -14,54 +14,55 @@ import java.util.regex.Pattern; * @since 1.11 */ public class PathsUtils { - public static Collection resolvePaths(String pathExpr) { - List paths = new ArrayList<>(); - if (pathExpr.contains("/*") == false) { //说明没有*符 - paths.add(pathExpr); - return paths; - } + public static Collection resolvePaths(String pathExpr) { + List paths = new ArrayList<>(); - //确定目录 - int dirIdx = pathExpr.indexOf("/*"); - String dir = pathExpr.substring(0, dirIdx); + if (pathExpr.contains("/*") == false) { // 说明没有*符 + paths.add(pathExpr); + return paths; + } - //确定后缀 - int sufIdx = pathExpr.lastIndexOf("."); - String suf = null; - if (sufIdx > 0) { - suf = pathExpr.substring(sufIdx); - if (suf.contains("*")) { - sufIdx = -1; - suf = null; - } - } + // 确定目录 + int dirIdx = pathExpr.indexOf("/*"); + String dir = pathExpr.substring(0, dirIdx); - int sufIdx2 = sufIdx; - String suf2 = suf; + // 确定后缀 + int sufIdx = pathExpr.lastIndexOf("."); + String suf = null; + if (sufIdx > 0) { + suf = pathExpr.substring(sufIdx); + if (suf.contains("*")) { + sufIdx = -1; + suf = null; + } + } - //匹配表达式 - String expr = pathExpr.replaceAll("/\\*\\.", "/[^\\.]*\\."); - expr = expr.replaceAll("/\\*\\*/", "(/[^/]*)*/"); + int sufIdx2 = sufIdx; + String suf2 = suf; - Pattern pattern = Pattern.compile(expr); + // 匹配表达式 + String expr = pathExpr.replaceAll("/\\*\\.", "/[^\\.]*\\."); + expr = expr.replaceAll("/\\*\\*/", "(/[^/]*)*/"); - ScanUtil.scan(dir, n -> { - //进行后缀过滤,相对比较快 - if (sufIdx2 > 0) { - return n.endsWith(suf2); - } else { - return true; - } - }) - .forEach(uri -> { - //再进行表达式过滤 - if (pattern.matcher(uri).find()) { - paths.add(uri); - } - }); + Pattern pattern = Pattern.compile(expr); + ScanUtil.scan(dir, n -> { + // 进行后缀过滤,相对比较快 + if (sufIdx2 > 0) { + return n.endsWith(suf2); + } + else { + return true; + } + }).forEach(uri -> { + // 再进行表达式过滤 + if (pattern.matcher(uri).find()) { + paths.add(uri); + } + }); + + return paths; + } - return paths; - } } 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 f52f1e5f..2d643b30 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 @@ -21,79 +21,81 @@ import java.util.Properties; * @since 2.9 */ public class XPluginImpl implements Plugin { - @Override - public void start(AopContext context) { - //加载默认配置 - Properties defProps = Utils.loadProperties("META-INF/liteflow-default.properties"); - if (defProps != null && defProps.size() > 0) { - defProps.forEach((k, v) -> { - context.cfg().putIfAbsent(k, v); - }); - } - //是否启用 - boolean enable = context.cfg().getBool("liteflow.enable", false); + @Override + public void start(AopContext context) { + // 加载默认配置 + Properties defProps = Utils.loadProperties("META-INF/liteflow-default.properties"); + if (defProps != null && defProps.size() > 0) { + defProps.forEach((k, v) -> { + context.cfg().putIfAbsent(k, v); + }); + } - if (!enable) { - return; - } + // 是否启用 + boolean enable = context.cfg().getBool("liteflow.enable", false); - //放到前面 - context.beanMake(LiteflowProperty.class); - context.beanMake(LiteflowMonitorProperty.class); - context.beanMake(LiteflowAutoConfiguration.class); - context.beanMake(LiteflowMainAutoConfiguration.class); + if (!enable) { + return; + } - //订阅 NodeComponent 组件 - context.subWrapsOfType(NodeComponent.class, bw -> { - NodeComponent node1 = bw.raw(); - node1.setNodeId(bw.name()); + // 放到前面 + context.beanMake(LiteflowProperty.class); + context.beanMake(LiteflowMonitorProperty.class); + context.beanMake(LiteflowAutoConfiguration.class); + context.beanMake(LiteflowMainAutoConfiguration.class); - FlowBus.addSpringScanNode(bw.name(), bw.raw()); - }); + // 订阅 NodeComponent 组件 + context.subWrapsOfType(NodeComponent.class, bw -> { + NodeComponent node1 = bw.raw(); + node1.setNodeId(bw.name()); - context.beanExtractorAdd(LiteflowMethod.class, (bw, method, anno) -> { - NodeComponent node1 = null; - switch (anno.value()) { - case PROCESS_SWITCH: - node1 = new NodeSwitchComponentOfMethod(bw, method, anno.value()); - break; - case PROCESS_IF: - node1 = new NodeIfComponentOfMethod(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()); - } + FlowBus.addSpringScanNode(bw.name(), bw.raw()); + }); + context.beanExtractorAdd(LiteflowMethod.class, (bw, method, anno) -> { + NodeComponent node1 = null; + switch (anno.value()) { + case PROCESS_SWITCH: + node1 = new NodeSwitchComponentOfMethod(bw, method, anno.value()); + break; + case PROCESS_IF: + node1 = new NodeIfComponentOfMethod(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()); + } - String nodeId = Utils.annoAlias(anno.nodeId(), bw.name()); - node1.setNodeId(nodeId); - node1.setType(anno.nodeType()); + String nodeId = Utils.annoAlias(anno.nodeId(), bw.name()); + node1.setNodeId(nodeId); + node1.setType(anno.nodeType()); - FlowBus.addSpringScanNode(nodeId, node1); - }); + FlowBus.addSpringScanNode(nodeId, node1); + }); - context.beanBuilderAdd(LiteflowComponent.class, (clz, bw, anno) -> { - if(NodeComponent.class.isAssignableFrom(clz)) { - NodeComponent node1 = bw.raw(); - String nodeId = Utils.annoAlias(anno.id(), anno.value()); + context.beanBuilderAdd(LiteflowComponent.class, (clz, bw, anno) -> { + if (NodeComponent.class.isAssignableFrom(clz)) { + NodeComponent node1 = bw.raw(); + String nodeId = Utils.annoAlias(anno.id(), anno.value()); - node1.setNodeId(nodeId); - node1.setName(anno.name()); + node1.setNodeId(nodeId); + node1.setName(anno.name()); + + FlowBus.addSpringScanNode(nodeId, node1); + } + else { + context.beanExtract(bw); // 尝试提取 LiteflowMethod 函数 + } + }); + } - FlowBus.addSpringScanNode(nodeId, node1); - }else{ - context.beanExtract(bw); //尝试提取 LiteflowMethod 函数 - } - }); - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/ResourceUtils.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/ResourceUtils.java index 1ea0574c..7e94f0e7 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/ResourceUtils.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/ResourceUtils.java @@ -1,27 +1,41 @@ package com.yomahub.liteflow.spi.solon; - /** * @author noear 2022/10/10 created */ public final class ResourceUtils { - public static final String CLASSPATH_URL_PREFIX = "classpath:"; - public static final String FILE_URL_PREFIX = "file:"; - public static final String JAR_URL_PREFIX = "jar:"; - public static final String WAR_URL_PREFIX = "war:"; - public static final String URL_PROTOCOL_FILE = "file"; - public static final String URL_PROTOCOL_JAR = "jar"; - public static final String URL_PROTOCOL_WAR = "war"; - public static final String URL_PROTOCOL_ZIP = "zip"; - public static final String URL_PROTOCOL_WSJAR = "wsjar"; - public static final String URL_PROTOCOL_VFSZIP = "vfszip"; - public static final String URL_PROTOCOL_VFSFILE = "vfsfile"; - public static final String URL_PROTOCOL_VFS = "vfs"; - public static final String JAR_FILE_EXTENSION = ".jar"; - public static final String JAR_URL_SEPARATOR = "!/"; - public static final String WAR_URL_SEPARATOR = "*/"; - public static final String CLASSPATH_ALL_URL_PREFIX = "classpath*:"; + public static final String CLASSPATH_URL_PREFIX = "classpath:"; + + public static final String FILE_URL_PREFIX = "file:"; + + public static final String JAR_URL_PREFIX = "jar:"; + + public static final String WAR_URL_PREFIX = "war:"; + + public static final String URL_PROTOCOL_FILE = "file"; + + public static final String URL_PROTOCOL_JAR = "jar"; + + public static final String URL_PROTOCOL_WAR = "war"; + + public static final String URL_PROTOCOL_ZIP = "zip"; + + public static final String URL_PROTOCOL_WSJAR = "wsjar"; + + public static final String URL_PROTOCOL_VFSZIP = "vfszip"; + + public static final String URL_PROTOCOL_VFSFILE = "vfsfile"; + + public static final String URL_PROTOCOL_VFS = "vfs"; + + public static final String JAR_FILE_EXTENSION = ".jar"; + + public static final String JAR_URL_SEPARATOR = "!/"; + + public static final String WAR_URL_SEPARATOR = "*/"; + + public static final String CLASSPATH_ALL_URL_PREFIX = "classpath*:"; } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonCmpAroundAspect.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonCmpAroundAspect.java index 5fdf92cb..2e5a2a2c 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonCmpAroundAspect.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonCmpAroundAspect.java @@ -8,35 +8,37 @@ import org.noear.solon.Solon; /** * Solon 环境全局组件切面实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class SolonCmpAroundAspect implements CmpAroundAspect { - public static ICmpAroundAspect cmpAroundAspect; - static { - Solon.context().getBeanAsync(ICmpAroundAspect.class, bean -> { - cmpAroundAspect = bean; - }); - } + public static ICmpAroundAspect cmpAroundAspect; + static { + Solon.context().getBeanAsync(ICmpAroundAspect.class, bean -> { + cmpAroundAspect = bean; + }); + } - @Override - public void beforeProcess(String nodeId, Slot slot) { - if (ObjectUtil.isNotNull(cmpAroundAspect)) { - cmpAroundAspect.beforeProcess(nodeId, slot); - } - } + @Override + public void beforeProcess(String nodeId, Slot slot) { + if (ObjectUtil.isNotNull(cmpAroundAspect)) { + cmpAroundAspect.beforeProcess(nodeId, slot); + } + } - @Override - public void afterProcess(String nodeId, Slot slot) { - if (ObjectUtil.isNotNull(cmpAroundAspect)) { - cmpAroundAspect.afterProcess(nodeId, slot); - } - } + @Override + public void afterProcess(String nodeId, Slot slot) { + if (ObjectUtil.isNotNull(cmpAroundAspect)) { + cmpAroundAspect.afterProcess(nodeId, slot); + } + } + + @Override + public int priority() { + return 1; + } - @Override - public int priority() { - return 1; - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java index fb93e425..8488019a 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextAware.java @@ -7,73 +7,78 @@ import org.noear.solon.core.BeanWrap; /** * 基于代码形式的 Solon 上下文工具类 + * * @author Bryan.Zhang */ public class SolonContextAware implements ContextAware { - @Override - public T getBean(String name) { - try{ - return Solon.context().getBean(name); - }catch (Exception e){ - return null; - } - } + @Override + public T getBean(String name) { + try { + return Solon.context().getBean(name); + } + catch (Exception e) { + return null; + } + } - @Override - public T getBean(Class clazz) { - try{ - return Solon.context().getBean(clazz); - }catch (Exception e){ - return null; - } - } + @Override + public T getBean(Class clazz) { + try { + return Solon.context().getBean(clazz); + } + catch (Exception e) { + return null; + } + } - private T getBean(String beanName, Class clazz) { - try{ - return Solon.context().getBean(beanName); - }catch (Exception e){ - return null; - } - } + private T getBean(String beanName, Class clazz) { + try { + return Solon.context().getBean(beanName); + } + catch (Exception e) { + return null; + } + } - @Override - public T registerBean(String beanName, Class c) { - BeanWrap beanWrap = new BeanWrap(Solon.context(), c, null, beanName); - Solon.context().putWrap(beanName, beanWrap); + @Override + public T registerBean(String beanName, Class c) { + BeanWrap beanWrap = new BeanWrap(Solon.context(), c, null, beanName); + Solon.context().putWrap(beanName, beanWrap); - return beanWrap.get(); - } + return beanWrap.get(); + } - @Override - public T registerBean(Class c) { - return registerBean(c.getName(), c); - } + @Override + public T registerBean(Class c) { + return registerBean(c.getName(), c); + } - @Override - public T registerBean(String beanName, Object bean) { - BeanWrap beanWrap = new BeanWrap(Solon.context(), bean.getClass(), bean, beanName); - Solon.context().putWrap(beanName, beanWrap); + @Override + public T registerBean(String beanName, Object bean) { + BeanWrap beanWrap = new BeanWrap(Solon.context(), bean.getClass(), bean, beanName); + Solon.context().putWrap(beanName, beanWrap); - return beanWrap.get(); - } + return beanWrap.get(); + } - @Override - public T registerOrGet(String beanName, Class clazz) { - T t = getBean(beanName, clazz); - if (ObjectUtil.isNull(t)) { - t = registerBean(beanName, clazz); - } - return t; - } + @Override + public T registerOrGet(String beanName, Class clazz) { + T t = getBean(beanName, clazz); + if (ObjectUtil.isNull(t)) { + t = registerBean(beanName, clazz); + } + return t; + } - @Override - public boolean hasBean(String beanName) { - return Solon.context().hasWrap(beanName); - } + @Override + public boolean hasBean(String beanName) { + return Solon.context().hasWrap(beanName); + } + + @Override + public int priority() { + return 1; + } - @Override - public int priority() { - return 1; - } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextCmpInit.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextCmpInit.java index 14baf0d1..41ec564a 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextCmpInit.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonContextCmpInit.java @@ -2,20 +2,22 @@ package com.yomahub.liteflow.spi.solon; import com.yomahub.liteflow.spi.ContextCmpInit; - /** * Solon 环境容器上下文组件初始化实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class SolonContextCmpInit implements ContextCmpInit { - @Override - public void initCmp() { - //已在 XPluginImpl 添加组件 - } - @Override - public int priority() { - return 1; - } + @Override + public void initCmp() { + // 已在 XPluginImpl 添加组件 + } + + @Override + public int priority() { + return 1; + } + } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java index ce5bd32a..06b9de06 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonLiteflowComponentSupport.java @@ -7,24 +7,28 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; /** * Solon 环境 LiteflowComponent 注解的处理器 + * * @author Bryan.Zhang * @since 2.6.11 */ public class SolonLiteflowComponentSupport implements LiteflowComponentSupport { - @Override - public String getCmpName(NodeComponent nodeComponent) { - //判断NodeComponent是否是标识了@LiteflowComponent的标注 - //如果标注了,那么要从中取到name字段 - LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); - if (ObjectUtil.isNotNull(liteflowComponent)) { - return liteflowComponent.name(); - }else{ - return null; - } - } - @Override - public int priority() { - return 1; - } + @Override + public String getCmpName(NodeComponent nodeComponent) { + // 判断NodeComponent是否是标识了@LiteflowComponent的标注 + // 如果标注了,那么要从中取到name字段 + LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); + if (ObjectUtil.isNotNull(liteflowComponent)) { + return liteflowComponent.name(); + } + else { + return null; + } + } + + @Override + public int priority() { + return 1; + } + } \ No newline at end of file diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java index e25dbe9a..e1ea3f71 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/spi/solon/SolonPathContentParser.java @@ -20,63 +20,63 @@ import java.util.Set; import java.util.stream.Collectors; public class SolonPathContentParser implements PathContentParser { - @Override - public List parseContent(List pathList) throws Exception { - List allResource = getUrls(pathList); - //转换成内容List - List contentList = new ArrayList<>(); - for (URL resource : allResource) { - String content = IoUtil.read(resource.openStream(), CharsetUtil.CHARSET_UTF_8); - if (StrUtil.isNotBlank(content)) { - contentList.add(content); - } - } + @Override + public List parseContent(List pathList) throws Exception { + List allResource = getUrls(pathList); - return contentList; - } + // 转换成内容List + List contentList = new ArrayList<>(); + for (URL resource : allResource) { + String content = IoUtil.read(resource.openStream(), CharsetUtil.CHARSET_UTF_8); + if (StrUtil.isNotBlank(content)) { + contentList.add(content); + } + } - @Override - public List getFileAbsolutePath(List pathList) throws Exception { - List allResource = getUrls(pathList); - return StreamUtil.of(allResource) - .map(URL::getPath) - .filter(FileUtil::isFile) - .collect(Collectors.toList()); - } + return contentList; + } - private static List getUrls(List pathList) throws MalformedURLException { - if (CollectionUtil.isEmpty(pathList)) { - throw new ConfigErrorException("rule source must not be null"); - } + @Override + public List getFileAbsolutePath(List pathList) throws Exception { + List allResource = getUrls(pathList); + return StreamUtil.of(allResource).map(URL::getPath).filter(FileUtil::isFile).collect(Collectors.toList()); + } - List allResource = new ArrayList<>(); - for (String path : pathList) { - //如果 path 是绝对路径且这个文件存在时,我们认为这是一个本地文件路径,而并非classpath路径 - if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { - allResource.add(new File(path).toURI().toURL()); - } else { - if (path.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) { - path = path.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()); - } + private static List getUrls(List pathList) throws MalformedURLException { + if (CollectionUtil.isEmpty(pathList)) { + throw new ConfigErrorException("rule source must not be null"); + } - if (Utils.getResource(path) != null) { - allResource.add(Utils.getResource(path)); - } - } - } + List allResource = new ArrayList<>(); + for (String path : pathList) { + // 如果 path 是绝对路径且这个文件存在时,我们认为这是一个本地文件路径,而并非classpath路径 + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { + allResource.add(new File(path).toURI().toURL()); + } + else { + if (path.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) { + path = path.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()); + } - //如果有多个资源,检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 - Set fileTypeSet = new HashSet<>(); - allResource.forEach(resource -> fileTypeSet.add(FileUtil.extName(resource.getPath()))); - if (fileTypeSet.size() > 1) { - throw new ConfigErrorException("config error,please use the same type of configuration"); - } - return allResource; - } + if (Utils.getResource(path) != null) { + allResource.add(Utils.getResource(path)); + } + } + } + + // 如果有多个资源,检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 + Set fileTypeSet = new HashSet<>(); + allResource.forEach(resource -> fileTypeSet.add(FileUtil.extName(resource.getPath()))); + if (fileTypeSet.size() > 1) { + throw new ConfigErrorException("config error,please use the same type of configuration"); + } + return allResource; + } + + @Override + public int priority() { + return 1; + } - @Override - public int priority() { - return 1; - } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowExecutorInit.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowExecutorInit.java index 831251c4..2113178b 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowExecutorInit.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowExecutorInit.java @@ -4,20 +4,21 @@ import com.yomahub.liteflow.core.FlowExecutor; import org.springframework.beans.factory.InitializingBean; /** - * 执行器初始化类 - * 主要用于在启动时执行执行器的初始化方法,避免在运行执行器时第一次初始化而耗费时间 + * 执行器初始化类 主要用于在启动时执行执行器的初始化方法,避免在运行执行器时第一次初始化而耗费时间 + * * @author Bryan.Zhang */ public class LiteflowExecutorInit implements InitializingBean { - private final FlowExecutor flowExecutor; + private final FlowExecutor flowExecutor; - public LiteflowExecutorInit(FlowExecutor flowExecutor) { - this.flowExecutor = flowExecutor; - } + public LiteflowExecutorInit(FlowExecutor flowExecutor) { + this.flowExecutor = flowExecutor; + } + + @Override + public void afterPropertiesSet() throws Exception { + flowExecutor.init(true); + } - @Override - public void afterPropertiesSet() throws Exception { - flowExecutor.init(true); - } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowMonitorProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowMonitorProperty.java index 6e7119b6..9fe4ff7b 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowMonitorProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowMonitorProperty.java @@ -4,52 +4,54 @@ import org.springframework.boot.context.properties.ConfigurationProperties; /** * 监控器的基础参数类 + * * @author Bryan.Zhang */ @ConfigurationProperties(prefix = "liteflow.monitor", ignoreUnknownFields = true) public class LiteflowMonitorProperty { - //是否打印监控日志 - private boolean enableLog; + // 是否打印监控日志 + private boolean enableLog; - //监控队列存储的最大数量 - private int queueLimit; + // 监控队列存储的最大数量 + private int queueLimit; - //延迟多少毫秒打印 - private long delay; + // 延迟多少毫秒打印 + private long delay; - //每隔多少毫秒打印 - private long period; + // 每隔多少毫秒打印 + private long period; - public boolean isEnableLog() { - return enableLog; - } + public boolean isEnableLog() { + return enableLog; + } - public void setEnableLog(boolean enableLog) { - this.enableLog = enableLog; - } + public void setEnableLog(boolean enableLog) { + this.enableLog = enableLog; + } - public int getQueueLimit() { - return queueLimit; - } + public int getQueueLimit() { + return queueLimit; + } - public void setQueueLimit(int queueLimit) { - this.queueLimit = queueLimit; - } + public void setQueueLimit(int queueLimit) { + this.queueLimit = queueLimit; + } - public long getDelay() { - return delay; - } + public long getDelay() { + return delay; + } - public void setDelay(long delay) { - this.delay = delay; - } + public void setDelay(long delay) { + this.delay = delay; + } - public long getPeriod() { - return period; - } + public long getPeriod() { + return period; + } + + public void setPeriod(long period) { + this.period = period; + } - public void setPeriod(long period) { - this.period = period; - } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index 6b015546..dcf36ff8 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -6,230 +6,232 @@ import java.util.Map; /** * 执行流程主要的参数类 + * * @author Bryan.Zhang */ @ConfigurationProperties(prefix = "liteflow", ignoreUnknownFields = true) public class LiteflowProperty { - //是否装配liteflow - private boolean enable; + // 是否装配liteflow + private boolean enable; - //流程定义资源地址 - private String ruleSource; + // 流程定义资源地址 + private String ruleSource; - //流程资源扩展数据,String格式 - private String ruleSourceExtData; + // 流程资源扩展数据,String格式 + private String ruleSourceExtData; - //流程资源扩展数据,Map格式 - private Map ruleSourceExtDataMap; + // 流程资源扩展数据,Map格式 + private Map ruleSourceExtDataMap; - //slot的数量 - private int slotSize; + // slot的数量 + private int slotSize; - //FlowExecutor的execute2Future的线程数 - private int mainExecutorWorks; + // FlowExecutor的execute2Future的线程数 + private int mainExecutorWorks; - //FlowExecutor的execute2Future的自定义线程池 - private String mainExecutorClass; + // FlowExecutor的execute2Future的自定义线程池 + private String mainExecutorClass; - //并行线程执行器class路径 - private String threadExecutorClass; + // 并行线程执行器class路径 + private String threadExecutorClass; - //异步线程最大等待描述 - private int whenMaxWaitSeconds; + // 异步线程最大等待描述 + private int whenMaxWaitSeconds; - //异步线程池最大线程数 - private int whenMaxWorkers; + // 异步线程池最大线程数 + private int whenMaxWorkers; - //异步线程池最大队列数量 - private int whenQueueLimit; + // 异步线程池最大队列数量 + private int whenQueueLimit; - //是否在启动时解析规则文件 - //这个参数主要给编码式注册元数据的场景用的,结合FlowBus.addNode一起用 - private boolean parseOnStart; + // 是否在启动时解析规则文件 + // 这个参数主要给编码式注册元数据的场景用的,结合FlowBus.addNode一起用 + private boolean parseOnStart; - //这个属性为true,则支持多种不同的类型的配置 - //但是要注意,不能将主流程和子流程分配在不同类型配置文件中 - private boolean supportMultipleType; + // 这个属性为true,则支持多种不同的类型的配置 + // 但是要注意,不能将主流程和子流程分配在不同类型配置文件中 + private boolean supportMultipleType; - //重试次数 - private int retryCount; + // 重试次数 + private int retryCount; - //是否打印liteflow banner - private boolean printBanner; + // 是否打印liteflow banner + private boolean printBanner; - // 节点执行器class全名 - private String nodeExecutorClass; + // 节点执行器class全名 + private String nodeExecutorClass; - // requestId 生成器 - private String requestIdGeneratorClass; + // requestId 生成器 + private String requestIdGeneratorClass; - //是否打印执行过程中的日志 - private boolean printExecutionLog; + // 是否打印执行过程中的日志 + private boolean printExecutionLog; - //替补组件的class路径 - private String substituteCmpClass; + // 替补组件的class路径 + private String substituteCmpClass; - // 规则文件/脚本文件变更监听 - private Boolean enableMonitorFile; + // 规则文件/脚本文件变更监听 + private Boolean enableMonitorFile; - public Boolean getEnableMonitorFile() { - return enableMonitorFile; - } + public Boolean getEnableMonitorFile() { + return enableMonitorFile; + } - public void setEnableMonitorFile(Boolean enableMonitorFile) { - this.enableMonitorFile = enableMonitorFile; - } + public void setEnableMonitorFile(Boolean enableMonitorFile) { + this.enableMonitorFile = enableMonitorFile; + } - public boolean isEnable() { - return enable; - } + public boolean isEnable() { + return enable; + } - public void setEnable(boolean enable) { - this.enable = enable; - } + public void setEnable(boolean enable) { + this.enable = enable; + } - public String getRuleSource() { - return ruleSource; - } + public String getRuleSource() { + return ruleSource; + } - public void setRuleSource(String ruleSource) { - this.ruleSource = ruleSource; - } + public void setRuleSource(String ruleSource) { + this.ruleSource = ruleSource; + } - public int getSlotSize() { - return slotSize; - } + public int getSlotSize() { + return slotSize; + } - public void setSlotSize(int slotSize) { - this.slotSize = slotSize; - } + public void setSlotSize(int slotSize) { + this.slotSize = slotSize; + } - public int getWhenMaxWaitSeconds() { - return whenMaxWaitSeconds; - } + public int getWhenMaxWaitSeconds() { + return whenMaxWaitSeconds; + } - public void setWhenMaxWaitSeconds(int whenMaxWaitSeconds) { - this.whenMaxWaitSeconds = whenMaxWaitSeconds; - } + public void setWhenMaxWaitSeconds(int whenMaxWaitSeconds) { + this.whenMaxWaitSeconds = whenMaxWaitSeconds; + } - public int getWhenMaxWorkers() { - return whenMaxWorkers; - } + public int getWhenMaxWorkers() { + return whenMaxWorkers; + } - public void setWhenMaxWorkers(int whenMaxWorkers) { - this.whenMaxWorkers = whenMaxWorkers; - } + public void setWhenMaxWorkers(int whenMaxWorkers) { + this.whenMaxWorkers = whenMaxWorkers; + } - public int getWhenQueueLimit() { - return whenQueueLimit; - } + public int getWhenQueueLimit() { + return whenQueueLimit; + } - public void setWhenQueueLimit(int whenQueueLimit) { - this.whenQueueLimit = whenQueueLimit; - } + public void setWhenQueueLimit(int whenQueueLimit) { + this.whenQueueLimit = whenQueueLimit; + } - public boolean isParseOnStart() { - return parseOnStart; - } + public boolean isParseOnStart() { + return parseOnStart; + } - public void setParseOnStart(boolean parseOnStart) { - this.parseOnStart = parseOnStart; - } + public void setParseOnStart(boolean parseOnStart) { + this.parseOnStart = parseOnStart; + } - public boolean isSupportMultipleType() { - return supportMultipleType; - } + public boolean isSupportMultipleType() { + return supportMultipleType; + } - public void setSupportMultipleType(boolean supportMultipleType) { - this.supportMultipleType = supportMultipleType; - } + public void setSupportMultipleType(boolean supportMultipleType) { + this.supportMultipleType = supportMultipleType; + } - public int getRetryCount() { - return retryCount; - } + public int getRetryCount() { + return retryCount; + } - public void setRetryCount(int retryCount) { - this.retryCount = retryCount; - } + public void setRetryCount(int retryCount) { + this.retryCount = retryCount; + } - public boolean isPrintBanner() { - return printBanner; - } + public boolean isPrintBanner() { + return printBanner; + } - public void setPrintBanner(boolean printBanner) { - this.printBanner = printBanner; - } + public void setPrintBanner(boolean printBanner) { + this.printBanner = printBanner; + } - public String getThreadExecutorClass() { - return threadExecutorClass; - } + public String getThreadExecutorClass() { + return threadExecutorClass; + } - public void setThreadExecutorClass(String threadExecutorClass) { - this.threadExecutorClass = threadExecutorClass; - } + public void setThreadExecutorClass(String threadExecutorClass) { + this.threadExecutorClass = threadExecutorClass; + } - public String getNodeExecutorClass() { - return nodeExecutorClass; - } + public String getNodeExecutorClass() { + return nodeExecutorClass; + } - public void setNodeExecutorClass(String nodeExecutorClass) { - this.nodeExecutorClass = nodeExecutorClass; - } + public void setNodeExecutorClass(String nodeExecutorClass) { + this.nodeExecutorClass = nodeExecutorClass; + } - public int getMainExecutorWorks() { - return mainExecutorWorks; - } + public int getMainExecutorWorks() { + return mainExecutorWorks; + } - public void setMainExecutorWorks(int mainExecutorWorks) { - this.mainExecutorWorks = mainExecutorWorks; - } + public void setMainExecutorWorks(int mainExecutorWorks) { + this.mainExecutorWorks = mainExecutorWorks; + } - public String getMainExecutorClass() { - return mainExecutorClass; - } + public String getMainExecutorClass() { + return mainExecutorClass; + } - public void setMainExecutorClass(String mainExecutorClass) { - this.mainExecutorClass = mainExecutorClass; - } + public void setMainExecutorClass(String mainExecutorClass) { + this.mainExecutorClass = mainExecutorClass; + } - public boolean isPrintExecutionLog() { - return printExecutionLog; - } + public boolean isPrintExecutionLog() { + return printExecutionLog; + } - public void setPrintExecutionLog(boolean printExecutionLog) { - this.printExecutionLog = printExecutionLog; - } + public void setPrintExecutionLog(boolean printExecutionLog) { + this.printExecutionLog = printExecutionLog; + } - public String getRequestIdGeneratorClass() { - return requestIdGeneratorClass; - } + public String getRequestIdGeneratorClass() { + return requestIdGeneratorClass; + } - public void setRequestIdGeneratorClass(String requestIdGeneratorClass) { - this.requestIdGeneratorClass = requestIdGeneratorClass; - } + public void setRequestIdGeneratorClass(String requestIdGeneratorClass) { + this.requestIdGeneratorClass = requestIdGeneratorClass; + } - public String getSubstituteCmpClass() { - return substituteCmpClass; - } + public String getSubstituteCmpClass() { + return substituteCmpClass; + } - public void setSubstituteCmpClass(String substituteCmpClass) { - this.substituteCmpClass = substituteCmpClass; - } + public void setSubstituteCmpClass(String substituteCmpClass) { + this.substituteCmpClass = substituteCmpClass; + } - public String getRuleSourceExtData() { - return ruleSourceExtData; - } + public String getRuleSourceExtData() { + return ruleSourceExtData; + } - public void setRuleSourceExtData(String ruleSourceExtData) { - this.ruleSourceExtData = ruleSourceExtData; - } + public void setRuleSourceExtData(String ruleSourceExtData) { + this.ruleSourceExtData = ruleSourceExtData; + } - public Map getRuleSourceExtDataMap() { - return ruleSourceExtDataMap; - } + public Map getRuleSourceExtDataMap() { + return ruleSourceExtDataMap; + } + + public void setRuleSourceExtDataMap(Map ruleSourceExtDataMap) { + this.ruleSourceExtDataMap = ruleSourceExtDataMap; + } - public void setRuleSourceExtDataMap(Map ruleSourceExtDataMap) { - this.ruleSourceExtDataMap = ruleSourceExtDataMap; - } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java index 6c93a215..edad7857 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java @@ -15,47 +15,47 @@ import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Import; /** - * 主要的业务装配器 - * 在这个装配器里装配了执行器,执行器初始化类,监控器 + * 主要的业务装配器 在这个装配器里装配了执行器,执行器初始化类,监控器 * 这个装配前置条件是需要LiteflowConfig,LiteflowPropertyAutoConfiguration以及SpringAware * * @author Bryan.Zhang */ @Configuration -@AutoConfigureAfter({LiteflowPropertyAutoConfiguration.class}) +@AutoConfigureAfter({ LiteflowPropertyAutoConfiguration.class }) @ConditionalOnBean(LiteflowConfig.class) @ConditionalOnProperty(prefix = "liteflow", name = "enable", havingValue = "true") @Import(SpringAware.class) public class LiteflowMainAutoConfiguration { - //实例化ComponentScanner - //多加一个SpringAware的意义是,确保在执行这个的时候,SpringAware这个bean已经被初始化 - @Bean - public ComponentScanner componentScanner(LiteflowConfig liteflowConfig, SpringAware springAware){ - return new ComponentScanner(liteflowConfig); - } + // 实例化ComponentScanner + // 多加一个SpringAware的意义是,确保在执行这个的时候,SpringAware这个bean已经被初始化 + @Bean + public ComponentScanner componentScanner(LiteflowConfig liteflowConfig, SpringAware springAware) { + return new ComponentScanner(liteflowConfig); + } - //实例化FlowExecutor - //多加一个SpringAware的意义是,确保在执行这个的时候,SpringAware这个bean已经被初始化 - @Bean - public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig, SpringAware springAware) { - FlowExecutor flowExecutor = new FlowExecutor(); - flowExecutor.setLiteflowConfig(liteflowConfig); - return flowExecutor; - } + // 实例化FlowExecutor + // 多加一个SpringAware的意义是,确保在执行这个的时候,SpringAware这个bean已经被初始化 + @Bean + public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig, SpringAware springAware) { + FlowExecutor flowExecutor = new FlowExecutor(); + flowExecutor.setLiteflowConfig(liteflowConfig); + return flowExecutor; + } - //FlowExecutor的初始化工作,和实例化分开来 - @Bean - @ConditionalOnProperty(prefix = "liteflow", name = "parse-on-start", havingValue = "true") - public LiteflowExecutorInit liteflowExecutorInit(FlowExecutor flowExecutor) { - return new LiteflowExecutorInit(flowExecutor); - } + // FlowExecutor的初始化工作,和实例化分开来 + @Bean + @ConditionalOnProperty(prefix = "liteflow", name = "parse-on-start", havingValue = "true") + public LiteflowExecutorInit liteflowExecutorInit(FlowExecutor flowExecutor) { + return new LiteflowExecutorInit(flowExecutor); + } + + // 实例化MonitorBus + // 多加一个SpringAware的意义是,确保在执行这个的时候,SpringAware这个bean已经被初始化 + @Bean("monitorBus") + @ConditionalOnProperty(prefix = "liteflow", name = "monitor.enable-log", havingValue = "true") + public MonitorBus monitorBus(LiteflowConfig liteflowConfig, SpringAware springAware) { + return new MonitorBus(liteflowConfig); + } - //实例化MonitorBus - //多加一个SpringAware的意义是,确保在执行这个的时候,SpringAware这个bean已经被初始化 - @Bean("monitorBus") - @ConditionalOnProperty(prefix = "liteflow", name = "monitor.enable-log", havingValue = "true") - public MonitorBus monitorBus(LiteflowConfig liteflowConfig, SpringAware springAware) { - return new MonitorBus(liteflowConfig); - } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index 8f2f5150..a5b0d142 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -9,45 +9,44 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; /** - * LiteflowConfig的装配类 - * 这个装配类主要是把监控器的配置参数类和流程配置参数类作一个合并,转换成统一的配置参数类。 + * LiteflowConfig的装配类 这个装配类主要是把监控器的配置参数类和流程配置参数类作一个合并,转换成统一的配置参数类。 * 同时这里设置了默认的参数路径,如果在springboot的application.properties/yml里没取到的话,就取默认值 + * * @author Bryan.Zhang */ @Configuration -@EnableConfigurationProperties({LiteflowProperty.class, LiteflowMonitorProperty.class}) -@PropertySource( - name = "Liteflow Default Properties", - value = "classpath:/META-INF/liteflow-default.properties") +@EnableConfigurationProperties({ LiteflowProperty.class, LiteflowMonitorProperty.class }) +@PropertySource(name = "Liteflow Default Properties", value = "classpath:/META-INF/liteflow-default.properties") public class LiteflowPropertyAutoConfiguration { - @Bean - public LiteflowConfig liteflowConfig(LiteflowProperty property, LiteflowMonitorProperty liteflowMonitorProperty){ - LiteflowConfig liteflowConfig = new LiteflowConfig(); - liteflowConfig.setRuleSource(property.getRuleSource()); - liteflowConfig.setRuleSourceExtData(property.getRuleSourceExtData()); - liteflowConfig.setRuleSourceExtDataMap(property.getRuleSourceExtDataMap()); - liteflowConfig.setSlotSize(property.getSlotSize()); - liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); - liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); - liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); - liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); - liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); - liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); - liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); - liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); - liteflowConfig.setParseOnStart(property.isParseOnStart()); - liteflowConfig.setEnable(property.isEnable()); - liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); - liteflowConfig.setRetryCount(property.getRetryCount()); - liteflowConfig.setPrintBanner(property.isPrintBanner()); - liteflowConfig.setNodeExecutorClass(property.getNodeExecutorClass()); - liteflowConfig.setRequestIdGeneratorClass(property.getRequestIdGeneratorClass()); - liteflowConfig.setMainExecutorWorks(property.getMainExecutorWorks()); - liteflowConfig.setMainExecutorClass(property.getMainExecutorClass()); - liteflowConfig.setPrintExecutionLog(property.isPrintExecutionLog()); - liteflowConfig.setSubstituteCmpClass(property.getSubstituteCmpClass()); - liteflowConfig.setEnableMonitorFile(property.getEnableMonitorFile()); - return liteflowConfig; - } + @Bean + public LiteflowConfig liteflowConfig(LiteflowProperty property, LiteflowMonitorProperty liteflowMonitorProperty) { + LiteflowConfig liteflowConfig = new LiteflowConfig(); + liteflowConfig.setRuleSource(property.getRuleSource()); + liteflowConfig.setRuleSourceExtData(property.getRuleSourceExtData()); + liteflowConfig.setRuleSourceExtDataMap(property.getRuleSourceExtDataMap()); + liteflowConfig.setSlotSize(property.getSlotSize()); + liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); + liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); + liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); + liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); + liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); + liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); + liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); + liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); + liteflowConfig.setParseOnStart(property.isParseOnStart()); + liteflowConfig.setEnable(property.isEnable()); + liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); + liteflowConfig.setRetryCount(property.getRetryCount()); + liteflowConfig.setPrintBanner(property.isPrintBanner()); + liteflowConfig.setNodeExecutorClass(property.getNodeExecutorClass()); + liteflowConfig.setRequestIdGeneratorClass(property.getRequestIdGeneratorClass()); + liteflowConfig.setMainExecutorWorks(property.getMainExecutorWorks()); + liteflowConfig.setMainExecutorClass(property.getMainExecutorClass()); + liteflowConfig.setPrintExecutionLog(property.isPrintExecutionLog()); + liteflowConfig.setSubstituteCmpClass(property.getSubstituteCmpClass()); + liteflowConfig.setEnableMonitorFile(property.getEnableMonitorFile()); + return liteflowConfig; + } + } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java index 8c3a58ab..efdcec10 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/annotation/LiteflowComponent.java @@ -10,18 +10,19 @@ import java.lang.annotation.*; * @author Bryan.Zhang * @since 2.6.0 */ -@Target({ElementType.TYPE}) +@Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @Component public @interface LiteflowComponent { - @AliasFor(annotation = Component.class, attribute = "value") - String value() default ""; + @AliasFor(annotation = Component.class, attribute = "value") + String value() default ""; - @AliasFor(annotation = Component.class, attribute = "value") - String id() default ""; + @AliasFor(annotation = Component.class, attribute = "value") + String id() default ""; + + String name() default ""; - String name() default ""; } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java index 8e765750..232adecb 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java @@ -14,83 +14,88 @@ import org.springframework.context.ConfigurableApplicationContext; /** * 基于代码形式的spring上下文工具类 + * * @author Bryan.Zhang */ public class SpringAware implements ApplicationContextAware, ContextAware { - private static ApplicationContext applicationContext = null; + private static ApplicationContext applicationContext = null; - public SpringAware() { - } + public SpringAware() { + } - @Override - public void setApplicationContext(ApplicationContext ac) throws BeansException { - applicationContext = ac; - } + @Override + public void setApplicationContext(ApplicationContext ac) throws BeansException { + applicationContext = ac; + } - public static ApplicationContext getApplicationContext() { - return applicationContext; - } + public static ApplicationContext getApplicationContext() { + return applicationContext; + } - @Override - public T getBean(String name) { - T t = (T) applicationContext.getBean(name); - return t; - } + @Override + public T getBean(String name) { + T t = (T) applicationContext.getBean(name); + return t; + } - @Override - public T getBean(Class clazz) { - T t = applicationContext.getBean(clazz); - return t; - } + @Override + public T getBean(Class clazz) { + T t = applicationContext.getBean(clazz); + return t; + } - private T getBean(String beanName, Class clazz) { - T t = applicationContext.getBean(beanName, clazz); - return t; - } + private T getBean(String beanName, Class clazz) { + T t = applicationContext.getBean(beanName, clazz); + return t; + } - @Override - public T registerBean(String beanName, Class c) { - DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getAutowireCapableBeanFactory(); - BeanDefinition beanDefinition = new GenericBeanDefinition(); - beanDefinition.setBeanClassName(c.getName()); - beanFactory.setAllowBeanDefinitionOverriding(true); - beanFactory.registerBeanDefinition(beanName, beanDefinition); - return getBean(beanName); - } + @Override + public T registerBean(String beanName, Class c) { + DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext + .getAutowireCapableBeanFactory(); + BeanDefinition beanDefinition = new GenericBeanDefinition(); + beanDefinition.setBeanClassName(c.getName()); + beanFactory.setAllowBeanDefinitionOverriding(true); + beanFactory.registerBeanDefinition(beanName, beanDefinition); + return getBean(beanName); + } - @Override - public T registerBean(Class c) { - return registerBean(c.getName(), c); - } + @Override + public T registerBean(Class c) { + return registerBean(c.getName(), c); + } - @Override - public T registerBean(String beanName, Object bean) { - ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; - DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext.getAutowireCapableBeanFactory(); - defaultListableBeanFactory.registerSingleton(beanName,bean); - return (T) configurableApplicationContext.getBean(beanName); - } + @Override + public T registerBean(String beanName, Object bean) { + ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; + DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext + .getAutowireCapableBeanFactory(); + defaultListableBeanFactory.registerSingleton(beanName, bean); + return (T) configurableApplicationContext.getBean(beanName); + } - @Override - public T registerOrGet(String beanName, Class clazz) { - if (ObjectUtil.isNull(applicationContext)){ - return null; - } - try{ - return getBean(beanName, clazz); - }catch (Exception e){ - return registerBean(beanName, clazz); - } - } + @Override + public T registerOrGet(String beanName, Class clazz) { + if (ObjectUtil.isNull(applicationContext)) { + return null; + } + try { + return getBean(beanName, clazz); + } + catch (Exception e) { + return registerBean(beanName, clazz); + } + } - @Override - public boolean hasBean(String beanName){ - return applicationContext.containsBean(beanName); - } + @Override + public boolean hasBean(String beanName) { + return applicationContext.containsBean(beanName); + } + + @Override + public int priority() { + return 1; + } - @Override - public int priority() { - return 1; - } } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringCmpAroundAspect.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringCmpAroundAspect.java index 42011f2f..9e7ff129 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringCmpAroundAspect.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringCmpAroundAspect.java @@ -7,26 +7,29 @@ import com.yomahub.liteflow.spring.ComponentScanner; /** * Spring环境全局组件切面实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class SpringCmpAroundAspect implements CmpAroundAspect { - @Override - public void beforeProcess(String nodeId, Slot slot) { - if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) { - ComponentScanner.cmpAroundAspect.beforeProcess(nodeId, slot); - } - } - @Override - public void afterProcess(String nodeId, Slot slot) { - if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) { - ComponentScanner.cmpAroundAspect.afterProcess(nodeId, slot); - } - } + @Override + public void beforeProcess(String nodeId, Slot slot) { + if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) { + ComponentScanner.cmpAroundAspect.beforeProcess(nodeId, slot); + } + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) { + ComponentScanner.cmpAroundAspect.afterProcess(nodeId, slot); + } + } + + @Override + public int priority() { + return 1; + } - @Override - public int priority() { - return 1; - } } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringContextCmpInit.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringContextCmpInit.java index e7ae4de7..fe387b9b 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringContextCmpInit.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringContextCmpInit.java @@ -9,21 +9,24 @@ import java.util.Map; /** * Spring环境容器上下文组件初始化实现 + * * @author Bryan.Zhang * @since 2.6.11 */ public class SpringContextCmpInit implements ContextCmpInit { - @Override - public void initCmp() { - for (Map.Entry componentEntry : ComponentScanner.nodeComponentMap.entrySet()) { - if (!FlowBus.containNode(componentEntry.getKey())) { - FlowBus.addSpringScanNode(componentEntry.getKey(), componentEntry.getValue()); - } - } - } - @Override - public int priority() { - return 1; - } + @Override + public void initCmp() { + for (Map.Entry componentEntry : ComponentScanner.nodeComponentMap.entrySet()) { + if (!FlowBus.containNode(componentEntry.getKey())) { + FlowBus.addSpringScanNode(componentEntry.getKey(), componentEntry.getValue()); + } + } + } + + @Override + public int priority() { + return 1; + } + } diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java index 13267eb7..a88fdb9e 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringLiteflowComponentSupport.java @@ -8,24 +8,28 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport; /** * spring环境LiteflowComponent注解的处理器 + * * @author Bryan.Zhang * @since 2.6.11 */ public class SpringLiteflowComponentSupport implements LiteflowComponentSupport { - @Override - public String getCmpName(NodeComponent nodeComponent) { - //判断NodeComponent是否是标识了@LiteflowComponent的标注 - //如果标注了,那么要从中取到name字段 - LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); - if (ObjectUtil.isNotNull(liteflowComponent)) { - return liteflowComponent.name(); - }else{ - return null; - } - } - @Override - public int priority() { - return 1; - } + @Override + public String getCmpName(NodeComponent nodeComponent) { + // 判断NodeComponent是否是标识了@LiteflowComponent的标注 + // 如果标注了,那么要从中取到name字段 + LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class); + if (ObjectUtil.isNotNull(liteflowComponent)) { + return liteflowComponent.name(); + } + else { + return null; + } + } + + @Override + public int priority() { + return 1; + } + } \ No newline at end of file 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 a0f433ce..a3f6fc0b 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 @@ -23,77 +23,83 @@ import java.util.Set; import java.util.stream.Collectors; public class SpringPathContentParser implements PathContentParser { - @Override - public List parseContent(List pathList) throws Exception { - List allResource = getResources(pathList); - //转换成内容List - List contentList = new ArrayList<>(); - for (Resource resource : allResource) { - String content = IoUtil.read(resource.getInputStream(), CharsetUtil.CHARSET_UTF_8); - if (StrUtil.isNotBlank(content)) { - contentList.add(content); - } - } + @Override + public List parseContent(List pathList) throws Exception { + List allResource = getResources(pathList); - return contentList; - } + // 转换成内容List + List contentList = new ArrayList<>(); + for (Resource resource : allResource) { + String content = IoUtil.read(resource.getInputStream(), CharsetUtil.CHARSET_UTF_8); + if (StrUtil.isNotBlank(content)) { + contentList.add(content); + } + } - @Override - public List getFileAbsolutePath(List pathList) throws Exception { - List allResource = getResources(pathList); + return contentList; + } - return StreamUtil.of(allResource) - // 过滤非 file 类型 Resource - .filter(Resource::isFile) - .map(r -> { - try { - return r.getFile().getAbsolutePath(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }).collect(Collectors.toList()); - } + @Override + public List getFileAbsolutePath(List pathList) throws Exception { + List allResource = getResources(pathList); - private List getResources(List pathList) throws IOException { - if (CollectionUtil.isEmpty(pathList)) { - throw new ConfigErrorException("rule source must not be null"); - } + return StreamUtil.of(allResource) + // 过滤非 file 类型 Resource + .filter(Resource::isFile) + .map(r -> { + try { + return r.getFile().getAbsolutePath(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + }) + .collect(Collectors.toList()); + } - List allResource = new ArrayList<>(); - for (String path : pathList) { - String locationPattern; + private List getResources(List pathList) throws IOException { + if (CollectionUtil.isEmpty(pathList)) { + throw new ConfigErrorException("rule source must not be null"); + } - //如果path是绝对路径且这个文件存在时,我们认为这是一个本地文件路径,而并非classpath路径 - if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { - locationPattern = ResourceUtils.FILE_URL_PREFIX + path; - } else { - if (!path.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX) && !path.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) { - locationPattern = ResourceUtils.CLASSPATH_URL_PREFIX + path; - } else { - locationPattern = path; - } - } + List allResource = new ArrayList<>(); + for (String path : pathList) { + String locationPattern; - PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); - Resource[] resources = resolver.getResources(locationPattern); - if (ArrayUtil.isNotEmpty(resources)) { - allResource.addAll(ListUtil.toList(resources)); - } - } + // 如果path是绝对路径且这个文件存在时,我们认为这是一个本地文件路径,而并非classpath路径 + if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) { + locationPattern = ResourceUtils.FILE_URL_PREFIX + path; + } + else { + if (!path.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX) + && !path.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) { + locationPattern = ResourceUtils.CLASSPATH_URL_PREFIX + path; + } + else { + locationPattern = path; + } + } - //检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 - 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; - } + PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + Resource[] resources = resolver.getResources(locationPattern); + if (ArrayUtil.isNotEmpty(resources)) { + allResource.addAll(ListUtil.toList(resources)); + } + } + // 检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示 + 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 + public int priority() { + return 1; + } - @Override - public int priority() { - return 1; - } } 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 86125884..bf1978ad 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 @@ -42,112 +42,107 @@ import java.util.stream.Collectors; */ public class ComponentScanner implements BeanPostProcessor { - private static final Logger LOG = LoggerFactory.getLogger(ComponentScanner.class); + private static final Logger LOG = LoggerFactory.getLogger(ComponentScanner.class); - public static Map nodeComponentMap = new HashMap<>(); + public static Map nodeComponentMap = new HashMap<>(); - private LiteflowConfig liteflowConfig; + private LiteflowConfig liteflowConfig; - public static ICmpAroundAspect cmpAroundAspect; + public static ICmpAroundAspect cmpAroundAspect; - public ComponentScanner() { - LOGOPrinter.print(); - } + public ComponentScanner() { + LOGOPrinter.print(); + } - public ComponentScanner(LiteflowConfig liteflowConfig) { - this.liteflowConfig = liteflowConfig; - if (liteflowConfig.getPrintBanner()) { - // 打印liteflow的LOGO - LOGOPrinter.print(); - } - } + public ComponentScanner(LiteflowConfig liteflowConfig) { + this.liteflowConfig = liteflowConfig; + if (liteflowConfig.getPrintBanner()) { + // 打印liteflow的LOGO + LOGOPrinter.print(); + } + } - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - return bean; - } + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + return bean; + } - @SuppressWarnings("rawtypes") - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - Class clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); + @SuppressWarnings("rawtypes") + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + Class clazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); - //判断是不是声明式组件 - //如果是,就缓存到类属性的map中 - if (LiteFlowProxyUtil.isDeclareCmp(bean.getClass())) { - LOG.info("proxy component[{}] has been found", beanName); - List nodeComponents = LiteFlowProxyUtil.proxy2NodeComponent(bean, beanName); - nodeComponents.forEach( - nodeComponent -> { - String nodeId = nodeComponent.getNodeId(); - nodeId = StrUtil.isEmpty(nodeId) ? beanName : nodeId; - nodeComponentMap.put(nodeId, nodeComponent); - } - ); - // 只有注解支持单bean多Node,所以一个直接返回 - if (nodeComponents.size() == 1) { - return nodeComponents.get(0); - } - return bean; - } + // 判断是不是声明式组件 + // 如果是,就缓存到类属性的map中 + if (LiteFlowProxyUtil.isDeclareCmp(bean.getClass())) { + LOG.info("proxy component[{}] has been found", beanName); + List nodeComponents = LiteFlowProxyUtil.proxy2NodeComponent(bean, beanName); + nodeComponents.forEach(nodeComponent -> { + String nodeId = nodeComponent.getNodeId(); + nodeId = StrUtil.isEmpty(nodeId) ? beanName : nodeId; + nodeComponentMap.put(nodeId, nodeComponent); + }); + // 只有注解支持单bean多Node,所以一个直接返回 + if (nodeComponents.size() == 1) { + return nodeComponents.get(0); + } + return bean; + } - // 组件的扫描发现,扫到之后缓存到类属性map中 - if (NodeComponent.class.isAssignableFrom(clazz)) { - LOG.info("component[{}] has been found", beanName); - NodeComponent nodeComponent = (NodeComponent) bean; - nodeComponentMap.put(beanName, nodeComponent); - return nodeComponent; - } + // 组件的扫描发现,扫到之后缓存到类属性map中 + if (NodeComponent.class.isAssignableFrom(clazz)) { + LOG.info("component[{}] has been found", beanName); + NodeComponent nodeComponent = (NodeComponent) bean; + nodeComponentMap.put(beanName, nodeComponent); + return nodeComponent; + } - // 组件Aop的实现类加载 - if (ICmpAroundAspect.class.isAssignableFrom(clazz)) { - LOG.info("component aspect implement[{}] has been found", beanName); - cmpAroundAspect = (ICmpAroundAspect) bean; - return cmpAroundAspect; - } + // 组件Aop的实现类加载 + if (ICmpAroundAspect.class.isAssignableFrom(clazz)) { + LOG.info("component aspect implement[{}] has been found", beanName); + cmpAroundAspect = (ICmpAroundAspect) bean; + return cmpAroundAspect; + } - // 扫描@ScriptBean修饰的类 - ScriptBean scriptBean = AnnoUtil.getAnnotation(clazz, ScriptBean.class); - if (ObjectUtil.isNotNull(scriptBean)) { - ScriptBeanProxy proxy = new ScriptBeanProxy(bean, clazz, scriptBean); - ScriptBeanManager.addScriptBean(scriptBean.value(), proxy.getProxyScriptBean()); - return bean; - } + // 扫描@ScriptBean修饰的类 + ScriptBean scriptBean = AnnoUtil.getAnnotation(clazz, ScriptBean.class); + if (ObjectUtil.isNotNull(scriptBean)) { + ScriptBeanProxy proxy = new ScriptBeanProxy(bean, clazz, scriptBean); + ScriptBeanManager.addScriptBean(scriptBean.value(), proxy.getProxyScriptBean()); + return bean; + } - // 扫描@ScriptMethod修饰的类 - List scriptMethods = Arrays.stream(clazz.getMethods()) - .filter(method -> { - ScriptMethod scriptMethod = AnnoUtil.getAnnotation(method, ScriptMethod.class); - return ObjectUtil.isNotNull(scriptMethod) && StrUtil.isNotEmpty(scriptMethod.value()); - }) - .collect(Collectors.toList()); - if (CollUtil.isNotEmpty(scriptMethods)) { - Map> scriptMethodsGroupByValue = CollStreamUtil.groupBy(scriptMethods, method -> { - ScriptMethod scriptMethod = AnnoUtil.getAnnotation(method, ScriptMethod.class); - return scriptMethod.value(); - }, Collectors.toList()); + // 扫描@ScriptMethod修饰的类 + List scriptMethods = Arrays.stream(clazz.getMethods()).filter(method -> { + ScriptMethod scriptMethod = AnnoUtil.getAnnotation(method, ScriptMethod.class); + return ObjectUtil.isNotNull(scriptMethod) && StrUtil.isNotEmpty(scriptMethod.value()); + }).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(scriptMethods)) { + Map> scriptMethodsGroupByValue = CollStreamUtil.groupBy(scriptMethods, method -> { + ScriptMethod scriptMethod = AnnoUtil.getAnnotation(method, ScriptMethod.class); + return scriptMethod.value(); + }, Collectors.toList()); + for (Map.Entry> entry : scriptMethodsGroupByValue.entrySet()) { + String key = entry.getKey(); + List methods = entry.getValue(); + ScriptMethodProxy proxy = new ScriptMethodProxy(bean, clazz, methods); - for (Map.Entry> entry : scriptMethodsGroupByValue.entrySet()) { - String key = entry.getKey(); - List methods = entry.getValue(); - ScriptMethodProxy proxy = new ScriptMethodProxy(bean, clazz, methods); + ScriptBeanManager.addScriptBean(key, proxy.getProxyScriptMethod()); - ScriptBeanManager.addScriptBean(key, proxy.getProxyScriptMethod()); + } - } + return bean; + } - return bean; - } + return bean; + } - return bean; - } + /** + * 用于清除 spring 上下文扫描到的组件实体 + */ + public static void cleanCache() { + nodeComponentMap.clear(); + } - /** - * 用于清除 spring 上下文扫描到的组件实体 - */ - public static void cleanCache() { - nodeComponentMap.clear(); - } } - diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java index e464dcba..8837f3ac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/ApolloWithXmlELSpringbootTest.java @@ -35,7 +35,7 @@ import static org.mockito.Mockito.*; @TestPropertySource(value = "classpath:/apollo/application-xml.properties") @SpringBootTest(classes = ApolloWithXmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.apollo.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.apollo.cmp" }) public class ApolloWithXmlELSpringbootTest { @MockBean(name = "chainConfig") @@ -48,7 +48,7 @@ public class ApolloWithXmlELSpringbootTest { private FlowExecutor flowExecutor; @Before - public void setUp(){ + public void setUp() { MockitoAnnotations.initMocks(this); } @@ -58,7 +58,7 @@ public class ApolloWithXmlELSpringbootTest { } @Test - public void testApolloWithXml1(){ + public void testApolloWithXml1() { Set chainNameList = Sets.newHashSet("chain1"); Set scriptNodeValueList = Sets.newHashSet("s1:script:脚本s1"); when(chainConfig.getPropertyNames()).thenReturn(chainNameList); @@ -72,4 +72,5 @@ public class ApolloWithXmlELSpringbootTest { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStrWithoutTime()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java index 871f8144..9124a8c7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-apollo-springboot/src/test/java/com/yomahub/liteflow/test/apollo/cmp/ACmp.java @@ -18,4 +18,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 12625060..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,14 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java index 5cae44d2..241105e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclMultiSpringbootTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -25,17 +26,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/absoluteConfigPath/application.properties") @SpringBootTest(classes = AbsoluteConfigPathELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.absoluteConfigPath.cmp" }) public class AbsoluteConfigPathELDeclMultiSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testAbsoluteConfig() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CmpMultiDefine.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CmpMultiDefine.java index 088128a5..da6d90da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CmpMultiDefine.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CmpMultiDefine.java @@ -14,20 +14,21 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent -public class CmpMultiDefine{ +public class CmpMultiDefine { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a",nodeType = NodeTypeEnum.COMMON) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a", nodeType = NodeTypeEnum.COMMON) public void processA(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") public void processB(NodeComponent bindCmp) { System.out.println("BCmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") public void processC(NodeComponent bindCmp) { System.out.println("CCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclMultiSpringbootTest.java index 5621ee8d..7e6c56d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclMultiSpringbootTest.java @@ -21,6 +21,7 @@ import javax.annotation.Resource; /** * 切面场景单元测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @@ -28,52 +29,53 @@ import javax.annotation.Resource; @SpringBootTest(classes = GlobalAOPELDeclMultiSpringbootTest.class) @EnableAutoConfiguration @Import(CmpAspect.class) -@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.aop.cmp1", "com.yomahub.liteflow.test.aop.cmp2" }) public class GlobalAOPELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试全局AOP,串行场景 - @Test - public void testGlobalAopS() { - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,串行场景 + @Test + public void testGlobalAopS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - //测试全局AOP,并行场景 - @Test - public void testGlobalAopP() { - LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,并行场景 + @Test + public void testGlobalAopP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - @Test - public void testGlobalAopException() { - LiteflowResponse response= flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("f")); - } + @Test + public void testGlobalAopException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("f")); + } + + @AfterClass + public static void cleanScanCache() { + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } - @AfterClass - public static void cleanScanCache(){ - BaseTest.cleanScanCache(); - ComponentScanner.cmpAroundAspect = null; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java index 3704a146..e3884622 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java @@ -6,15 +6,17 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; public class CmpAspect implements ICmpAroundAspect { - @Override - public void beforeProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, "before"); - } - @Override - public void afterProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); - } + @Override + public void beforeProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, "before"); + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java index a8df2001..535f04e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java @@ -11,17 +11,18 @@ import org.aspectj.lang.annotation.Pointcut; @Aspect public class CustomAspect { - @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process(*))") - public void cut() { - } + @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process(*))") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId(), "before"); + Object returnObj = jp.proceed(); + context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); + return returnObj; + } - @Around("cut()") - public Object around(ProceedingJoinPoint jp) throws Throwable { - NodeComponent cmp = (NodeComponent) jp.getThis(); - DefaultContext context = cmp.getFirstContextBean(); - context.setData(cmp.getNodeId(), "before"); - Object returnObj = jp.proceed(); - context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); - return returnObj; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/Cmp1Config.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/Cmp1Config.java index 6f0b6e97..b756480c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/Cmp1Config.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/Cmp1Config.java @@ -7,19 +7,20 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class Cmp1Config { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("Acomp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("Bcomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("Ccomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("Ccomp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/Cmp2Config.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/Cmp2Config.java index 49e50512..710b8acc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/Cmp2Config.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/Cmp2Config.java @@ -7,19 +7,20 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class Cmp2Config { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("Dcomp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - System.out.println("Ecomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { - throw new RuntimeException("test error"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("Ecomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { + throw new RuntimeException("test error"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclMultiSpringbootTest.java index 30c4445b..796302a2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclMultiSpringbootTest.java @@ -18,8 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author ssss */ @@ -27,113 +26,114 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/asyncNode/application.properties") @SpringBootTest(classes = AsyncNodeELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.asyncNode.cmp" }) public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - /***** - * 标准chain 嵌套选择 嵌套子chain进行执行 - * 验证了when情况下 多个node是并行执行 - * 验证了默认参数情况下 when可以加载执行 - * **/ - @Test - public void testAsyncFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - System.out.println(response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; - //这个和test1有点类似,只不过进一步验证了步骤 - @Test - public void testAsyncFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); - Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", - "b==>j==>h==>g==>f","b==>j==>h==>f==>g", - "b==>j==>f==>h==>g","b==>j==>f==>g==>h" - ).contains(response.getExecuteStepStr())); - } + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 验证了when情况下 多个node是并行执行 验证了默认参数情况下 when可以加载执行 + **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getExecuteStepStr()); + } - //测试errorResume,默认的errorResume为false,这里测试默认的 - @Test - public void testAsyncFlow3_1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); - } + // 这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue( + ListUtil + .toList("b==>j==>g==>f==>h", "b==>j==>g==>h==>f", "b==>j==>h==>g==>f", "b==>j==>h==>f==>g", + "b==>j==>f==>h==>g", "b==>j==>f==>g==>h") + .contains(response.getExecuteStepStr())); + } - //测试errorResume,默认的errorResume为false,这里设置为true - @Test - public void testAsyncFlow3_2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - } + // 测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 - @Test - public void testAsyncFlow4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //因为不记录错误,所以最终结果是true - Assert.assertTrue(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为配置了不抛错,所以response里的cause应该为null - Assert.assertNull(response.getCause()); - } + // 测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 - @Test - public void testAsyncFlow5() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //整个并行组是报错的,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为第一个when配置了会报错,所以response里的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } - //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 - @Test - public void testAsyncFlow6() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第一个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(1), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } - //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 - @Test - public void testAsyncFlow7() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第二个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - // 传递了slotIndex,则set的size==2 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(1), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 测试任意异步一个执行完即继续的场景 + // d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + // 最终执行效果应该是h先返回,然后执行abc,最后gd + // 这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("check").toString().startsWith("habc")); + } - //测试任意异步一个执行完即继续的场景 - //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 - //最终执行效果应该是h先返回,然后执行abc,最后gd - //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 - @Test - public void testAsyncFlow8() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("check").toString().startsWith("habc")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CmpConfig.java index 9ffb0cf1..0a785f57 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CmpConfig.java @@ -10,129 +10,138 @@ import com.yomahub.liteflow.test.asyncNode.exception.TestException; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Acomp executed!"); - } - @LiteflowMethod(value =LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Bcomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Ccomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) throws Exception { - Thread.sleep(1000); - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Dcomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchE(NodeComponent bindCmp) throws Exception { - System.out.println("Ecomp executed!"); - return "g"; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) throws Exception { + Thread.sleep(1000); + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) throws Exception { - System.out.println("Fcomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "e", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void processG(NodeComponent bindCmp) throws Exception { - Thread.sleep(500); - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Gcomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) throws Exception { + System.out.println("Fcomp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "h") - public void processH(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void processG(NodeComponent bindCmp) throws Exception { + Thread.sleep(500); + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "h") + public void processH(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } - System.out.println("Hcomp executed!"); - } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "i") - public void processI(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (this){ - if (context.hasData("count")){ - Integer count = context.getData("count"); - context.setData("count", ++count); - } else{ - context.setData("count", 1); - } - } - System.out.println("Icomp executed! throw Exception!"); - throw new TestException(); - } + System.out.println("Hcomp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "i") + public void processI(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (this) { + if (context.hasData("count")) { + Integer count = context.getData("count"); + context.setData("count", ++count); + } + else { + context.setData("count", 1); + } + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "j", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchJ(NodeComponent bindCmp) throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "j",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchJ(NodeComponent bindCmp) throws Exception { - System.out.println("Jcomp executed!"); - return "chain3"; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java index e786e9f8..fa8827df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -1,4 +1,5 @@ package com.yomahub.liteflow.test.asyncNode.exception; -public class TestException extends Exception{ +public class TestException extends Exception { + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclMultiSpringbootTest.java index 1ab13fcb..31978fd0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,16 +24,16 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/base/application.properties") @SpringBootTest(classes = BaseELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.base.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.base.cmp" }) public class BaseELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testBase() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testBase() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java index 0156fae9..5689c278 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CmpConfig.java @@ -10,31 +10,29 @@ import javax.annotation.Resource; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") - public void processB(NodeComponent bindCmp) { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + System.out.println("BCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - @Resource - private TestDomain testDomain; + @Resource + private TestDomain testDomain; - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - testDomain.sayHi(); - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + testDomain.sayHi(); + System.out.println("CCmp executed!"); + } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java index 16f15932..31ec520c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java @@ -4,7 +4,9 @@ import org.springframework.stereotype.Component; @Component public class TestDomain { - public void sayHi(){ - System.out.println("hello"); - } + + public void sayHi() { + System.out.println("hello"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest1.java index eaf6135a..9221bfed 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest1.java @@ -24,145 +24,157 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class BuilderELDeclMultiSpringbootTest1 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //基于普通组件的builder模式测试 - @Test - public void testBuilder() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") - .build(); + // 基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") + .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + // 基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz(GCmp.class) + .build(); - //基于普通组件的builder模式测试 - @Test - public void testBuilderForClassAndCode() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz(BCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz(DCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz(ECmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz(FCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz(GCmp.class) - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + @Test + public void testBuilderForSameNodeMultiTimes() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a1") + .setName("组件A1") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("a2") + .setName("组件A2") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c1") + .setName("组件C1") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c2") + .setName("组件C2") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(a1,c2,a2,c1)").build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); + } - @Test - public void testBuilderForSameNodeMultiTimes() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a1") - .setName("组件A1") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("a2") - .setName("组件A2") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c1") - .setName("组件C1") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c2") - .setName("组件C2") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a1,c2,a2,c1)" - ).build(); - - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest2.java index 8db32fe8..88b3e73d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclMultiSpringbootTest2.java @@ -19,21 +19,20 @@ import javax.annotation.Resource; @RunWith(SpringRunner.class) @SpringBootTest(classes = BuilderELDeclMultiSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.builder.cmp2" }) public class BuilderELDeclMultiSpringbootTest2 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //通过spring去扫描组件,通过代码去构建chain - @Test - public void testBuilder() throws Exception { - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(h, i, j)" - ).build(); + // 通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(h, i, j)").build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java index 659f386f..7b128bad 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -11,10 +11,11 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java index 29c7d5b3..de421bf3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java index fac09c1e..ef51ea46 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java index 7f5e10c6..daea220f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java index 6786d33e..e8cf23ec 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; -public class ECmp{ +public class ECmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java index 4ee40b50..cdca24e4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java index 25a8a0a2..a2bf0eba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class GCmp{ +public class GCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java index 110c05f3..b7977019 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("h") -public class HCmp{ +public class HCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java index 467b44f5..ca5bde31 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("i") -public class ICmp{ +public class ICmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java index 119130f7..b666b295 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("j") -public class JCmp{ +public class JCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclMultiSpringbootTest.java index 5eba736f..9b655b1b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclMultiSpringbootTest.java @@ -14,9 +14,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的节点执行器 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -24,40 +24,41 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/cmpRetry/application.properties") @SpringBootTest(classes = LiteflowRetryELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpRetry.cmp" }) public class LiteflowRetryELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //全局重试配置测试 - @Test - public void testRetry1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); - } + // 全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); + } - //单个组件重试配置测试 - @Test - public void testRetry2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); - } + // 单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); + } - //单个组件指定异常,但抛出的并不是指定异常的场景测试 - @Test - public void testRetry3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - } + // 单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + // 单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); + } - //单个组件指定异常重试,抛出的是指定异常或者 - @Test - public void testRetry4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CmpConfig.java index 4bf32252..e2cfac57 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CmpConfig.java @@ -9,61 +9,54 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - - private int flag = 0; - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - if (flag < 2){ - flag++; - throw new RuntimeException("demo exception"); - } - } - - @LiteflowRetry(5) - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - throw new RuntimeException("demo exception"); - } - - @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("DCmp executed!"); - throw new RuntimeException("demo exception"); - } - - @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - System.out.println("ECmp executed!"); - throw new NullPointerException("demo null exception"); - } - - @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { - System.out.println("ECmp executed!"); - throw new NullPointerException("demo null exception"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.AFTER_PROCESS,nodeId = "f") - public void after(NodeComponent bindCmp) { - System.out.println("ECmp executed!"); - throw new NullPointerException("demo null exception"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + private int flag = 0; + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2) { + flag++; + throw new RuntimeException("demo exception"); + } + } + @LiteflowRetry(5) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + throw new RuntimeException("demo exception"); + } + @LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new RuntimeException("demo exception"); + } + @LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + @LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.AFTER_PROCESS, nodeId = "f") + public void after(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java index d07e7100..753261b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java @@ -21,6 +21,7 @@ import java.util.Set; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -28,47 +29,49 @@ import java.util.Set; @TestPropertySource(value = "classpath:/cmpStep/application.properties") @SpringBootTest(classes = CmpStepELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpStep.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpStep.cmp" }) public class CmpStepELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testStep() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); - } + @Test + public void testStep() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); + } - @Test - public void testStep2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testStep2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testStep3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Map stepMap = response.getExecuteSteps(); - Assert.assertEquals(2, stepMap.size()); - Queue queue = response.getExecuteStepQueue(); - Assert.assertEquals(5, queue.size()); + @Test + public void testStep3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Map stepMap = response.getExecuteSteps(); + Assert.assertEquals(2, stepMap.size()); + Queue queue = response.getExecuteStepQueue(); + Assert.assertEquals(5, queue.size()); - Set tagSet = new HashSet<>(); - response.getExecuteStepQueue().stream().filter( - cmpStep -> cmpStep.getNodeId().equals("a") - ).forEach(cmpStep -> tagSet.add(cmpStep.getTag())); + Set tagSet = new HashSet<>(); + response.getExecuteStepQueue() + .stream() + .filter(cmpStep -> cmpStep.getNodeId().equals("a")) + .forEach(cmpStep -> tagSet.add(cmpStep.getTag())); - Assert.assertEquals(3, tagSet.size()); + Assert.assertEquals(3, tagSet.size()); + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CmpConfig.java index d7a446f0..3b393392 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CmpConfig.java @@ -8,42 +8,38 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) throws Exception{ - Thread.sleep(5000L); - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) throws Exception { + Thread.sleep(5000L); + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) throws Exception { + System.out.println("CCmp executed!"); + Thread.sleep(2000); + throw new RuntimeException("test error c"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) throws Exception{ - System.out.println("CCmp executed!"); - Thread.sleep(2000); - throw new RuntimeException("test error c"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - throw new RuntimeException("test error d"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - System.out.println("ECmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "e") - public boolean isAccessE(NodeComponent bindCmp) { - return false; - } - + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + throw new RuntimeException("test error d"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "e") + public boolean isAccessE(NodeComponent bindCmp) { + return false; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELDeclMultiSpringbootTest.java index e959fbb1..acfa4bcc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELDeclMultiSpringbootTest.java @@ -19,7 +19,7 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/comments/application.properties") @SpringBootTest(classes = LiteflowNodeELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.comments.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.comments.cmp" }) public class LiteflowNodeELDeclMultiSpringbootTest extends BaseTest { @Resource @@ -30,6 +30,7 @@ public class LiteflowNodeELDeclMultiSpringbootTest extends BaseTest { public void testAsyncFlow1() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr())); + Assert.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr())); } + } \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CmpConfig.java index 465d26f5..0f90b7f2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CmpConfig.java @@ -8,19 +8,19 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest1.java index d787e6a7..1327e75b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest1.java @@ -16,33 +16,35 @@ import javax.annotation.Resource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/complex/application1.properties") @SpringBootTest(classes = ComplexELDeclMultiSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.complex.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.complex.cmp1" }) public class ComplexELDeclMultiSpringbootTest1 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest2.java index c3074ac6..12c0c765 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclMultiSpringbootTest2.java @@ -16,33 +16,35 @@ import javax.annotation.Resource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/complex/application2.properties") @SpringBootTest(classes = ComplexELDeclMultiSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.complex.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.complex.cmp2" }) public class ComplexELDeclMultiSpringbootTest2 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CmpConfig1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CmpConfig1.java index 3e39d0d2..df89ed12 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CmpConfig1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CmpConfig1.java @@ -9,74 +9,74 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent public class CmpConfig1 { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "A") + public void processA(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "A") - public void processA(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "B") + public void processB(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "B") - public void processB(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "C") + public void processC(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "C") - public void processC(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "D") + public void processD(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "D") - public void processD(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "E") + public void processE(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "E") - public void processE(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "F") + public void processF(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "F") - public void processF(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "G", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchG(NodeComponent bindCmp) throws Exception { + return "t1"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "G",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchG(NodeComponent bindCmp) throws Exception { - return "t1"; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "H") + public void processH(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "H") - public void processH(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "J") + public void processJ(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "J") - public void processJ(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "K") + public void processK(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "K") - public void processK(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "L") + public void processL(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "L") - public void processL(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "M") + public void processM(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "M") - public void processM(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "N") + public void processN(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "N") - public void processN(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "Z") + public void processZ(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "Z") - public void processZ(NodeComponent bindCmp) { + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java index eca509c6..a403dd66 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CmpConfig2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CmpConfig2.java index 250c0712..443f10e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CmpConfig2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CmpConfig2.java @@ -9,74 +9,74 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent public class CmpConfig2 { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "A") + public void processA(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "A") - public void processA(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH, nodeId = "B") + public String processSwitchB(NodeComponent bindCmp) { + return "t3"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeType = NodeTypeEnum.SWITCH,nodeId = "B") - public String processSwitchB(NodeComponent bindCmp) { - return "t3"; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "C") + public void processC(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "C") - public void processC(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "D") + public void processD(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "D") - public void processD(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "E") + public void processE(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "E") - public void processE(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "F") + public void processF(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "F") - public void processF(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH, nodeId = "G") + public String processSwitchG(NodeComponent bindCmp) throws Exception { + return "t2"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeType = NodeTypeEnum.SWITCH,nodeId = "G") - public String processSwitchG(NodeComponent bindCmp) throws Exception { - return "t2"; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "H") + public void processH(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "H") - public void processH(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "J") + public void processJ(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "J") - public void processJ(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "K") + public void processK(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "K") - public void processK(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "L") + public void processL(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "L") - public void processL(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "M") + public void processM(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "M") - public void processM(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "N") + public void processN(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "N") - public void processN(NodeComponent bindCmp) { + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "Z") + public void processZ(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId ="Z") - public void processZ(NodeComponent bindCmp) { + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java index 08d07119..71f28e45 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclMultiSpringbootTest.java index b6d3224b..c99a0842 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclMultiSpringbootTest.java @@ -18,8 +18,7 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; /** - * 组件功能点测试 - * 单元测试 + * 组件功能点测试 单元测试 * * @author donguo.tao */ @@ -27,67 +26,68 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/component/application.properties") @SpringBootTest(classes = FlowExecutorELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.component.cmp1", "com.yomahub.liteflow.test.component.cmp2" }) public class FlowExecutorELDeclMultiSpringbootTest extends BaseTest { - private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELDeclMultiSpringbootTest.class); - @Resource - private FlowExecutor flowExecutor; + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELDeclMultiSpringbootTest.class); - //isAccess方法的功能测试 - @Test - public void testIsAccess() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); - Assert.assertTrue(response.isSuccess()); - Assert.assertNotNull(response.getSlot().getResponseData()); - } + @Resource + private FlowExecutor flowExecutor; - //组件抛错的功能点测试 - @Test(expected = ArithmeticException.class) - public void testComponentException() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("/ by zero", response.getMessage()); - ReflectionUtils.rethrowException(response.getCause()); - } + // isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } - //isContinueOnError方法的功能点测试 - @Test - public void testIsContinueOnError() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCause()); - } + // 组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } - //isEnd方法的功能点测试 - @Test - public void testIsEnd() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d",response.getExecuteStepStr()); - } + // isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } - //setIsEnd方法的功能点测试 - @Test - public void testSetIsEnd1() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("e",response.getExecuteStepStr()); - } + // isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d", response.getExecuteStepStr()); + } - //条件组件的功能点测试 - @Test - public void testNodeCondComponent() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); - Assert.assertTrue(response.isSuccess()); - } + // setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e", response.getExecuteStepStr()); + } - //测试setIsEnd如果为true,continueError也为true,那不应该continue了 - @Test - public void testSetIsEnd2() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g",response.getExecuteStepStr()); - } + // 条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + // 测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CmpConfig1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CmpConfig1.java index 887c98e6..9f8ed9fd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CmpConfig1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CmpConfig1.java @@ -11,106 +11,101 @@ import java.util.Objects; @LiteflowComponent public class CmpConfig1 { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("AComp executed!"); - bindCmp.getSlot().setResponseData("AComp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("AComp executed!"); + bindCmp.getSlot().setResponseData("AComp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "a") - public boolean isAccessA(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.nonNull(requestData) && requestData > 100){ - return true; - } - System.out.println("AComp isAccess false."); - return false; - } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "a") + public boolean isAccessA(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100) { + return true; + } + System.out.println("AComp isAccess false."); + return false; + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BComp executed!"); + Integer requestData = bindCmp.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BComp executed!"); - Integer requestData = bindCmp.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - bindCmp.getSlot().setResponseData(result); - } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "b") + public boolean isAccessB(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } - @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "b") - public boolean isAccessB(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CComp executed!"); + Integer requestData = bindCmp.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + System.out.println("responseData=" + Integer.parseInt(bindCmp.getSlot().getResponseData())); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CComp executed!"); - Integer requestData = bindCmp.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - bindCmp.getSlot().setResponseData(result); - System.out.println("responseData="+Integer.parseInt(bindCmp.getSlot().getResponseData())); - } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR, nodeId = "c") + public boolean isContinueOnErrorC(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } - @LiteflowMethod(value = LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR,nodeId = "c") - public boolean isContinueOnErrorC(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) throws Exception { + System.out.println("DComp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_END, nodeId = "d") + public boolean isEndD(NodeComponent bindCmp) { + // 组件的process执行完之后才会执行isEnd + Object requestData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(requestData)) { + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) throws Exception { - System.out.println("DComp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) throws Exception { + System.out.println("EComp executed!"); + Object responseData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(responseData)) { + System.out.println("EComp responseData flow must be set end ."); + // 执行到某个条件时,手动结束流程。 + bindCmp.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); + } - @LiteflowMethod(value = LiteFlowMethodEnum.IS_END,nodeId = "d") - public boolean isEndD(NodeComponent bindCmp) { - //组件的process执行完之后才会执行isEnd - Object requestData = bindCmp.getSlot().getResponseData(); - if (Objects.isNull(requestData)){ - System.out.println("DComp flow isEnd, because of responseData is null."); - return true; - } - return false; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void processF(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + bindCmp.setIsEnd(true); + } + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + return true; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) throws Exception { - System.out.println("EComp executed!"); - Object responseData = bindCmp.getSlot().getResponseData(); - if (Objects.isNull(responseData)){ - System.out.println("EComp responseData flow must be set end ."); - //执行到某个条件时,手动结束流程。 - bindCmp.setIsEnd(true); - } - System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); - } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void processF(NodeComponent bindCmp) { - System.out.println("GCmp executed!"); - bindCmp.setIsEnd(true); - } - - @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) - public boolean isContinueOnError(NodeComponent bindCmp) { - return true; - } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "h") - public void processH(NodeComponent bindCmp) { - System.out.println("HCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "h") + public void processH(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java index dc5a23f6..04919824 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java @@ -8,18 +8,21 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import java.util.Objects; - @LiteflowComponent -public class FCondCmp{ - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "f",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchF(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.isNull(requestData)){ - return "d"; - } else if(requestData == 0){ - return "c"; - } else { - return "b"; - } - } +public class FCondCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "f", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchF(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.isNull(requestData)) { + return "d"; + } + else if (requestData == 0) { + return "c"; + } + else { + return "b"; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclMultiSpringbootTest.java index f0d0312b..f349416f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * 声明式组件自定义方法的测试用例 + * * @author Bryan.Zhang * @since 2.7.2 */ @@ -23,15 +24,16 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customMethodName/application.properties") @SpringBootTest(classes = CustomMethodNameELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customMethodName.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.customMethodName.cmp" }) public class CustomMethodNameELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomMethodName() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testCustomMethodName() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java index 54ca00a2..9a852fbe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java @@ -9,46 +9,46 @@ import com.yomahub.liteflow.slot.Slot; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processAcmp(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processAcmp(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "a") - public boolean isAcmpAccess(NodeComponent bindCmp){ - return true; - } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "a") + public boolean isAcmpAccess(NodeComponent bindCmp) { + return true; + } - @LiteflowMethod(value = LiteFlowMethodEnum.BEFORE_PROCESS,nodeId = "a") - public void beforeAcmp(NodeComponent bindCmp){ - System.out.println("before A"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.BEFORE_PROCESS, nodeId = "a") + public void beforeAcmp(NodeComponent bindCmp) { + System.out.println("before A"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.AFTER_PROCESS,nodeId = "a") - public void afterAcmp(NodeComponent bindCmp){ - System.out.println("after A"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.AFTER_PROCESS, nodeId = "a") + public void afterAcmp(NodeComponent bindCmp) { + System.out.println("after A"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId ="a") - public void onAcmpSuccess(NodeComponent bindCmp){ - System.out.println("Acmp success"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "a") + public void onAcmpSuccess(NodeComponent bindCmp) { + System.out.println("Acmp success"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR,nodeId = "a") - public void onAcmpError(NodeComponent bindCmp){ - System.out.println("Acmp error"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR, nodeId = "a") + public void onAcmpError(NodeComponent bindCmp) { + System.out.println("Acmp error"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.IS_END,nodeId = "a") - public boolean isAcmpEnd(NodeComponent bindCmp) { - System.out.println("Acmp end config"); - return false; - } - /////////////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processBcmp(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_END, nodeId = "a") + public boolean isAcmpEnd(NodeComponent bindCmp) { + System.out.println("Acmp end config"); + return false; + } + /////////////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processBcmp(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclMultiSpringbootTest.java index b5ffa105..9a66e2be 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclMultiSpringbootTest.java @@ -17,8 +17,8 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境下自定义声明节点的测试 - * 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * springboot环境下自定义声明节点的测试 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,19 +26,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customNodes/application.properties") @SpringBootTest(classes = CustomNodesELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +@ComponentScan({ "com.yomahub.liteflow.test.customNodes.domain" }) public class CustomNodesELDeclMultiSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testCustomNodes() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java index b0cbdf15..276d4979 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -11,10 +11,11 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java index 7a56ecf7..fe37f706 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; import javax.annotation.Resource; -public class BCmp{ +public class BCmp { @Resource private DemoDomain demoDomain; @@ -24,4 +24,5 @@ public class BCmp{ demoDomain.sayHi(); System.out.println("BCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java index 48d6f228..6bc3a942 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java index d7778c8a..1584380a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java index 362f4cd3..a34fea18 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; import javax.annotation.Resource; -public class ECmp{ +public class ECmp { @Resource private DemoDomain demoDomain; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java index 29e1e2db..6647e1ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java index d0b10dc0..745da51d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoDomain { - public void sayHi(){ - System.out.println("hi"); - } + public void sayHi() { + System.out.println("hi"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6f88c4cd..6034ba62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -9,17 +9,15 @@ import java.util.concurrent.ExecutorService; public class CustomThreadExecutor1 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-1-thead-"); - } + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 7d45e4ad..8f9008e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor2 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-2-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index 875dc3d1..dc6f6399 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor3 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-3-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java index f5d8e322..a4ea53ff 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java @@ -27,49 +27,49 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customWhenThreadPool/application.properties") @SpringBootTest(classes = CustomWhenThreadPoolELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.customWhenThreadPool.cmp" }) public class CustomWhenThreadPoolELDeclMultiSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 测试全局线程池配置 - */ - @Test - public void testGlobalThreadPool() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); - } + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); + } - /** - * 测试全局和when上自定义线程池-优先以when上为准 - */ - @Test - public void testGlobalAndCustomWhenThreadPool() { - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response1.getFirstContextBean(); - Assert.assertTrue(response1.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - } + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - /** - * when配置的线程池可以共用 - */ - @Test - public void testCustomWhenThreadPool() { - // 使用when - thread1 - testGlobalAndCustomWhenThreadPool(); - // chain配置同一个thead1 - LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response2.getFirstContextBean(); - Assert.assertTrue(response2.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CmpConfig.java index 68e6f5d1..aa7fdfac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CmpConfig.java @@ -9,44 +9,45 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("threadName", Thread.currentThread().getName()); - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("threadName", Thread.currentThread().getName()); - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("CCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("threadName", Thread.currentThread().getName()); - System.out.println("DCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("DCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("threadName", Thread.currentThread().getName()); - System.out.println("ECmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("threadName", Thread.currentThread().getName()); - System.out.println("FCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ECmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclMultiSpringbootTest.java index 90a0f853..634ea3b7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclMultiSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,41 +25,41 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/event/application.properties") @SpringBootTest(classes = EventELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.event.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.event.cmp" }) public class EventELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试组件成功事件 - @Test - public void testEvent1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("abc", context.getData("test")); - } + // 测试组件成功事件 + @Test + public void testEvent1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("abc", context.getData("test")); + } - //测试组件失败事件 - @Test - public void testEvent2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("ab", context.getData("test")); - Assert.assertEquals("error:d", context.getData("error")); - } + // 测试组件失败事件 + @Test + public void testEvent2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("ab", context.getData("test")); + Assert.assertEquals("error:d", context.getData("error")); + } - //测试组件失败事件本身抛出异常 - @Test - public void testEvent3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("a", context.getData("test")); - Assert.assertEquals("error:e", context.getData("error")); - } + // 测试组件失败事件本身抛出异常 + @Test + public void testEvent3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("a", context.getData("test")); + Assert.assertEquals("error:e", context.getData("error")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CmpConfig.java index ba0fadf3..21fcb58c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CmpConfig.java @@ -9,69 +9,74 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("test",""); - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("test", ""); + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId = "a") - public void onSuccessA(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - String str = context.getData("test"); - str += bindCmp.getNodeId(); - context.setData("test", str); - } - //////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "a") + public void onSuccessA(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String str = context.getData("test"); + str += bindCmp.getNodeId(); + context.setData("test", str); + } - @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId = "b") - public void onSuccessB(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - String str = context.getData("test"); - str += bindCmp.getNodeId(); - context.setData("test", str); - } - /////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + //////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS,nodeId = "c") - public void onSuccessC(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - String str = context.getData("test"); - str += bindCmp.getNodeId(); - context.setData("test", str); - } - /////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) throws Exception{ - System.out.println("CCmp executed!"); - throw new NullPointerException(); - } + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "b") + public void onSuccessB(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String str = context.getData("test"); + str += bindCmp.getNodeId(); + context.setData("test", str); + } - @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR,nodeId = "d") - public void onErrorD(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("error","error:"+bindCmp.getNodeId()); - } - /////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) throws Exception{ - System.out.println("CCmp executed!"); - throw new NullPointerException(); - } + /////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "c") + public void onSuccessC(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String str = context.getData("test"); + str += bindCmp.getNodeId(); + context.setData("test", str); + } + + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) throws Exception { + System.out.println("CCmp executed!"); + throw new NullPointerException(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR, nodeId = "d") + public void onErrorD(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("error", "error:" + bindCmp.getNodeId()); + } + + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) throws Exception { + System.out.println("CCmp executed!"); + throw new NullPointerException(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR, nodeId = "e") + public void onErrorE(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("error", "error:" + bindCmp.getNodeId()); + throw new IllegalAccessException("错误事件回调本身抛出异常"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR,nodeId = "e") - public void onErrorE(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("error","error:"+bindCmp.getNodeId()); - throw new IllegalAccessException("错误事件回调本身抛出异常"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java index 11441ab5..e7b2394c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java @@ -6,7 +6,9 @@ import com.yomahub.liteflow.exception.LiteFlowException; * 用户自定义带状态码的异常 */ public class CustomStatefulException extends LiteFlowException { + public CustomStatefulException(String code, String message) { super(code, message); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclMultiSpringBootTest.java index d91cb322..6ffc613d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclMultiSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclMultiSpringBootTest.java @@ -16,8 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @@ -26,36 +25,37 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class Exception1ELDeclMultiSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 验证 chain 节点重复的异常 - */ - @Test(expected = ChainDuplicateException.class) - public void testChainDuplicateException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-exception.el.xml"); - flowExecutor.reloadRule(); - } + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = ChainDuplicateException.class) + public void testChainDuplicateException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = ConfigErrorException.class) - public void testConfigErrorException() { - flowExecutor.setLiteflowConfig(null); - flowExecutor.reloadRule(); - } + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testFlowExecutorNotInitException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("error/flow.txt"); - flowExecutor.reloadRule(); - } + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("error/flow.txt"); + flowExecutor.reloadRule(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-blank.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testNoConditionInChainException() throws Exception { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-blank.el.xml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclMultiSpringBootTest.java index 4eca8c32..a0b8bd03 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclMultiSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclMultiSpringBootTest.java @@ -18,8 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @@ -27,51 +26,52 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/exception/application.properties") @SpringBootTest(classes = Exception2ELDeclMultiSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.exception.cmp" }) public class Exception2ELDeclMultiSpringBootTest extends BaseTest { - - @Resource - private FlowExecutor flowExecutor; - @Test(expected = ChainNotFoundException.class) - public void testChainNotFoundException() throws Exception { - flowExecutor.execute("chain0", "it's a request"); - } + @Resource + private FlowExecutor flowExecutor; - @Test(expected = RuntimeException.class) - public void testComponentCustomException() throws Exception { - flowExecutor.execute("chain1", "exception"); - } + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } - @Test - public void testGetSlotFromResponseWhenException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); - Assert.assertFalse(response.isSuccess()); - Assert.assertNotNull(response.getCause()); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } - @Test(expected = NoSwitchTargetNodeException.class) - public void testNoTargetFindException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); - Assert.assertFalse(response.isSuccess()); - throw response.getCause(); - } + @Test + public void testGetSlotFromResponseWhenException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } - @Test - public void testInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("300", response.getCode()); - Assert.assertNotNull(response.getCause()); - Assert.assertTrue(response.getCause() instanceof LiteFlowException); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = NoSwitchTargetNodeException.class) + public void testNoTargetFindException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); + Assert.assertFalse(response.isSuccess()); + throw response.getCause(); + } + + @Test + public void testInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("300", response.getCode()); + Assert.assertNotNull(response.getCause()); + Assert.assertTrue(response.getCause() instanceof LiteFlowException); + Assert.assertNotNull(response.getSlot()); + } + + @Test + public void testNotInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCode()); + } - @Test - public void testNotInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCode()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CmpConfig.java index c868ffc9..627eddf9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CmpConfig.java @@ -12,65 +12,70 @@ import org.slf4j.LoggerFactory; @LiteflowComponent public class CmpConfig { - private static final Logger LOG = LoggerFactory.getLogger(CmpConfig.class); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { - throw new RuntimeException("chain execute execption"); - } - LOG.info("Acomp executed!"); - } - ////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) throws InterruptedException { - String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("when")) { - try { - LOG.info("Bcomp sleep begin"); - Thread.sleep(3000); - LOG.info("Bcomp sleep end"); - } catch (InterruptedException e) { - throw e; - } - } - LOG.info("Bcomp executed!"); - } - ////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - LOG.info("Ccomp executed!"); - } + private static final Logger LOG = LoggerFactory.getLogger(CmpConfig.class); - ////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - if(1==1){ - int a = 1/0; - } - LOG.info("Dcomp executed!"); - } - //////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchE(NodeComponent bindCmp) throws Exception { - return "a"; - } - ////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { - String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { - throw new CustomStatefulException("300", "chain execute custom stateful execption"); - } - LOG.info("Fcomp executed!"); - } - //////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void processG(NodeComponent bindCmp) { - LOG.info("Gcomp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + String str = bindCmp.getRequestData(); + if (StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new RuntimeException("chain execute execption"); + } + LOG.info("Acomp executed!"); + } + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) throws InterruptedException { + String str = bindCmp.getRequestData(); + if (StrUtil.isNotBlank(str) && str.equals("when")) { + try { + LOG.info("Bcomp sleep begin"); + Thread.sleep(3000); + LOG.info("Bcomp sleep end"); + } + catch (InterruptedException e) { + throw e; + } + } + LOG.info("Bcomp executed!"); + } + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + LOG.info("Ccomp executed!"); + } + + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + if (1 == 1) { + int a = 1 / 0; + } + LOG.info("Dcomp executed!"); + } + + //////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "e", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + return "a"; + } + + ////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { + String str = bindCmp.getRequestData(); + if (StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { + throw new CustomStatefulException("300", "chain execute custom stateful execption"); + } + LOG.info("Fcomp executed!"); + } + + //////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void processG(NodeComponent bindCmp) { + LOG.info("Gcomp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclMultiSpringbootTest.java index 834b73af..06c9866d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclMultiSpringbootTest.java @@ -18,6 +18,7 @@ import java.util.concurrent.Future; /** * springboot环境执行返回future的例子 + * * @author Bryan.Zhang * @since 2.6.13 */ @@ -25,17 +26,17 @@ import java.util.concurrent.Future; @TestPropertySource(value = "classpath:/execute2Future/application.properties") @SpringBootTest(classes = Executor2FutureELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.execute2Future.cmp" }) public class Executor2FutureELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testFuture() throws Exception{ - Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); - LiteflowResponse response = future.get(); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testFuture() throws Exception { + Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CmpConfig.java index 5fe0d8cd..ee1ee49e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CmpConfig.java @@ -7,28 +7,26 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } - + System.out.println("CCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclMultiSpringbootTest.java index 84663428..768d603f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境测试声明式组件继承其他类的场景 + * * @author Bryan.Zhang * @since 2.7.1 */ @@ -23,16 +24,16 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/extend/application.properties") @SpringBootTest(classes = CmpExtendELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.extend.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.extend.cmp" }) public class CmpExtendELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testExtend() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testExtend() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CmpConfig.java index 7b1936b7..45cb5bcb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CmpConfig.java @@ -9,24 +9,24 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - System.out.println(this.sayHi("jack")); - } - protected String sayHi(String name){ - return StrUtil.format("hi,{}",name); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + System.out.println(this.sayHi("jack")); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + protected String sayHi(String name) { + return StrUtil.format("hi,{}", name); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclMultiSpringbootTest.java index d2e53886..40701689 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclMultiSpringbootTest.java @@ -17,44 +17,45 @@ import javax.annotation.Resource; /** * springboot环境获取ChainName的测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/getChainName/application.properties") @SpringBootTest(classes = GetChainNameELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.getChainName.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.getChainName.cmp" }) public class GetChainNameELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testGetChainName1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - } + @Test + public void testGetChainName1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } - @Test - public void testGetChainName2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("chain2", context.getData("g")); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - Assert.assertEquals("sub5", context.getData("f")); - Assert.assertEquals("sub5_chain2", context.getData("e")); - Assert.assertEquals("sub6", context.getData("h")); - Assert.assertEquals("sub6", context.getData("j")); - Assert.assertNull(context.getData("k")); - } + @Test + public void testGetChainName2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CmpConfig.java index 45a69022..77d4d759 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CmpConfig.java @@ -9,75 +9,71 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - if (context.hasData(bindCmp.getNodeId())){ - context.setData(bindCmp.getNodeId(), context.getData(bindCmp.getNodeId()) + "_" + bindCmp.getCurrChainId()); - }else{ - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void processG(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "h",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchH(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - return "j"; - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "j") - public void processJ(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "k") - public void process(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + if (context.hasData(bindCmp.getNodeId())) { + context.setData(bindCmp.getNodeId(), context.getData(bindCmp.getNodeId()) + "_" + bindCmp.getCurrChainId()); + } + else { + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void processG(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "h", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchH(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + return "j"; + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "j") + public void processJ(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "k") + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclMultiSpringbootTest.java index 5123b459..41094404 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,66 +24,66 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/ifelse/application.properties") @SpringBootTest(classes = IfElseELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.ifelse.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.ifelse.cmp" }) public class IfElseELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/CmpConfig.java index 76a2bff5..4957712c 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 @@ -9,33 +9,30 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("DCmp executed!"); - } - - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF,nodeId = "x1",nodeType = NodeTypeEnum.IF) - public boolean processIfX1(NodeComponent bindCmp) throws Exception { - return Boolean.parseBoolean(bindCmp.getTag()); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "x1", nodeType = NodeTypeEnum.IF) + public boolean processIfX1(NodeComponent bindCmp) throws Exception { + return Boolean.parseBoolean(bindCmp.getTag()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELDeclMultiSpringbootTest.java index e8563a67..a9eac119 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELDeclMultiSpringbootTest.java @@ -19,6 +19,7 @@ import java.util.List; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,32 +27,32 @@ import java.util.List; @TestPropertySource(value = "classpath:/iterator/application.properties") @SpringBootTest(classes = IteratorELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.iterator.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.iterator.cmp" }) public class IteratorELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testIt1() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("123", str); - } + // 最简单的情况 + @Test + public void testIt1() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("123", str); + } - //迭代器带break - @Test - public void testIt2() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("12", str); - } + // 迭代器带break + @Test + public void testIt2() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("12", str); + } } 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 c6311927..fede383f 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 @@ -15,28 +15,29 @@ import java.util.List; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") - public void processA(NodeComponent bindCmp) { - String key = "test"; - DefaultContext context = bindCmp.getFirstContextBean(); - if (!context.hasData(key)){ - context.setData(key, bindCmp.getCurrLoopObj()); - }else{ - String str = context.getData(key); - str += bindCmp.getCurrLoopObj(); - context.setData(key, str); - } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + String key = "test"; + DefaultContext context = bindCmp.getFirstContextBean(); + if (!context.hasData(key)) { + context.setData(key, bindCmp.getCurrLoopObj()); + } + else { + String str = context.getData(key); + str += bindCmp.getCurrLoopObj(); + context.setData(key, str); + } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "b", nodeType = NodeTypeEnum.BREAK) + public boolean processB(NodeComponent bindCmp) { + return bindCmp.getLoopIndex() == 1; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "it", nodeType = NodeTypeEnum.ITERATOR) + public Iterator processIT(NodeComponent bindCmp) { + List list = bindCmp.getRequestData(); + return list.iterator(); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "b", nodeType = NodeTypeEnum.BREAK) - public boolean processB(NodeComponent bindCmp) { - return bindCmp.getLoopIndex() == 1; - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "it", nodeType = NodeTypeEnum.ITERATOR) - public Iterator processIT(NodeComponent bindCmp) { - List list = bindCmp.getRequestData(); - return list.iterator(); - } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclMultiSpringbootTest.java index 2512ca92..fa1fd1cf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclMultiSpringbootTest.java @@ -10,12 +10,12 @@ import com.yomahub.liteflow.test.BaseTest; @ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"})*/ public class LazyELDeclMultiSpringbootTest extends BaseTest { - /*@Resource - private FlowExecutor flowExecutor; + /* + * @Resource private FlowExecutor flowExecutor; + * + * @Test public void testLazy() throws Exception{ LiteflowResponse response = + * flowExecutor.execute2Resp("chain1", "arg"); + * Assert.assertTrue(response.isSuccess()); } + */ - @Test - public void testLazy() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - }*/ } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java index 2c33d4c6..f0d5fe44 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -15,10 +15,11 @@ import org.springframework.stereotype.Component; @Lazy @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java index 9f6cff9f..9fe293b1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java index 13c3c043..8c3cb4fd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclMultiSpringbootTest.java index 9cd3a9c5..ddfb1fac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclMultiSpringbootTest.java @@ -13,9 +13,9 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试@LiteflowComponent标注 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -23,16 +23,17 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(value = "classpath:/lfCmpAnno/application.properties") @SpringBootTest(classes = LiteflowComponentELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.lfCmpAnno.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.lfCmpAnno.cmp" }) public class LiteflowComponentELDeclMultiSpringbootTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); + } - @Test - public void testConfig() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java index f3d8c876..15a8830e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent(id = "a", name = "A组件") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java index 3a6fefc4..33c2ce51 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent(id = "b", name = "B组件") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java index 514293d3..7d684bd1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent(id = "c", name = "C组件") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java index f541bf72..a963b484 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclMultiSpringbootTest.java index 930ffe27..98f6706b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclMultiSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,71 +25,73 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/loop/application.properties") @SpringBootTest(classes = LoopELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.loop.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.loop.cmp" }) public class LoopELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //测试FOR循环中的index - @Test - public void testLoop6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } + // 测试FOR循环中的index + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } - //测试WHILE循环中的index - @Test - public void testLoop7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } + // 测试WHILE循环中的index + @Test + public void testLoop7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } } 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 c8ff7543..52902d55 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 @@ -11,70 +11,72 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") - public void processB(NodeComponent bindCmp) { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") - public void processD(NodeComponent bindCmp){ - DefaultContext context = bindCmp.getFirstContextBean(); - String key = "test"; - if (context.hasData(key)){ - int count = context.getData(key); - context.setData(key, ++count); - }else{ - context.setData(key, 1); - } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } + else { + context.setData(key, 1); + } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - String key = StrUtil.format("{}_{}", "loop", bindCmp.getTag()); - if (context.hasData(key)){ - String loopStr = context.getData(key); - String loopStrReturn = StrUtil.format("{}{}", loopStr, bindCmp.getLoopIndex()); - context.setData(key, loopStrReturn); - }else{ - context.setData(key, bindCmp.getLoopIndex().toString()); - } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = StrUtil.format("{}_{}", "loop", bindCmp.getTag()); + if (context.hasData(key)) { + String loopStr = context.getData(key); + String loopStrReturn = StrUtil.format("{}{}", loopStr, bindCmp.getLoopIndex()); + context.setData(key, loopStrReturn); + } + else { + context.setData(key, bindCmp.getLoopIndex().toString()); + } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeId = "x", nodeType = NodeTypeEnum.FOR) - public int processX(NodeComponent bindCmp){ - return 3; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeId = "x", nodeType = NodeTypeEnum.FOR) + public int processX(NodeComponent bindCmp) { + return 3; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "y", nodeType = NodeTypeEnum.BREAK) - public boolean processY(NodeComponent bindCmp){ - DefaultContext context = bindCmp.getFirstContextBean(); - int count = context.getData("test"); - return count > 3; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "y", nodeType = NodeTypeEnum.BREAK) + 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) + public boolean processZ(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } + else { + return true; + } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "z", nodeType = NodeTypeEnum.WHILE) - public boolean processZ(NodeComponent bindCmp){ - DefaultContext context = bindCmp.getFirstContextBean(); - String key = "test"; - if (context.hasData(key)){ - int count = context.getData("test"); - return count < 5; - }else{ - return true; - } - } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/MixDefineELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/MixDefineELDeclMultiSpringbootTest.java index d6a1a133..ee4c8ad6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/MixDefineELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/MixDefineELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,17 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/mixDefine/application.properties") @SpringBootTest(classes = MixDefineELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.mixDefine.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.mixDefine.cmp" }) public class MixDefineELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //类声明和方法声明一起定义 - @Test - public void testMixDefine1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 类声明和方法声明一起定义 + @Test + public void testMixDefine1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/cmp/CmpConfig.java index 5a6b2716..74ae0564 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/mixDefine/cmp/CmpConfig.java @@ -14,21 +14,19 @@ import javax.annotation.Resource; @LiteflowCmpDefine(NodeTypeEnum.COMMON) public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS) - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS) + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "d", nodeType = NodeTypeEnum.IF) + public boolean processIf(NodeComponent bindCmp) { + return true; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "d", nodeType = NodeTypeEnum.IF) - public boolean processIf(NodeComponent bindCmp) { - return true; - } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclMultiSpringbootTest.java index 6f54c4c0..1ca5b55e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclMultiSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,24 +27,24 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/monitor/application.properties") @SpringBootTest(classes = MonitorELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.monitor.cmp" }) public class MonitorELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); + @Test + public void testMonitor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); - Thread.sleep(10000); - } + Thread.sleep(10000); + } - @AfterClass - public static void clean(){ - MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); - monitorBus.closeScheduler(); - } + @AfterClass + public static void clean() { + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CmpConfig.java index e6c0ff29..0945ced0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CmpConfig.java @@ -10,35 +10,38 @@ import java.util.Random; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - try { - Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ - e.printStackTrace(); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + } + catch (Exception e) { + e.printStackTrace(); + } - System.out.println("ACmp executed!"); - } + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + } + catch (Exception e) { + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + } + catch (Exception e) { + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - try { - Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ - e.printStackTrace(); - } - System.out.println("BCmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void process(NodeComponent bindCmp) { - try { - Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ - e.printStackTrace(); - } - System.out.println("BCmp executed!"); - } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java index 1b8ee1d3..24c8602c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclMultiSpringbootTest.java @@ -22,20 +22,22 @@ import java.io.File; @TestPropertySource(value = "classpath:/monitorFile/application.properties") @SpringBootTest(classes = MonitorFileELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.monitorFile.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.monitorFile.cmp" }) public class MonitorFileELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java index 029ba45a..19873353 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CmpConfig.java @@ -10,19 +10,19 @@ import java.util.Random; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void process(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java index af8bfad4..793d85e1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java @@ -2,23 +2,24 @@ package com.yomahub.liteflow.test.multiContext; public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclMultiSpringbootTest.java index 0a7af8d0..2279d9ca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclMultiSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,29 +27,29 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/multiContext/application.properties") @SpringBootTest(classes = MultiContextELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.multiContext.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.multiContext.cmp" }) public class MultiContextELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMultiContext1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("987XYZ", checkContext.getSign()); - Assert.assertEquals(95, checkContext.getRandomId()); - Assert.assertEquals("SO12345", orderContext.getOrderNo()); - Assert.assertEquals(2, orderContext.getOrderType()); - Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); - } + @Test + public void testMultiContext1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("987XYZ", checkContext.getSign()); + Assert.assertEquals(95, checkContext.getRandomId()); + Assert.assertEquals("SO12345", orderContext.getOrderNo()); + Assert.assertEquals(2, orderContext.getOrderType()); + Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); + } - @Test(expected = NoSuchContextBeanException.class) - public void testMultiContext2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - DefaultContext context = response.getContextBean(DefaultContext.class); - } + @Test(expected = NoSuchContextBeanException.class) + public void testMultiContext2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + DefaultContext context = response.getContextBean(DefaultContext.class); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java index c477108b..292db52b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java @@ -4,33 +4,34 @@ import java.util.Date; public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CmpConfig.java index ddf94e77..71ec8239 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CmpConfig.java @@ -11,40 +11,35 @@ import com.yomahub.liteflow.test.multiContext.OrderContext; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - CheckContext checkContext = bindCmp.getContextBean(CheckContext.class); - checkContext.setSign("987XYZ"); - checkContext.setRandomId(95); - System.out.println("ACmp executed!"); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + CheckContext checkContext = bindCmp.getContextBean(CheckContext.class); + checkContext.setSign("987XYZ"); + checkContext.setRandomId(95); + System.out.println("ACmp executed!"); - } + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + // getContextBean无参方法是获取到第一个上下文 + OrderContext orderContext = bindCmp.getFirstContextBean(); + orderContext.setOrderNo("SO12345"); + System.out.println("BCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + OrderContext orderContext = bindCmp.getContextBean(OrderContext.class); + orderContext.setOrderType(2); + System.out.println("CCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - //getContextBean无参方法是获取到第一个上下文 - OrderContext orderContext = bindCmp.getFirstContextBean(); - orderContext.setOrderNo("SO12345"); - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + OrderContext orderContext = bindCmp.getContextBean(OrderContext.class); + orderContext.setCreateTime(DateUtil.parseDate("2022-06-15")); + System.out.println("CCmp executed!"); + } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - OrderContext orderContext = bindCmp.getContextBean(OrderContext.class); - orderContext.setOrderType(2); - System.out.println("CCmp executed!"); - } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - OrderContext orderContext = bindCmp.getContextBean(OrderContext.class); - orderContext.setCreateTime(DateUtil.parseDate("2022-06-15")); - System.out.println("CCmp executed!"); - } } - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclMultiSpringbootTest.java index 18c8c130..26c17b9d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclMultiSpringbootTest.java @@ -13,9 +13,9 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试springboot下混合格式规则的场景 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -23,19 +23,20 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(value = "classpath:/multipleType/application.properties") @SpringBootTest(classes = LiteflowMultipleTypeELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.multipleType.cmp" }) public class LiteflowMultipleTypeELDeclMultiSpringbootTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } - @Test - public void testMultipleType() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); - response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CmpConfig.java index 12808259..7798b966 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CmpConfig.java @@ -8,20 +8,19 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java index 9fb99224..9cce6d74 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -8,11 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义默认的节点执行器 */ public class CustomerDefaultNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerDefaultNodeExecutor进行执行"); - context.setData("customerDefaultNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + context.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java index e4ef70e0..f4d447b6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -8,12 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义节点执行器 */ public class CustomerNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutor进行执行"); - context.setData("customerNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutor进行执行"); + context.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java index 202005b1..130208a7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -10,19 +10,21 @@ import java.util.concurrent.TimeUnit; * 自定义节点执行器 */ public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); - context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); - super.execute(instance); - } - @Override - protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { - TimeUnit.MICROSECONDS.sleep(20L); - DefaultContext context = instance.getFirstContextBean(); - context.setData("retryLogic", this.getClass()); - super.retry(instance, currentRetryCount); - } + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + DefaultContext context = instance.getFirstContextBean(); + context.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclMultiSpringbootTest.java index b415a860..7e3b298e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclMultiSpringbootTest.java @@ -15,7 +15,6 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的组件重试 * @@ -26,47 +25,48 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/nodeExecutor/application.properties") @SpringBootTest(classes = LiteflowNodeExecutorELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.nodeExecutor.cmp" }) public class LiteflowNodeExecutorELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - // 默认执行器测试 - @Test - public void testCustomerDefaultNodeExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("a", response.getExecuteStepStr()); - } + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getExecuteStepStr()); + } - //默认执行器测试+全局重试配置测试 - @Test - public void testDefaultExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); - } + // 默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); + } - //自定义执行器测试 - @Test - public void testCustomerExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("c", response.getExecuteStepStr()); - } + // 自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStr()); + } + + // 自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); + } - //自定义执行器测试+全局重试配置测试 - @Test - public void testCustomExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); - Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CmpConfig.java index 62665992..f3f91b0a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CmpConfig.java @@ -12,48 +12,46 @@ import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + /////////////////// + private int flag = 0; - /////////////////// - private int flag = 0; + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2) { + flag++; + throw new RuntimeException("demo exception"); + } + } + /////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - if (flag < 2){ - flag++; - throw new RuntimeException("demo exception"); - } - } - /////////////////// + @LiteflowRetry(5) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - @LiteflowRetry(5) - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS, nodeId = "c") + public Class getNodeExecutorClassC(NodeComponent bindCmp) { + return CustomerNodeExecutor.class; + } - @LiteflowMethod(value = LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS,nodeId = "c") - public Class getNodeExecutorClassC(NodeComponent bindCmp) { - return CustomerNodeExecutor.class; - } + /////////////////// + @LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } - /////////////////// - @LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("DCmp executed!"); - throw new NullPointerException("demo exception"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS, nodeId = "d") + public Class getNodeExecutorClassD(NodeComponent bindCmp) { + return CustomerNodeExecutorAndCustomRetry.class; + } - @LiteflowMethod(value= LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS,nodeId = "d") - public Class getNodeExecutorClassD(NodeComponent bindCmp) { - return CustomerNodeExecutorAndCustomRetry.class; - } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclMultiSpringbootTest.java index fa635730..58a52274 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境的自定义json parser单元测试 + * * @author dongguo.tao * @since 2.5.0 */ @@ -23,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties") @SpringBootTest(classes = CustomParserJsonELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.parsecustom.cmp" }) public class CustomParserJsonELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testJsonCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclMultiSpringbootTest.java index fb476fb3..444b67ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclMultiSpringbootTest.java @@ -15,8 +15,8 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ @@ -24,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties") @SpringBootTest(classes = CustomParserXmlELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.parsecustom.cmp", "com.yomahub.liteflow.test.parsecustom.bean" }) public class CustomParserXmlELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testXmlCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java index 6e6d9f57..e96fa077 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class TestBean { - public String returnXmlContent(){ - return "THEN(a,b,c,d)"; - } + public String returnXmlContent() { + return "THEN(a,b,c,d)"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CmpConfig.java index 2fbbf941..822b68b1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CmpConfig.java @@ -10,52 +10,51 @@ import com.yomahub.liteflow.exception.FlowSystemException; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { - throw new FlowSystemException("chain execute execption"); - } - System.out.println("ACmp executed!"); - } - /////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + String str = bindCmp.getRequestData(); + if (StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new FlowSystemException("chain execute execption"); + } + System.out.println("ACmp executed!"); + } + /////////////////// - /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + /////////////////// - /////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("DCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - /////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchE(NodeComponent bindCmp) throws Exception { - return "g"; - } - ////////////////// + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { - System.out.println("FCmp executed!"); - } + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "e", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + return "g"; + } + ////////////////// - /////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void processG(NodeComponent bindCmp) { - System.out.println("GCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + /////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void processG(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } } - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java index 1f4eac49..cf0b024d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -4,28 +4,22 @@ import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser; /** * 模拟用户自定义源解析 + * * @author dongguo.tao * @since 2.5.0 */ public class CustomJsonFlowParser extends ClassJsonFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - String content = "{\n" + - " \"flow\": {\n" + - " \"chain\": [\n" + - " {\n" + - " \"name\": \"chain2\",\n" + - " \"value\": \"THEN(c, g, f)\"\n" + - " },\n" + - " {\n" + - " \"name\": \"chain1\",\n" + - " \"value\": \"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"\n" + - " }\n" + - " ]\n" + - " }\n" + - "}"; - System.out.println(content); - return content; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + String content = "{\n" + " \"flow\": {\n" + " \"chain\": [\n" + " {\n" + + " \"name\": \"chain2\",\n" + " \"value\": \"THEN(c, g, f)\"\n" + + " },\n" + " {\n" + " \"name\": \"chain1\",\n" + + " \"value\": \"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"\n" + + " }\n" + " ]\n" + " }\n" + "}"; + System.out.println(content); + return content; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java index 473ad502..3405882d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -6,18 +6,19 @@ import com.yomahub.liteflow.test.parsecustom.bean.TestBean; import javax.annotation.Resource; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ public class CustomXmlFlowParser extends ClassXmlFlowELParser { - @Resource - private TestBean testBean; + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } - @Override - public String parseCustom() { - return testBean.returnXmlContent(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclMultiSpringbootTest.java index b0e74815..f94b292c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * spring环境的json parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -23,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parser/application-json.properties") @SpringBootTest(classes = JsonParserELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.parser.cmp" }) public class JsonParserELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的json parser - @Test - public void testJsonParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclMultiSpringbootTest.java index 038a78aa..262e3f15 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclMultiSpringbootTest.java @@ -18,16 +18,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parser/application-springEL.properties") @SpringBootTest(classes = SpringELSupportELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.parser.cmp" }) public class SpringELSupportELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springEL的解析情况 + @Test + public void testSpringELParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试springEL的解析情况 - @Test - public void testSpringELParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclMultiSpringbootTest.java index 0b90a310..dbdb47bb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -23,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parser/application-xml.properties") @SpringBootTest(classes = XmlParserELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.parser.cmp" }) public class XmlParserELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试无springboot场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的xml parser - @Test - public void testXmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclMultiSpringbootTest.java index 85cef10a..01fd8d6c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot下的yml parser测试用例 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -23,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parser/application-yml.properties") @SpringBootTest(classes = YmlParserELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.parser.cmp" }) public class YmlParserELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试无springboot场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的yml parser - @Test - public void testYmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CmpConfig.java index e8d339f6..507bc751 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CmpConfig.java @@ -8,49 +8,47 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent public class CmpConfig { - ////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - ////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } - ////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - ////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("DCmp executed!"); - } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } - ////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchE(NodeComponent bindCmp) throws Exception { - return "g"; - } - - ////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { - System.out.println("FCmp executed!"); - } - - ////////////////// - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void processG(NodeComponent bindCmp) { - System.out.println("GCmp executed!"); - } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "e", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchE(NodeComponent bindCmp) throws Exception { + return "g"; + } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + ////////////////// + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void processG(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclMultiSpringbootTest.java index 11f4129a..76faa833 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclMultiSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境下pre节点和finally节点的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,49 +25,50 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/preAndFinally/application.properties") @SpringBootTest(classes = PreAndFinallyELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.preAndFinally.cmp" }) public class PreAndFinallyELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通的pre和finally节点 - @Test - public void testPreAndFinally1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试pre和finally节点不放在开头和结尾的情况 - @Test - public void testPreAndFinally2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 - @Test - public void testPreAndFinally3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); - } + // 测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); + } - //测试在finally节点里是否能获取exception - @Test - public void testPreAndFinally4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(context.getData("hasEx")); - } + // 测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(context.getData("hasEx")); + } + + @Test + public void testPreAndFinally5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testPreAndFinally5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CmpConfig.java index 74ede4b8..c6a17288 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CmpConfig.java @@ -11,64 +11,58 @@ import com.yomahub.liteflow.slot.Slot; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + int i = 1 / 0; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - int i = 1/0; - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f1") - public void processF1(NodeComponent bindCmp) { - System.out.println("Finally1Cmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f2") - public void processF2(NodeComponent bindCmp) { - System.out.println("Finally2Cmp executed!"); - } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f3") - public void processF3(NodeComponent bindCmp) throws Exception{ - Slot slot = bindCmp.getSlot(); - DefaultContext context = slot.getFirstContextBean(); - if (ObjectUtil.isNull(slot.getException())){ - context.setData("hasEx", false); - }else{ - context.setData("hasEx", true); - } - System.out.println("Finally3Cmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "p1") - public void processP1(NodeComponent bindCmp) { - System.out.println("Pre1Cmp executed!"); - } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "p2") - public void processP2(NodeComponent bindCmp) { - System.out.println("Pre2Cmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f1") + public void processF1(NodeComponent bindCmp) { + System.out.println("Finally1Cmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f2") + public void processF2(NodeComponent bindCmp) { + System.out.println("Finally2Cmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f3") + public void processF3(NodeComponent bindCmp) throws Exception { + Slot slot = bindCmp.getSlot(); + DefaultContext context = slot.getFirstContextBean(); + if (ObjectUtil.isNull(slot.getException())) { + context.setData("hasEx", false); + } + else { + context.setData("hasEx", true); + } + System.out.println("Finally3Cmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "p1") + public void processP1(NodeComponent bindCmp) { + System.out.println("Pre1Cmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "p2") + public void processP2(NodeComponent bindCmp) { + System.out.println("Pre2Cmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclMultiSpringbootTest.java index 825e7975..a47628d8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclMultiSpringbootTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,18 +26,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/privateDelivery/application.properties") @SpringBootTest(classes = PrivateDeliveryELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.privateDelivery.cmp" }) public class PrivateDeliveryELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + ConcurrentHashSet set = context.getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } - @Test - public void testPrivateDelivery() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - ConcurrentHashSet set = context.getData("testSet"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(100, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CmpConfig.java index 4df9c375..aa03e14c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CmpConfig.java @@ -9,33 +9,35 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("testSet", new ConcurrentHashSet<>()); - for (int i = 0; i < 100; i++) { - bindCmp.sendPrivateDeliveryData("b",i+1); - } } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("testSet", new ConcurrentHashSet<>()); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - Integer value = bindCmp.getPrivateDeliveryData(); - DefaultContext context = bindCmp.getFirstContextBean(); - ConcurrentHashSet testSet = context.getData("testSet"); - testSet.add(value); - } + for (int i = 0; i < 100; i++) { + bindCmp.sendPrivateDeliveryData("b", i + 1); + } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + Integer value = bindCmp.getPrivateDeliveryData(); + DefaultContext context = bindCmp.getFirstContextBean(); + ConcurrentHashSet testSet = context.getData("testSet"); + testSet.add(value); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclMultiSpringbootTest.java index 68b3e35f..21222419 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclMultiSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,44 +27,47 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/refreshRule/application.properties") @SpringBootTest(classes = RefreshRuleELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.refreshRule.cmp" }) public class RefreshRuleELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通刷新流程的场景 - @Test - public void testRefresh1() throws Exception{ - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception { + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试优雅刷新的场景 - @Test - public void testRefresh2() throws Exception{ - new Thread(() -> { - try { - Thread.sleep(3000L); - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - } catch (Exception e) { - e.printStackTrace(); - } + // 测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception { + new Thread(() -> { + try { + Thread.sleep(3000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + } + catch (Exception e) { + e.printStackTrace(); + } - }).start(); + }).start(); - for (int i = 0; i < 500; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - try { - Thread.sleep(10L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CmpConfig.java index 27de6d52..7bef1bc9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CmpConfig.java @@ -7,20 +7,21 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclMultiSpringbootTest.java index 12a26958..cdb72ce0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -23,18 +24,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/reload/application.properties") @SpringBootTest(classes = ReloadELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.reload.cmp" }) public class ReloadELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + // 这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception { + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml - //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 - @Test - public void testReload() throws Exception{ - flowExecutor.reloadRule(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CmpConfig.java index 9f194fbb..dab6d2fc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CmpConfig.java @@ -7,20 +7,21 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclMultiSpringbootTest.java index 33892140..3154263f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclMultiSpringbootTest.java @@ -21,17 +21,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/requestId/application.properties") @SpringBootTest(classes = LiteflowRequestIdELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.requestId.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.requestId.cmp" }) public class LiteflowRequestIdELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testRequestId() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1", response.getSlot().getRequestId()); - } + @Test + public void testRequestId() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", response.getSlot().getRequestId()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/CmpConfig.java index d38cbc10..cb71753c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/CmpConfig.java @@ -7,20 +7,21 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java index 00445932..e705db34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java @@ -9,11 +9,11 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class CustomRequestIdGenerator implements RequestIdGenerator { - private final AtomicInteger atomicInteger = new AtomicInteger(0); + private final AtomicInteger atomicInteger = new AtomicInteger(0); - @Override - public String generate() { - return atomicInteger.incrementAndGet() + ""; - } + @Override + public String generate() { + return atomicInteger.incrementAndGet() + ""; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclMultiSpringbootTest.java index 3e6b09e0..32288826 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclMultiSpringbootTest.java @@ -18,8 +18,7 @@ import java.util.HashSet; import java.util.Set; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author justin.xu */ @@ -27,39 +26,41 @@ import java.util.Set; @TestPropertySource(value = "classpath:/subflow/application-implicit.properties") @SpringBootTest(classes = ImplicitSubFlowELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp2" }) public class ImplicitSubFlowELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - public static final Set RUN_TIME_SLOT = new HashSet<>(); + @Resource + private FlowExecutor flowExecutor; - //这里GCmp中隐式的调用chain4,从而执行了h,m - @Test - public void testImplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); + public static final Set RUN_TIME_SLOT = new HashSet<>(); - // 传递了slotIndex,则set的size==1 - Assert.assertEquals(1, RUN_TIME_SLOT.size()); - // set中第一次设置的requestId和response中的requestId一致 - Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); - //requestData的取值正确 - Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); - } + // 这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); - //在p里多线程调用q 10次,每个q取到的参数都是不同的。 - @Test - public void testImplicitSubFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + // requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); + } - Set set = context.getData("test"); + // 在p里多线程调用q 10次,每个q取到的参数都是不同的。 + @Test + public void testImplicitSubFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + + Set set = context.getData("test"); + + // requestData的取值正确 + Assert.assertEquals(10, set.size()); + } - //requestData的取值正确 - Assert.assertEquals(10, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclMultiSpringbootTest.java index b5c8055e..8459e6af 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclMultiSpringbootTest.java @@ -27,27 +27,29 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-subInDifferentConfig1.properties") @SpringBootTest(classes = SubflowInDifferentConfigELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1","com.yomahub.liteflow.test.subflow.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1", "com.yomahub.liteflow.test.subflow.cmp2" }) public class SubflowInDifferentConfigELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; - @Autowired - private ApplicationContext context; + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); + } + + @Autowired + private ApplicationContext context; + + // 主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml"); + flowExecutor.reloadRule(); + } - //主要测试有不同的配置类型后会不会报出既定的错误 - @Test(expected = MultipleParsersException.class) - public void testExplicitSubFlow2() { - LiteflowConfig config = context.getBean(LiteflowConfig.class); - config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclMultiSpringBootTest.java index 24da8cbe..35a8a96d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclMultiSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclMultiSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(json) - * 单元测试 + * 测试显示调用子流程(json) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-json.properties") @SpringBootTest(classes = SubflowJsonELDeclMultiSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowJsonELDeclMultiSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclMultiSpringBootTest.java index 7a030a91..b25b2115 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclMultiSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclMultiSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(xml) - * 单元测试 + * 测试显示调用子流程(xml) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-xml.properties") @SpringBootTest(classes = SubflowXMLELDeclMultiSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowXMLELDeclMultiSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclMultiSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclMultiSpringBootTest.java index 94d41724..76cc3be9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclMultiSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclMultiSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(yml) - * 单元测试 + * 测试显示调用子流程(yml) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-yml.properties") @SpringBootTest(classes = SubflowYmlELDeclMultiSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowYmlELDeclMultiSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlowYml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java index cc9fcf6c..3039de59 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CmpConfig1.java @@ -7,33 +7,31 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig1 { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("DCmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - System.out.println("ECmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/CmpConfig2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/CmpConfig2.java index ddd179e3..70ecdd36 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/CmpConfig2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/CmpConfig2.java @@ -16,84 +16,84 @@ import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclMultiSpring @LiteflowComponent public class CmpConfig2 { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF(NodeComponent bindCmp) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF(NodeComponent bindCmp) { + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + System.out.println("Fcomp executed!"); - System.out.println("Fcomp executed!"); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void processG(NodeComponent bindCmp) throws Exception { + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void processG(NodeComponent bindCmp) throws Exception { - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + System.out.println("Gcmp executed!"); - System.out.println("Gcmp executed!"); + bindCmp.invoke("chain4", "it's implicit subflow."); - bindCmp.invoke("chain4", "it's implicit subflow."); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "h") + public void processH(NodeComponent bindCmp) { + String requestData = bindCmp.getSubChainReqData(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("innerRequest", requestData); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "h") - public void processH(NodeComponent bindCmp) { - String requestData = bindCmp.getSubChainReqData(); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("innerRequest", requestData); + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "m") + public void processM(NodeComponent bindCmp) { + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + System.out.println("Mcomp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "p") + public void processP(NodeComponent bindCmp) throws Exception { + int slotIndex = bindCmp.getSlotIndex(); + for (int i = 0; i < 10; i++) { + int finalI = i; + new Thread(() -> { + try { + flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); + } + catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); + } + Thread.sleep(1000); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "m") - public void processM(NodeComponent bindCmp) { - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "q") + public void processQ(NodeComponent bindCmp) throws Exception { + String requestData = bindCmp.getSubChainReqDataInAsync(); + DefaultContext context = bindCmp.getFirstContextBean(); - System.out.println("Mcomp executed!"); } + synchronized (this) { + if (context.hasData("test")) { + Set set = context.getData("test"); + set.add(requestData); + } + else { + Set set = new HashSet<>(); + set.add(requestData); + context.setData("test", set); + } + } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - System.out.println("ECmp executed!"); - } - - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "p") - public void processP(NodeComponent bindCmp) throws Exception { - int slotIndex = bindCmp.getSlotIndex(); - for (int i = 0; i < 10; i++) { - int finalI = i; - new Thread(() -> { - try { - flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); - } catch (Exception e) { - throw new RuntimeException(e); - } - }).start(); - } - Thread.sleep(1000); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "q") - public void processQ(NodeComponent bindCmp) throws Exception { - String requestData = bindCmp.getSubChainReqDataInAsync(); - DefaultContext context = bindCmp.getFirstContextBean(); - - synchronized (this){ - if (context.hasData("test")){ - Set set = context.getData("test"); - set.add(requestData); - }else{ - Set set = new HashSet<>(); - set.add(requestData); - context.setData("test", set); - } - } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclMultiSpringbootTest.java index 87a50a77..08f9e0a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclMultiSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,45 +24,45 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/switchcase/application.properties") @SpringBootTest(classes = SwitchELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.switchcase.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.switchcase.cmp" }) public class SwitchELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testSwitch1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); - } + @Test + public void testSwitch1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d", response.getExecuteStepStr()); + } - @Test - public void testSwitch3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>f==>b",response.getExecuteStepStr()); - } + @Test + public void testSwitch3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>f==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>g==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>g==>d", response.getExecuteStepStr()); + } - @Test - public void testSwitch5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } + @Test + public void testSwitch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CmpConfig.java index 465067c4..06ed8546 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CmpConfig.java @@ -9,46 +9,45 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") - public void processB(NodeComponent bindCmp) { + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - } + System.out.println("BCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = NodeTypeEnum.SWITCH) - public String processE(NodeComponent bindCmp) { - return "d"; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "e", nodeType = NodeTypeEnum.SWITCH) + public String processE(NodeComponent bindCmp) { + return "d"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "f",nodeType = NodeTypeEnum.SWITCH) - public String processF(NodeComponent bindCmp) { - return ":td"; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "f", nodeType = NodeTypeEnum.SWITCH) + public String processF(NodeComponent bindCmp) { + return ":td"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "g",nodeType = NodeTypeEnum.SWITCH) - public String processG(NodeComponent bindCmp) { - return "d:td"; - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "g", nodeType = NodeTypeEnum.SWITCH) + public String processG(NodeComponent bindCmp) { + return "d:td"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "h", nodeType = NodeTypeEnum.SWITCH) + public String processH(NodeComponent bindCmp) { + return "tag:td"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "h",nodeType = NodeTypeEnum.SWITCH) - public String processH(NodeComponent bindCmp) { - return "tag:td"; - } } - - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootJsonTest.java index 35930c00..28cce58a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootJsonTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,45 +26,46 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/tag/application-json.properties") @SpringBootTest(classes = NodeTagELDeclMultiSpringbootJsonTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.tag.cmp" }) public class NodeTagELDeclMultiSpringbootJsonTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootXmlTest.java index 3208a64c..9e4b2f40 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootXmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclMultiSpringbootXmlTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,45 +26,46 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/tag/application-xml.properties") @SpringBootTest(classes = NodeTagELDeclMultiSpringbootXmlTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.tag.cmp" }) public class NodeTagELDeclMultiSpringbootXmlTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CmpConfig.java index 64247751..816fc068 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CmpConfig.java @@ -10,71 +10,72 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - String testKey = "test"; - DefaultContext context = bindCmp.getFirstContextBean(); - if (context.getData(testKey) == null){ - context.setData(testKey,bindCmp.getTag()); - }else{ - String s = context.getData(testKey); - s += bindCmp.getTag(); - context.setData(testKey, s); - } } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + String testKey = "test"; - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b1") - public void processB1(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("test",new ConcurrentHashSet()); + DefaultContext context = bindCmp.getFirstContextBean(); + if (context.getData(testKey) == null) { + context.setData(testKey, bindCmp.getTag()); + } + else { + String s = context.getData(testKey); + s += bindCmp.getTag(); + context.setData(testKey, s); + } + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b1") + public void processB1(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("test", new ConcurrentHashSet()); - } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - ConcurrentHashSet testSet = context.getData("test"); - testSet.add(bindCmp.getTag()); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + ConcurrentHashSet testSet = context.getData("test"); + testSet.add(bindCmp.getTag()); - } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "c",nodeType = NodeTypeEnum.SWITCH) - public String processSwitchC(NodeComponent bindCmp) { - if(bindCmp.getTag().equals("2")){ - return "e"; - }else{ - return "d"; - } } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "c", nodeType = NodeTypeEnum.SWITCH) + public String processSwitchC(NodeComponent bindCmp) { + if (bindCmp.getTag().equals("2")) { + return "e"; + } + else { + return "d"; + } + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("ECmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("ECmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processF() { + System.out.println("FCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - System.out.println(bindCmp.getTag()); - System.out.println("ECmp executed!"); } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - System.out.println(bindCmp.getTag()); - System.out.println("ECmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void processF() { - System.out.println("FCmp executed!"); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS,nodeId = "f") - public boolean isAccessF(NodeComponent bindCmp) { - return Boolean.parseBoolean(bindCmp.getTag()); - } - - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "g") - public void process(NodeComponent bindCmp) { - System.out.println("GCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "f") + public boolean isAccessF(NodeComponent bindCmp) { + return Boolean.parseBoolean(bindCmp.getTag()); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "g") + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java index fee0055e..3de938a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -4,13 +4,14 @@ import com.alibaba.ttl.TransmittableThreadLocal; public class TestTL { - public static ThreadLocal tl = new TransmittableThreadLocal<>(); + public static ThreadLocal tl = new TransmittableThreadLocal<>(); - public static String get(){ - return tl.get(); - } + public static String get() { + return tl.get(); + } + + public static void set(String value) { + tl.set(value); + } - public static void set(String value){ - tl.set(value); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclMultiSpringbootTest.java index 07269953..1a736d3c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclMultiSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * * @author Bryan.Zhang * @since 2.6.3 */ @@ -24,20 +25,21 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/useTTLInWhen/application.properties") @SpringBootTest(classes = UseTTLInWhenELDeclMultiSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.useTTLInWhen.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.useTTLInWhen.cmp" }) public class UseTTLInWhenELDeclMultiSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,b", context.getData("b")); + Assert.assertEquals("hello,c", context.getData("c")); + Assert.assertEquals("hello,d", context.getData("d")); + Assert.assertEquals("hello,e", context.getData("e")); + Assert.assertEquals("hello,f", context.getData("f")); + } - @Test - public void testUseTTLInWhen() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,b", context.getData("b")); - Assert.assertEquals("hello,c", context.getData("c")); - Assert.assertEquals("hello,d", context.getData("d")); - Assert.assertEquals("hello,e", context.getData("e")); - Assert.assertEquals("hello,f", context.getData("f")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CmpConfig.java index d44125e3..159ae027 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CmpConfig.java @@ -9,51 +9,52 @@ import com.yomahub.liteflow.test.useTTLInWhen.TestTL; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - TestTL.set("hello"); - System.out.println("ACmp executed!"); } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - String value = TestTL.get(); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",b"); - System.out.println("BCmp executed!"); + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + TestTL.set("hello"); + System.out.println("ACmp executed!"); + } - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), value + ",b"); + System.out.println("BCmp executed!"); - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - String value = TestTL.get(); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",c"); - System.out.println("CCmp executed!"); - } + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), value + ",c"); + System.out.println("CCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), value + ",d"); + System.out.println("DCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), value + ",e"); + System.out.println("ECmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - String value = TestTL.get(); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",d"); - System.out.println("DCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData(bindCmp.getNodeId(), value + ",f"); + System.out.println("FCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - String value = TestTL.get(); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",e"); - System.out.println("ECmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void process(NodeComponent bindCmp) { - String value = TestTL.get(); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",f"); - System.out.println("FCmp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest1.java index cebe5d99..f0116e0f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest1.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,19 +27,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/whenTimeOut/application1.properties") @SpringBootTest(classes = WhenTimeOutELDeclMultiSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.whenTimeOut.cmp" }) public class WhenTimeOutELDeclMultiSpringbootTest1 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } - //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest2.java index 151d46fd..2f1b8bea 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclMultiSpringbootTest2.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -25,18 +26,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/whenTimeOut/application2.properties") @SpringBootTest(classes = WhenTimeOutELDeclMultiSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.whenTimeOut.cmp" }) public class WhenTimeOutELDeclMultiSpringbootTest2 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CmpConfig.java index 1542726d..cdd1563b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CmpConfig.java @@ -7,60 +7,65 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent public class CmpConfig { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "a") - public void processA(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "b") - public void processB(NodeComponent bindCmp) { - try { - Thread.sleep(4000); - }catch (Exception ignored){ + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } - } - System.out.println("BCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + } + catch (Exception ignored) { - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c") - public void processC(NodeComponent bindCmp) { - try { - Thread.sleep(3500); - }catch (Exception ignored){ + } + System.out.println("BCmp executed!"); + } - } - System.out.println("CCmp executed!"); - } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "c") + public void processC(NodeComponent bindCmp) { + try { + Thread.sleep(3500); + } + catch (Exception ignored) { + } + System.out.println("CCmp executed!"); + } + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + } + catch (Exception ignored) { + } + System.out.println("DCmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d") - public void processD(NodeComponent bindCmp) { - try { - Thread.sleep(4000); - }catch (Exception ignored){ + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "e") + public void processE(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + } + catch (Exception ignored) { - } - System.out.println("DCmp executed!"); - } + } + System.out.println("ECmp executed!"); + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "e") - public void processE(NodeComponent bindCmp) { - try { - Thread.sleep(4000); - }catch (Exception ignored){ + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + } + catch (Exception ignored) { - } - System.out.println("ECmp executed!"); - } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "f") - public void process(NodeComponent bindCmp) { - try { - Thread.sleep(4000); - }catch (Exception ignored){ + } + System.out.println("FCmp executed!"); + } - } - System.out.println("FCmp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 12625060..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,14 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java index f52bea7a..7270c2ca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELDeclSpringbootTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -25,17 +26,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/absoluteConfigPath/application.properties") @SpringBootTest(classes = AbsoluteConfigPathELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.absoluteConfigPath.cmp" }) public class AbsoluteConfigPathELDeclSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testAbsoluteConfig() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java index fe0067da..e3d7a290 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java index 2df638bc..2de2dd56 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java index ee9bb4e8..e6aee277 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELDeclSpringbootTest.java index 24eb053c..3f18688f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELDeclSpringbootTest.java @@ -3,39 +3,45 @@ package com.yomahub.liteflow.test.aop; import com.yomahub.liteflow.test.BaseTest; /** - * 切面场景单元测试 - * 在声明式组件场景中,自定义aspect的aop不生效的,因为生成的代理类并不是原类,也不是原类的子类,而是NodeComponent的子类 + * 切面场景单元测试 在声明式组件场景中,自定义aspect的aop不生效的,因为生成的代理类并不是原类,也不是原类的子类,而是NodeComponent的子类 * 所以切不到,暂且没有想出办法来解决,这个测试类暂时不用 + * * @author Bryan.Zhang */ -/*@RunWith(SpringRunner.class) -@TestPropertySource(value = "classpath:/aop/application.properties") -@SpringBootTest(classes = CustomAOPSpringbootTest.class) -@EnableAutoConfiguration -@Import(CustomAspect.class) -@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})*/ +/* + * @RunWith(SpringRunner.class) + * + * @TestPropertySource(value = "classpath:/aop/application.properties") + * + * @SpringBootTest(classes = CustomAOPSpringbootTest.class) + * + * @EnableAutoConfiguration + * + * @Import(CustomAspect.class) + * + * @ComponentScan({"com.yomahub.liteflow.test.aop.cmp1", + * "com.yomahub.liteflow.test.aop.cmp2"}) + */ public class CustomAOPELDeclSpringbootTest extends BaseTest { - /*@Resource - private FlowExecutor flowExecutor; + /* + * @Resource private FlowExecutor flowExecutor; + * + * //测试自定义AOP,串行场景 + * + * @Test public void testCustomAopS() { LiteflowResponse response= + * flowExecutor.execute2Resp("chain1", "it's a request"); + * Assert.assertTrue(response.isSuccess()); Assert.assertEquals("before_after", + * response.getContextBean.getData("a")); Assert.assertEquals("before_after", + * context.getData("b")); Assert.assertEquals("before_after", context.getData("c")); } + * + * //测试自定义AOP,并行场景 + * + * @Test public void testCustomAopP() { LiteflowResponse response= + * flowExecutor.execute2Resp("chain2", "it's a request"); + * Assert.assertTrue(response.isSuccess()); Assert.assertEquals("before_after", + * context.getData("a")); Assert.assertEquals("before_after", context.getData("b")); + * Assert.assertEquals("before_after", context.getData("c")); } + */ - //测试自定义AOP,串行场景 - @Test - public void testCustomAopS() { - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", response.getContextBean.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - } - - //测试自定义AOP,并行场景 - @Test - public void testCustomAopP() { - LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - }*/ } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclSpringbootTest.java index e6eb8a15..f3ee21e5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELDeclSpringbootTest.java @@ -21,6 +21,7 @@ import javax.annotation.Resource; /** * 切面场景单元测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @@ -28,52 +29,53 @@ import javax.annotation.Resource; @SpringBootTest(classes = GlobalAOPELDeclSpringbootTest.class) @EnableAutoConfiguration @Import(CmpAspect.class) -@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.aop.cmp1", "com.yomahub.liteflow.test.aop.cmp2" }) public class GlobalAOPELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试全局AOP,串行场景 - @Test - public void testGlobalAopS() { - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,串行场景 + @Test + public void testGlobalAopS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - //测试全局AOP,并行场景 - @Test - public void testGlobalAopP() { - LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,并行场景 + @Test + public void testGlobalAopP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - @Test - public void testGlobalAopException() { - LiteflowResponse response= flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("f")); - } + @Test + public void testGlobalAopException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("f")); + } + + @AfterClass + public static void cleanScanCache() { + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } - @AfterClass - public static void cleanScanCache(){ - BaseTest.cleanScanCache(); - ComponentScanner.cmpAroundAspect = null; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java index 3704a146..e3884622 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java @@ -6,15 +6,17 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; public class CmpAspect implements ICmpAroundAspect { - @Override - public void beforeProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, "before"); - } - @Override - public void afterProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); - } + @Override + public void beforeProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, "before"); + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java index dd2e6145..2b6c2817 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java @@ -12,17 +12,18 @@ import org.aspectj.lang.annotation.Pointcut; @Aspect public class CustomAspect { - @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process(*))") - public void cut() { - } + @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process(*))") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId(), "before"); + Object returnObj = jp.proceed(); + context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); + return returnObj; + } - @Around("cut()") - public Object around(ProceedingJoinPoint jp) throws Throwable { - NodeComponent cmp = (NodeComponent) jp.getThis(); - DefaultContext context = cmp.getFirstContextBean(); - context.setData(cmp.getNodeId(), "before"); - Object returnObj = jp.proceed(); - context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); - return returnObj; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java index c5bb6eed..7a2c9f41 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java index 21068d90..08c4d376 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java index adfb0f06..c4a89d20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java index 5e154802..df3c0be3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java index 29aef936..a3c84998 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java index baaf1492..ac4699f8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclSpringbootTest.java index 3b8c58ff..3d9c34b3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELDeclSpringbootTest.java @@ -18,8 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author ssss */ @@ -27,113 +26,114 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/asyncNode/application.properties") @SpringBootTest(classes = AsyncNodeELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.asyncNode.cmp" }) public class AsyncNodeELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - /***** - * 标准chain 嵌套选择 嵌套子chain进行执行 - * 验证了when情况下 多个node是并行执行 - * 验证了默认参数情况下 when可以加载执行 - * **/ - @Test - public void testAsyncFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - System.out.println(response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; - //这个和test1有点类似,只不过进一步验证了步骤 - @Test - public void testAsyncFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); - Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", - "b==>j==>h==>g==>f","b==>j==>h==>f==>g", - "b==>j==>f==>h==>g","b==>j==>f==>g==>h" - ).contains(response.getExecuteStepStr())); - } + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 验证了when情况下 多个node是并行执行 验证了默认参数情况下 when可以加载执行 + **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getExecuteStepStr()); + } - //测试errorResume,默认的errorResume为false,这里测试默认的 - @Test - public void testAsyncFlow3_1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); - } + // 这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue( + ListUtil + .toList("b==>j==>g==>f==>h", "b==>j==>g==>h==>f", "b==>j==>h==>g==>f", "b==>j==>h==>f==>g", + "b==>j==>f==>h==>g", "b==>j==>f==>g==>h") + .contains(response.getExecuteStepStr())); + } - //测试errorResume,默认的errorResume为false,这里设置为true - @Test - public void testAsyncFlow3_2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - } + // 测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 - @Test - public void testAsyncFlow4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //因为不记录错误,所以最终结果是true - Assert.assertTrue(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为配置了不抛错,所以response里的cause应该为null - Assert.assertNull(response.getCause()); - } + // 测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 - @Test - public void testAsyncFlow5() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //整个并行组是报错的,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为第一个when配置了会报错,所以response里的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } - //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 - @Test - public void testAsyncFlow6() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第一个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(1), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } - //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 - @Test - public void testAsyncFlow7() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第二个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - // 传递了slotIndex,则set的size==2 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(1), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 测试任意异步一个执行完即继续的场景 + // d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + // 最终执行效果应该是h先返回,然后执行abc,最后gd + // 这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("check").toString().startsWith("habc")); + } - //测试任意异步一个执行完即继续的场景 - //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 - //最终执行效果应该是h先返回,然后执行abc,最后gd - //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 - @Test - public void testAsyncFlow8() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("check").toString().startsWith("habc")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java index a4905bce..cdcaefce 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java @@ -6,21 +6,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("a") -public class ACmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Acomp executed!"); - } +public class ACmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java index 5d486f0e..e04413bd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java @@ -6,21 +6,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("b") -public class BCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Bcomp executed!"); - } +public class BCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java index 50d92291..3225d2b3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java @@ -6,21 +6,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("c") -public class CCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Ccomp executed!"); - } +public class CCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java index 79c0256b..05cdaa1f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java @@ -6,22 +6,24 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("d") -public class DCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - Thread.sleep(1000); - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Dcomp executed!"); - } +public class DCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Thread.sleep(1000); + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java index a93d3679..e375687f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java @@ -6,13 +6,13 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; - @Component("e") -public class ECmp{ +public class ECmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) + public String processSwitch(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) - public String processSwitch(NodeComponent bindCmp) throws Exception { - System.out.println("Ecomp executed!"); - return "g"; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java index c98b1d1e..d7dd6c66 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java @@ -5,12 +5,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("f") -public class FCmp{ +public class FCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Fcomp executed!"); + } - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - System.out.println("Fcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java index 722ae667..4e4b320d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java @@ -6,23 +6,24 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("g") -public class GCmp{ +public class GCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Thread.sleep(500); + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - Thread.sleep(500); - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } - System.out.println("Gcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java index 65c645cf..70022193 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java @@ -6,23 +6,24 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("h") -public class HCmp{ +public class HCmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += bindCmp.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", bindCmp.getNodeId()); - } - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += bindCmp.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", bindCmp.getNodeId()); + } + } + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java index a4ce6001..58a94e52 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java @@ -7,22 +7,23 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.test.asyncNode.exception.TestException; import org.springframework.stereotype.Component; - @Component("i") public class ICmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - synchronized (ICmp.class){ - if (context.hasData("count")){ - Integer count = context.getData("count"); - context.setData("count", ++count); - } else{ - context.setData("count", 1); - } - } - System.out.println("Icomp executed! throw Exception!"); - throw new TestException(); - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + synchronized (ICmp.class) { + if (context.hasData("count")) { + Integer count = context.getData("count"); + context.setData("count", ++count); + } + else { + context.setData("count", 1); + } + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java index 95e4308d..0d5c13ad 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java @@ -6,13 +6,13 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; - @Component("j") -public class JCmp{ +public class JCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) + public String processSwitch(NodeComponent bindCmp) throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) - public String processSwitch(NodeComponent bindCmp) throws Exception { - System.out.println("Jcomp executed!"); - return "chain3"; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java index e786e9f8..fa8827df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -1,4 +1,5 @@ package com.yomahub.liteflow.test.asyncNode.exception; -public class TestException extends Exception{ +public class TestException extends Exception { + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclSpringbootTest.java index 628aab79..13705781 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELDeclSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,16 +24,16 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/base/application.properties") @SpringBootTest(classes = BaseELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.base.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.base.cmp" }) public class BaseELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testBase() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testBase() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java index 72946b21..a4c0a8c4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java @@ -16,10 +16,11 @@ import org.springframework.stereotype.Component; @Component("a") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java index 77b842db..a7fa07c8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @Component("b") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java index 96850958..03a5168d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @Component("c") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java index 4f7e88a5..93346a6e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java @@ -18,7 +18,7 @@ import javax.annotation.Resource; @Component("d") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class DCmp{ +public class DCmp { @Resource private TestDomain testDomain; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java index 16f15932..31ec520c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java @@ -4,7 +4,9 @@ import org.springframework.stereotype.Component; @Component public class TestDomain { - public void sayHi(){ - System.out.println("hello"); - } + + public void sayHi() { + System.out.println("hello"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest1.java index fae36327..01fc730b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest1.java @@ -22,41 +22,40 @@ import javax.annotation.Resource; @RunWith(SpringRunner.class) @SpringBootTest(classes = BuilderELDeclSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.builder.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.builder.cmp1" }) public class BuilderELDeclSpringbootTest1 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //基于普通组件的builder模式测试 - @Test - public void testBuilder() throws Exception { - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + // 基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>e==>c==>d", response.getExecuteStepStrWithoutTime()); - } + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>e==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //基于普通组件的builder模式测试 - @Test - public void testBuilderForConditionNode() throws Exception { - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + // 基于普通组件的builder模式测试 + @Test + public void testBuilderForConditionNode() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a.tag('hello'), b, WHEN(SWITCH(e).to(f.tag('FHello'), g, chain2)))" - ).build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a.tag('hello'), b, WHEN(SWITCH(e).to(f.tag('FHello'), g, chain2)))") + .build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>e==>c==>d", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>e==>c==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest2.java index e0de9387..22f938a1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELDeclSpringbootTest2.java @@ -19,21 +19,20 @@ import javax.annotation.Resource; @RunWith(SpringRunner.class) @SpringBootTest(classes = BuilderELDeclSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.builder.cmp2" }) public class BuilderELDeclSpringbootTest2 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //通过spring去扫描组件,通过代码去构建chain - @Test - public void testBuilder() throws Exception { - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(h, i, j)" - ).build(); + // 通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(h, i, j)").build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java index 93bdcedb..9a2d7410 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java index 5345fa3b..89bee6af 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java index 69826aba..6ce54fec 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java index 26eec0f8..b957c22c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java index 5b4ea7de..31964772 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java index 22332977..5163e07a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java index 3c259d1e..7300475b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("g") -public class GCmp{ +public class GCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java index 110c05f3..b7977019 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("h") -public class HCmp{ +public class HCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java index 467b44f5..ca5bde31 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("i") -public class ICmp{ +public class ICmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java index 119130f7..b666b295 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("j") -public class JCmp{ +public class JCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclSpringbootTest.java index a42cb248..e110847f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELDeclSpringbootTest.java @@ -14,9 +14,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的节点执行器 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -24,40 +24,41 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/cmpRetry/application.properties") @SpringBootTest(classes = LiteflowRetryELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpRetry.cmp" }) public class LiteflowRetryELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //全局重试配置测试 - @Test - public void testRetry1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); - } + // 全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); + } - //单个组件重试配置测试 - @Test - public void testRetry2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); - } + // 单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); + } - //单个组件指定异常,但抛出的并不是指定异常的场景测试 - @Test - public void testRetry3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - } + // 单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + // 单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); + } - //单个组件指定异常重试,抛出的是指定异常或者 - @Test - public void testRetry4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java index 3ad13319..11543a14 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java index 7179ec99..815b5c25 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -20,7 +20,7 @@ public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java index e0e539ae..1e336cee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java @@ -15,7 +15,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("c") @LiteflowRetry(5) -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java index be1968d4..a4637c99 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -14,8 +14,8 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) -public class DCmp{ +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java index c9eaed4d..f353a609 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -14,8 +14,8 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("e") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) -public class ECmp{ +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java index d07e7100..753261b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELDeclSpringbootTest.java @@ -21,6 +21,7 @@ import java.util.Set; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -28,47 +29,49 @@ import java.util.Set; @TestPropertySource(value = "classpath:/cmpStep/application.properties") @SpringBootTest(classes = CmpStepELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpStep.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpStep.cmp" }) public class CmpStepELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testStep() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); - } + @Test + public void testStep() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); + } - @Test - public void testStep2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testStep2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testStep3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Map stepMap = response.getExecuteSteps(); - Assert.assertEquals(2, stepMap.size()); - Queue queue = response.getExecuteStepQueue(); - Assert.assertEquals(5, queue.size()); + @Test + public void testStep3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Map stepMap = response.getExecuteSteps(); + Assert.assertEquals(2, stepMap.size()); + Queue queue = response.getExecuteStepQueue(); + Assert.assertEquals(5, queue.size()); - Set tagSet = new HashSet<>(); - response.getExecuteStepQueue().stream().filter( - cmpStep -> cmpStep.getNodeId().equals("a") - ).forEach(cmpStep -> tagSet.add(cmpStep.getTag())); + Set tagSet = new HashSet<>(); + response.getExecuteStepQueue() + .stream() + .filter(cmpStep -> cmpStep.getNodeId().equals("a")) + .forEach(cmpStep -> tagSet.add(cmpStep.getTag())); - Assert.assertEquals(3, tagSet.size()); + Assert.assertEquals(3, tagSet.size()); + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java index e3224a31..e1ce6276 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java @@ -13,11 +13,12 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception{ + public void process(NodeComponent bindCmp) throws Exception { Thread.sleep(5000L); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/BCmp.java index fa461686..4b636b30 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java index 84290ad4..ccfdc1a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java @@ -13,10 +13,10 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception{ + public void process(NodeComponent bindCmp) throws Exception { System.out.println("CCmp executed!"); Thread.sleep(2000); throw new RuntimeException("test error c"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/DCmp.java index 12908f2b..95f73992 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java index 74aa2576..0642d344 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -24,4 +24,5 @@ public class ECmp{ public boolean isAccess(NodeComponent bindCmp) { return false; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java index cad44ba2..287f2626 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java @@ -19,7 +19,7 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/comments/application.properties") @SpringBootTest(classes = LiteflowNodeELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.comments.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.comments.cmp" }) public class LiteflowNodeELSpringbootTest extends BaseTest { @Resource @@ -30,6 +30,7 @@ public class LiteflowNodeELSpringbootTest extends BaseTest { public void testAsyncFlow1() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr())); + Assert.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr())); } + } \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java index 99e6c277..f50b451a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java index 1a5864b4..5673981e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java index 692cfeb0..82dd69c0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest1.java index 8da0296d..9b94331b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest1.java @@ -16,33 +16,35 @@ import javax.annotation.Resource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/complex/application1.properties") @SpringBootTest(classes = ComplexELDeclSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.complex.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.complex.cmp1" }) public class ComplexELDeclSpringbootTest1 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest2.java index 9a6aa033..9ca148ef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELDeclSpringbootTest2.java @@ -16,33 +16,35 @@ import javax.annotation.Resource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/complex/application2.properties") @SpringBootTest(classes = ComplexELDeclSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.complex.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.complex.cmp2" }) public class ComplexELDeclSpringbootTest2 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java index 75188128..5e7daab6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("A") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java index 4e9956c2..1a7859d1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("B") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { - + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java index 73e4b24c..be0d07b6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("C") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java index 810f6fcd..1a4619d5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("D") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java index 1aa885f9..150e2387 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("E") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java index aa2400cb..4db2caeb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("F") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java index 2fed786c..fe8d182c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("G") -public class GCmp{ +public class GCmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { return "t1"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java index 2a8e967c..a968b538 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("H") -public class HCmp{ +public class HCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java index eca509c6..a403dd66 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java index 69b8d9e0..6cd2058a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("J") -public class JCmp{ +public class JCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java index 8d9b2c50..5e080506 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("K") -public class KCmp{ +public class KCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java index 40ff74b5..027515a2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java @@ -19,4 +19,5 @@ public class LCmp { public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java index 082bcee1..ca030e4d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java @@ -19,4 +19,5 @@ public class MCmp { public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java index 80aa491f..020ad400 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java @@ -19,4 +19,5 @@ public class NCmp { public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java index 84ba4bbd..332e87e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("Z") -public class ZCmp{ +public class ZCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java index b216337f..75e0e7a5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("A") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java index 11c32ed6..6becf721 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("B") -public class BCmp{ +public class BCmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) { return "t3"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java index f0b7a4dd..959de092 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("C") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java index 9fd0f447..47c14e8b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("D") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java index ad67f757..0d5d8305 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("E") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java index a789eedf..f155fd6f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("F") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java index 3ed2e0b9..ed2e3315 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("G") -public class GCmp{ +public class GCmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { return "t2"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java index 2b00ec54..9d864ed1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("H") -public class HCmp{ +public class HCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java index 08d07119..71f28e45 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java index 802b6db7..951eb206 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("J") -public class JCmp{ +public class JCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java index c4f6b93c..1e8c532e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("K") -public class KCmp{ +public class KCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java index c6dca1b5..5fbccc5e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java @@ -19,4 +19,5 @@ public class LCmp { public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java index 47c085cc..784cbb26 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java @@ -19,4 +19,5 @@ public class MCmp { public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java index cd973360..f1e94854 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java @@ -19,4 +19,5 @@ public class NCmp { public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java index ea79585b..fb231f92 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("Z") -public class ZCmp{ +public class ZCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclSpringbootTest.java index 185fe349..28206f8c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELDeclSpringbootTest.java @@ -18,8 +18,7 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; /** - * 组件功能点测试 - * 单元测试 + * 组件功能点测试 单元测试 * * @author donguo.tao */ @@ -27,67 +26,68 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/component/application.properties") @SpringBootTest(classes = FlowExecutorELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.component.cmp1", "com.yomahub.liteflow.test.component.cmp2" }) public class FlowExecutorELDeclSpringbootTest extends BaseTest { - private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELDeclSpringbootTest.class); - @Resource - private FlowExecutor flowExecutor; + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELDeclSpringbootTest.class); - //isAccess方法的功能测试 - @Test - public void testIsAccess() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); - Assert.assertTrue(response.isSuccess()); - Assert.assertNotNull(response.getSlot().getResponseData()); - } + @Resource + private FlowExecutor flowExecutor; - //组件抛错的功能点测试 - @Test(expected = ArithmeticException.class) - public void testComponentException() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("/ by zero", response.getMessage()); - ReflectionUtils.rethrowException(response.getCause()); - } + // isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } - //isContinueOnError方法的功能点测试 - @Test - public void testIsContinueOnError() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCause()); - } + // 组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } - //isEnd方法的功能点测试 - @Test - public void testIsEnd() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d",response.getExecuteStepStr()); - } + // isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } - //setIsEnd方法的功能点测试 - @Test - public void testSetIsEnd1() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("e",response.getExecuteStepStr()); - } + // isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d", response.getExecuteStepStr()); + } - //条件组件的功能点测试 - @Test - public void testNodeCondComponent() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); - Assert.assertTrue(response.isSuccess()); - } + // setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e", response.getExecuteStepStr()); + } - //测试setIsEnd如果为true,continueError也为true,那不应该continue了 - @Test - public void testSetIsEnd2() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g",response.getExecuteStepStr()); - } + // 条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + // 测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java index 56269128..fb27766b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -7,22 +7,23 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("a") -public class ACmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("AComp executed!"); - bindCmp.getSlot().setResponseData("AComp executed!"); - } +public class ACmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("AComp executed!"); + bindCmp.getSlot().setResponseData("AComp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100) { + return true; + } + System.out.println("AComp isAccess false."); + return false; + } - @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) - public boolean isAccess(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.nonNull(requestData) && requestData > 100){ - return true; - } - System.out.println("AComp isAccess false."); - return false; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java index 569613e6..80fab73d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -7,25 +7,25 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("b") -public class BCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("BComp executed!"); - Integer requestData = bindCmp.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - bindCmp.getSlot().setResponseData(result); - } +public class BCmp { - @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) - public boolean isAccess(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BComp executed!"); + Integer requestData = bindCmp.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java index fefce4f6..1a92da54 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -7,25 +7,26 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("c") -public class CCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("CComp executed!"); - Integer requestData = bindCmp.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - bindCmp.getSlot().setResponseData(result); - System.out.println("responseData="+Integer.parseInt(bindCmp.getSlot().getResponseData())); - } +public class CCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CComp executed!"); + Integer requestData = bindCmp.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + System.out.println("responseData=" + Integer.parseInt(bindCmp.getSlot().getResponseData())); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } - @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) - public boolean isContinueOnError(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java index fbfc0dde..19b0cbb2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -7,22 +7,23 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("d") -public class DCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - System.out.println("DComp executed!"); - } +public class DCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("DComp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_END) + public boolean isEnd(NodeComponent bindCmp) { + // 组件的process执行完之后才会执行isEnd + Object requestData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(requestData)) { + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } - @LiteflowMethod(LiteFlowMethodEnum.IS_END) - public boolean isEnd(NodeComponent bindCmp) { - //组件的process执行完之后才会执行isEnd - Object requestData = bindCmp.getSlot().getResponseData(); - if (Objects.isNull(requestData)){ - System.out.println("DComp flow isEnd, because of responseData is null."); - return true; - } - return false; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java index 51f5aa09..48477660 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -8,19 +8,19 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("e") -public class ECmp{ +public class ECmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("EComp executed!"); + Object responseData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(responseData)) { + System.out.println("EComp responseData flow must be set end ."); + // 执行到某个条件时,手动结束流程。 + bindCmp.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); + } - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - System.out.println("EComp executed!"); - Object responseData = bindCmp.getSlot().getResponseData(); - if (Objects.isNull(responseData)){ - System.out.println("EComp responseData flow must be set end ."); - //执行到某个条件时,手动结束流程。 - bindCmp.setIsEnd(true); - } - System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java index 1a7d28a4..8ef4ee0c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("g") -public class GCmp{ +public class GCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -25,4 +25,5 @@ public class GCmp{ public boolean isContinueOnError(NodeComponent bindCmp) { return true; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java index 03b6e95f..e8ff3174 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("h") -public class HCmp{ +public class HCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("HCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java index 0d93692f..0c9cbcae 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java @@ -8,18 +8,21 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("f") -public class FCondCmp{ - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) - public String processSwitch(NodeComponent bindCmp) { - Integer requestData = bindCmp.getRequestData(); - if (Objects.isNull(requestData)){ - return "d"; - } else if(requestData == 0){ - return "c"; - } else { - return "b"; - } - } +public class FCondCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) + public String processSwitch(NodeComponent bindCmp) { + Integer requestData = bindCmp.getRequestData(); + if (Objects.isNull(requestData)) { + return "d"; + } + else if (requestData == 0) { + return "c"; + } + else { + return "b"; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclSpringbootTest.java index dc589077..c607c371 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/CustomMethodNameELDeclSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * 声明式组件自定义方法的测试用例 + * * @author Bryan.Zhang * @since 2.7.2 */ @@ -23,15 +24,16 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customMethodName/application.properties") @SpringBootTest(classes = CustomMethodNameELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customMethodName.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.customMethodName.cmp" }) public class CustomMethodNameELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomMethodName() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testCustomMethodName() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java index acfbcbf0..117904e5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.Slot; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void processAcmp(NodeComponent bindCmp) { @@ -22,27 +22,27 @@ public class ACmp{ } @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) - public boolean isAcmpAccess(NodeComponent bindCmp){ + public boolean isAcmpAccess(NodeComponent bindCmp) { return true; } @LiteflowMethod(LiteFlowMethodEnum.BEFORE_PROCESS) - public void beforeAcmp(NodeComponent bindCmp){ + public void beforeAcmp(NodeComponent bindCmp) { System.out.println("before A"); } @LiteflowMethod(LiteFlowMethodEnum.AFTER_PROCESS) - public void afterAcmp(NodeComponent bindCmp){ + public void afterAcmp(NodeComponent bindCmp) { System.out.println("after A"); } @LiteflowMethod(LiteFlowMethodEnum.ON_SUCCESS) - public void onAcmpSuccess(NodeComponent bindCmp){ + public void onAcmpSuccess(NodeComponent bindCmp) { System.out.println("Acmp success"); } @LiteflowMethod(LiteFlowMethodEnum.ON_ERROR) - public void onAcmpError(NodeComponent bindCmp){ + public void onAcmpError(NodeComponent bindCmp) { System.out.println("Acmp error"); } @@ -51,4 +51,5 @@ public class ACmp{ System.out.println("Acmp end config"); return false; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java index c57ac04f..5b54adce 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void processBcmp(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclSpringbootTest.java index a846e3f2..acff88e5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELDeclSpringbootTest.java @@ -17,8 +17,8 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境下自定义声明节点的测试 - * 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * springboot环境下自定义声明节点的测试 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,19 +26,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customNodes/application.properties") @SpringBootTest(classes = CustomNodesELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +@ComponentScan({ "com.yomahub.liteflow.test.customNodes.domain" }) public class CustomNodesELDeclSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testCustomNodes() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java index b0cbdf15..276d4979 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -11,10 +11,11 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java index 7a56ecf7..fe37f706 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; import javax.annotation.Resource; -public class BCmp{ +public class BCmp { @Resource private DemoDomain demoDomain; @@ -24,4 +24,5 @@ public class BCmp{ demoDomain.sayHi(); System.out.println("BCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java index 48d6f228..6bc3a942 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java index d7778c8a..1584380a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java index 362f4cd3..a34fea18 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; import javax.annotation.Resource; -public class ECmp{ +public class ECmp { @Resource private DemoDomain demoDomain; diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java index 29e1e2db..6647e1ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java index d0b10dc0..745da51d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoDomain { - public void sayHi(){ - System.out.println("hi"); - } + public void sayHi() { + System.out.println("hi"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6f88c4cd..6034ba62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -9,17 +9,15 @@ import java.util.concurrent.ExecutorService; public class CustomThreadExecutor1 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-1-thead-"); - } + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 7d45e4ad..8f9008e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor2 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-2-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index 875dc3d1..dc6f6399 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor3 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-3-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java index c96e897d..7cd9996e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java @@ -27,49 +27,49 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customWhenThreadPool/application.properties") @SpringBootTest(classes = CustomWhenThreadPoolELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.customWhenThreadPool.cmp" }) public class CustomWhenThreadPoolELDeclSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 测试全局线程池配置 - */ - @Test - public void testGlobalThreadPool() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); - } + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); + } - /** - * 测试全局和when上自定义线程池-优先以when上为准 - */ - @Test - public void testGlobalAndCustomWhenThreadPool() { - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response1.getFirstContextBean(); - Assert.assertTrue(response1.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - } + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - /** - * when配置的线程池可以共用 - */ - @Test - public void testCustomWhenThreadPool() { - // 使用when - thread1 - testGlobalAndCustomWhenThreadPool(); - // chain配置同一个thead1 - LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response2.getFirstContextBean(); - Assert.assertTrue(response2.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java index 78cda802..dcb0e699 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java index eb6ec119..7c0bdfe9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java index 5d9612b6..43de67bf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java index 8d47b21f..05cd771a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java index c2a141ac..60f7a9ff 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java index 241013d3..a1b9bbb9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclSpringbootTest.java index 0db32bc2..47937059 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELDeclSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,41 +25,41 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/event/application.properties") @SpringBootTest(classes = EventELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.event.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.event.cmp" }) public class EventELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试组件成功事件 - @Test - public void testEvent1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("abc", context.getData("test")); - } + // 测试组件成功事件 + @Test + public void testEvent1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("abc", context.getData("test")); + } - //测试组件失败事件 - @Test - public void testEvent2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("ab", context.getData("test")); - Assert.assertEquals("error:d", context.getData("error")); - } + // 测试组件失败事件 + @Test + public void testEvent2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("ab", context.getData("test")); + Assert.assertEquals("error:d", context.getData("error")); + } - //测试组件失败事件本身抛出异常 - @Test - public void testEvent3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("a", context.getData("test")); - Assert.assertEquals("error:e", context.getData("error")); - } + // 测试组件失败事件本身抛出异常 + @Test + public void testEvent3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("a", context.getData("test")); + Assert.assertEquals("error:e", context.getData("error")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java index 0c07a3e9..aeb8fcf7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java @@ -14,12 +14,12 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("test",""); + context.setData("test", ""); System.out.println("ACmp executed!"); } @@ -30,4 +30,5 @@ public class ACmp{ str += bindCmp.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java index 5ae1923b..c1bcabc3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -28,4 +28,5 @@ public class BCmp{ str += bindCmp.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java index 5eb9a69e..a3436a8e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -28,4 +28,5 @@ public class CCmp{ str += bindCmp.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java index 4a22a3bb..b299e555 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java @@ -14,10 +14,10 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception{ + public void process(NodeComponent bindCmp) throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -25,6 +25,7 @@ public class DCmp{ @LiteflowMethod(LiteFlowMethodEnum.ON_ERROR) public void onError(NodeComponent bindCmp) throws Exception { DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("error","error:"+bindCmp.getNodeId()); + context.setData("error", "error:" + bindCmp.getNodeId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java index 34c7af4e..7ca3b3e6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java @@ -14,10 +14,10 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception{ + public void process(NodeComponent bindCmp) throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -25,7 +25,8 @@ public class ECmp{ @LiteflowMethod(LiteFlowMethodEnum.ON_ERROR) public void onError(NodeComponent bindCmp) throws Exception { DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("error","error:"+bindCmp.getNodeId()); + context.setData("error", "error:" + bindCmp.getNodeId()); throw new IllegalAccessException("错误事件回调本身抛出异常"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java index 11441ab5..e7b2394c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java @@ -6,7 +6,9 @@ import com.yomahub.liteflow.exception.LiteFlowException; * 用户自定义带状态码的异常 */ public class CustomStatefulException extends LiteFlowException { + public CustomStatefulException(String code, String message) { super(code, message); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclSpringBootTest.java index b8f6befb..acdd913b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELDeclSpringBootTest.java @@ -16,8 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @@ -26,36 +25,37 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class Exception1ELDeclSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 验证 chain 节点重复的异常 - */ - @Test(expected = ChainDuplicateException.class) - public void testChainDuplicateException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-exception.el.xml"); - flowExecutor.reloadRule(); - } + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = ChainDuplicateException.class) + public void testChainDuplicateException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = ConfigErrorException.class) - public void testConfigErrorException() { - flowExecutor.setLiteflowConfig(null); - flowExecutor.reloadRule(); - } + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testFlowExecutorNotInitException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("error/flow.txt"); - flowExecutor.reloadRule(); - } + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("error/flow.txt"); + flowExecutor.reloadRule(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-blank.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testNoConditionInChainException() throws Exception { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-blank.el.xml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclSpringBootTest.java index bfd196d8..c33486d8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELDeclSpringBootTest.java @@ -17,8 +17,7 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @@ -26,51 +25,52 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/exception/application.properties") @SpringBootTest(classes = Exception2ELDeclSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.exception.cmp" }) public class Exception2ELDeclSpringBootTest extends BaseTest { - - @Resource - private FlowExecutor flowExecutor; - @Test(expected = ChainNotFoundException.class) - public void testChainNotFoundException() throws Exception { - flowExecutor.execute("chain0", "it's a request"); - } + @Resource + private FlowExecutor flowExecutor; - @Test(expected = RuntimeException.class) - public void testComponentCustomException() throws Exception { - flowExecutor.execute("chain1", "exception"); - } + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } - @Test - public void testGetSlotFromResponseWhenException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); - Assert.assertFalse(response.isSuccess()); - Assert.assertNotNull(response.getCause()); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } - @Test(expected = NoSwitchTargetNodeException.class) - public void testNoTargetFindException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); - Assert.assertFalse(response.isSuccess()); - throw response.getCause(); - } + @Test + public void testGetSlotFromResponseWhenException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } - @Test - public void testInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("300", response.getCode()); - Assert.assertNotNull(response.getCause()); - Assert.assertTrue(response.getCause() instanceof LiteFlowException); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = NoSwitchTargetNodeException.class) + public void testNoTargetFindException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); + Assert.assertFalse(response.isSuccess()); + throw response.getCause(); + } + + @Test + public void testInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("300", response.getCode()); + Assert.assertNotNull(response.getCause()); + Assert.assertTrue(response.getCause() instanceof LiteFlowException); + Assert.assertNotNull(response.getSlot()); + } + + @Test + public void testNotInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCode()); + } - @Test - public void testNotInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCode()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java index 66a3f801..ffc46f36 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -16,14 +16,14 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ - +public class ACmp { + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); - + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new RuntimeException("chain execute execption"); } LOG.info("Acomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java index 2ac98ebf..6e32bcf3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -16,22 +16,24 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ - +public class BCmp { + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) throws InterruptedException { String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("when")) { + if (StrUtil.isNotBlank(str) && str.equals("when")) { try { LOG.info("Bcomp sleep begin"); Thread.sleep(3000); LOG.info("Bcomp sleep end"); - } catch (InterruptedException e) { + } + catch (InterruptedException e) { throw e; } } LOG.info("Bcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java index 35dff59a..7e9b7e04 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -15,12 +15,13 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ - +public class CCmp { + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); - + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { LOG.info("Ccomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java index 0c26c156..21007b66 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -15,15 +15,16 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ - +public class DCmp { + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); - + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { - if(1==1){ - int a = 1/0; + if (1 == 1) { + int a = 1 / 0; } LOG.info("Dcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java index b8b91713..3d41ccd1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { return "a"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java index de83a200..be423d93 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java @@ -18,13 +18,13 @@ import org.springframework.stereotype.Component; @Component("f") public class FCmp { - + private static final Logger LOG = LoggerFactory.getLogger(FCmp.class); - + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { + if (StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { throw new CustomStatefulException("300", "chain execute custom stateful execption"); } LOG.info("Fcomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java index 248f0416..c3af1156 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java @@ -16,11 +16,12 @@ import org.springframework.stereotype.Component; @Component("g") public class GCmp { - + private static final Logger LOG = LoggerFactory.getLogger(GCmp.class); - + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { LOG.info("Gcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclSpringbootTest.java index 95727f49..e1193169 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELDeclSpringbootTest.java @@ -18,6 +18,7 @@ import java.util.concurrent.Future; /** * springboot环境执行返回future的例子 + * * @author Bryan.Zhang * @since 2.6.13 */ @@ -25,17 +26,17 @@ import java.util.concurrent.Future; @TestPropertySource(value = "classpath:/execute2Future/application.properties") @SpringBootTest(classes = Executor2FutureELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.execute2Future.cmp" }) public class Executor2FutureELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testFuture() throws Exception{ - Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); - LiteflowResponse response = future.get(); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testFuture() throws Exception { + Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java index 90b09361..48d43ae3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java index 10c60574..739188c6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java index a362776f..c29ac08c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java index aa31001c..a3eeb00a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclSpringbootTest.java index c64696b3..2b0101d2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/CmpExtendELDeclSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境测试声明式组件继承其他类的场景 + * * @author Bryan.Zhang * @since 2.7.1 */ @@ -23,16 +24,16 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/extend/application.properties") @SpringBootTest(classes = CmpExtendELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.extend.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.extend.cmp" }) public class CmpExtendELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testExtend() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testExtend() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ACmp.java index 0fb19c86..430bb129 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/BCmp.java index c2188ce7..1a67359c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp extends ParentCmp{ +public class BCmp extends ParentCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CCmp.java index 2bd7db0a..b5e7c951 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ParentCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ParentCmp.java index a739a262..bcf55883 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ParentCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/extend/cmp/ParentCmp.java @@ -4,7 +4,8 @@ import cn.hutool.core.util.StrUtil; public class ParentCmp { - protected String sayHi(String name){ - return StrUtil.format("hi,{}",name); - } + protected String sayHi(String name) { + return StrUtil.format("hi,{}", name); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java index 76e4af17..252156aa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELDeclSpringbootTest.java @@ -17,44 +17,45 @@ import javax.annotation.Resource; /** * springboot环境获取ChainName的测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/getChainName/application.properties") @SpringBootTest(classes = GetChainNameELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.getChainName.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.getChainName.cmp" }) public class GetChainNameELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testGetChainName1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - } + @Test + public void testGetChainName1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } - @Test - public void testGetChainName2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("chain2", context.getData("g")); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - Assert.assertEquals("sub5", context.getData("f")); - Assert.assertEquals("sub5_chain2", context.getData("e")); - Assert.assertEquals("sub6", context.getData("h")); - Assert.assertEquals("sub6", context.getData("j")); - Assert.assertNull(context.getData("k")); - } + @Test + public void testGetChainName2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java index 6e4177c7..5debe2e4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -14,11 +14,12 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java index e7a84d10..1a0083d5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/BCmp.java @@ -21,4 +21,5 @@ public class BCmp { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java index a13f5ab7..614af7a8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/CCmp.java @@ -21,4 +21,5 @@ public class CCmp { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java index 6b57d565..277ddc0e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/DCmp.java @@ -21,4 +21,5 @@ public class DCmp { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java index 714b3bdc..7fc574b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -19,10 +19,12 @@ public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); - if (context.hasData(bindCmp.getNodeId())){ + if (context.hasData(bindCmp.getNodeId())) { context.setData(bindCmp.getNodeId(), context.getData(bindCmp.getNodeId()) + "_" + bindCmp.getCurrChainId()); - }else{ + } + else { context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java index 32e609f1..74a5b4e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/FCmp.java @@ -21,4 +21,5 @@ public class FCmp { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java index 30973a2c..71992922 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/GCmp.java @@ -21,4 +21,5 @@ public class GCmp { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java index 71542650..af80f24e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/HCmp.java @@ -15,7 +15,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("h") -public class HCmp{ +public class HCmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java index 60bba585..67a403c0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/JCmp.java @@ -21,4 +21,5 @@ public class JCmp { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java index cf124de7..d0280213 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/KCmp.java @@ -21,4 +21,5 @@ public class KCmp { DefaultContext context = bindCmp.getFirstContextBean(); context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclSpringbootTest.java index 2b7bcab3..d30f7edd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELDeclSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,66 +24,66 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/ifelse/application.properties") @SpringBootTest(classes = IfElseELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.ifelse.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.ifelse.cmp" }) public class IfElseELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/ACmp.java index f03f0287..ae98805b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/cmp/ACmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { 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 77959ac0..79c6b3bb 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 @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("x1") -public class X1Cmp{ +public class X1Cmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeType = NodeTypeEnum.IF) 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/IteratorELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELDeclSpringbootTest.java index fdc1d51e..715aba47 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELDeclSpringbootTest.java @@ -19,6 +19,7 @@ import java.util.List; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,32 +27,32 @@ import java.util.List; @TestPropertySource(value = "classpath:/iterator/application.properties") @SpringBootTest(classes = IteratorELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.iterator.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.iterator.cmp" }) public class IteratorELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testIt1() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("123", str); - } + // 最简单的情况 + @Test + public void testIt1() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("123", str); + } - //迭代器带break - @Test - public void testIt2() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("12", str); - } + // 迭代器带break + @Test + public void testIt2() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("12", str); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java index fc53c287..620a5f60 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java @@ -17,18 +17,20 @@ import org.springframework.stereotype.Component; @Component("a") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String key = "test"; DefaultContext context = bindCmp.getFirstContextBean(); - if (!context.hasData(key)){ + if (!context.hasData(key)) { context.setData(key, bindCmp.getCurrLoopObj()); - }else{ + } + else { String str = context.getData(key); str += bindCmp.getCurrLoopObj(); context.setData(key, str); } } + } 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 642ba8b3..58181ba8 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 @@ -11,10 +11,11 @@ import org.springframework.stereotype.Component; @Component("b") @LiteflowCmpDefine(NodeTypeEnum.BREAK) -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS_BREAK) 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/iterator/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java index 43c60973..cd53b17d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java @@ -13,10 +13,12 @@ import java.util.List; @Component("it") @LiteflowCmpDefine(NodeTypeEnum.ITERATOR) -public class ITCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS_ITERATOR) - public Iterator processIterator(NodeComponent bindCmp) throws Exception { - List list = bindCmp.getRequestData(); - return list.iterator(); - } +public class ITCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_ITERATOR) + public Iterator processIterator(NodeComponent bindCmp) throws Exception { + List list = bindCmp.getRequestData(); + return list.iterator(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclSpringbootTest.java index e02e79ad..a83730d7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELDeclSpringbootTest.java @@ -22,12 +22,12 @@ import javax.annotation.Resource; @ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"})*/ public class LazyELDeclSpringbootTest extends BaseTest { - /*@Resource - private FlowExecutor flowExecutor; + /* + * @Resource private FlowExecutor flowExecutor; + * + * @Test public void testLazy() throws Exception{ LiteflowResponse response = + * flowExecutor.execute2Resp("chain1", "arg"); + * Assert.assertTrue(response.isSuccess()); } + */ - @Test - public void testLazy() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - }*/ } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java index 2c33d4c6..f0d5fe44 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -15,10 +15,11 @@ import org.springframework.stereotype.Component; @Lazy @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java index 9f6cff9f..9fe293b1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java index 13c3c043..8c3cb4fd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclSpringbootTest.java index 7d88243d..0a4385e9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELDeclSpringbootTest.java @@ -13,9 +13,9 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试@LiteflowComponent标注 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -23,16 +23,17 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(value = "classpath:/lfCmpAnno/application.properties") @SpringBootTest(classes = LiteflowComponentELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.lfCmpAnno.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.lfCmpAnno.cmp" }) public class LiteflowComponentELDeclSpringbootTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); + } - @Test - public void testConfig() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java index f3d8c876..15a8830e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent(id = "a", name = "A组件") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java index 3a6fefc4..33c2ce51 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent(id = "b", name = "B组件") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java index 514293d3..7d684bd1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent(id = "c", name = "C组件") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java index f541bf72..a963b484 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclSpringbootTest.java index c5a506ec..c2b3d196 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELDeclSpringbootTest.java @@ -17,76 +17,80 @@ import javax.annotation.Resource; /** * springboot环境EL循环的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/loop/application.properties") @SpringBootTest(classes = LoopELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.loop.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.loop.cmp" }) public class LoopELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //测试FOR循环中的index - @Test - public void testLoop6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } + // 测试FOR循环中的index + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } + + // 测试WHILE循环中的index + @Test + public void testLoop7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } - //测试WHILE循环中的index - @Test - public void testLoop7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java index 6c0daa4a..fe587794 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/BCmp.java index 147f4fa9..6aa15202 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CCmp.java index 70b8bf90..396a12db 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java index a8d3742b..e1578c8c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java @@ -14,16 +14,17 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java index 76e39e94..1b9378ef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java @@ -15,17 +15,18 @@ import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); String key = StrUtil.format("{}_{}", "loop", bindCmp.getTag()); - if (context.hasData(key)){ + if (context.hasData(key)) { String loopStr = context.getData(key); String loopStrReturn = StrUtil.format("{}{}", loopStr, bindCmp.getLoopIndex()); context.setData(key, loopStrReturn); - }else{ + } + else { context.setData(key, bindCmp.getLoopIndex().toString()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java index da3837c4..148cbd4a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java @@ -7,10 +7,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("x") -public class XCmp{ +public class XCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeType = NodeTypeEnum.FOR) + public int processFor(NodeComponent bindCmp) throws Exception { + return 3; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeType = NodeTypeEnum.FOR) - public int processFor(NodeComponent bindCmp) throws Exception { - return 3; - } } 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 39c0faac..34967f9f 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 @@ -8,12 +8,13 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") -public class YCmp{ +public class YCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeType = NodeTypeEnum.BREAK) + public boolean processBreak(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + int count = context.getData("test"); + return count > 3; + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeType = NodeTypeEnum.BREAK) - public boolean processBreak(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - int count = context.getData("test"); - return count > 3; - } } 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 006a2b36..ec494511 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 @@ -8,17 +8,19 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") -public class ZCmp{ +public class ZCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE) + public boolean processWhile(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } + else { + return true; + } + } - @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE) - public boolean processWhile(NodeComponent bindCmp) throws Exception { - DefaultContext context = bindCmp.getFirstContextBean(); - String key = "test"; - if (context.hasData(key)){ - int count = context.getData("test"); - return count < 5; - }else{ - return true; - } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclSpringbootTest.java index eb1b5f9a..7ce1c34f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELDeclSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,24 +27,24 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/monitor/application.properties") @SpringBootTest(classes = MonitorELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.monitor.cmp" }) public class MonitorELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); + @Test + public void testMonitor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); - Thread.sleep(10000); - } + Thread.sleep(10000); + } - @AfterClass - public static void clean(){ - MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); - monitorBus.closeScheduler(); - } + @AfterClass + public static void clean() { + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java index 30acf080..cbef46e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java @@ -15,16 +15,18 @@ import org.springframework.stereotype.Component; import java.util.Random; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java index e0c0a2dd..c3deab91 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java @@ -15,13 +15,14 @@ import org.springframework.stereotype.Component; import java.util.Random; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java index 20d66dfc..8444ce7c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java @@ -15,13 +15,14 @@ import org.springframework.stereotype.Component; import java.util.Random; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java index d5ff49d1..acf28f87 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELDeclSpringbootTest.java @@ -22,19 +22,21 @@ import java.io.File; @TestPropertySource(value = "classpath:/monitorFile/application.properties") @SpringBootTest(classes = MonitorFileELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.monitorFile.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.monitorFile.cmp" }) public class MonitorFileELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java index bf247b61..753f3d95 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -15,10 +15,11 @@ import org.springframework.stereotype.Component; import java.util.Random; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java index 67c835e8..2cf61833 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/BCmp.java @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; import java.util.Random; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java index 0d1ff95f..697d5dab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/CCmp.java @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; import java.util.Random; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java index af8bfad4..793d85e1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java @@ -2,23 +2,24 @@ package com.yomahub.liteflow.test.multiContext; public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclSpringbootTest.java index 0556db2b..2d5b7642 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELDeclSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,29 +27,29 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/multiContext/application.properties") @SpringBootTest(classes = MultiContextELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.multiContext.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.multiContext.cmp" }) public class MultiContextELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMultiContext1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("987XYZ", checkContext.getSign()); - Assert.assertEquals(95, checkContext.getRandomId()); - Assert.assertEquals("SO12345", orderContext.getOrderNo()); - Assert.assertEquals(2, orderContext.getOrderType()); - Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); - } + @Test + public void testMultiContext1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("987XYZ", checkContext.getSign()); + Assert.assertEquals(95, checkContext.getRandomId()); + Assert.assertEquals("SO12345", orderContext.getOrderNo()); + Assert.assertEquals(2, orderContext.getOrderType()); + Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); + } - @Test(expected = NoSuchContextBeanException.class) - public void testMultiContext2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - DefaultContext context = response.getContextBean(DefaultContext.class); - } + @Test(expected = NoSuchContextBeanException.class) + public void testMultiContext2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + DefaultContext context = response.getContextBean(DefaultContext.class); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java index c477108b..292db52b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java @@ -4,33 +4,34 @@ import java.util.Date; public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java index e1edab2f..3ed412b6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.test.multiContext.CheckContext; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -23,4 +23,5 @@ public class ACmp{ checkContext.setRandomId(95); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java index 86afeac4..850e21df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java @@ -14,11 +14,11 @@ import com.yomahub.liteflow.test.multiContext.OrderContext; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { - //getContextBean无参方法是获取到第一个上下文 + // getContextBean无参方法是获取到第一个上下文 OrderContext orderContext = bindCmp.getFirstContextBean(); orderContext.setOrderNo("SO12345"); System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CCmp.java index f61c28a9..f16387d3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/CCmp.java @@ -14,7 +14,7 @@ import com.yomahub.liteflow.test.multiContext.OrderContext; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/DCmp.java index 39d21049..a5e1864d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/DCmp.java @@ -15,7 +15,7 @@ import com.yomahub.liteflow.test.multiContext.OrderContext; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclSpringbootTest.java index d4a70a25..983a4ab4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELDeclSpringbootTest.java @@ -13,9 +13,9 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试springboot下混合格式规则的场景 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -23,19 +23,20 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(value = "classpath:/multipleType/application.properties") @SpringBootTest(classes = LiteflowMultipleTypeELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.multipleType.cmp" }) public class LiteflowMultipleTypeELDeclSpringbootTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } - @Test - public void testMultipleType() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); - response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java index c144929b..828f22aa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java index a92cf8d6..c06d7bef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java index f0cc64cf..ee7a72fe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java index 0ced9da9..5572a472 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -10,11 +10,13 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; * 自定义默认的节点执行器 */ public class CustomerDefaultNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerDefaultNodeExecutor进行执行"); - context.setData("customerDefaultNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + context.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java index 5a9f2e58..16f32a7c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -10,12 +10,13 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; * 自定义节点执行器 */ public class CustomerNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutor进行执行"); - context.setData("customerNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutor进行执行"); + context.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java index 003d3331..81c6604f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -12,19 +12,21 @@ import java.util.concurrent.TimeUnit; * 自定义节点执行器 */ public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); - context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); - super.execute(instance); - } - @Override - protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { - TimeUnit.MICROSECONDS.sleep(20L); - DefaultContext context = instance.getFirstContextBean(); - context.setData("retryLogic", this.getClass()); - super.retry(instance, currentRetryCount); - } + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + DefaultContext context = instance.getFirstContextBean(); + context.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclSpringbootTest.java index bfbca501..10d68eb7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELDeclSpringbootTest.java @@ -15,7 +15,6 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的组件重试 * @@ -26,47 +25,48 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/nodeExecutor/application.properties") @SpringBootTest(classes = LiteflowNodeExecutorELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.nodeExecutor.cmp" }) public class LiteflowNodeExecutorELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - // 默认执行器测试 - @Test - public void testCustomerDefaultNodeExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("a", response.getExecuteStepStr()); - } + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getExecuteStepStr()); + } - //默认执行器测试+全局重试配置测试 - @Test - public void testDefaultExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); - } + // 默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); + } - //自定义执行器测试 - @Test - public void testCustomerExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("c", response.getExecuteStepStr()); - } + // 自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStr()); + } + + // 自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); + } - //自定义执行器测试+全局重试配置测试 - @Test - public void testCustomExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); - Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java index 954dfd70..9cee0f48 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java @@ -14,11 +14,11 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("a") -public class ACmp{ +public class ACmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java index e1a1eb19..9bd9fa6c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -13,14 +13,14 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("b") -public class BCmp{ +public class BCmp { private int flag = 0; @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java index 73e46fa5..968f2962 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -17,7 +17,7 @@ import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; @LiteflowComponent("c") @LiteflowRetry(5) -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -25,7 +25,8 @@ public class CCmp{ } @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) - public Class getNodeExecutorClass(NodeComponent bindCmp) { + public Class getNodeExecutorClass(NodeComponent bindCmp) { return CustomerNodeExecutor.class; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java index 6a9da70e..6a48cc90 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -17,17 +17,18 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) -public class DCmp{ +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) +public class DCmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("DCmp executed!"); - throw new NullPointerException("demo exception"); - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) + public Class getNodeExecutorClass(NodeComponent bindCmp) { + return CustomerNodeExecutorAndCustomRetry.class; + } - @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) - public Class getNodeExecutorClass(NodeComponent bindCmp) { - return CustomerNodeExecutorAndCustomRetry.class; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclSpringbootTest.java index 960edf70..d91a89ef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELDeclSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境的自定义json parser单元测试 + * * @author dongguo.tao * @since 2.5.0 */ @@ -23,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties") @SpringBootTest(classes = CustomParserJsonELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.parsecustom.cmp" }) public class CustomParserJsonELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testJsonCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclSpringbootTest.java index 50340f56..43ca2189 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELDeclSpringbootTest.java @@ -15,8 +15,8 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ @@ -24,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties") @SpringBootTest(classes = CustomParserXmlELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.parsecustom.cmp", "com.yomahub.liteflow.test.parsecustom.bean" }) public class CustomParserXmlELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testXmlCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java index 6e6d9f57..e96fa077 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class TestBean { - public String returnXmlContent(){ - return "THEN(a,b,c,d)"; - } + public String returnXmlContent() { + return "THEN(a,b,c,d)"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java index 6428e5b0..64c236fa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -15,14 +15,15 @@ import com.yomahub.liteflow.exception.FlowSystemException; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String str = bindCmp.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new FlowSystemException("chain execute execption"); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java index 2dac6864..8bb6960d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java index 4d8334f3..5fa7ceca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java index 5858ea69..b4f97bc3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java index a92d98af..8361c0e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java index 8a95d2e9..b2937c37 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java index 0a29fac2..e8345468 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("g") -public class GCmp{ +public class GCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java index 42f5eeed..a164ba09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -4,14 +4,17 @@ import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser; /** * 模拟用户自定义源解析 + * * @author dongguo.tao * @since 2.5.0 */ public class CustomJsonFlowParser extends ClassJsonFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; - return content; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; + return content; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java index 473ad502..3405882d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -6,18 +6,19 @@ import com.yomahub.liteflow.test.parsecustom.bean.TestBean; import javax.annotation.Resource; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ public class CustomXmlFlowParser extends ClassXmlFlowELParser { - @Resource - private TestBean testBean; + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } - @Override - public String parseCustom() { - return testBean.returnXmlContent(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclSpringbootTest.java index 1e7752cd..32af794e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELDeclSpringbootTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * spring环境的json parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -24,13 +25,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class JsonParserELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的json parser - @Test - public void testJsonParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclSpringbootTest.java index 095a6cc3..31c31aaa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELDeclSpringbootTest.java @@ -19,13 +19,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class SpringELSupportELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springEL的解析情况 + @Test + public void testSpringELParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试springEL的解析情况 - @Test - public void testSpringELParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclSpringbootTest.java index 56f16792..3de6b0e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELDeclSpringbootTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * springboot环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -24,13 +25,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class XmlParserELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试无springboot场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的xml parser - @Test - public void testXmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclSpringbootTest.java index 3105e08a..4966cfe5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELDeclSpringbootTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * springboot下的yml parser测试用例 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -24,13 +25,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class YmlParserELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试无springboot场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的yml parser - @Test - public void testYmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java index 0d98b16b..c0131647 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java index b5c67c8b..fa15c7f3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java index 4024e4cf..39aea659 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java index 6d1ad9f5..48463cfb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java index 955fbc9a..a2bf249d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java index cf4e48fd..346a7221 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java index f3b33a04..ced5e35d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("g") -public class GCmp{ +public class GCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclSpringbootTest.java index 70848334..7e3a0976 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELDeclSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境下pre节点和finally节点的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,49 +25,50 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/preAndFinally/application.properties") @SpringBootTest(classes = PreAndFinallyELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.preAndFinally.cmp" }) public class PreAndFinallyELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通的pre和finally节点 - @Test - public void testPreAndFinally1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试pre和finally节点不放在开头和结尾的情况 - @Test - public void testPreAndFinally2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 - @Test - public void testPreAndFinally3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); - } + // 测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); + } - //测试在finally节点里是否能获取exception - @Test - public void testPreAndFinally4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(context.getData("hasEx")); - } + // 测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(context.getData("hasEx")); + } + + @Test + public void testPreAndFinally5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testPreAndFinally5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java index 02363bf7..3e99c9a1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java index 50381712..a5a98a84 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java index 58b1b621..f74ed123 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java index 73c34345..d8f5c96a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -13,12 +13,12 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("CCmp executed!"); - int i = 1/0; + int i = 1 / 0; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java index 19efc5dc..64ab1cb1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("f1") -public class Finally1Cmp{ +public class Finally1Cmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("Finally1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java index bc877847..4c8f6488 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("f2") -public class Finally2Cmp{ +public class Finally2Cmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("Finally2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java index f36868df..b0f85534 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -16,17 +16,19 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("f3") -public class Finally3Cmp{ +public class Finally3Cmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception{ + public void process(NodeComponent bindCmp) throws Exception { Slot slot = bindCmp.getSlot(); DefaultContext context = slot.getFirstContextBean(); - if (ObjectUtil.isNull(slot.getException())){ + if (ObjectUtil.isNull(slot.getException())) { context.setData("hasEx", false); - }else{ + } + else { context.setData("hasEx", true); } System.out.println("Finally3Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java index 3ca35339..5e0d8c58 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("p1") -public class Pre1Cmp{ +public class Pre1Cmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("Pre1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java index f62407cc..2c875d97 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("p2") -public class Pre2Cmp{ +public class Pre2Cmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("Pre2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclSpringbootTest.java index ca13b8f9..c8114b84 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELDeclSpringbootTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,18 +26,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/privateDelivery/application.properties") @SpringBootTest(classes = PrivateDeliveryELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.privateDelivery.cmp" }) public class PrivateDeliveryELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + ConcurrentHashSet set = context.getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } - @Test - public void testPrivateDelivery() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - ConcurrentHashSet set = context.getData("testSet"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(100, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java index 29e388b1..47667a45 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -15,7 +15,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -24,8 +24,8 @@ public class ACmp{ context.setData("testSet", new ConcurrentHashSet<>()); for (int i = 0; i < 100; i++) { - bindCmp.sendPrivateDeliveryData("b",i+1); + bindCmp.sendPrivateDeliveryData("b", i + 1); } } -} +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java index 9aacae97..b1b29266 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -15,15 +15,15 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("b") -public class BCmp{ +public class BCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + Integer value = bindCmp.getPrivateDeliveryData(); + DefaultContext context = bindCmp.getFirstContextBean(); + ConcurrentHashSet testSet = context.getData("testSet"); + testSet.add(value); + } - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("BCmp executed!"); - Integer value = bindCmp.getPrivateDeliveryData(); - DefaultContext context = bindCmp.getFirstContextBean(); - ConcurrentHashSet testSet = context.getData("testSet"); - testSet.add(value); - } } - diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java index 0d661ba0..aed0ccbe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java index 3d78d2c1..d4528e2c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclSpringbootTest.java index 981d0357..ccccbfb0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELDeclSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,44 +27,47 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/refreshRule/application.properties") @SpringBootTest(classes = RefreshRuleELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.refreshRule.cmp" }) public class RefreshRuleELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通刷新流程的场景 - @Test - public void testRefresh1() throws Exception{ - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception { + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试优雅刷新的场景 - @Test - public void testRefresh2() throws Exception{ - new Thread(() -> { - try { - Thread.sleep(2000L); - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - } catch (Exception e) { - e.printStackTrace(); - } + // 测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception { + new Thread(() -> { + try { + Thread.sleep(2000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + } + catch (Exception e) { + e.printStackTrace(); + } - }).start(); + }).start(); - for (int i = 0; i < 500; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - try { - Thread.sleep(10L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java index 8db021e6..3a92fbc0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java index 8bc2540f..049896e3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java index b173b732..c8955fba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclSpringbootTest.java index 97657d4c..16dc9824 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELDeclSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -23,18 +24,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/reload/application.properties") @SpringBootTest(classes = ReloadELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.reload.cmp" }) public class ReloadELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + // 这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception { + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml - //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 - @Test - public void testReload() throws Exception{ - flowExecutor.reloadRule(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java index 5edf77bf..182aa63f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java index bcb59e06..85019529 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java index 0fd06df3..9ea3350e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclSpringbootTest.java index 77dbaf13..cf56d27e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELDeclSpringbootTest.java @@ -21,17 +21,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/requestId/application.properties") @SpringBootTest(classes = LiteflowRequestIdELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.requestId.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.requestId.cmp" }) public class LiteflowRequestIdELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testRequestId() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1", response.getSlot().getRequestId()); - } + @Test + public void testRequestId() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", response.getSlot().getRequestId()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java index e2369dbd..68916fab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java @@ -16,8 +16,9 @@ import org.springframework.stereotype.Component; @Component("a") public class ACmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java index 5e441aac..19e71b88 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java index 00445932..e705db34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java @@ -9,11 +9,11 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class CustomRequestIdGenerator implements RequestIdGenerator { - private final AtomicInteger atomicInteger = new AtomicInteger(0); + private final AtomicInteger atomicInteger = new AtomicInteger(0); - @Override - public String generate() { - return atomicInteger.incrementAndGet() + ""; - } + @Override + public String generate() { + return atomicInteger.incrementAndGet() + ""; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclSpringbootTest.java index a8d7fae6..a35ed55a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELDeclSpringbootTest.java @@ -18,8 +18,7 @@ import java.util.HashSet; import java.util.Set; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author justin.xu */ @@ -27,39 +26,41 @@ import java.util.Set; @TestPropertySource(value = "classpath:/subflow/application-implicit.properties") @SpringBootTest(classes = ImplicitSubFlowELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp2" }) public class ImplicitSubFlowELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - public static final Set RUN_TIME_SLOT = new HashSet<>(); + @Resource + private FlowExecutor flowExecutor; - //这里GCmp中隐式的调用chain4,从而执行了h,m - @Test - public void testImplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); + public static final Set RUN_TIME_SLOT = new HashSet<>(); - // 传递了slotIndex,则set的size==1 - Assert.assertEquals(1, RUN_TIME_SLOT.size()); - // set中第一次设置的requestId和response中的requestId一致 - Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); - //requestData的取值正确 - Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); - } + // 这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); - //在p里多线程调用q 10次,每个q取到的参数都是不同的。 - @Test - public void testImplicitSubFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + // requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); + } - Set set = context.getData("test"); + // 在p里多线程调用q 10次,每个q取到的参数都是不同的。 + @Test + public void testImplicitSubFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + + Set set = context.getData("test"); + + // requestData的取值正确 + Assert.assertEquals(10, set.size()); + } - //requestData的取值正确 - Assert.assertEquals(10, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclSpringbootTest.java index 2bc3bf53..8c6f729e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELDeclSpringbootTest.java @@ -27,27 +27,29 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-subInDifferentConfig1.properties") @SpringBootTest(classes = SubflowInDifferentConfigELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1","com.yomahub.liteflow.test.subflow.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1", "com.yomahub.liteflow.test.subflow.cmp2" }) public class SubflowInDifferentConfigELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; - @Autowired - private ApplicationContext context; + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); + } + + @Autowired + private ApplicationContext context; + + // 主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("subflow/flow-main.xml, subflow/flow-sub1.xml,subflow/flow-sub2.yml"); + flowExecutor.reloadRule(); + } - //主要测试有不同的配置类型后会不会报出既定的错误 - @Test(expected = MultipleParsersException.class) - public void testExplicitSubFlow2() { - LiteflowConfig config = context.getBean(LiteflowConfig.class); - config.setRuleSource("subflow/flow-main.xml, subflow/flow-sub1.xml,subflow/flow-sub2.yml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclSpringBootTest.java index 85e1a3f0..457bfedd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELDeclSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(json) - * 单元测试 + * 测试显示调用子流程(json) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-json.properties") @SpringBootTest(classes = SubflowJsonELDeclSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowJsonELDeclSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclSpringBootTest.java index 33e1363e..5fbd5a8d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELDeclSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(xml) - * 单元测试 + * 测试显示调用子流程(xml) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-xml.properties") @SpringBootTest(classes = SubflowXMLELDeclSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowXMLELDeclSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclSpringBootTest.java index e63159a8..fffe03a4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELDeclSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(yml) - * 单元测试 + * 测试显示调用子流程(yml) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-yml.properties") @SpringBootTest(classes = SubflowYmlELDeclSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowYmlELDeclSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlowYml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java index 629bf83f..16740a05 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -5,11 +5,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("a") -public class ACmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("Acomp executed!"); - } +public class ACmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java index 00549dab..044b4d60 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -5,11 +5,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("b") -public class BCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("Bcomp executed!"); - } +public class BCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java index 82030e98..7c335457 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -5,11 +5,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("c") -public class CCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - System.out.println("Ccomp executed!"); - } +public class CCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java index 0a0868f1..cbbb3bde 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -5,11 +5,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("d") -public class DCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - System.out.println("Dcomp executed!"); - } +public class DCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java index fa8f6094..e5950ed8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -5,12 +5,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; - @Component("e") -public class ECmp{ +public class ECmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + } - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - System.out.println("Ecomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java index c2e2cbfa..3a492eb7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -7,14 +7,15 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclSpringbootTest.RUN_TIME_SLOT; - @Component("f") -public class FCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { +public class FCmp { - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Fcomp executed!"); + } - System.out.println("Fcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java index 293fdf72..feea6b58 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -7,17 +7,17 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclSpringbootTest.RUN_TIME_SLOT; - @Component("g") -public class GCmp{ +public class GCmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); - System.out.println("Gcmp executed!"); + System.out.println("Gcmp executed!"); + + bindCmp.invoke("chain4", "it's implicit subflow."); + } - bindCmp.invoke("chain4", "it's implicit subflow."); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index 4cfcb663..e1c8975c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -8,17 +8,18 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclSpringbootTest.RUN_TIME_SLOT; - @Component("h") -public class HCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - String requestData = bindCmp.getSubChainReqData(); - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("innerRequest", requestData); +public class HCmp { - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + String requestData = bindCmp.getSubChainReqData(); + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("innerRequest", requestData); + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java index e946c042..3117e170 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -7,14 +7,15 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELDeclSpringbootTest.RUN_TIME_SLOT; - @Component("m") -public class MCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { +public class MCmp { - RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); + } - System.out.println("Mcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java index 7a95dfb0..dfd0c56b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java @@ -7,26 +7,27 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - @Component("p") -public class PCmp{ +public class PCmp { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + int slotIndex = bindCmp.getSlotIndex(); + for (int i = 0; i < 10; i++) { + int finalI = i; + new Thread(() -> { + try { + flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); + } + catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); + } + Thread.sleep(1000); + } - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - int slotIndex = bindCmp.getSlotIndex(); - for (int i = 0; i < 10; i++) { - int finalI = i; - new Thread(() -> { - try { - flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); - } catch (Exception e) { - throw new RuntimeException(e); - } - }).start(); - } - Thread.sleep(1000); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java index 90270d10..09ae19b0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java @@ -9,23 +9,25 @@ import org.springframework.stereotype.Component; import java.util.HashSet; import java.util.Set; - @Component("q") -public class QCmp{ - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) throws Exception { - String requestData = bindCmp.getSubChainReqDataInAsync(); - DefaultContext context = bindCmp.getFirstContextBean(); +public class QCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + String requestData = bindCmp.getSubChainReqDataInAsync(); + DefaultContext context = bindCmp.getFirstContextBean(); + + synchronized (QCmp.class) { + if (context.hasData("test")) { + Set set = context.getData("test"); + set.add(requestData); + } + else { + Set set = new HashSet<>(); + set.add(requestData); + context.setData("test", set); + } + } + } - synchronized (QCmp.class){ - if (context.hasData("test")){ - Set set = context.getData("test"); - set.add(requestData); - }else{ - Set set = new HashSet<>(); - set.add(requestData); - context.setData("test", set); - } - } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/SuperClassDefineELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/SuperClassDefineELDeclSpringbootTest.java index a05fdba6..0b6faf33 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/SuperClassDefineELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/SuperClassDefineELDeclSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境声明式父类声明组件方法测试 + * * @author Bryan.Zhang * @since 2.9.4 */ @@ -24,19 +25,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/superClassDefine/application.properties") @SpringBootTest(classes = SuperClassDefineELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.superClassDefine.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.superClassDefine.cmp" }) public class SuperClassDefineELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testSuperClassDefine() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>d", response.getExecuteStepStr()); - Assert.assertTrue(context.getData("isAccess")); - } + @Test + public void testSuperClassDefine() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>d", response.getExecuteStepStr()); + Assert.assertTrue(context.getData("isAccess")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/ACmp.java index 8aaed33b..81ac3ecb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/ACmp.java @@ -16,10 +16,11 @@ import org.springframework.stereotype.Component; @Component("a") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/BCmp.java index 416a7f2d..f91d8f88 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/BCmp.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @Component("b") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class BCmp extends SuperClass{ +public class BCmp extends SuperClass { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/CCmp.java index d95cc4f9..236988cb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/CCmp.java @@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; @Component("c") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/DCmp.java index 57ea2b3e..ee5840f7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/DCmp.java @@ -14,10 +14,9 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; - @Component("d") @LiteflowCmpDefine(NodeTypeEnum.COMMON) -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/SuperClass.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/SuperClass.java index 92197b3a..8ee48ab6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/SuperClass.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/superClassDefine/cmp/SuperClass.java @@ -7,10 +7,11 @@ import com.yomahub.liteflow.slot.DefaultContext; public abstract class SuperClass { - @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) - public boolean isAccess(NodeComponent bindCmp) { - DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("isAccess", true); - return true; - } + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("isAccess", true); + return true; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclSpringbootTest.java index 8a640b2d..22cc5f54 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELDeclSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,44 +24,45 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/switchcase/application.properties") @SpringBootTest(classes = SwitchELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.switchcase.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.switchcase.cmp" }) public class SwitchELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testSwitch1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); - } + @Test + public void testSwitch1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d", response.getExecuteStepStr()); + } - @Test - public void testSwitch3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>f==>b",response.getExecuteStepStr()); - } + @Test + public void testSwitch3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>f==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>g==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>g==>d", response.getExecuteStepStr()); + } + + @Test + public void testSwitch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java index 1db4c43e..bee71a01 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/BCmp.java index 30232385..3192e977 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CCmp.java index 0519b48b..0695c09a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/DCmp.java index f77031f2..7c662bb5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java index 73cc61b6..bd45505d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("e") -public class ESwitchCmp{ +public class ESwitchCmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { return "d"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java index afdd51b0..ca9f1d40 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java @@ -14,10 +14,11 @@ import com.yomahub.liteflow.enums.NodeTypeEnum; import org.springframework.stereotype.Component; @Component("f") -public class FSwitchCmp{ +public class FSwitchCmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { return ":td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java index 185e5550..dd51e8a5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java @@ -20,4 +20,5 @@ public class GSwitchCmp { public String processSwitch(NodeComponent bindCmp) throws Exception { return "d:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java index 44823626..315bcf4b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java @@ -20,4 +20,5 @@ public class HSwitchCmp { public String processSwitch(NodeComponent bindCmp) throws Exception { return "tag:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootJsonTest.java index 22d29d58..cf07233b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootJsonTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,45 +26,46 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/tag/application-json.properties") @SpringBootTest(classes = NodeTagELDeclSpringbootJsonTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.tag.cmp" }) public class NodeTagELDeclSpringbootJsonTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootXmlTest.java index 22bb4a6c..ea4d57e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootXmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELDeclSpringbootXmlTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,45 +26,46 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/tag/application-xml.properties") @SpringBootTest(classes = NodeTagELDeclSpringbootXmlTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.tag.cmp" }) public class NodeTagELDeclSpringbootXmlTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java index 408f7d57..29005b25 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java @@ -14,19 +14,21 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String testKey = "test"; DefaultContext context = bindCmp.getFirstContextBean(); - if (context.getData(testKey) == null){ - context.setData(testKey,bindCmp.getTag()); - }else{ + if (context.getData(testKey) == null) { + context.setData(testKey, bindCmp.getTag()); + } + else { String s = context.getData(testKey); s += bindCmp.getTag(); context.setData(testKey, s); } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java index 6a78f555..dfe11f24 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -15,11 +15,12 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("b1") -public class B1Cmp{ +public class B1Cmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { DefaultContext context = bindCmp.getFirstContextBean(); - context.setData("test",new ConcurrentHashSet()); + context.setData("test", new ConcurrentHashSet()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java index 06ec2488..11a3a03c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java @@ -15,7 +15,7 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { @@ -23,4 +23,5 @@ public class BCmp{ ConcurrentHashSet testSet = context.getData("test"); testSet.add(bindCmp.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java index 6384a4e3..b7a227b4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java @@ -14,14 +14,16 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import com.yomahub.liteflow.enums.NodeTypeEnum; @LiteflowComponent("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH) public String processSwitch(NodeComponent bindCmp) throws Exception { - if(bindCmp.getTag().equals("2")){ + if (bindCmp.getTag().equals("2")) { return "e"; - }else{ + } + else { return "d"; } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java index 14bb6a16..d3c04b2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -13,11 +13,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println(bindCmp.getTag()); System.out.println("DCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java index b941236b..5053e0d8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -13,11 +13,12 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println(bindCmp.getTag()); System.out.println("ECmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java index f4023156..1ec0c8e3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process() { @@ -24,4 +24,5 @@ public class FCmp{ public boolean isAccess(NodeComponent bindCmp) { return Boolean.parseBoolean(bindCmp.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java index f342ffcc..7d88059b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.enums.LiteFlowMethodEnum; @LiteflowComponent("g") -public class GCmp{ +public class GCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("GCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java index fee0055e..3de938a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -4,13 +4,14 @@ import com.alibaba.ttl.TransmittableThreadLocal; public class TestTL { - public static ThreadLocal tl = new TransmittableThreadLocal<>(); + public static ThreadLocal tl = new TransmittableThreadLocal<>(); - public static String get(){ - return tl.get(); - } + public static String get() { + return tl.get(); + } + + public static void set(String value) { + tl.set(value); + } - public static void set(String value){ - tl.set(value); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclSpringbootTest.java index 7e118a66..3664207e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELDeclSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * * @author Bryan.Zhang * @since 2.6.3 */ @@ -24,20 +25,21 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/useTTLInWhen/application.properties") @SpringBootTest(classes = UseTTLInWhenELDeclSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.useTTLInWhen.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.useTTLInWhen.cmp" }) public class UseTTLInWhenELDeclSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,b", context.getData("b")); + Assert.assertEquals("hello,c", context.getData("c")); + Assert.assertEquals("hello,d", context.getData("d")); + Assert.assertEquals("hello,e", context.getData("e")); + Assert.assertEquals("hello,f", context.getData("f")); + } - @Test - public void testUseTTLInWhen() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,b", context.getData("b")); - Assert.assertEquals("hello,c", context.getData("c")); - Assert.assertEquals("hello,d", context.getData("d")); - Assert.assertEquals("hello,e", context.getData("e")); - Assert.assertEquals("hello,f", context.getData("f")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java index 9ae3d347..823ae5f6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java @@ -14,11 +14,12 @@ import com.yomahub.liteflow.test.useTTLInWhen.TestTL; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { TestTL.set("hello"); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java index 7a1acc8b..d65d6071 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -15,13 +15,13 @@ import com.yomahub.liteflow.test.useTTLInWhen.TestTL; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String value = TestTL.get(); DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",b"); + context.setData(bindCmp.getNodeId(), value + ",b"); System.out.println("BCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java index 63c7c246..77d87c0d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -15,13 +15,13 @@ import com.yomahub.liteflow.test.useTTLInWhen.TestTL; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String value = TestTL.get(); DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",c"); + context.setData(bindCmp.getNodeId(), value + ",c"); System.out.println("CCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java index 4d8c8b48..63f52456 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -15,13 +15,13 @@ import com.yomahub.liteflow.test.useTTLInWhen.TestTL; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String value = TestTL.get(); DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",d"); + context.setData(bindCmp.getNodeId(), value + ",d"); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java index 514acb74..86aff40a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -15,13 +15,13 @@ import com.yomahub.liteflow.test.useTTLInWhen.TestTL; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String value = TestTL.get(); DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",e"); + context.setData(bindCmp.getNodeId(), value + ",e"); System.out.println("ECmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java index 4c79e0a9..109d24d6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -15,13 +15,13 @@ import com.yomahub.liteflow.test.useTTLInWhen.TestTL; import org.springframework.stereotype.Component; @Component("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { String value = TestTL.get(); DefaultContext context = bindCmp.getFirstContextBean(); - context.setData(bindCmp.getNodeId(),value+",f"); + context.setData(bindCmp.getNodeId(), value + ",f"); System.out.println("FCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest1.java index a0ba5e7a..c763a638 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest1.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,19 +27,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/whenTimeOut/application1.properties") @SpringBootTest(classes = WhenTimeOutELDeclSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.whenTimeOut.cmp" }) public class WhenTimeOutELDeclSpringbootTest1 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } - //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest2.java index 90c5ad12..36f5c3b1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELDeclSpringbootTest2.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -25,18 +26,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/whenTimeOut/application2.properties") @SpringBootTest(classes = WhenTimeOutELDeclSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.whenTimeOut.cmp" }) public class WhenTimeOutELDeclSpringbootTest2 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java index 4b681e50..52716622 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java index 0d1c8146..d4981448 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -13,13 +13,14 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java index 719ee415..daea027d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -13,13 +13,14 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(3500); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java index a1cccbb6..8e571ad4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -13,13 +13,14 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("d") -public class DCmp{ +public class DCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("DCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java index 34e43e25..29ee8d6e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -13,13 +13,14 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("e") -public class ECmp{ +public class ECmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("ECmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java index ca0539ac..52cd4a9e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -13,13 +13,14 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("f") -public class FCmp{ +public class FCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("FCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java index eee5c3b2..33d61b6f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/EtcdWithXmlELSpringbootTest.java @@ -28,75 +28,78 @@ import static org.mockito.Mockito.*; @TestPropertySource(value = "classpath:/etcd/application-xml-cluster.properties") @SpringBootTest(classes = EtcdWithXmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.etcd.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.etcd.cmp" }) public class EtcdWithXmlELSpringbootTest extends BaseTest { - @MockBean - private EtcdClient etcdClient; + @MockBean + private EtcdClient etcdClient; - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - private static final String SEPARATOR = "/"; + private static final String SEPARATOR = "/"; - private static final String CHAIN_PATH = "/liteflow/chain"; + private static final String CHAIN_PATH = "/liteflow/chain"; - private static final String SCRIPT_PATH = "/liteflow/script"; + private static final String SCRIPT_PATH = "/liteflow/script"; - @Before - public void setUp(){ - MockitoAnnotations.initMocks(this); - } + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } - @After - public void after(){ - FlowBus.cleanCache(); - } + @After + public void after() { + FlowBus.cleanCache(); + } - @Test - public void testEtcdNodeWithXml1() throws Exception { - List chainNameList = Lists.newArrayList("chain1"); - List scriptNodeValueList = Lists.newArrayList("s1:script:脚本s1"); - when(etcdClient.getChildrenKeys(anyString(), anyString())).thenReturn(chainNameList).thenReturn(scriptNodeValueList); + @Test + public void testEtcdNodeWithXml1() throws Exception { + List chainNameList = Lists.newArrayList("chain1"); + List scriptNodeValueList = Lists.newArrayList("s1:script:脚本s1"); + when(etcdClient.getChildrenKeys(anyString(), anyString())).thenReturn(chainNameList) + .thenReturn(scriptNodeValueList); - String chain1Data = "THEN(a, b, c, s1);"; - String scriptNodeValue = "defaultContext.setData(\"test\",\"hello\");"; - when(etcdClient.get(anyString())).thenReturn(chain1Data).thenReturn(scriptNodeValue); + String chain1Data = "THEN(a, b, c, s1);"; + String scriptNodeValue = "defaultContext.setData(\"test\",\"hello\");"; + when(etcdClient.get(anyString())).thenReturn(chain1Data).thenReturn(scriptNodeValue); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr()); - Assert.assertEquals("hello", context.getData("test")); - } + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr()); + Assert.assertEquals("hello", context.getData("test")); + } - @Test - public void testEtcdNodeWithXml2() throws Exception { - List chainNameList = Lists.newArrayList("chain1"); - List scriptNodeValueList = Lists.newArrayList("s1:script:脚本s1"); - when(etcdClient.getChildrenKeys(CHAIN_PATH, SEPARATOR)).thenReturn(chainNameList); - when(etcdClient.getChildrenKeys(SCRIPT_PATH, SEPARATOR)).thenReturn(scriptNodeValueList); + @Test + public void testEtcdNodeWithXml2() throws Exception { + List chainNameList = Lists.newArrayList("chain1"); + List scriptNodeValueList = Lists.newArrayList("s1:script:脚本s1"); + when(etcdClient.getChildrenKeys(CHAIN_PATH, SEPARATOR)).thenReturn(chainNameList); + when(etcdClient.getChildrenKeys(SCRIPT_PATH, SEPARATOR)).thenReturn(scriptNodeValueList); - String chain1Data = "THEN(a, b, c, s1);"; - String chain1ChangedData = "THEN(a, b, s1);"; - String scriptNodeValue = "defaultContext.setData(\"test\",\"hello\");"; - String scriptNodeChangedValue = "defaultContext.setData(\"test\",\"hello world\");"; - when(etcdClient.get(CHAIN_PATH + SEPARATOR + "chain1")).thenReturn(chain1Data).thenReturn(chain1ChangedData); - when(etcdClient.get(SCRIPT_PATH + SEPARATOR + "s1:script:脚本s1")).thenReturn(scriptNodeValue).thenReturn(scriptNodeChangedValue); + String chain1Data = "THEN(a, b, c, s1);"; + String chain1ChangedData = "THEN(a, b, s1);"; + String scriptNodeValue = "defaultContext.setData(\"test\",\"hello\");"; + String scriptNodeChangedValue = "defaultContext.setData(\"test\",\"hello world\");"; + when(etcdClient.get(CHAIN_PATH + SEPARATOR + "chain1")).thenReturn(chain1Data).thenReturn(chain1ChangedData); + when(etcdClient.get(SCRIPT_PATH + SEPARATOR + "s1:script:脚本s1")).thenReturn(scriptNodeValue) + .thenReturn(scriptNodeChangedValue); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr()); - Assert.assertEquals("hello", context.getData("test")); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStr()); + Assert.assertEquals("hello", context.getData("test")); - flowExecutor.reloadRule(); + flowExecutor.reloadRule(); - LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context2 = response2.getFirstContextBean(); - Assert.assertTrue(response2.isSuccess()); - Assert.assertEquals("a==>b==>s1[脚本s1]", response2.getExecuteStepStr()); - Assert.assertEquals("hello world", context2.getData("test")); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context2 = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertEquals("a==>b==>s1[脚本s1]", response2.getExecuteStepStr()); + Assert.assertEquals("hello world", context2.getData("test")); + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/cmp/ACmp.java index 6d1ae42c..2a481f4b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-etcd-springboot/src/test/java/com/yomahub/liteflow/test/etcd/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java index cfdebcee..1f5a97f2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/NacosWithXmlELSpringbootTest.java @@ -26,8 +26,8 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; /** - * springboot环境下的nacos配置源功能测试 - * nacos存储数据的格式为xml文件 + * springboot环境下的nacos配置源功能测试 nacos存储数据的格式为xml文件 + * * @author mll * @since 2.9.0 */ @@ -35,41 +35,43 @@ import static org.mockito.Mockito.when; @TestPropertySource(value = "classpath:/nacos/application-xml.properties") @SpringBootTest(classes = NacosWithXmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.nacos.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.nacos.cmp" }) public class NacosWithXmlELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @MockBean - private NacosConfigService nacosConfigService; + @MockBean + private NacosConfigService nacosConfigService; - @After - public void after(){ - FlowBus.cleanCache(); - } + @After + public void after() { + FlowBus.cleanCache(); + } - @Test - public void testNacosWithXml1() throws Exception { - String flowXml = "THEN(a, b, c);"; - when(nacosConfigService.getConfig(anyString(), anyString(), anyLong())).thenReturn(flowXml); + @Test + public void testNacosWithXml1() throws Exception { + String flowXml = "THEN(a, b, c);"; + when(nacosConfigService.getConfig(anyString(), anyString(), anyLong())).thenReturn(flowXml); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStrWithoutTime()); - } + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testNacosWithXml2() throws Exception { - String flowXml = "THEN(a, b, c);"; - String changedFlowXml = "THEN(a, c);"; - when(nacosConfigService.getConfig(anyString(), anyString(), anyLong())).thenReturn(flowXml).thenReturn(changedFlowXml); + @Test + public void testNacosWithXml2() throws Exception { + String flowXml = "THEN(a, b, c);"; + String changedFlowXml = "THEN(a, c);"; + when(nacosConfigService.getConfig(anyString(), anyString(), anyLong())).thenReturn(flowXml) + .thenReturn(changedFlowXml); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStrWithoutTime()); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStrWithoutTime()); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML,changedFlowXml); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, changedFlowXml); + + response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); + } - response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/cmp/ACmp.java index 6e6300a7..d8a4f979 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nacos-springboot/src/test/java/com/yomahub/liteflow/test/nacos/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 6721d3d6..1acabc13 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowExecutorHolder.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowExecutorHolder.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java index fc2c0369..537fb9ce 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathTest.java @@ -11,23 +11,25 @@ import org.junit.Test; /** * 非spring环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.11 */ public class AbsoluteConfigPathTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("/usr/local/flow2.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("/usr/local/flow2.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testAbsoluteConfig() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testAbsoluteConfig() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java index 65c4175b..d1b05485 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/asyncNode/AsyncNodeTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeTest.java index 22562ac2..d538d1b7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeTest.java @@ -13,124 +13,123 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author ssss */ public class AsyncNodeTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("asyncNode/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("asyncNode/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - /***** - * 标准chain 嵌套选择 嵌套子chain进行执行 - * 验证了when情况下 多个node是并行执行 - * 验证了默认参数情况下 when可以加载执行 - * **/ - @Test - public void testAsyncFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - System.out.println(response.getExecuteStepStr()); - } + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 验证了when情况下 多个node是并行执行 验证了默认参数情况下 when可以加载执行 + **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getExecuteStepStr()); + } - //这个和test1有点类似,只不过进一步验证了步骤 - @Test - public void testAsyncFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); - Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", - "b==>j==>h==>g==>f","b==>j==>h==>f==>g", - "b==>j==>f==>h==>g","b==>j==>f==>g==>h" - ).contains(response.getExecuteStepStr())); - } + // 这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue( + ListUtil + .toList("b==>j==>g==>f==>h", "b==>j==>g==>h==>f", "b==>j==>h==>g==>f", "b==>j==>h==>f==>g", + "b==>j==>f==>h==>g", "b==>j==>f==>g==>h") + .contains(response.getExecuteStepStr())); + } - //测试errorResume,默认的errorResume为false,这里测试默认的 - @Test - public void testAsyncFlow3_1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); - } + // 测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } - //测试errorResume,默认的errorResume为false,这里设置为true - @Test - public void testAsyncFlow3_2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - } + // 测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 - @Test - public void testAsyncFlow4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //因为不记录错误,所以最终结果是true - Assert.assertTrue(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为配置了不抛错,所以response里的cause应该为null - Assert.assertNull(response.getCause()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 - @Test - public void testAsyncFlow5() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //整个并行组是报错的,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为第一个when配置了会报错,所以response里的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } - //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 - @Test - public void testAsyncFlow6() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第一个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(1), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(1), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } - //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 - @Test - public void testAsyncFlow7() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第二个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - // 传递了slotIndex,则set的size==2 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 测试任意异步一个执行完即继续的场景 + // d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + // 最终执行效果应该是h先返回,然后执行abc,最后gd + // 这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("check").toString().startsWith("habc")); + } - //测试任意异步一个执行完即继续的场景 - //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 - //最终执行效果应该是h先返回,然后执行abc,最后gd - //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 - @Test - public void testAsyncFlow8() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("check").toString().startsWith("habc")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java index 78a70c66..55d836c0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java @@ -3,20 +3,22 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; - public class ACmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Acomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java index 82619326..40680dca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java @@ -3,20 +3,22 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; - public class BCmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Bcomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java index 269e8d7f..1974cc5a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java @@ -3,20 +3,22 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; - public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java index 4dff67b0..572d4412 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java @@ -3,21 +3,23 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; - public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(1000); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + Thread.sleep(1000); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java index 656b8139..4153ab47 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java @@ -2,12 +2,12 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; - public class ECmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Ecomp executed!"); - return "g"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java index 90829331..0d7ec471 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java @@ -2,11 +2,11 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; - public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Fcomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Fcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java index 5e956d24..a515c498 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java @@ -3,22 +3,23 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; - public class GCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(500); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Gcomp executed!"); - } + @Override + public void process() throws Exception { + Thread.sleep(500); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java index dc10078a..6d4da563 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java @@ -3,22 +3,23 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; - public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java index 4ad3043b..876bab54 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java @@ -4,21 +4,22 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.test.asyncNode.exception.TestException; - public class ICmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (ICmp.class){ - if (context.hasData("count")) { - Integer count = context.getData("count"); - context.setData("count", ++count); - } else { - context.setData("count", 1); - } - } - System.out.println("Icomp executed! throw Exception!"); - throw new TestException(); - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (ICmp.class) { + if (context.hasData("count")) { + Integer count = context.getData("count"); + context.setData("count", ++count); + } + else { + context.setData("count", 1); + } + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } + } \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java index 0a954eb3..5155accc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java @@ -2,12 +2,12 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; - public class JCmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Jcomp executed!"); - return "chain3"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java index e786e9f8..fa8827df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -1,4 +1,5 @@ package com.yomahub.liteflow.test.asyncNode.exception; -public class TestException extends Exception{ +public class TestException extends Exception { + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java index 48bad8b7..e3f91c40 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/BaseCommonTest.java @@ -9,20 +9,21 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -public class BaseCommonTest extends BaseTest{ +public class BaseCommonTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("base/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("base/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testBase() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "test0"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testBase(){ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "test0"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java index e7d9de39..ea85a4f2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/base/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/cmp/ECmp.java index df59cd64..0f728b92 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/base/cmp/ECmp.java @@ -15,4 +15,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/BuilderTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/BuilderTest.java index 0a0ab6b0..e3acc5f7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/BuilderTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/BuilderTest.java @@ -16,149 +16,163 @@ import org.junit.Test; public class BuilderTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //基于普通组件的builder模式测试 - @Test - public void testBuilder() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp.BCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp.CCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz("com.yomahub.liteflow.test.builder.cmp.ECmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp.FCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp.GCmp") - .build(); + // 基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.BCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.CCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz("com.yomahub.liteflow.test.builder.cmp.ECmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.FCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp.GCmp") + .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + // 基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz(GCmp.class) + .build(); - //基于普通组件的builder模式测试 - @Test - public void testBuilderForClassAndCode() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz(BCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz(DCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz(ECmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz(FCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz(GCmp.class) - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + // 基于普通组件的builder模式测试 + @Test + public void testBuilderForSameNodeMultiTimes() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a1") + .setName("组件A1") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("a2") + .setName("组件A2") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c1") + .setName("组件C1") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c2") + .setName("组件C2") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); - //基于普通组件的builder模式测试 - @Test - public void testBuilderForSameNodeMultiTimes() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a1") - .setName("组件A1") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("a2") - .setName("组件A2") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c1") - .setName("组件C1") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c2") - .setName("组件C2") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(a1,c2,a2,c1)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a1,c2,a2,c1)" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/cmp/ACmp.java index 79528ab3..512b0f2f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/builder/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/cmpRetry/LiteflowRetryTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryTest.java index 19eb7df8..f8ed19ce 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryTest.java @@ -9,53 +9,54 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; - /** * 测试非spring下的节点执行器 + * * @author Bryan.Zhang * @since 2.5.10 */ public class LiteflowRetryTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("cmpRetry/flow.el.xml"); - config.setRetryCount(3); - config.setSlotSize(512); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("cmpRetry/flow.el.xml"); + config.setRetryCount(3); + config.setSlotSize(512); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //全局重试配置测试 - @Test - public void testRetry1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); - } + // 全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); + } - //单个组件重试配置测试 - @Test - public void testRetry2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); - } + // 单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); + } - //单个组件指定异常,但抛出的并不是指定异常的场景测试 - @Test - public void testRetry3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - } + // 单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + // 单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); + } - //单个组件指定异常重试,抛出的是指定异常或者 - @Test - public void testRetry4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java index 19337ec4..da165277 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/cmpRetry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java index 0eaf4623..e0abb492 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -16,7 +16,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java index a1f51a9e..1425a2a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -10,7 +10,7 @@ package com.yomahub.liteflow.test.cmpRetry.cmp; import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java index bef09bb5..23088bc6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -10,7 +10,7 @@ package com.yomahub.liteflow.test.cmpRetry.cmp; import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class ECmp extends NodeComponent { @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepTest.java index e4b253fb..07e65f86 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepTest.java @@ -15,52 +15,54 @@ import java.util.Map; import java.util.Queue; import java.util.Set; -public class CmpStepTest extends BaseTest{ +public class CmpStepTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("cmpStep/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("cmpStep/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testStep1(){ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); - } + @Test + public void testStep1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); + } - @Test - public void testStep2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testStep2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testStep3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Map stepMap = response.getExecuteSteps(); - Assert.assertEquals(2, stepMap.size()); - Queue queue = response.getExecuteStepQueue(); - Assert.assertEquals(5, queue.size()); + @Test + public void testStep3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Map stepMap = response.getExecuteSteps(); + Assert.assertEquals(2, stepMap.size()); + Queue queue = response.getExecuteStepQueue(); + Assert.assertEquals(5, queue.size()); - Set tagSet = new HashSet<>(); - response.getExecuteStepQueue().stream().filter( - cmpStep -> cmpStep.getNodeId().equals("a") - ).forEach(cmpStep -> tagSet.add(cmpStep.getTag())); + Set tagSet = new HashSet<>(); + response.getExecuteStepQueue() + .stream() + .filter(cmpStep -> cmpStep.getNodeId().equals("a")) + .forEach(cmpStep -> tagSet.add(cmpStep.getTag())); - Assert.assertEquals(3, tagSet.size()); + Assert.assertEquals(3, tagSet.size()); + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java index 5f9cb70f..78c125ae 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java @@ -12,8 +12,9 @@ import com.yomahub.liteflow.core.NodeComponent; public class ACmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Thread.sleep(5000L); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java index ed3f5e4e..ad3b4cc8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.core.NodeComponent; public class CCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); Thread.sleep(2000); throw new RuntimeException("test error c"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java index 10d6b90e..a61ab0a5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java @@ -20,4 +20,5 @@ public class ECmp extends NodeComponent { public boolean isAccess() { return false; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeTest.java index 4585b5b1..b48125f6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeTest.java @@ -18,7 +18,7 @@ public class LiteflowNodeTest extends BaseTest { private static FlowExecutor flowExecutor; @BeforeClass - public static void init(){ + public static void init() { LiteflowConfig config = new LiteflowConfig(); config.setRuleSource("comments/flow.el.xml"); flowExecutor = FlowExecutorHolder.loadInstance(config); @@ -29,6 +29,7 @@ public class LiteflowNodeTest extends BaseTest { public void testAsyncFlow1() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr())); + Assert.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr())); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java index c078f3ba..d0f42433 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java @@ -9,10 +9,11 @@ package com.yomahub.liteflow.test.comments.cmp; import com.yomahub.liteflow.core.NodeComponent; -public class ACmp extends 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/comments/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java index e129a3a3..32300389 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java @@ -16,4 +16,5 @@ public class BCmp extends NodeComponent { public void process() { System.out.println("BCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java index 24d5c3f3..de97af78 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java @@ -10,75 +10,75 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * 组件功能点测试 - * 单元测试 + * 组件功能点测试 单元测试 * * @author donguo.tao */ public class FlowExecutorTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("component/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("component/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //isAccess方法的功能测试 - @Test - public void testIsAccess() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); - Assert.assertTrue(response.isSuccess()); - Assert.assertNotNull(response.getSlot().getResponseData()); - } + // isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } - //组件抛错的功能点测试 - @Test(expected = ArithmeticException.class) - public void testComponentException() throws Throwable { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("/ by zero", response.getMessage()); - throw response.getCause(); - } + // 组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Throwable { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + throw response.getCause(); + } - //isContinueOnError方法的功能点测试 - @Test - public void testIsContinueOnError() throws Throwable { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCause()); - } + // isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Throwable { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } - //isEnd方法的功能点测试 - @Test - public void testIsEnd() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d",response.getExecuteStepStr()); - } + // isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d", response.getExecuteStepStr()); + } - //setIsEnd方法的功能点测试 - @Test - public void testSetIsEnd1() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("e",response.getExecuteStepStr()); - } + // setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e", response.getExecuteStepStr()); + } - //条件组件的功能点测试 - @Test - public void testNodeCondComponent() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); - Assert.assertTrue(response.isSuccess()); - } + // 条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + // 测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试setIsEnd如果为true,continueError也为true,那不应该continue了 - @Test - public void testSetIsEnd2() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g",response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java index a124e69c..8f805d0d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -4,21 +4,22 @@ import com.yomahub.liteflow.core.NodeComponent; import java.util.Objects; - public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("AComp executed!"); - this.getSlot().setResponseData("AComp executed!"); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData) && requestData > 100){ - return true; - } - System.out.println("AComp isAccess false."); - return false; - } + @Override + public void process() { + System.out.println("AComp executed!"); + this.getSlot().setResponseData("AComp executed!"); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100) { + return true; + } + System.out.println("AComp isAccess false."); + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java index 839751ab..1fb6f31b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -4,24 +4,24 @@ import com.yomahub.liteflow.core.NodeComponent; import java.util.Objects; - public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("BComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java index be659b12..7ad7d806 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -4,24 +4,25 @@ import com.yomahub.liteflow.core.NodeComponent; import java.util.Objects; - public class CCmp extends NodeComponent { - @Override - public void process() { - System.out.println("CComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - System.out.println("responseData="+Integer.parseInt(this.getSlot().getResponseData())); - } - @Override - public boolean isContinueOnError() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("CComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + System.out.println("responseData=" + Integer.parseInt(this.getSlot().getResponseData())); + } + + @Override + public boolean isContinueOnError() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java index b90d1f53..df6da43c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -4,21 +4,22 @@ import com.yomahub.liteflow.core.NodeComponent; import java.util.Objects; - public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("DComp executed!"); - } - @Override - public boolean isEnd() { - //组件的process执行完之后才会执行isEnd - Object requestData = this.getSlot().getResponseData(); - if (Objects.isNull(requestData)){ - System.out.println("DComp flow isEnd, because of responseData is null."); - return true; - } - return false; - } + @Override + public void process() throws Exception { + System.out.println("DComp executed!"); + } + + @Override + public boolean isEnd() { + // 组件的process执行完之后才会执行isEnd + Object requestData = this.getSlot().getResponseData(); + if (Objects.isNull(requestData)) { + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java index a637f809..c9f79ef3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -5,18 +5,18 @@ import com.yomahub.liteflow.util.JsonUtil; import java.util.Objects; - public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("EComp executed!"); - Object responseData = this.getSlot().getResponseData(); - if (Objects.isNull(responseData)){ - System.out.println("EComp responseData flow must be set end ."); - //执行到某个条件时,手动结束流程。 - this.setIsEnd(true); - } - System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); - } + @Override + public void process() throws Exception { + System.out.println("EComp executed!"); + Object responseData = this.getSlot().getResponseData(); + if (Objects.isNull(responseData)) { + System.out.println("EComp responseData flow must be set end ."); + // 执行到某个条件时,手动结束流程。 + this.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java index 2f0d6c95..2e8c19fb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -21,4 +21,5 @@ public class GCmp extends NodeComponent { public boolean isContinueOnError() { return true; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java index 21c9bccb..2f616241 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -15,4 +15,5 @@ public class HCmp extends NodeComponent { public void process() { System.out.println("HCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java index dd99beb9..f7a1167c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java @@ -5,15 +5,19 @@ import com.yomahub.liteflow.core.NodeSwitchComponent; import java.util.Objects; public class FSwitchCmp extends NodeSwitchComponent { - @Override - public String processSwitch() { - Integer requestData = this.getRequestData(); - if (Objects.isNull(requestData)){ - return "d"; - } else if(requestData == 0){ - return "c"; - } else { - return "b"; - } - } + + @Override + public String processSwitch() { + Integer requestData = this.getRequestData(); + if (Objects.isNull(requestData)) { + return "d"; + } + else if (requestData == 0) { + return "c"; + } + else { + return "b"; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java index 2195047a..f5eac6ee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java @@ -12,33 +12,35 @@ import org.junit.Test; /** * 非spring环境下参数单元测试 + * * @author zendwang * @since 2.5.0 */ public class LiteflowConfigTest1 extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; + + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("config/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testConfig() { + LiteflowConfig config = LiteflowConfigGetter.get(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("config/flow.el.xml", config.getRuleSource()); + Assert.assertEquals(15, config.getWhenMaxWaitSeconds().intValue()); + Assert.assertEquals(200, config.getQueueLimit().intValue()); + Assert.assertEquals(300000L, config.getDelay().longValue()); + Assert.assertEquals(300000L, config.getPeriod().longValue()); + Assert.assertFalse(config.getEnableLog()); + Assert.assertEquals(16, config.getWhenMaxWorkers().longValue()); + Assert.assertEquals(512, config.getWhenQueueLimit().longValue()); + Assert.assertEquals(true, config.isParseOnStart()); + } - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("config/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } - - @Test - public void testConfig() { - LiteflowConfig config = LiteflowConfigGetter.get(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("config/flow.el.xml", config.getRuleSource()); - Assert.assertEquals(15, config.getWhenMaxWaitSeconds().intValue()); - Assert.assertEquals(200, config.getQueueLimit().intValue()); - Assert.assertEquals(300000L, config.getDelay().longValue()); - Assert.assertEquals(300000L, config.getPeriod().longValue()); - Assert.assertFalse(config.getEnableLog()); - Assert.assertEquals(16, config.getWhenMaxWorkers().longValue()); - Assert.assertEquals(512, config.getWhenQueueLimit().longValue()); - Assert.assertEquals(true, config.isParseOnStart()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java index cecd0c49..703fbc7a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6f88c4cd..6034ba62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -9,17 +9,15 @@ import java.util.concurrent.ExecutorService; public class CustomThreadExecutor1 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-1-thead-"); - } + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 7d45e4ad..8f9008e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor2 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-2-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index 875dc3d1..dc6f6399 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor3 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-3-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java index a38b572f..6a6ae34c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java @@ -18,50 +18,50 @@ import org.junit.Test; */ public class CustomWhenThreadPoolTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("customWhenThreadPool/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("customWhenThreadPool/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - /** - * 测试全局线程池配置 - */ - @Test - public void testGlobalThreadPool() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); - } + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); + } - /** - * 测试全局和when上自定义线程池-优先以when上为准 - */ - @Test - public void testGlobalAndCustomWhenThreadPool() { - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response1.getFirstContextBean(); - Assert.assertTrue(response1.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - } + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - /** - * when配置的线程池可以共用 - */ - @Test - public void testCustomWhenThreadPool() { - // 使用when - thread1 - testGlobalAndCustomWhenThreadPool(); - // chain配置同一个thead1 - LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response2.getFirstContextBean(); - Assert.assertTrue(response2.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java index 904aa20d..d681ab2f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/event/EventTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/EventTest.java index 82ce0324..308e27e1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/EventTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/EventTest.java @@ -10,45 +10,46 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -public class EventTest extends BaseTest{ +public class EventTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("event/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("event/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //测试组件成功事件 - @Test - public void testEvent1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("abc", context.getData("test")); - } + // 测试组件成功事件 + @Test + public void testEvent1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("abc", context.getData("test")); + } - //测试组件失败事件 - @Test - public void testEvent2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("ab", context.getData("test")); - Assert.assertEquals("error:d", context.getData("error")); - } + // 测试组件失败事件 + @Test + public void testEvent2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("ab", context.getData("test")); + Assert.assertEquals("error:d", context.getData("error")); + } + + // 测试组件失败事件本身抛出异常 + @Test + public void testEvent3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("a", context.getData("test")); + Assert.assertEquals("error:e", context.getData("error")); + } - //测试组件失败事件本身抛出异常 - @Test - public void testEvent3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("a", context.getData("test")); - Assert.assertEquals("error:e", context.getData("error")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java index d4c72e05..b7272ce7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java @@ -15,7 +15,7 @@ public class ACmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",""); + context.setData("test", ""); System.out.println("ACmp executed!"); } @@ -26,4 +26,5 @@ public class ACmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java index b3328cd9..629cdb08 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java @@ -24,4 +24,5 @@ public class BCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java index 6815efbb..81de6b02 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java @@ -24,4 +24,5 @@ public class CCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java index 502b4e39..3114c491 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.slot.DefaultContext; public class DCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -21,6 +21,7 @@ public class DCmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java index 6bc89b13..a1d03798 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.slot.DefaultContext; public class ECmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -21,7 +21,8 @@ public class ECmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); throw new IllegalAccessException("错误事件回调本身抛出异常"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java index 11441ab5..e7b2394c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java @@ -6,7 +6,9 @@ import com.yomahub.liteflow.exception.LiteFlowException; * 用户自定义带状态码的异常 */ public class CustomStatefulException extends LiteFlowException { + public CustomStatefulException(String code, String message) { super(code, message); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java index a6ff7ac9..3f5daab6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception1Test.java @@ -17,43 +17,43 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ public class Exception1Test extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("exception/flow.el.xml"); - config.setWhenMaxWaitSeconds(1); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("exception/flow.el.xml"); + config.setWhenMaxWaitSeconds(1); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - /** - * 验证 chain 节点重复的异常 - */ - @Test(expected = ChainDuplicateException.class) - public void testChainDuplicateException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-exception.el.xml"); - flowExecutor.reloadRule(); - } + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = ChainDuplicateException.class) + public void testChainDuplicateException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = ConfigErrorException.class) - public void testConfigErrorException() { - flowExecutor.setLiteflowConfig(null); - flowExecutor.reloadRule(); - } + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.reloadRule(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("error/flow.txt"); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testFlowExecutorNotInitException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("error/flow.txt"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception2Test.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception2Test.java index 2757d566..69b9116c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception2Test.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/Exception2Test.java @@ -15,70 +15,71 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ public class Exception2Test extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("exception/flow.el.xml"); - config.setWhenMaxWaitSeconds(1); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } - @Test(expected = ChainNotFoundException.class) - public void testChainNotFoundException() throws Exception { - flowExecutor.execute("chain0", "it's a request"); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("exception/flow.el.xml"); + config.setWhenMaxWaitSeconds(1); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test(expected = RuntimeException.class) - public void testComponentCustomException() throws Exception { - flowExecutor.execute("chain1", "exception"); - } + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } - @Test(expected = FlowSystemException.class) - public void testNoConditionInChainException() throws Throwable { - LiteFlowChainELBuilder.createChain().setChainId("chain2").build(); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "test"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("no conditionList in this chain[chain2]", response.getMessage()); - throw response.getCause(); - } + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } - @Test - public void testGetSlotFromResponseWhenException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); - Assert.assertFalse(response.isSuccess()); - Assert.assertNotNull(response.getCause()); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = FlowSystemException.class) + public void testNoConditionInChainException() throws Throwable { + LiteFlowChainELBuilder.createChain().setChainId("chain2").build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("no conditionList in this chain[chain2]", response.getMessage()); + throw response.getCause(); + } - @Test(expected = NoSwitchTargetNodeException.class) - public void testNoTargetFindException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); - Assert.assertFalse(response.isSuccess()); - throw response.getCause(); - } + @Test + public void testGetSlotFromResponseWhenException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } - @Test - public void testInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("300", response.getCode()); - Assert.assertNotNull(response.getCause()); - Assert.assertTrue(response.getCause() instanceof LiteFlowException); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = NoSwitchTargetNodeException.class) + public void testNoTargetFindException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); + Assert.assertFalse(response.isSuccess()); + throw response.getCause(); + } + + @Test + public void testInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("300", response.getCode()); + Assert.assertNotNull(response.getCause()); + Assert.assertTrue(response.getCause() instanceof LiteFlowException); + Assert.assertNotNull(response.getSlot()); + } + + @Test + public void testNotInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCode()); + } - @Test - public void testNotInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCode()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java index 5067260a..a0dbe57d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -13,13 +13,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ACmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new RuntimeException("chain execute execption"); } LOG.info("Acomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java index 2bcd41e9..0aad248d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -13,21 +13,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class BCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); @Override public void process() throws InterruptedException { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("when")) { + if (StrUtil.isNotBlank(str) && str.equals("when")) { try { LOG.info("Bcomp sleep begin"); Thread.sleep(3000); LOG.info("Bcomp sleep end"); - } catch (InterruptedException e) { + } + catch (InterruptedException e) { throw e; } } LOG.info("Bcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java index 7adc2416..23ea9585 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -12,11 +12,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class CCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); - + @Override public void process() { LOG.info("Ccomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java index 17194763..b58ca786 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -12,14 +12,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); - + @Override public void process() { - if(1==1){ - int a = 1/0; + if (1 == 1) { + int a = 1 / 0; } LOG.info("Dcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java index 69314881..bc54af11 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java @@ -15,4 +15,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "a"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java index ea6977b0..d1a2e5d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java @@ -14,13 +14,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class FCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(FCmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { + if (StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { throw new CustomStatefulException("300", "chain execute custom stateful execption"); } LOG.info("Fcomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java index c82a9523..dcad4f2d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java @@ -12,11 +12,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class GCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(GCmp.class); - + @Override public void process() { LOG.info("Gcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureTest.java index e38c30f5..14d1412f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureTest.java @@ -14,25 +14,26 @@ import java.util.concurrent.Future; /** * nospring环境执行返回future的例子 + * * @author Bryan.Zhang * @since 2.6.13 */ public class Executor2FutureTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("execute2Future/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("execute2Future/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testFuture() throws Exception{ - Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); - LiteflowResponse response = future.get(); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testFuture() throws Exception { + Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java index bd4d7493..124e9301 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/flowmeta/FlowMetaTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaTest.java index 088f926e..aa4d2e45 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaTest.java @@ -14,22 +14,23 @@ import org.junit.Test; public class FlowMetaTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("flowmeta/flow.el.xml"); - config.setParseOnStart(false); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("flowmeta/flow.el.xml"); + config.setParseOnStart(false); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 测试动态添加元信息节点 + @Test + public void testFlowMeta() { + FlowBus.addNode("d", "d组件", NodeTypeEnum.COMMON, DCmp.class); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>d[d组件]", response.getExecuteStepStr()); + } - //测试动态添加元信息节点 - @Test - public void testFlowMeta() { - FlowBus.addNode("d", "d组件", NodeTypeEnum.COMMON, DCmp.class); - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>d[d组件]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java index a7d1fbe5..03ba6e25 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/getChainName/GetChainNameELTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELTest.java index bff523d4..038b996c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELTest.java @@ -12,45 +12,46 @@ import org.junit.Test; /** * nospring环境获取ChainName的测试 + * * @author Bryan.Zhang */ public class GetChainNameELTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("getChainName/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("getChainName/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testGetChainName1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - } + @Test + public void testGetChainName1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } - @Test - public void testGetChainName2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("chain2", context.getData("g")); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - Assert.assertEquals("sub5", context.getData("f")); - Assert.assertEquals("sub5_chain2", context.getData("e")); - Assert.assertEquals("sub6", context.getData("h")); - Assert.assertEquals("sub6", context.getData("j")); - Assert.assertNull(context.getData("k")); - } + @Test + public void testGetChainName2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java index fbbb648f..4edaf588 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { DefaultContext context = this.getFirstContextBean(); context.setData(this.getNodeId(), this.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java index 6866fe68..caec7f28 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -15,9 +15,10 @@ public class ECmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - if (context.hasData(this.getNodeId())){ + if (context.hasData(this.getNodeId())) { context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainId()); - }else{ + } + else { context.setData(this.getNodeId(), this.getCurrChainId()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseTest.java index bc56e00c..c2a2d583 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseTest.java @@ -9,70 +9,71 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -public class IfElseTest extends BaseTest{ +public class IfElseTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("ifelse/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("ifelse/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 9d209f97..65e08778 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 @@ -10,8 +10,10 @@ package com.yomahub.liteflow.test.ifelse.cmp; import com.yomahub.liteflow.core.NodeIfComponent; public class X1Cmp extends NodeIfComponent { + @Override public boolean processIf() 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/IteratorTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/IteratorTest.java index 5f3e2c0f..884281ec 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/IteratorTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/IteratorTest.java @@ -13,36 +13,37 @@ import org.junit.Test; import java.util.List; -public class IteratorTest extends BaseTest{ +public class IteratorTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("iterator/flow.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("iterator/flow.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //最简单的情况 - @Test - public void testIt1() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("123", str); - } + // 最简单的情况 + @Test + public void testIt1() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("123", str); + } + + // 迭代器带break + @Test + public void testIt2() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("12", str); + } - //迭代器带break - @Test - public void testIt2() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("12", str); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java index 8d366b37..55add7aa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java @@ -16,12 +16,14 @@ public class ACmp extends NodeComponent { public void process() { String key = "test"; DefaultContext context = this.getFirstContextBean(); - if (!context.hasData(key)){ + if (!context.hasData(key)) { context.setData(key, this.getCurrLoopObj()); - }else{ + } + else { String str = context.getData(key); str += this.getCurrLoopObj(); context.setData(key, str); } } + } 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 8ccfda17..2240c45d 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 @@ -9,4 +9,5 @@ public class BCmp extends NodeBreakComponent { public boolean processBreak() throws Exception { return this.getLoopIndex() == 1; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java index d3c5a763..1fca584d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java @@ -6,9 +6,11 @@ import java.util.Iterator; import java.util.List; public class ITCmp extends NodeIteratorComponent { - @Override - public Iterator processIterator() throws Exception { - List list = this.getRequestData(); - return list.iterator(); - } + + @Override + public Iterator processIterator() throws Exception { + List list = this.getRequestData(); + return list.iterator(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/LoopTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/LoopTest.java index e1f44955..a35bb973 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/LoopTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/LoopTest.java @@ -10,75 +10,78 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -public class LoopTest extends BaseTest{ +public class LoopTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("loop/flow.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("loop/flow.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //测试FOR循环中的index - @Test - public void testLoop6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } + // 测试FOR循环中的index + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } + + // 测试WHILE循环中的index + @Test + public void testLoop7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } - //测试WHILE循环中的index - @Test - public void testLoop7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java index eb98efda..074e96c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java index f2bf0d4c..2bd97a2d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java @@ -16,10 +16,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java index c289433e..418417dd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java @@ -17,11 +17,12 @@ public class ECmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = StrUtil.format("{}_{}", "loop", this.getTag()); - if (context.hasData(key)){ + if (context.hasData(key)) { String loopStr = context.getData(key); String loopStrReturn = StrUtil.format("{}{}", loopStr, this.getLoopIndex()); context.setData(key, loopStrReturn); - }else{ + } + else { context.setData(key, this.getLoopIndex().toString()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java index 9a8b1e97..1cc56579 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java @@ -3,8 +3,10 @@ package com.yomahub.liteflow.test.loop.cmp; import com.yomahub.liteflow.core.NodeForComponent; public class XCmp extends NodeForComponent { - @Override - public int processFor() throws Exception { - return 3; - } + + @Override + public int processFor() throws Exception { + return 3; + } + } 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 8aba0770..c201f9eb 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 @@ -4,10 +4,12 @@ import com.yomahub.liteflow.core.NodeBreakComponent; import com.yomahub.liteflow.slot.DefaultContext; public class YCmp extends NodeBreakComponent { - @Override - public boolean processBreak() throws Exception { - DefaultContext context = this.getFirstContextBean(); - int count = context.getData("test"); - return count > 3; - } + + @Override + public boolean processBreak() 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 0d66b22c..657bc890 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 @@ -4,15 +4,18 @@ import com.yomahub.liteflow.core.NodeWhileComponent; import com.yomahub.liteflow.slot.DefaultContext; public class ZCmp extends NodeWhileComponent { - @Override - public boolean processWhile() throws Exception { - DefaultContext context = this.getFirstContextBean(); - String key = "test"; - if (context.hasData(key)){ - int count = context.getData("test"); - return count < 5; - }else{ - return true; - } - } + + @Override + public boolean processWhile() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } + else { + return true; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java index 15a4f13a..3ca2731f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/LiteflowMonitorFileTest.java @@ -16,25 +16,25 @@ import java.io.File; public class LiteflowMonitorFileTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init() { - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("monitorFile/flow.el.xml"); - config.setEnableMonitorFile(true); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("monitorFile/flow.el.xml"); + config.setEnableMonitorFile(true); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testMonitor() throws InterruptedException { - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); - } + @Test + public void testMonitor() throws InterruptedException { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java index f022ab13..d99aa2b9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/multipleType/LiteflowMultipleTypeTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java index 11c6d40b..dfcbc6bc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java @@ -11,28 +11,30 @@ import org.junit.Test; /** * 测试非spring下混合格式规则的场景 + * * @author Bryan.Zhang * @since 2.5.10 */ public class LiteflowMultipleTypeTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("multipleType/flow.el.xml,multipleType/flow.el.yml"); - config.setSupportMultipleType(true); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("multipleType/flow.el.xml,multipleType/flow.el.yml"); + config.setSupportMultipleType(true); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } - @Test - public void testMultipleType() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); - response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java index a2080ed3..cf6136ae 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java index 9fb99224..9cce6d74 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -8,11 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义默认的节点执行器 */ public class CustomerDefaultNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerDefaultNodeExecutor进行执行"); - context.setData("customerDefaultNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + context.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java index e4ef70e0..f4d447b6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -8,12 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义节点执行器 */ public class CustomerNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutor进行执行"); - context.setData("customerNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutor进行执行"); + context.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java index 202005b1..130208a7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -10,19 +10,21 @@ import java.util.concurrent.TimeUnit; * 自定义节点执行器 */ public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); - context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); - super.execute(instance); - } - @Override - protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { - TimeUnit.MICROSECONDS.sleep(20L); - DefaultContext context = instance.getFirstContextBean(); - context.setData("retryLogic", this.getClass()); - super.retry(instance, currentRetryCount); - } + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + DefaultContext context = instance.getFirstContextBean(); + context.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorTest.java index eeebacde..0bdecdb9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorTest.java @@ -10,61 +10,62 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; - /** * 测试非spring环境下的自定义组件执行器 + * * @author Bryan.Zhang * @since 2.5.10 */ public class LiteflowNodeExecutorTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("nodeExecutor/flow.el.xml"); - config.setRetryCount(3); - config.setSlotSize(512); - config.setNodeExecutorClass("com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("nodeExecutor/flow.el.xml"); + config.setRetryCount(3); + config.setSlotSize(512); + config.setNodeExecutorClass("com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - // 默认执行器测试 - @Test - public void testCustomerDefaultNodeExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("a", response.getExecuteStepStr()); - } + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getExecuteStepStr()); + } - //默认执行器测试+全局重试配置测试 - @Test - public void testDefaultExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); - } + // 默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); + } - //自定义执行器测试 - @Test - public void testCustomerExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("c", response.getExecuteStepStr()); - } + // 自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStr()); + } + + // 自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); + } - //自定义执行器测试+全局重试配置测试 - @Test - public void testCustomExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); - Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java index 1396310b..3ef90d2e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java @@ -12,9 +12,9 @@ import com.yomahub.liteflow.core.NodeComponent; public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("ACmp executed!"); - } + @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/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java index 4ab073c4..ca4712d0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -16,7 +16,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java index 688c54d1..26c7859e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -21,7 +21,8 @@ public class CCmp extends NodeComponent { } @Override - public Class getNodeExecutorClass() { + public Class getNodeExecutorClass() { return CustomerNodeExecutor.class; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java index 00ca11e4..9b6280cc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -13,17 +13,18 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.flow.executor.NodeExecutor; import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { - @Override - public void process() { - System.out.println("DCmp executed!"); - throw new NullPointerException("demo exception"); - } + @Override + public void process() { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @Override + public Class getNodeExecutorClass() { + return CustomerNodeExecutorAndCustomRetry.class; + } - @Override - public Class getNodeExecutorClass() { - return CustomerNodeExecutorAndCustomRetry.class; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java index fb0f2f37..2aac6e70 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java @@ -16,22 +16,22 @@ import org.junit.Test; */ public class NullParamTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("nullParam/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("nullParam/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - /** - * 支持无参的flow执行,以及param 为null时的异常抛出 - */ - @Test - public void testNullParam() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - } + /** + * 支持无参的flow执行,以及param 为null时的异常抛出 + */ + @Test + public void testNullParam() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java index 4c29cc07..df35fe7a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { System.out.println("get request data:" + this.getRequestData()); this.getSlot().setInput("BCmp", "param for BCmp"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonTest.java index 9c497099..6bd18a78 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonTest.java @@ -11,24 +11,26 @@ import org.junit.Test; /** * 非spring环境的自定义json parser单元测试 + * * @author dongguo.tao * @since 2.5.0 */ public class CustomParserJsonTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 测试非spring场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试非spring场景的自定义json parser - @Test - public void testJsonCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlTest.java index 49947631..aaaf83d7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlTest.java @@ -11,24 +11,26 @@ import org.junit.Test; /** * 非spring环境的自定义xml parser单元测试 + * * @author bryan.zhang * @since 2.5.7 */ public class CustomParserXmlTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 测试非spring场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试非spring场景的自定义json parser - @Test - public void testXmlCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java index e3e6d44a..0dff7651 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -16,9 +16,10 @@ public class ACmp extends NodeComponent { @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new FlowSystemException("chain execute execption"); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java index 41b93022..e889c5ed 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -15,4 +15,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java index 42f5eeed..a164ba09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -4,14 +4,17 @@ import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser; /** * 模拟用户自定义源解析 + * * @author dongguo.tao * @since 2.5.0 */ public class CustomJsonFlowParser extends ClassJsonFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; - return content; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; + return content; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java index 857142d6..2522874b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -3,15 +3,16 @@ package com.yomahub.liteflow.test.parsecustom.parser; import com.yomahub.liteflow.parser.el.ClassXmlFlowELParser; /** - * 非spring环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入非spring中的其他依赖 + * 非spring环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入非spring中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ public class CustomXmlFlowParser extends ClassXmlFlowELParser { - @Override - public String parseCustom() { - return "THEN(a,b,c,d)"; - } + @Override + public String parseCustom() { + return "THEN(a,b,c,d)"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/JsonParserTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/JsonParserTest.java index 01b7c769..3aa7e4ac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/JsonParserTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/JsonParserTest.java @@ -11,24 +11,26 @@ import org.junit.Test; /** * 非spring环境的json parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class JsonParserTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("parser/flow.el.json"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("parser/flow.el.json"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的json parser - @Test - public void testJsonParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/XmlParserTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/XmlParserTest.java index 8b3c797c..585b23e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/XmlParserTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/XmlParserTest.java @@ -11,24 +11,26 @@ import org.junit.Test; /** * 非spring环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class XmlParserTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("parser/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("parser/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 测试无spring场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无spring场景的xml parser - @Test - public void testXmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/YmlParserTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/YmlParserTest.java index bbe97437..7d1a7600 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/YmlParserTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/YmlParserTest.java @@ -11,24 +11,26 @@ import org.junit.Test; /** * 非spring下的yml parser测试用例 + * * @author Bryan.Zhang * @since 2.5.0 */ public class YmlParserTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("parser/flow.el.yml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("parser/flow.el.yml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 测试无spring场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无spring场景的yml parser - @Test - public void testYmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java index 11b12cdd..37eaed56 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/parser/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java index ca04a9bd..9f75741a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -15,4 +15,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyTest.java index b9337d62..dc986bd1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyTest.java @@ -12,57 +12,59 @@ import org.junit.Test; /** * 非spring环境下pre节点和finally节点的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ public class PreAndFinallyTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("preAndFinally/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("preAndFinally/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //测试普通的pre和finally节点 - @Test - public void testPreAndFinally1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试pre和finally节点不放在开头和结尾的情况 - @Test - public void testPreAndFinally2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 - @Test - public void testPreAndFinally3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); - } + // 测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); + } - //测试在finally节点里是否能获取exception - @Test - public void testPreAndFinally4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(context.getData("hasEx")); - } + // 测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(context.getData("hasEx")); + } + + @Test + public void testPreAndFinally5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testPreAndFinally5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java index 704212d7..30389e2d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/preAndFinally/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java index fb494a98..39b9ca43 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -14,7 +14,7 @@ public class DCmp extends NodeComponent { @Override public void process() { System.out.println("CCmp executed!"); - int i = 1/0; + int i = 1 / 0; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java index 22b2322d..5eb33909 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -15,4 +15,5 @@ public class Finally1Cmp extends NodeComponent { public void process() { System.out.println("Finally1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java index e156a075..4e7859f0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -15,4 +15,5 @@ public class Finally2Cmp extends NodeComponent { public void process() { System.out.println("Finally2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java index 8777c80b..67471a55 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -15,14 +15,16 @@ import com.yomahub.liteflow.slot.Slot; public class Finally3Cmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Slot slot = this.getSlot(); DefaultContext context = slot.getFirstContextBean(); - if (ObjectUtil.isNull(slot.getException())){ + if (ObjectUtil.isNull(slot.getException())) { context.setData("hasEx", false); - }else{ + } + else { context.setData("hasEx", true); } System.out.println("Finally3Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java index 8b6b430d..63c2d439 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -15,4 +15,5 @@ public class Pre1Cmp extends NodeComponent { public void process() { System.out.println("Pre1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java index 263c1527..29d10283 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -15,4 +15,5 @@ public class Pre2Cmp extends NodeComponent { public void process() { System.out.println("Pre2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryTest.java index 64aa82dc..0e919db7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryTest.java @@ -13,26 +13,28 @@ import org.junit.Test; /** * 非spring环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class PrivateDeliveryTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("privateDelivery/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("privateDelivery/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testPrivateDelivery() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + ConcurrentHashSet set = context.getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } - @Test - public void testPrivateDelivery() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - ConcurrentHashSet set = context.getData("testSet"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(100, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java index a4e57be7..34d7786f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -20,8 +20,8 @@ public class ACmp extends NodeComponent { context.setData("testSet", new ConcurrentHashSet<>()); for (int i = 0; i < 100; i++) { - this.sendPrivateDeliveryData("b",i+1); + this.sendPrivateDeliveryData("b", i + 1); } } -} +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java index 98a391e1..0b797bf3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -13,13 +13,13 @@ import com.yomahub.liteflow.slot.DefaultContext; public class BCmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - System.out.println("BCmp executed!"); - Integer value = this.getPrivateDeliveryData(); - ConcurrentHashSet testSet = context.getData("testSet"); - testSet.add(value); - } -} + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + System.out.println("BCmp executed!"); + Integer value = this.getPrivateDeliveryData(); + ConcurrentHashSet testSet = context.getData("testSet"); + testSet.add(value); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleTest.java index 4d7414cc..e219333c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleTest.java @@ -14,52 +14,56 @@ import org.junit.Test; /** * 非spring环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.6.4 */ public class RefreshRuleTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("refreshRule/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("refreshRule/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //测试普通刷新流程的场景 - @Test - public void testRefresh1() throws Exception{ - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception { + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试优雅刷新的场景 - @Test - public void testRefresh2() throws Exception{ - new Thread(() -> { - try { - Thread.sleep(4000L); - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - } catch (Exception e) { - e.printStackTrace(); - } + // 测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception { + new Thread(() -> { + try { + Thread.sleep(4000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + } + catch (Exception e) { + e.printStackTrace(); + } - }).start(); + }).start(); - for (int i = 0; i < 500; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - try { - Thread.sleep(10L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java index 7b6cc9eb..68732157 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/reload/ReloadTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/reload/ReloadTest.java index bc3e76ed..92bb2ff8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/reload/ReloadTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/reload/ReloadTest.java @@ -11,26 +11,28 @@ import org.junit.Test; /** * 非spring环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class ReloadTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("reload/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("reload/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + // 这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception { + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml - //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 - @Test - public void testReload() throws Exception{ - flowExecutor.reloadRule(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java index b51731a8..9e40cc71 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/removeChain/RemoveChainTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainTest.java index bc7e25e7..2e3601e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainTest.java @@ -10,23 +10,24 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -public class RemoveChainTest extends BaseTest{ +public class RemoveChainTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("removeChain/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("removeChain/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testRemoveChain() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + FlowBus.removeChain("chain1"); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response2.isSuccess()); + } - @Test - public void testRemoveChain(){ - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response1.isSuccess()); - FlowBus.removeChain("chain1"); - LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response2.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java index a193745c..40b24121 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/requestId/LiteflowRequestIdSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdSpringbootTest.java index a0c2ec27..9aed5923 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdSpringbootTest.java @@ -14,21 +14,21 @@ import org.junit.Test; */ public class LiteflowRequestIdSpringbootTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("requestId/flow.el.xml"); - config.setRequestIdGeneratorClass("com.yomahub.liteflow.test.requestId.config.CustomRequestIdGenerator"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("requestId/flow.el.xml"); + config.setRequestIdGeneratorClass("com.yomahub.liteflow.test.requestId.config.CustomRequestIdGenerator"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testRequestId() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1", response.getSlot().getRequestId()); - } + @Test + public void testRequestId() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", response.getSlot().getRequestId()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java index 9d5a4c1b..8b60d2b0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java @@ -2,12 +2,11 @@ package com.yomahub.liteflow.test.requestId.cmp; import com.yomahub.liteflow.core.NodeComponent; - public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("AComp executed!"); - } + @Override + public void process() { + System.out.println("AComp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java index 2620d8f2..a4f008dd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java @@ -2,12 +2,11 @@ package com.yomahub.liteflow.test.requestId.cmp; import com.yomahub.liteflow.core.NodeComponent; - public class BCmp extends NodeComponent { - - @Override - public void process() { - System.out.println("BComp executed!"); - } + + @Override + public void process() { + System.out.println("BComp executed!"); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java index fcaa9e84..e705db34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java @@ -9,10 +9,11 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class CustomRequestIdGenerator implements RequestIdGenerator { - private final AtomicInteger atomicInteger = new AtomicInteger(0); + private final AtomicInteger atomicInteger = new AtomicInteger(0); + + @Override + public String generate() { + return atomicInteger.incrementAndGet() + ""; + } - @Override - public String generate() { - return atomicInteger.incrementAndGet() + ""; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java index 490e0ba3..bc3fdbdc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotTest.java @@ -21,47 +21,51 @@ import java.util.concurrent.Future; /** * 非spring环境下slot扩容测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class ResizeSlotTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("resizeSlot/flow.el.xml"); - config.setSlotSize(4); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("resizeSlot/flow.el.xml"); + config.setSlotSize(4); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testResize() throws Exception{ - try{ - ExecutorService pool = Executors.newCachedThreadPool(); + @Test + public void testResize() throws Exception { + try { + ExecutorService pool = Executors.newCachedThreadPool(); - List> futureList = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - Future future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); - futureList.add(future); - } + List> futureList = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + Future future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); + futureList.add(future); + } - for(Future future : futureList){ - Assert.assertTrue(future.get().isSuccess()); - } + for (Future future : futureList) { + Assert.assertTrue(future.get().isSuccess()); + } - //取到static的对象QUEUE - Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); - ConcurrentLinkedQueue queue = (ConcurrentLinkedQueue) ReflectUtil.getStaticFieldValue(field); + // 取到static的对象QUEUE + Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); + ConcurrentLinkedQueue queue = (ConcurrentLinkedQueue) ReflectUtil + .getStaticFieldValue(field); - //因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114 - //为什么不是直接114呢? - //因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的 - Assert.assertTrue(queue.size() > 4); - }catch (Exception e){ - e.printStackTrace(); - } + // 因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114 + // 为什么不是直接114呢? + // 因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的 + Assert.assertTrue(queue.size() > 4); + } + catch (Exception e) { + e.printStackTrace(); + } + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java index f2dd7931..a3b25142 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/subflow/ImplicitSubFlowTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java index 29a2b316..d53279ed 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowTest.java @@ -14,50 +14,50 @@ import java.util.HashSet; import java.util.Set; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author justin.xu */ public class ImplicitSubFlowTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("subflow/flow-implicit.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("subflow/flow-implicit.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - public static final Set RUN_TIME_SLOT = new HashSet<>(); + public static final Set RUN_TIME_SLOT = new HashSet<>(); - //这里GCmp中隐式的调用chain4,从而执行了h,m - @Test - public void testImplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); + // 这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); - // 传递了slotIndex,则set的size==1 - Assert.assertEquals(1, RUN_TIME_SLOT.size()); - // set中第一次设置的requestId和response中的requestId一致 - Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); - //requestData的取值正确 - Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); - } + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + // requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); + } - //在p里多线程调用q 10次,每个q取到的参数都是不同的。 - @Test - public void testImplicitSubFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); + // 在p里多线程调用q 10次,每个q取到的参数都是不同的。 + @Test + public void testImplicitSubFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); - Set set = context.getData("test"); + Set set = context.getData("test"); + + // requestData的取值正确 + Assert.assertEquals(10, set.size()); + } - //requestData的取值正确 - Assert.assertEquals(10, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigTest.java index e4386a4f..fca6e9a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigTest.java @@ -18,28 +18,29 @@ import org.junit.Test; */ public class SubflowInDifferentConfigTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); - } + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); + } + + // 主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml"); + flowExecutor.reloadRule(); + } - //主要测试有不同的配置类型后会不会报出既定的错误 - @Test(expected = MultipleParsersException.class) - public void testExplicitSubFlow2() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonTest.java index b954b7b1..0d523b3c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonTest.java @@ -10,27 +10,27 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * 测试显示调用子流程(json) - * 单元测试 + * 测试显示调用子流程(json) 单元测试 * * @author justin.xu */ public class SubflowJsonTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("subflow/flow.el.json"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("subflow/flow.el.json"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLTest.java index 3b90e962..63f394b0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLTest.java @@ -10,27 +10,27 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * 测试显示调用子流程(xml) - * 单元测试 + * 测试显示调用子流程(xml) 单元测试 * * @author justin.xu */ public class SubflowXMLTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("subflow/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("subflow/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlTest.java index 223dada2..deaae153 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlTest.java @@ -10,27 +10,27 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * 测试显示调用子流程(yml) - * 单元测试 + * 测试显示调用子流程(yml) 单元测试 * * @author justin.xu */ public class SubflowYmlTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("subflow/flow.el.yml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("subflow/flow.el.yml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlowYml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java index fd299fae..7e66eef6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -2,10 +2,11 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; - public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("Acomp executed!"); - } + + @Override + public void process() { + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java index 36613aed..480e6174 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -3,8 +3,10 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("Bcomp executed!"); - } + + @Override + public void process() { + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java index 1a95b17c..3494e5bc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -3,8 +3,10 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java index 0a954b4f..d802517c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -3,8 +3,10 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java index 07789037..07782fa3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -4,8 +4,9 @@ import com.yomahub.liteflow.core.NodeComponent; public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ecomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Ecomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java index 6efb4ab3..9b66a529 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -4,13 +4,14 @@ import com.yomahub.liteflow.core.NodeComponent; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; - public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Fcomp executed!"); + } - System.out.println("Fcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java index d4bb3688..47ba6fac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -1,18 +1,19 @@ package com.yomahub.liteflow.test.subflow.cmp2; + import com.yomahub.liteflow.core.NodeComponent; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; - public class GCmp extends NodeComponent { - @Override - public void process() throws Exception { + @Override + public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); - System.out.println("Gcmp executed!"); + System.out.println("Gcmp executed!"); + + this.invoke("chain4", "it's implicit subflow."); + } - this.invoke("chain4", "it's implicit subflow."); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index 2a727d47..3d67447e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -5,16 +5,17 @@ import com.yomahub.liteflow.slot.DefaultContext; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; - public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqData(); - DefaultContext context = this.getFirstContextBean(); - context.setData("innerRequest", requestData); - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqData(); + DefaultContext context = this.getFirstContextBean(); + context.setData("innerRequest", requestData); + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java index ac899b55..2f544b9f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -4,13 +4,14 @@ import com.yomahub.liteflow.core.NodeComponent; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT; - public class MCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); + } - System.out.println("Mcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java index ca7c1c58..f33351c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java @@ -4,24 +4,25 @@ import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.core.FlowExecutorHolder; import com.yomahub.liteflow.core.NodeComponent; - public class PCmp extends NodeComponent { - private FlowExecutor flowExecutor = FlowExecutorHolder.loadInstance(); + private FlowExecutor flowExecutor = FlowExecutorHolder.loadInstance(); + + @Override + public void process() throws Exception { + int slotIndex = this.getSlotIndex(); + for (int i = 0; i < 10; i++) { + int finalI = i; + new Thread(() -> { + try { + flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); + } + catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); + } + Thread.sleep(1000); + } - @Override - public void process() throws Exception { - int slotIndex = this.getSlotIndex(); - for (int i = 0; i < 10; i++) { - int finalI = i; - new Thread(() -> { - try { - flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); - } catch (Exception e) { - throw new RuntimeException(e); - } - }).start(); - } - Thread.sleep(1000); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java index c0f8cb34..d33b5f73 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java @@ -6,22 +6,24 @@ import com.yomahub.liteflow.slot.DefaultContext; import java.util.HashSet; import java.util.Set; - public class QCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqDataInAsync(); - DefaultContext context = this.getFirstContextBean(); - synchronized (QCmp.class){ - if (context.hasData("test")){ - Set set = context.getData("test"); - set.add(requestData); - }else{ - Set set = new HashSet<>(); - set.add(requestData); - context.setData("test", set); - } - } - } + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqDataInAsync(); + DefaultContext context = this.getFirstContextBean(); + + synchronized (QCmp.class) { + if (context.hasData("test")) { + Set set = context.getData("test"); + set.add(requestData); + } + else { + Set set = new HashSet<>(); + set.add(requestData); + context.setData("test", set); + } + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchTest.java index 41cca1ba..8c053255 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchTest.java @@ -9,49 +9,50 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -public class SwitchTest extends BaseTest{ +public class SwitchTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("switchcase/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("switchcase/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testSwitch1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); - } + @Test + public void testSwitch1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d", response.getExecuteStepStr()); + } - @Test - public void testSwitch3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>f==>b",response.getExecuteStepStr()); - } + @Test + public void testSwitch3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>f==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>g==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>g==>d", response.getExecuteStepStr()); + } + + @Test + public void testSwitch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java index 956ef525..7503a5f6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/switchcase/cmp/ESwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java index 30520e7f..baddb379 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java @@ -15,4 +15,5 @@ public class ESwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java index ad750f5e..b7bb7a42 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java @@ -15,4 +15,5 @@ public class FSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return ":td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java index 30336c44..1c41fad0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java @@ -15,4 +15,5 @@ public class GSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java index 820b80bd..caded42b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java @@ -15,4 +15,5 @@ public class HSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "tag:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagJsonTest.java index 2e9dbf7d..5ae9809b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagJsonTest.java @@ -13,53 +13,55 @@ import org.junit.Test; /** * 非spring环境下组件标签的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class NodeTagJsonTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("tag/flow.el.json"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("tag/flow.el.json"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagXmlTest.java index d1040399..1dd75078 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagXmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/NodeTagXmlTest.java @@ -13,53 +13,55 @@ import org.junit.Test; /** * 非spring环境下组件标签的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class NodeTagXmlTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("tag/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("tag/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java index c5a50085..15fbe06e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java @@ -17,12 +17,14 @@ public class ACmp extends NodeComponent { String testKey = "test"; DefaultContext context = this.getFirstContextBean(); - if (context.getData(testKey) == null){ - context.setData(testKey,this.getTag()); - }else{ + if (context.getData(testKey) == null) { + context.setData(testKey, this.getTag()); + } + else { String s = context.getData(testKey); s += this.getTag(); context.setData(testKey, s); } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java index f318f556..18480d5a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -16,6 +16,7 @@ public class B1Cmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",new ConcurrentHashSet()); + context.setData("test", new ConcurrentHashSet()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java index cc153b8f..13e2fc22 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java @@ -19,4 +19,5 @@ public class BCmp extends NodeComponent { ConcurrentHashSet testSet = context.getData("test"); testSet.add(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java index 84242cf0..ab32fe17 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java @@ -13,10 +13,12 @@ public class CCmp extends NodeSwitchComponent { @Override public String processSwitch() throws Exception { - if(this.getTag().equals("2")){ + if (this.getTag().equals("2")) { return "e"; - }else{ + } + else { return "d"; } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java index fcfc5e6b..b9ffc833 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -16,4 +16,5 @@ public class DCmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("DCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java index 121dead7..666015dc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -16,4 +16,5 @@ public class ECmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("ECmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java index 6a0df769..d280ee96 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -20,4 +20,5 @@ public class FCmp extends NodeComponent { public boolean isAccess() { return Boolean.parseBoolean(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java index 66ed40a9..f1ce9271 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -15,4 +15,5 @@ public class GCmp extends NodeComponent { public void process() { System.out.println("GCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java index fee0055e..3de938a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -4,13 +4,14 @@ import com.alibaba.ttl.TransmittableThreadLocal; public class TestTL { - public static ThreadLocal tl = new TransmittableThreadLocal<>(); + public static ThreadLocal tl = new TransmittableThreadLocal<>(); - public static String get(){ - return tl.get(); - } + public static String get() { + return tl.get(); + } + + public static void set(String value) { + tl.set(value); + } - public static void set(String value){ - tl.set(value); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenTest.java index facb0946..628b30e9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenTest.java @@ -12,28 +12,30 @@ import org.junit.Test; /** * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * * @author Bryan.Zhang * @since 2.6.3 */ public class UseTTLInWhenTest extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("useTTLInWhen/flow.el.xml"); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("useTTLInWhen/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testUseTTLInWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,b", context.getData("b")); + Assert.assertEquals("hello,c", context.getData("c")); + Assert.assertEquals("hello,d", context.getData("d")); + Assert.assertEquals("hello,e", context.getData("e")); + Assert.assertEquals("hello,f", context.getData("f")); + } - @Test - public void testUseTTLInWhen() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,b", context.getData("b")); - Assert.assertEquals("hello,c", context.getData("c")); - Assert.assertEquals("hello,d", context.getData("d")); - Assert.assertEquals("hello,e", context.getData("e")); - Assert.assertEquals("hello,f", context.getData("f")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java index bf52ea34..ab3bd767 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { TestTL.set("hello"); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java index 8737920c..83b90cb5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -17,7 +17,7 @@ public class BCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",b"); + context.setData(this.getNodeId(), value + ",b"); System.out.println("BCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java index f0022bee..267a30e8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -17,7 +17,7 @@ public class CCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",c"); + context.setData(this.getNodeId(), value + ",c"); System.out.println("CCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java index 9f99e133..c06e80b9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",d"); + context.setData(this.getNodeId(), value + ",d"); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java index 0d98daae..8b956385 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -17,7 +17,7 @@ public class ECmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",e"); + context.setData(this.getNodeId(), value + ",e"); System.out.println("ECmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java index 325a7a2e..05c26094 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -17,7 +17,7 @@ public class FCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",f"); + context.setData(this.getNodeId(), value + ",f"); System.out.println("FCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest1.java index c7758c4a..f81d73e3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest1.java @@ -12,26 +12,28 @@ import org.junit.Test; /** * 非spring环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ public class WhenTimeOutTest1 extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("whenTimeOut/flow1.el.xml"); - config.setWhenMaxWaitSeconds(3); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("whenTimeOut/flow1.el.xml"); + config.setWhenMaxWaitSeconds(3); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } - //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest2.java index c08a1b92..ad18b675 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutTest2.java @@ -11,25 +11,27 @@ import org.junit.Test; /** * 非spring环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ public class WhenTimeOutTest2 extends BaseTest { - private static FlowExecutor flowExecutor; + private static FlowExecutor flowExecutor; - @BeforeClass - public static void init(){ - LiteflowConfig config = new LiteflowConfig(); - config.setRuleSource("whenTimeOut/flow2.el.xml"); - config.setWhenMaxWaitSeconds(5); - flowExecutor = FlowExecutorHolder.loadInstance(config); - } + @BeforeClass + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("whenTimeOut/flow2.el.xml"); + config.setWhenMaxWaitSeconds(5); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // 其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java index f6faf478..31ae2123 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java index ba636d0e..891ea45e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -15,7 +15,8 @@ public class BCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java index 262415cc..310a4514 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -15,7 +15,8 @@ public class CCmp extends NodeComponent { public void process() { try { Thread.sleep(3500); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java index b40df5d0..a6ccdf24 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -15,7 +15,8 @@ public class DCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("DCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java index 8136cb1c..d7cb21f7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -15,7 +15,8 @@ public class ECmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("ECmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java index 2b96487c..704cccb3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -15,7 +15,8 @@ public class FCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("FCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/LiteflowXmlScriptCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/LiteflowXmlScriptCommonELTest.java index 3a707b09..46013f8d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/LiteflowXmlScriptCommonELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/LiteflowXmlScriptCommonELTest.java @@ -15,9 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的graaljs脚本组件,基于xml配置 + * * @author zendwang * @since 2.9.4 */ @@ -25,18 +25,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/common/application.properties") @SpringBootTest(classes = LiteflowXmlScriptCommonELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.common.cmp" }) public class LiteflowXmlScriptCommonELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试普通脚本节点 + @Test + public void testCommon1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(11), context.getData("s1")); + } - //测试普通脚本节点 - @Test - public void testCommon1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(11), context.getData("s1")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/cmp/ACmp.java index 59f2657b..19d2a6ac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/common/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/contextbean/LiteFlowScriptContextbeanGraaljsTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/LiteFlowScriptContextbeanGraaljsTest.java index 43f169a8..13ecb6c1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/LiteFlowScriptContextbeanGraaljsTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/LiteFlowScriptContextbeanGraaljsTest.java @@ -21,35 +21,38 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/contextbean/application.properties") @SpringBootTest(classes = LiteFlowScriptContextbeanGraaljsTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.contextbean.cmp","com.yomahub.liteflow.test.script.graaljs.contextbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.contextbean.cmp", + "com.yomahub.liteflow.test.script.graaljs.contextbean.bean" }) public class LiteFlowScriptContextbeanGraaljsTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testContextBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class); - Assert.assertTrue(response.isSuccess()); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Order2Context order2Context = response.getContextBean(Order2Context.class); - Assert.assertEquals("order1", orderContext.getOrderNo()); - Assert.assertEquals("d", checkContext.getSign()); - Assert.assertEquals("order2", order2Context.getOrderNo()); - } + @Test + public void testContextBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assert.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assert.assertEquals("order1", orderContext.getOrderNo()); + Assert.assertEquals("d", checkContext.getSign()); + Assert.assertEquals("order2", order2Context.getOrderNo()); + } - @Test - public void testContextBean2() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("order1"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("sign1"); - Order2Context orderContext2 = new Order2Context(); - orderContext2.setOrderNo("order2"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2); - Assert.assertTrue(response.isSuccess()); + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assert.assertTrue(response.isSuccess()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/CheckContext.java index e2a341cb..9b8487a8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/CheckContext.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.context.ContextBean; @ContextBean public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/Order2Context.java index 7ac1738f..1ae46638 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/Order2Context.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/Order2Context.java @@ -4,33 +4,34 @@ import java.util.Date; public class Order2Context { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/OrderContext.java index 48d87ea4..48910891 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/bean/OrderContext.java @@ -7,33 +7,34 @@ import java.util.Date; @ContextBean("order") public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/cmp/ACmp.java index ba361ed4..c19185b3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/contextbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/ifelse/LiteFlowXmlScriptIfelseJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/LiteFlowXmlScriptIfelseJsELTest.java index c9b9c67f..1468cebd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/LiteFlowXmlScriptIfelseJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/LiteFlowXmlScriptIfelseJsELTest.java @@ -18,65 +18,66 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/ifelse/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptIfelseJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.ifelse.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.ifelse.cmp" }) public class LiteFlowXmlScriptIfelseJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/cmp/ACmp.java index b8560f3f..1de6d629 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/ifelse/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/cmp/DCmp.java index 728f131e..feee87b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/ifelse/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/LiteFlowXmlScriptLoopJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/LiteFlowXmlScriptLoopJsELTest.java index 1b8e4a63..c80b8ebe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/LiteFlowXmlScriptLoopJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/LiteFlowXmlScriptLoopJsELTest.java @@ -18,48 +18,51 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/loop/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptLoopJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.loop.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.loop.cmp" }) public class LiteFlowXmlScriptLoopJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } + + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/cmp/ACmp.java index caaea63d..0ba98af3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/cmp/DCmp.java index 711ef67e..5423f358 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/loop/cmp/DCmp.java @@ -18,10 +18,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/LiteflowXmlScriptMetaELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/LiteflowXmlScriptMetaELTest.java index 6cb9d7cf..7cf0e7e3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/LiteflowXmlScriptMetaELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/LiteflowXmlScriptMetaELTest.java @@ -15,9 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试与Java交互的元数据 + * * @author zendwang * @since 2.9.4 */ @@ -25,19 +25,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/meta/application.properties") @SpringBootTest(classes = LiteflowXmlScriptMetaELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.meta.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.meta.cmp" }) public class LiteflowXmlScriptMetaELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMeta() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain1", context.getData("currChainId")); + Assert.assertEquals("arg", context.getData("requestData")); + Assert.assertEquals("s1", context.getData("nodeId")); + } - @Test - public void testMeta() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("chain1", context.getData("currChainId")); - Assert.assertEquals("arg", context.getData("requestData")); - Assert.assertEquals("s1", context.getData("nodeId")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/cmp/ACmp.java index c9e1fc79..bebbeaa6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/meta/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/refresh/LiteflowXmlScriptJsRefreshELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/LiteflowXmlScriptJsRefreshELTest.java index c93055c9..ffd03d98 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/LiteflowXmlScriptJsRefreshELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/LiteflowXmlScriptJsRefreshELTest.java @@ -17,9 +17,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的graaljs脚本组件,基于xml配置 + * * @author zendwang * @since 2.9.4 */ @@ -27,27 +27,28 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/refresh/application.properties") @SpringBootTest(classes = LiteflowXmlScriptJsRefreshELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.refresh.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.refresh.cmp" }) public class LiteflowXmlScriptJsRefreshELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试脚本的热重载 - @Test - public void testRefresh1() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /refresh/flow_update.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + // 测试脚本的热重载 + @Test + public void testRefresh1() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /refresh/flow_update.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/cmp/ACmp.java index a66aa35f..1d5cc45a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/refresh/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/cmp/DCmp.java index b8213fc2..f13c7f64 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/refresh/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/LiteFlowScriptScriptbeanJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/LiteFlowScriptScriptbeanJsELTest.java index 008deed1..4c086fd9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/LiteFlowScriptScriptbeanJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/LiteFlowScriptScriptbeanJsELTest.java @@ -19,26 +19,27 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/scriptbean/application.properties") @SpringBootTest(classes = LiteFlowScriptScriptbeanJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.scriptbean.cmp", "com.yomahub.liteflow.test.script.graaljs.scriptbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.scriptbean.cmp", + "com.yomahub.liteflow.test.script.graaljs.scriptbean.bean" }) public class LiteFlowScriptScriptbeanJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean1.java index 5b63a16b..81c7fb94 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean1.java @@ -9,14 +9,15 @@ import javax.annotation.Resource; @ScriptBean("demo") public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; - public String getDemoStr1(){ - return "hello"; - } + public String getDemoStr1() { + return "hello"; + } + + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } - public String getDemoStr2(String name){ - return demoBean2.getDemoStr2(name); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean2.java index 94f52aa8..2021970d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/cmp/ACmp.java index 47efb9b4..7262958d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/scriptmethod/LiteFlowScriptScripMethodJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/LiteFlowScriptScripMethodJsELTest.java index 75a29808..bb9ff548 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/LiteFlowScriptScripMethodJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/LiteFlowScriptScripMethodJsELTest.java @@ -19,26 +19,27 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/scriptmethod/application.properties") @SpringBootTest(classes = LiteFlowScriptScripMethodJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.scriptmethod.cmp", "com.yomahub.liteflow.test.script.graaljs.scriptmethod.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.scriptmethod.cmp", + "com.yomahub.liteflow.test.script.graaljs.scriptmethod.bean" }) public class LiteFlowScriptScripMethodJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobekobe", context.getData("demo")); - } + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobekobe", context.getData("demo")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean1.java index ae7381bf..948d768b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean1.java @@ -8,22 +8,22 @@ import javax.annotation.Resource; @Component public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; - @ScriptMethod("demo1") - public String getDemoStr1() { - return "hello"; - } + @ScriptMethod("demo1") + public String getDemoStr1() { + return "hello"; + } - @ScriptMethod("demo") - public String getDemoStr2(String name) { - return demoBean2.getDemoStr2(name); - } + @ScriptMethod("demo") + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } - @ScriptMethod("demo") - public String getDemoStr2(String name1, String name2) { - return demoBean2.getDemoStr2(name1 + name2); - } + @ScriptMethod("demo") + public String getDemoStr2(String name1, String name2) { + return demoBean2.getDemoStr2(name1 + name2); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean2.java index 0ade3fa5..8f41f7cd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/cmp/ACmp.java index ae79657c..79fcda47 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/scriptmethod/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/sw/LiteflowXmlScriptJsSwitchELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/LiteflowXmlScriptJsSwitchELTest.java index e4a1c3ae..b4d229b5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/LiteflowXmlScriptJsSwitchELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/LiteflowXmlScriptJsSwitchELTest.java @@ -14,9 +14,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的graaljs脚本组件,基于xml配置 + * * @author zendwang * @since 2.9.4 */ @@ -24,17 +24,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/sw/application.properties") @SpringBootTest(classes = LiteflowXmlScriptJsSwitchELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.sw.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.graaljs.sw.cmp" }) public class LiteflowXmlScriptJsSwitchELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试选择脚本节点 + @Test + public void testSw1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s1[选择脚本]==>a", response.getExecuteStepStr()); + } - //测试选择脚本节点 - @Test - public void testSw1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s1[选择脚本]==>a", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/cmp/ACmp.java index 493ac564..3f6ffc70 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/sw/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/cmp/DCmp.java index 2624d787..08bbf96a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-graaljs-springboot/src/test/java/com/yomahub/liteflow/test/script/graaljs/sw/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/CmpDataGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/CmpDataGroovyELTest.java index bb3055bd..5fdb7043 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/CmpDataGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/CmpDataGroovyELTest.java @@ -17,24 +17,26 @@ import javax.annotation.Resource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/cmpdata/application.properties") @SpringBootTest(classes = CmpDataGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.cmpdata.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.cmpdata.cmp" }) public class CmpDataGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 最简单的情况 + @Test + public void testCmpData1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1995-10-01", context.getData("s1")); + } - //最简单的情况 - @Test - public void testCmpData1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1995-10-01", context.getData("s1")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/cmp/ACmp.java index 84376134..534823a2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/cmpdata/cmp/ACmp.java @@ -18,4 +18,5 @@ public class ACmp extends NodeComponent { System.out.println(this.getCmpData(String.class)); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteFlowXmlScriptBuilderGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteFlowXmlScriptBuilderGroovyELTest.java index 5f46ffda..dcca3e7d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteFlowXmlScriptBuilderGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteFlowXmlScriptBuilderGroovyELTest.java @@ -23,122 +23,124 @@ import java.util.List; @EnableAutoConfiguration public class LiteFlowXmlScriptBuilderGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 测试通过builder方式运行普通script节点,以file绝对路径的方式运行 - */ - @Test - public void testAbsoluteScriptFilePath(){ - String absolutePath = new ClassPathResource("classpath:builder/s2.groovy").getAbsolutePath(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("s2") - .setName("条件脚本S2") - .setType(NodeTypeEnum.SWITCH_SCRIPT) - .setFile(absolutePath) - .build(); - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.BCmp") - .build(); + /** + * 测试通过builder方式运行普通script节点,以file绝对路径的方式运行 + */ + @Test + public void testAbsoluteScriptFilePath() { + String absolutePath = new ClassPathResource("classpath:builder/s2.groovy").getAbsolutePath(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("s2") + .setName("条件脚本S2") + .setType(NodeTypeEnum.SWITCH_SCRIPT) + .setFile(absolutePath) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.BCmp") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2") - .setEL("THEN(d,SWITCH(s2).to(a,b))") - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(d,SWITCH(s2).to(a,b))").build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg1"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d[组件D]==>s2[条件脚本S2]==>a[组件A]", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain2","arg1"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d[组件D]==>s2[条件脚本S2]==>a[组件A]", response.getExecuteStepStr()); - } + // 测试通过builder方式运行普通script节点,以脚本文本的方式运行 + @Test + public void testBuilderScript1() { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.BCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.CCmp") + .build(); + LiteFlowNodeBuilder.createScriptNode() + .setId("s1") + .setName("普通脚本S1") + .setType(NodeTypeEnum.SCRIPT) + .setScript("import cn.hutool.core.collection.ListUtil;" + "import java.util.stream.Collectors;" + + "Integer a=3;Integer b=2;defaultContext.setData(\"s1\",a*b);" + + "List list = ListUtil.toList(\"a\", \"b\", \"c\");" + + "List resultList = list.stream().map(s -> \"hello,\" + s).collect(Collectors.toList());" + + "defaultContext.setData(\"resultList\", resultList)") + .build(); - //测试通过builder方式运行普通script节点,以脚本文本的方式运行 - @Test - public void testBuilderScript1() { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.BCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.CCmp") - .build(); - LiteFlowNodeBuilder.createScriptNode() - .setId("s1") - .setName("普通脚本S1") - .setType(NodeTypeEnum.SCRIPT) - .setScript("import cn.hutool.core.collection.ListUtil;" + - "import java.util.stream.Collectors;" + - "Integer a=3;Integer b=2;defaultContext.setData(\"s1\",a*b);" + - "List list = ListUtil.toList(\"a\", \"b\", \"c\");" + - "List resultList = list.stream().map(s -> \"hello,\" + s).collect(Collectors.toList());" + - "defaultContext.setData(\"resultList\", resultList)") - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(a,b,c,s1)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1") - .setEL("THEN(a,b,c,s1)") - .build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg1"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + List resultList = context.getData("resultList"); + Assert.assertEquals(3, resultList.size()); + } + // 测试通过builder方式运行普通script节点,以file的方式运行 + @Test + public void testBuilderScript2() { + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("s2") + .setName("条件脚本S2") + .setType(NodeTypeEnum.SWITCH_SCRIPT) + .setFile("builder/s2.groovy") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.BCmp") + .build(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1","arg1"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - List resultList = context.getData("resultList"); - Assert.assertEquals(3, resultList.size()); - } + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(d,SWITCH(s2).to(a,b))").build(); - //测试通过builder方式运行普通script节点,以file的方式运行 - @Test - public void testBuilderScript2() { - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("s2") - .setName("条件脚本S2") - .setType(NodeTypeEnum.SWITCH_SCRIPT) - .setFile("builder/s2.groovy") - .build(); - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.groovy.common.cmp.BCmp") - .build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg1"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d[组件D]==>s2[条件脚本S2]==>a[组件A]", response.getExecuteStepStr()); + } - LiteFlowChainELBuilder.createChain().setChainName("chain2") - .setEL("THEN(d,SWITCH(s2).to(a,b))") - .build(); - - - LiteflowResponse response = flowExecutor.execute2Resp("chain2","arg1"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d[组件D]==>s2[条件脚本S2]==>a[组件A]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptFileGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptFileGroovyELTest.java index 6640522d..d2bab54f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptFileGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptFileGroovyELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于json配置 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -28,66 +28,68 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/json-script-file/application.properties") @SpringBootTest(classes = LiteflowJsonScriptFileGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.common.cmp" }) public class LiteflowJsonScriptFileGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试条件脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>a", response.getExecuteStepStr()); - } + // 测试条件脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>a", response.getExecuteStepStr()); + } - //测试脚本的热重载 - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>a", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + // 测试脚本的热重载 + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>a", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //测试脚本&规则平滑重载刷新 - @Test - public void testScript4() throws Exception{ - new Thread(() -> { - try{ - Thread.sleep(2000L); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); - }catch (Exception e){ - e.printStackTrace(); - } - }).start(); + // 测试脚本&规则平滑重载刷新 + @Test + public void testScript4() throws Exception { + new Thread(() -> { + try { + Thread.sleep(2000L); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + } + catch (Exception e) { + e.printStackTrace(); + } + }).start(); + + for (int i = 0; i < 300; i++) { + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Thread.sleep(10L); + } + } - for (int i = 0; i < 300; i++) { - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Thread.sleep(10L); - } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptGroovyELTest.java index 73248ade..d62c0b30 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowJsonScriptGroovyELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于json配置 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -28,44 +28,45 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/json-script/application.properties") @SpringBootTest(classes = LiteflowJsonScriptGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.common.cmp" }) public class LiteflowJsonScriptGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试条件脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>a", response.getExecuteStepStr()); - } + // 测试条件脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>a", response.getExecuteStepStr()); + } - //测试脚本的热重载 - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>a", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /json-script/flow_update.el.json"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + // 测试脚本的热重载 + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>a", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /json-script/flow_update.el.json"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptFileGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptFileGroovyELTest.java index f012daf0..673b2135 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptFileGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptFileGroovyELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于xml配置,file脚本 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -28,66 +28,68 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/xml-script-file/application.properties") @SpringBootTest(classes = LiteflowXmlScriptFileGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.common.cmp" }) public class LiteflowXmlScriptFileGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试条件脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>a", response.getExecuteStepStr()); - } + // 测试条件脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>a", response.getExecuteStepStr()); + } - //测试脚本的热重载 - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>a", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + // 测试脚本的热重载 + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>a", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //测试脚本&规则平滑重载刷新 - @Test - public void testScript4() throws Exception{ - new Thread(() -> { - try{ - Thread.sleep(2000L); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); - }catch (Exception e){ - e.printStackTrace(); - } - }).start(); + // 测试脚本&规则平滑重载刷新 + @Test + public void testScript4() throws Exception { + new Thread(() -> { + try { + Thread.sleep(2000L); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + } + catch (Exception e) { + e.printStackTrace(); + } + }).start(); + + for (int i = 0; i < 300; i++) { + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Thread.sleep(10L); + } + } - for (int i = 0; i < 300; i++) { - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Thread.sleep(10L); - } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptGroovyELTest.java index 28b264f6..6c166715 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/LiteflowXmlScriptGroovyELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -28,53 +28,54 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/xml-script/application.properties") @SpringBootTest(classes = LiteflowXmlScriptGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.common.cmp" }) public class LiteflowXmlScriptGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试选择脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[选择脚本]==>a", response.getExecuteStepStr()); - } + // 测试选择脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[选择脚本]==>a", response.getExecuteStepStr()); + } - //测试脚本的热重载 - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[选择脚本]==>a", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script/flow_update.el.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + // 测试脚本的热重载 + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[选择脚本]==>a", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script/flow_update.el.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>b==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } + + // 测试脚本中的requestData的引用 + @Test + public void testScript4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("s4:arg", context.getData("s4")); + } - //测试脚本中的requestData的引用 - @Test - public void testScript4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("s4:arg", context.getData("s4")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/ACmp.java index 3acbd12c..a56b547c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/DCmp.java index 6fff0a7d..00ad0c79 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/common/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/LiteFlowScriptContextbeanGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/LiteFlowScriptContextbeanGroovyELTest.java index ad0937f2..5c0700f2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/LiteFlowScriptContextbeanGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/LiteFlowScriptContextbeanGroovyELTest.java @@ -21,35 +21,38 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/contextbean/application.properties") @SpringBootTest(classes = LiteFlowScriptContextbeanGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.contextbean.cmp","com.yomahub.liteflow.test.script.groovy.contextbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.contextbean.cmp", + "com.yomahub.liteflow.test.script.groovy.contextbean.bean" }) public class LiteFlowScriptContextbeanGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testContextBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class); - Assert.assertTrue(response.isSuccess()); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Order2Context order2Context = response.getContextBean(Order2Context.class); - Assert.assertEquals("order1", orderContext.getOrderNo()); - Assert.assertEquals("sign1", checkContext.getSign()); - Assert.assertEquals("order2", order2Context.getOrderNo()); - } + @Test + public void testContextBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assert.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assert.assertEquals("order1", orderContext.getOrderNo()); + Assert.assertEquals("sign1", checkContext.getSign()); + Assert.assertEquals("order2", order2Context.getOrderNo()); + } - @Test - public void testContextBean2() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("order1"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("sign1"); - Order2Context orderContext2 = new Order2Context(); - orderContext2.setOrderNo("order2"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2); - Assert.assertTrue(response.isSuccess()); + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assert.assertTrue(response.isSuccess()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/CheckContext.java index 0f2e7cd4..91b3afc5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/CheckContext.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.context.ContextBean; @ContextBean public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/Order2Context.java index 54b59dac..ac544ef1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/Order2Context.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/Order2Context.java @@ -4,33 +4,34 @@ import java.util.Date; public class Order2Context { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/OrderContext.java index 40273204..4f026cdf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/bean/OrderContext.java @@ -7,33 +7,34 @@ import java.util.Date; @ContextBean("order") public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/cmp/ACmp.java index 55d06110..8713fdda 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/contextbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/LiteFlowXmlScriptIfelseGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/LiteFlowXmlScriptIfelseGroovyELTest.java index 20cb9eb9..4d8cf9f3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/LiteFlowXmlScriptIfelseGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/LiteFlowXmlScriptIfelseGroovyELTest.java @@ -18,65 +18,66 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/ifelse/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptIfelseGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.ifelse.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.ifelse.cmp" }) public class LiteFlowXmlScriptIfelseGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/ACmp.java index b422c041..87924d46 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/DCmp.java index b3cd6e1e..30ae04af 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/ifelse/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java index 25a8591f..46cded74 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/LiteFlowXmlScriptLoopGroovyELTest.java @@ -18,48 +18,51 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/loop/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptLoopGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.loop.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.loop.cmp" }) public class LiteFlowXmlScriptLoopGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } + + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ACmp.java index ec88b534..ebfb889d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/DCmp.java index 11a5bb25..128af5dd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/loop/cmp/DCmp.java @@ -18,10 +18,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptOrder/LiteflowScriptOrderGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptOrder/LiteflowScriptOrderGroovyELTest.java index 5518562e..7f3506e9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptOrder/LiteflowScriptOrderGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptOrder/LiteflowScriptOrderGroovyELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -30,13 +30,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class LiteflowScriptOrderGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java index 64c78b0b..b9c6520c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/LiteFlowScriptScriptbeanGroovyELTest.java @@ -23,70 +23,72 @@ import java.util.Map; @TestPropertySource(value = "classpath:/scriptbean/application.properties") @SpringBootTest(classes = LiteFlowScriptScriptbeanGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.scriptbean.cmp","com.yomahub.liteflow.test.script.groovy.scriptbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.scriptbean.cmp", + "com.yomahub.liteflow.test.script.groovy.scriptbean.bean" }) public class LiteFlowScriptScriptbeanGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } - //测试scriptBean includeMethodName配置包含情况下 - @Test - public void testScriptBean3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + // 测试scriptBean includeMethodName配置包含情况下 + @Test + public void testScriptBean3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } - //测试scriptBean includeMethodName配置不包含情况下 - @Test - public void testScriptBean4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); - } + // 测试scriptBean includeMethodName配置不包含情况下 + @Test + public void testScriptBean4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); + } - //测试scriptBean excludeMethodName配置不包含情况下 - @Test - public void testScriptBean5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + // 测试scriptBean excludeMethodName配置不包含情况下 + @Test + public void testScriptBean5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } - //测试scriptBean excludeMethodName配置包含情况下 - @Test - public void testScriptBean6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); - } + // 测试scriptBean excludeMethodName配置包含情况下 + @Test + public void testScriptBean6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(ScriptBeanMethodInvokeException.class, response.getCause().getClass()); + } + + // 测试在ScriptBeanManager里放入上下文,实现自定义脚本引用名称 + @Test + public void testScriptBean7() throws Exception { + Map map = new HashMap<>(); + ScriptBeanManager.addScriptBean("abcCx", map); + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg", map); + Assert.assertTrue(response.isSuccess()); + Map context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.get("demo")); + } - //测试在ScriptBeanManager里放入上下文,实现自定义脚本引用名称 - @Test - public void testScriptBean7() throws Exception{ - Map map = new HashMap<>(); - ScriptBeanManager.addScriptBean("abcCx", map); - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg", map); - Assert.assertTrue(response.isSuccess()); - Map context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.get("demo")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean1.java index 23fa5c25..bd326632 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean1.java @@ -9,14 +9,15 @@ import javax.annotation.Resource; @ScriptBean("demo") public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; - public String getDemoStr1(){ - return "hello"; - } + public String getDemoStr1() { + return "hello"; + } + + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } - public String getDemoStr2(String name){ - return demoBean2.getDemoStr2(name); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean2.java index d7772e3a..2ecfe357 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean3.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean3.java index 37dcbc38..52457e62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean3.java @@ -4,18 +4,19 @@ import com.yomahub.liteflow.script.annotation.ScriptBean; import org.springframework.stereotype.Component; @Component -@ScriptBean(name = "demo3", includeMethodName = {"test1","test2"}) +@ScriptBean(name = "demo3", includeMethodName = { "test1", "test2" }) public class DemoBean3 { - public String test1(String name){ - return "hello,"+name; - } + public String test1(String name) { + return "hello," + name; + } - public String test2(String name){ - return "hello,"+name; - } + public String test2(String name) { + return "hello," + name; + } + + public String test3(String name) { + return "hello," + name; + } - public String test3(String name){ - return "hello,"+name; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean4.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean4.java index 34ac5075..c0518bbd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean4.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/bean/DemoBean4.java @@ -4,18 +4,19 @@ import com.yomahub.liteflow.script.annotation.ScriptBean; import org.springframework.stereotype.Component; @Component -@ScriptBean(name = "demo4", excludeMethodName = {"test2","test3"}) +@ScriptBean(name = "demo4", excludeMethodName = { "test2", "test3" }) public class DemoBean4 { - public String test1(String name){ - return "hello,"+name; - } + public String test1(String name) { + return "hello," + name; + } - public String test2(String name){ - return "hello,"+name; - } + public String test2(String name) { + return "hello," + name; + } + + public String test3(String name) { + return "hello," + name; + } - public String test3(String name){ - return "hello,"+name; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/cmp/ACmp.java index 6bcb5fb9..9dd1ab29 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/LiteFlowScriptScriptMethodGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/LiteFlowScriptScriptMethodGroovyELTest.java index 06524ece..6bfd95be 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/LiteFlowScriptScriptMethodGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/LiteFlowScriptScriptMethodGroovyELTest.java @@ -19,25 +19,27 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/scriptmethod/application.properties") @SpringBootTest(classes = LiteFlowScriptScriptMethodGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.scriptmethod.cmp","com.yomahub.liteflow.test.script.groovy.scriptmethod.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.scriptmethod.cmp", + "com.yomahub.liteflow.test.script.groovy.scriptmethod.bean" }) public class LiteFlowScriptScriptMethodGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } + + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean1.java index 466913a2..5d2fd1ec 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean1.java @@ -8,18 +8,17 @@ import javax.annotation.Resource; @Component public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; + @ScriptMethod("demo") + public String getDemoStr1() { + return "hello"; + } - @ScriptMethod("demo") - public String getDemoStr1() { - return "hello"; - } - - @ScriptMethod("demo2") - public String getDemoStr2(String name) { - return demoBean2.getDemoStr2(name); - } + @ScriptMethod("demo2") + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean2.java index 3a92c376..384be5a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/cmp/ACmp.java index 63a0f937..660f55cc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/scriptmethod/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java index 5375d09b..23479020 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/TestException.java @@ -3,11 +3,13 @@ package com.yomahub.liteflow.test.script.groovy.throwException; import com.yomahub.liteflow.exception.LiteFlowException; public class TestException extends LiteFlowException { - public TestException(String message) { - super(message); - } - public TestException(String code, String message) { - super(code, message); - } + public TestException(String message) { + super(message); + } + + public TestException(String code, String message) { + super(code, message); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java index 60ee8313..712c85d3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/ThrowExceptionScriptGroovyELTest.java @@ -14,9 +14,9 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本抛错 + * * @author Bryan.Zhang * @since 2.9.4 */ @@ -24,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/throwException/application.properties") @SpringBootTest(classes = ThrowExceptionScriptGroovyELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.groovy.throwException.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.groovy.throwException.cmp" }) public class ThrowExceptionScriptGroovyELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void test1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("T01", response.getCode()); + } - @Test - public void test1(){ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("T01", response.getCode()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java index 69465f37..b5b22814 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-groovy-springboot/src/test/java/com/yomahub/liteflow/test/script/groovy/throwException/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/LiteflowXmlScriptJsCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/LiteflowXmlScriptJsCommonELTest.java index b10bf871..005be1c2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/LiteflowXmlScriptJsCommonELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/LiteflowXmlScriptJsCommonELTest.java @@ -15,9 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -25,18 +25,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/common/application.properties") @SpringBootTest(classes = LiteflowXmlScriptJsCommonELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.common.cmp" }) public class LiteflowXmlScriptJsCommonELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试普通脚本节点 + @Test + public void testCommon1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Double.valueOf(11), context.getData("s1")); + } - //测试普通脚本节点 - @Test - public void testCommon1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Double.valueOf(11), context.getData("s1")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/cmp/ACmp.java index c746d2bc..e056c979 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/common/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/cmp/DCmp.java index 05541c69..9281d2ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/common/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/LiteFlowScriptContextbeanJavaScriptTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/LiteFlowScriptContextbeanJavaScriptTest.java index 5e8b3ec1..7872643c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/LiteFlowScriptContextbeanJavaScriptTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/LiteFlowScriptContextbeanJavaScriptTest.java @@ -21,35 +21,38 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/contextbean/application.properties") @SpringBootTest(classes = LiteFlowScriptContextbeanJavaScriptTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.contextbean.cmp","com.yomahub.liteflow.test.script.javascript.contextbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.contextbean.cmp", + "com.yomahub.liteflow.test.script.javascript.contextbean.bean" }) public class LiteFlowScriptContextbeanJavaScriptTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testContextBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class); - Assert.assertTrue(response.isSuccess()); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Order2Context order2Context = response.getContextBean(Order2Context.class); - Assert.assertEquals("order1", orderContext.getOrderNo()); - Assert.assertEquals("sign1", checkContext.getSign()); - Assert.assertEquals("order2", order2Context.getOrderNo()); - } + @Test + public void testContextBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assert.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assert.assertEquals("order1", orderContext.getOrderNo()); + Assert.assertEquals("sign1", checkContext.getSign()); + Assert.assertEquals("order2", order2Context.getOrderNo()); + } - @Test - public void testContextBean2() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("order1"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("sign1"); - Order2Context orderContext2 = new Order2Context(); - orderContext2.setOrderNo("order2"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2); - Assert.assertTrue(response.isSuccess()); + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assert.assertTrue(response.isSuccess()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/CheckContext.java index cb88f3ec..e345ce99 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/CheckContext.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.context.ContextBean; @ContextBean public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/Order2Context.java index 33e5b3d3..41e6ba94 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/Order2Context.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/Order2Context.java @@ -4,33 +4,34 @@ import java.util.Date; public class Order2Context { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/OrderContext.java index 95bf9a4a..c0ae7b61 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/bean/OrderContext.java @@ -7,33 +7,34 @@ import java.util.Date; @ContextBean("order") public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/cmp/ACmp.java index 215232b7..2fef8d49 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/contextbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/ifelse/LiteFlowXmlScriptIfelseJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/LiteFlowXmlScriptIfelseJsELTest.java index abdd26b5..d4e03f85 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/LiteFlowXmlScriptIfelseJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/LiteFlowXmlScriptIfelseJsELTest.java @@ -18,65 +18,66 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/ifelse/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptIfelseJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.ifelse.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.ifelse.cmp" }) public class LiteFlowXmlScriptIfelseJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/ACmp.java index 9cd41a1c..e02141f1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/ifelse/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/DCmp.java index b97e293a..d9732f9f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/ifelse/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/LiteFlowXmlScriptLoopJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/LiteFlowXmlScriptLoopJsELTest.java index 172414d3..eaac5290 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/LiteFlowXmlScriptLoopJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/LiteFlowXmlScriptLoopJsELTest.java @@ -18,48 +18,51 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/loop/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptLoopJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.loop.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.loop.cmp" }) public class LiteFlowXmlScriptLoopJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } + + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/ACmp.java index e0f62fca..7f0d5da5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/DCmp.java index 08b4d059..0ef3d944 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/loop/cmp/DCmp.java @@ -18,10 +18,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/LiteflowXmlScriptJsRefreshELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/LiteflowXmlScriptJsRefreshELTest.java index 4846a57f..30f76684 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/LiteflowXmlScriptJsRefreshELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/LiteflowXmlScriptJsRefreshELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -28,27 +28,28 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/refresh/application.properties") @SpringBootTest(classes = LiteflowXmlScriptJsRefreshELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.refresh.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.refresh.cmp" }) public class LiteflowXmlScriptJsRefreshELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试脚本的热重载 - @Test - public void testRefresh1() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /refresh/flow_update.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + // 测试脚本的热重载 + @Test + public void testRefresh1() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s1[选择脚本]==>a", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /refresh/flow_update.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s1[选择脚本_改]==>b==>s2[普通脚本_新增]", responseNew.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/ACmp.java index 97bf04cb..f237a915 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/refresh/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/DCmp.java index 9b25b218..5c7a66a3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/refresh/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/LiteFlowScriptScriptbeanJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/LiteFlowScriptScriptbeanJsELTest.java index 3177177e..f1ec1bfd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/LiteFlowScriptScriptbeanJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/LiteFlowScriptScriptbeanJsELTest.java @@ -19,26 +19,27 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/scriptbean/application.properties") @SpringBootTest(classes = LiteFlowScriptScriptbeanJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.scriptbean.cmp","com.yomahub.liteflow.test.script.javascript.scriptbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.scriptbean.cmp", + "com.yomahub.liteflow.test.script.javascript.scriptbean.bean" }) public class LiteFlowScriptScriptbeanJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean1.java index 60bb7dba..985adf5d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean1.java @@ -9,14 +9,15 @@ import javax.annotation.Resource; @ScriptBean("demo") public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; - public String getDemoStr1(){ - return "hello"; - } + public String getDemoStr1() { + return "hello"; + } + + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } - public String getDemoStr2(String name){ - return demoBean2.getDemoStr2(name); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean2.java index 253b5221..809f07f4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/cmp/ACmp.java index d709d953..c6803159 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/scriptmethod/LiteFlowScriptScriptMethodJsELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/LiteFlowScriptScriptMethodJsELTest.java index dbfc340c..30103cfb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/LiteFlowScriptScriptMethodJsELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/LiteFlowScriptScriptMethodJsELTest.java @@ -19,26 +19,27 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/scriptmethod/application.properties") @SpringBootTest(classes = LiteFlowScriptScriptMethodJsELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.scriptmethod.cmp","com.yomahub.liteflow.test.script.javascript.scriptmethod.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.scriptmethod.cmp", + "com.yomahub.liteflow.test.script.javascript.scriptmethod.bean" }) public class LiteFlowScriptScriptMethodJsELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean1.java index 0b4e2d9e..f370f7d1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean1.java @@ -8,21 +8,22 @@ import javax.annotation.Resource; @Component public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; - @ScriptMethod("demo") - public String getDemoStr1() { - return "hello"; - } + @ScriptMethod("demo") + public String getDemoStr1() { + return "hello"; + } - @ScriptMethod("demo2") - public String getDemoStr2(String name) { - return demoBean2.getDemoStr2(name); - } + @ScriptMethod("demo2") + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } + + @ScriptMethod("demo3") + public String getDemoStr3(String name, String name2) { + return demoBean2.getDemoStr2(name) + name2; + } - @ScriptMethod("demo3") - public String getDemoStr3(String name, String name2) { - return demoBean2.getDemoStr2(name) + name2; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean2.java index 77c7e7e5..99b4705c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/cmp/ACmp.java index d1792cd5..153a801c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/scriptmethod/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/sw/LiteflowXmlScriptJsSwitchELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/LiteflowXmlScriptJsSwitchELTest.java index 94046342..2dc8e3ef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/LiteflowXmlScriptJsSwitchELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/LiteflowXmlScriptJsSwitchELTest.java @@ -14,9 +14,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -24,17 +24,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/sw/application.properties") @SpringBootTest(classes = LiteflowXmlScriptJsSwitchELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.sw.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.sw.cmp" }) public class LiteflowXmlScriptJsSwitchELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试选择脚本节点 + @Test + public void testSw1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s1[选择脚本]==>a", response.getExecuteStepStr()); + } - //测试选择脚本节点 - @Test - public void testSw1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s1[选择脚本]==>a", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/cmp/ACmp.java index a5a7bfa3..921281e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/sw/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/cmp/DCmp.java index 5bcb6047..598242f3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/sw/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/ThrowExceptionScriptJsCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/ThrowExceptionScriptJsCommonELTest.java index 772c591d..e90e9614 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/ThrowExceptionScriptJsCommonELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/ThrowExceptionScriptJsCommonELTest.java @@ -15,9 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的groovy脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -25,17 +25,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/throwException/application.properties") @SpringBootTest(classes = ThrowExceptionScriptJsCommonELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.javascript.throwException.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.javascript.throwException.cmp" }) public class ThrowExceptionScriptJsCommonELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试普通脚本节点 + @Test + public void testCommon1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + } - //测试普通脚本节点 - @Test - public void testCommon1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/cmp/ACmp.java index 3b2e916a..06d38100 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-javascript-springboot/src/test/java/com/yomahub/liteflow/test/script/javascript/throwException/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/ScriptLuaCommonELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/ScriptLuaCommonELTest.java index 23e8d540..defa3579 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/ScriptLuaCommonELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/ScriptLuaCommonELTest.java @@ -15,9 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的lua脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.9.5 */ @@ -25,18 +25,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/common/application.properties") @SpringBootTest(classes = ScriptLuaCommonELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.lua.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.lua.common.cmp" }) public class ScriptLuaCommonELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试普通脚本节点 + @Test + public void testCommon1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(30), context.getData("s1")); + } - //测试普通脚本节点 - @Test - public void testCommon1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(30), context.getData("s1")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/ACmp.java index 87b7c114..b821fe95 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/DCmp.java index eeae798e..e97f8f4c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/common/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/LiteFlowScriptContextbeanLuaTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/LiteFlowScriptContextbeanLuaTest.java index f5630d6f..306109d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/LiteFlowScriptContextbeanLuaTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/LiteFlowScriptContextbeanLuaTest.java @@ -21,35 +21,38 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/contextbean/application.properties") @SpringBootTest(classes = LiteFlowScriptContextbeanLuaTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.lua.contextbean.cmp","com.yomahub.liteflow.test.script.lua.contextbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.lua.contextbean.cmp", + "com.yomahub.liteflow.test.script.lua.contextbean.bean" }) public class LiteFlowScriptContextbeanLuaTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testContextBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class); - Assert.assertTrue(response.isSuccess()); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Order2Context order2Context = response.getContextBean(Order2Context.class); - Assert.assertEquals(30, orderContext.getOrderType()); - Assert.assertEquals("d", checkContext.getSign()); - Assert.assertEquals("order2", order2Context.getOrderNo()); - } + @Test + public void testContextBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assert.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assert.assertEquals(30, orderContext.getOrderType()); + Assert.assertEquals("d", checkContext.getSign()); + Assert.assertEquals("order2", order2Context.getOrderNo()); + } - @Test - public void testContextBean2() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("order1"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("sign1"); - Order2Context orderContext2 = new Order2Context(); - orderContext2.setOrderNo("order2"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2); - Assert.assertTrue(response.isSuccess()); + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assert.assertTrue(response.isSuccess()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/CheckContext.java index 01e76b3a..45b29178 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/CheckContext.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.context.ContextBean; @ContextBean public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/Order2Context.java index 75985749..4f583424 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/Order2Context.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/Order2Context.java @@ -4,33 +4,34 @@ import java.util.Date; public class Order2Context { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/OrderContext.java index 6291a291..1b503ab2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/bean/OrderContext.java @@ -7,33 +7,34 @@ import java.util.Date; @ContextBean("order") public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/cmp/ACmp.java index 5bdab2bf..212758c1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-lua-springboot/src/test/java/com/yomahub/liteflow/test/script/lua/contextbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/MultiLanguageELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/MultiLanguageELTest.java index 78f6e193..3c09fb1f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/MultiLanguageELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/MultiLanguageELTest.java @@ -21,9 +21,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.util.Map; - /** * 测试springboot下的groovy脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -31,21 +31,22 @@ import java.util.Map; @TestPropertySource(value = "classpath:/multiLanguage/application.properties") @SpringBootTest(classes = MultiLanguageELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.multi.language.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.multi.language.cmp" }) public class MultiLanguageELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试普通脚本节点 + @Test + public void testMultiLanguage1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Object student = context.getData("student"); + Map studentMap = JsonUtil.parseObject(JsonUtil.toJsonString(student), Map.class); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(18), context.getData("s1")); + Assert.assertEquals(10032, studentMap.get("studentID")); + } - //测试普通脚本节点 - @Test - public void testMultiLanguage1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Object student = context.getData("student"); - Map studentMap = JsonUtil.parseObject(JsonUtil.toJsonString(student), Map.class); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(18), context.getData("s1")); - Assert.assertEquals(10032, studentMap.get("studentID")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/cmp/ACmp.java index a9c0fd84..3a5f90e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-multi-language-springboot/src/test/java/com/yomahub/liteflow/test/script/multi/language/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } 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 2c7abdb6..a1a0d87a 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 @@ -15,9 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的python脚本组件,基于xml配置 + * * @author Bryan.Zhang * @since 2.9.5 */ @@ -25,19 +25,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/common/application.properties") @SpringBootTest(classes = ScriptPythonCommonELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.python.common.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.python.common.cmp" }) public class ScriptPythonCommonELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试普通脚本节点 + @Test + public void testCommon1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(30), context.getData("s1")); + Assert.assertEquals("杰克", context.getData("name")); + } - //测试普通脚本节点 - @Test - public void testCommon1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(30), context.getData("s1")); - Assert.assertEquals("杰克", context.getData("name")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/ACmp.java index 32f84b00..9d5ac442 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/DCmp.java index 2bb84daa..bec5e704 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/common/cmp/DCmp.java @@ -17,7 +17,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",198); + context.setData("count", 198); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/LiteFlowScriptContextbeanPythonTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/LiteFlowScriptContextbeanPythonTest.java index b502f34e..e8acb793 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/LiteFlowScriptContextbeanPythonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/LiteFlowScriptContextbeanPythonTest.java @@ -21,35 +21,38 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/contextbean/application.properties") @SpringBootTest(classes = LiteFlowScriptContextbeanPythonTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.python.contextbean.cmp","com.yomahub.liteflow.test.script.python.contextbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.python.contextbean.cmp", + "com.yomahub.liteflow.test.script.python.contextbean.bean" }) public class LiteFlowScriptContextbeanPythonTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testContextBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class); - Assert.assertTrue(response.isSuccess()); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Order2Context order2Context = response.getContextBean(Order2Context.class); - Assert.assertEquals(30, orderContext.getOrderType()); - Assert.assertEquals("d", checkContext.getSign()); - Assert.assertEquals("order2", order2Context.getOrderNo()); - } + @Test + public void testContextBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assert.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assert.assertEquals(30, orderContext.getOrderType()); + Assert.assertEquals("d", checkContext.getSign()); + Assert.assertEquals("order2", order2Context.getOrderNo()); + } - @Test - public void testContextBean2() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("order1"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("sign1"); - Order2Context orderContext2 = new Order2Context(); - orderContext2.setOrderNo("order2"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2); - Assert.assertTrue(response.isSuccess()); + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assert.assertTrue(response.isSuccess()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/CheckContext.java index 488d0bcd..afaa6a0b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/CheckContext.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.context.ContextBean; @ContextBean public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/Order2Context.java index d6e3fea8..f5f5016e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/Order2Context.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/Order2Context.java @@ -4,33 +4,34 @@ import java.util.Date; public class Order2Context { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/OrderContext.java index 77ebd20f..cf4303e6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/bean/OrderContext.java @@ -7,33 +7,34 @@ import java.util.Date; @ContextBean("order") public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/cmp/ACmp.java index 16595cee..fa952a3e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-python-springboot/src/test/java/com/yomahub/liteflow/test/script/python/contextbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptBuilderQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptBuilderQLExpressELTest.java index dca3ebd6..4a47e958 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptBuilderQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptBuilderQLExpressELTest.java @@ -21,76 +21,78 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class LiteFlowXmlScriptBuilderQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试通过builder方式运行普通script节点,以脚本文本的方式运行 - @Test - public void testBuilderScript1() { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.BCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.CCmp") - .build(); - LiteFlowNodeBuilder.createScriptNode() - .setId("s1") - .setName("普通脚本S1") - .setType(NodeTypeEnum.SCRIPT) - .setScript("a=3;b=2;defaultContext.setData(\"s1\",a*b);") - .build(); + // 测试通过builder方式运行普通script节点,以脚本文本的方式运行 + @Test + public void testBuilderScript1() { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.BCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.CCmp") + .build(); + LiteFlowNodeBuilder.createScriptNode() + .setId("s1") + .setName("普通脚本S1") + .setType(NodeTypeEnum.SCRIPT) + .setScript("a=3;b=2;defaultContext.setData(\"s1\",a*b);") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1") - .setEL("THEN(a,b,c,s1)") - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(a,b,c,s1)").build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg1"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1","arg1"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试通过builder方式运行普通script节点,以file的方式运行 + @Test + public void testBuilderScript2() { + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("s2") + .setName("条件脚本S2") + .setType(NodeTypeEnum.SWITCH_SCRIPT) + .setFile("builder/s2.ql") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.BCmp") + .build(); - //测试通过builder方式运行普通script节点,以file的方式运行 - @Test - public void testBuilderScript2() { - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("s2") - .setName("条件脚本S2") - .setType(NodeTypeEnum.SWITCH_SCRIPT) - .setFile("builder/s2.ql") - .build(); - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.script.qlexpress.cmp.BCmp") - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(d,SWITCH(s2).to(a,b))").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2") - .setEL("THEN(d,SWITCH(s2).to(a,b))") - .build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d[组件D]==>s2[条件脚本S2]==>b[组件B]", response.getExecuteStepStr()); + } - - LiteflowResponse response = flowExecutor.execute2Resp("chain2","arg1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d[组件D]==>s2[条件脚本S2]==>b[组件B]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptIfelseQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptIfelseQLExpressELTest.java index d0d518b4..2d507c64 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptIfelseQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteFlowXmlScriptIfelseQLExpressELTest.java @@ -18,65 +18,66 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/ifelse/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptIfelseQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.cmp" }) public class LiteFlowXmlScriptIfelseQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x0==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x0==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptFileQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptFileQLExpressELTest.java index 098a1550..93feff77 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptFileQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptFileQLExpressELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的脚本组件 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -28,65 +28,67 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/json-script-file/application.properties") @SpringBootTest(classes = LiteflowJsonScriptFileQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.cmp" }) public class LiteflowJsonScriptFileQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试条件脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); - } + // 测试条件脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); + } - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //测试脚本&规则平滑重载刷新 - @Test - public void testScript4() throws Exception{ - new Thread(() -> { - try{ - Thread.sleep(2000L); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); - }catch (Exception e){ - e.printStackTrace(); - } - }).start(); + // 测试脚本&规则平滑重载刷新 + @Test + public void testScript4() throws Exception { + new Thread(() -> { + try { + Thread.sleep(2000L); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /json-script-file/flow_update.el.json"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + } + catch (Exception e) { + e.printStackTrace(); + } + }).start(); + + for (int i = 0; i < 300; i++) { + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Thread.sleep(10L); + } + } - for (int i = 0; i < 300; i++) { - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Thread.sleep(10L); - } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptQLExpressELTest.java index 2ca63eb0..753ad877 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowJsonScriptQLExpressELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的脚本组件 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -28,43 +28,44 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/json-script/application.properties") @SpringBootTest(classes = LiteflowJsonScriptQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.cmp" }) public class LiteflowJsonScriptQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试条件脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); - } + // 测试条件脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); + } - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /json-script/flow_update.el.json"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /json-script/flow_update.el.json"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_JSON, newContent); + + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptFileQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptFileQLExpressELTest.java index d19a40e0..5d3640ad 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptFileQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptFileQLExpressELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的脚本组件 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -28,65 +28,67 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/xml-script-file/application.properties") @SpringBootTest(classes = LiteflowXmlScriptFileQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.cmp" }) public class LiteflowXmlScriptFileQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试条件脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); - } + // 测试条件脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); + } - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //测试脚本&规则平滑重载刷新 - @Test - public void testScript4() throws Exception{ - new Thread(() -> { - try{ - Thread.sleep(2000L); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); - }catch (Exception e){ - e.printStackTrace(); - } - }).start(); + // 测试脚本&规则平滑重载刷新 + @Test + public void testScript4() throws Exception { + new Thread(() -> { + try { + Thread.sleep(2000L); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script-file/flow_update.el.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + } + catch (Exception e) { + e.printStackTrace(); + } + }).start(); + + for (int i = 0; i < 300; i++) { + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Thread.sleep(10L); + } + } - for (int i = 0; i < 300; i++) { - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Thread.sleep(10L); - } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptQLExpressELTest.java index 223dd9bb..7a7646ae 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/LiteflowXmlScriptQLExpressELTest.java @@ -18,9 +18,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的脚本组件 + * * @author Bryan.Zhang * @since 2.6.0 */ @@ -28,43 +28,44 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/xml-script/application.properties") @SpringBootTest(classes = LiteflowXmlScriptQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.cmp" }) public class LiteflowXmlScriptQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通脚本节点 - @Test - public void testScript1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); - } + // 测试普通脚本节点 + @Test + public void testScript1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(Integer.valueOf(6), context.getData("s1")); + } - //测试条件脚本节点 - @Test - public void testScript2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); - } + // 测试条件脚本节点 + @Test + public void testScript2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", response.getExecuteStepStr()); + } - @Test - public void testScript3() throws Exception{ - //根据配置,加载的应该是flow.xml,执行原来的规则 - LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseOld.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); - //更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 - String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script/flow_update.el.xml"); - //进行刷新 - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + @Test + public void testScript3() throws Exception { + // 根据配置,加载的应该是flow.xml,执行原来的规则 + LiteflowResponse responseOld = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseOld.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本]==>b", responseOld.getExecuteStepStr()); + // 更改规则,重新加载,更改的规则内容从flow_update.xml里读取,这里只是为了模拟下获取新的内容。不一定是从文件中读取 + String newContent = ResourceUtil.readUtf8Str("classpath: /xml-script/flow_update.el.xml"); + // 进行刷新 + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, newContent); + + // 重新执行chain2这个链路,结果会变 + LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(responseNew.isSuccess()); + Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); + } - //重新执行chain2这个链路,结果会变 - LiteflowResponse responseNew = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(responseNew.isSuccess()); - Assert.assertEquals("d==>s2[条件脚本_改]==>a==>s3[普通脚本_新增]", responseNew.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/ACmp.java index 0db8d6bf..f0afeb8b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/DCmp.java index ecc648de..f022214e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/cmp/DCmp.java @@ -18,7 +18,7 @@ public class DCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("count",97); + context.setData("count", 97); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/LiteFlowScriptContextbeanQLExpressTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/LiteFlowScriptContextbeanQLExpressTest.java index 8dc77af5..2fb50fb7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/LiteFlowScriptContextbeanQLExpressTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/LiteFlowScriptContextbeanQLExpressTest.java @@ -21,35 +21,38 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/contextbean/application.properties") @SpringBootTest(classes = LiteFlowScriptContextbeanQLExpressTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.contextbean.cmp","com.yomahub.liteflow.test.script.qlexpress.contextbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.contextbean.cmp", + "com.yomahub.liteflow.test.script.qlexpress.contextbean.bean" }) public class LiteFlowScriptContextbeanQLExpressTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testContextBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class); - Assert.assertTrue(response.isSuccess()); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Order2Context order2Context = response.getContextBean(Order2Context.class); - Assert.assertEquals(6, orderContext.getOrderType()); - Assert.assertEquals("d", checkContext.getSign()); - Assert.assertEquals("order2", order2Context.getOrderNo()); - } + @Test + public void testContextBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, + Order2Context.class); + Assert.assertTrue(response.isSuccess()); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Order2Context order2Context = response.getContextBean(Order2Context.class); + Assert.assertEquals(6, orderContext.getOrderType()); + Assert.assertEquals("d", checkContext.getSign()); + Assert.assertEquals("order2", order2Context.getOrderNo()); + } - @Test - public void testContextBean2() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("order1"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("sign1"); - Order2Context orderContext2 = new Order2Context(); - orderContext2.setOrderNo("order2"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2); - Assert.assertTrue(response.isSuccess()); + @Test + public void testContextBean2() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("order1"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("sign1"); + Order2Context orderContext2 = new Order2Context(); + orderContext2.setOrderNo("order2"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, + orderContext2); + Assert.assertTrue(response.isSuccess()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/CheckContext.java index 24b1e24a..23edaebc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/CheckContext.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.context.ContextBean; @ContextBean public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/Order2Context.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/Order2Context.java index 86f797b0..11042c89 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/Order2Context.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/Order2Context.java @@ -4,33 +4,34 @@ import java.util.Date; public class Order2Context { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/OrderContext.java index 3ec3d9d7..819c4dc4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/bean/OrderContext.java @@ -7,33 +7,34 @@ import java.util.Date; @ContextBean("order") public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/cmp/ACmp.java index 4731ae51..6cabdd19 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/contextbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/LiteFlowXmlScriptLoopQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/LiteFlowXmlScriptLoopQLExpressELTest.java index ebb4c03b..b1988dba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/LiteFlowXmlScriptLoopQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/LiteFlowXmlScriptLoopQLExpressELTest.java @@ -18,48 +18,51 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/loop/application.properties") @SpringBootTest(classes = LiteFlowXmlScriptLoopQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.loop.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.loop.cmp" }) public class LiteFlowXmlScriptLoopQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } + + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/ACmp.java index a777cbbf..9a30a9e6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/DCmp.java index b57b4629..2c54108b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/loop/cmp/DCmp.java @@ -18,10 +18,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/LiteFlowScriptScriptbeanQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/LiteFlowScriptScriptbeanQLExpressELTest.java index ebcf4d22..5c7f7b33 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/LiteFlowScriptScriptbeanQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/LiteFlowScriptScriptbeanQLExpressELTest.java @@ -19,26 +19,27 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/scriptbean/application.properties") @SpringBootTest(classes = LiteFlowScriptScriptbeanQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.scriptbean.cmp","com.yomahub.liteflow.test.script.qlexpress.scriptbean.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.scriptbean.cmp", + "com.yomahub.liteflow.test.script.qlexpress.scriptbean.bean" }) public class LiteFlowScriptScriptbeanQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean1.java index 5b6bc770..3f730c93 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean1.java @@ -9,14 +9,15 @@ import javax.annotation.Resource; @ScriptBean("demo") public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; - public String getDemoStr1(){ - return "hello"; - } + public String getDemoStr1() { + return "hello"; + } + + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } - public String getDemoStr2(String name){ - return demoBean2.getDemoStr2(name); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean2.java index da9387c7..32346900 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/cmp/ACmp.java index 7b9926af..eb0ee236 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptbean/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/LiteFlowScriptScriptMethodQLExpressELTest.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/LiteFlowScriptScriptMethodQLExpressELTest.java index 49c0f2f6..fd9948b9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/LiteFlowScriptScriptMethodQLExpressELTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/LiteFlowScriptScriptMethodQLExpressELTest.java @@ -19,26 +19,27 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/scriptmethod/application.properties") @SpringBootTest(classes = LiteFlowScriptScriptMethodQLExpressELTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.scriptmethod.cmp","com.yomahub.liteflow.test.script.qlexpress.scriptmethod.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.script.qlexpress.scriptmethod.cmp", + "com.yomahub.liteflow.test.script.qlexpress.scriptmethod.bean" }) public class LiteFlowScriptScriptMethodQLExpressELTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testScriptBean1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello", context.getData("demo")); - } + @Test + public void testScriptBean1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello", context.getData("demo")); + } - @Test - public void testScriptBean2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,kobe", context.getData("demo")); - } + @Test + public void testScriptBean2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,kobe", context.getData("demo")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean1.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean1.java index 00e942d3..c632f45e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean1.java @@ -8,16 +8,17 @@ import javax.annotation.Resource; @Component public class DemoBean1 { - @Resource - private DemoBean2 demoBean2; + @Resource + private DemoBean2 demoBean2; - @ScriptMethod("demo") - public String getDemoStr1(){ - return "hello"; - } + @ScriptMethod("demo") + public String getDemoStr1() { + return "hello"; + } + + @ScriptMethod("demo2") + public String getDemoStr2(String name) { + return demoBean2.getDemoStr2(name); + } - @ScriptMethod("demo2") - public String getDemoStr2(String name){ - return demoBean2.getDemoStr2(name); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean2.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean2.java index f725fb50..db646dba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/bean/DemoBean2.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoBean2 { - public String getDemoStr2(String name){ - return "hello,"+name; - } + public String getDemoStr2(String name) { + return "hello," + name; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/cmp/ACmp.java index 63c59755..b8ccea69 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-script-qlexpress-springboot/src/test/java/com/yomahub/liteflow/test/script/qlexpress/scriptmethod/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 717afe93..487da486 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -9,12 +9,13 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index 64ab7a80..ed8cd7eb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -21,14 +22,15 @@ import org.slf4j.LoggerFactory; @TestPropertySource("classpath:/absoluteConfigPath/application.properties") public class AbsoluteConfigPathELSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testAbsoluteConfig() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java index 1df923f5..134fcec6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/asyncNode/AsyncNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java index fe6994de..a2ad5455 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 @@ -14,119 +14,119 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author ssss */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/asyncNode/application.properties") public class AsyncNodeELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; - /***** - * 标准chain 嵌套选择 嵌套子chain进行执行 - * 验证了when情况下 多个node是并行执行 - * 验证了默认参数情况下 when可以加载执行 - * **/ - @Test - public void testAsyncFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - System.out.println(response.getExecuteStepStr()); - } + @Inject + private FlowExecutor flowExecutor; - //这个和test1有点类似,只不过进一步验证了步骤 - @Test - public void testAsyncFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); - Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", - "b==>j==>h==>g==>f","b==>j==>h==>f==>g", - "b==>j==>f==>h==>g","b==>j==>f==>g==>h" - ).contains(response.getExecuteStepStr())); - } + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 验证了when情况下 多个node是并行执行 验证了默认参数情况下 when可以加载执行 + **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getExecuteStepStr()); + } - //测试errorResume,默认的errorResume为false,这里测试默认的 - @Test - public void testAsyncFlow3_1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); - } + // 这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue( + ListUtil + .toList("b==>j==>g==>f==>h", "b==>j==>g==>h==>f", "b==>j==>h==>g==>f", "b==>j==>h==>f==>g", + "b==>j==>f==>h==>g", "b==>j==>f==>g==>h") + .contains(response.getExecuteStepStr())); + } - //测试errorResume,默认的errorResume为false,这里设置为true - @Test - public void testAsyncFlow3_2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - } + // 测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 - @Test - public void testAsyncFlow4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); - //因为不记录错误,所以最终结果是true - Assert.assertTrue(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为配置了不抛错,所以response里的cause应该为null - Assert.assertNull(response.getCause()); - } + // 测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 - @Test - public void testAsyncFlow5() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); - //整个并行组是报错的,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为第一个when配置了会报错,所以response里的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + // 因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } - //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 - @Test - public void testAsyncFlow6() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); - //第一个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(1), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + // 整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } - //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 - @Test - public void testAsyncFlow7() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); - //第二个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - // 传递了slotIndex,则set的size==2 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + // 第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(1), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + // 第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 测试任意异步一个执行完即继续的场景 + // d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + // 最终执行效果应该是h先返回,然后执行abc,最后gd + // 这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("check").toString().startsWith("habc")); + } - //测试任意异步一个执行完即继续的场景 - //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 - //最终执行效果应该是h先返回,然后执行abc,最后gd - //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 - @Test - public void testAsyncFlow8() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("check").toString().startsWith("habc")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java index 87c4da66..5945662f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java @@ -4,21 +4,23 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; - @Component("a") public class ACmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Acomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java index 0e1f21f9..9f9ec3eb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java @@ -4,21 +4,23 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Bcomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java index e7b1174c..129c6793 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java @@ -4,21 +4,23 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java index 85dc9b63..ab2e8e25 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java @@ -4,22 +4,24 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(1000); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + Thread.sleep(1000); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java index e69fc8fa..9071a80f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java @@ -3,13 +3,13 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; import org.noear.solon.annotation.Component; - @Component("e") public class ECmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Ecomp executed!"); - return "g"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java index 40a99b85..966dd7da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java @@ -3,12 +3,12 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("f") public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Fcomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Fcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java index 43ad1003..165f5ffe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java @@ -4,23 +4,24 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; - @Component("g") public class GCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(500); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Gcomp executed!"); - } + @Override + public void process() throws Exception { + Thread.sleep(500); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java index bd35f6f6..df9a81eb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java @@ -4,23 +4,24 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.noear.solon.annotation.Component; - @Component("h") public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java index 27538bb5..0797835d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java @@ -5,22 +5,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.test.asyncNode.exception.TestException; import org.noear.solon.annotation.Component; - @Component("i") public class ICmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (ICmp.class){ - if (context.hasData("count")){ - Integer count = context.getData("count"); - context.setData("count", ++count); - } else{ - context.setData("count", 1); - } - } - System.out.println("Icomp executed! throw Exception!"); - throw new TestException(); - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (ICmp.class) { + if (context.hasData("count")) { + Integer count = context.getData("count"); + context.setData("count", ++count); + } + else { + context.setData("count", 1); + } + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java index b93fdaf9..0736dfde 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java @@ -3,13 +3,13 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; import org.noear.solon.annotation.Component; - @Component("j") public class JCmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Jcomp executed!"); - return "chain3"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java index e786e9f8..fa8827df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -1,4 +1,5 @@ package com.yomahub.liteflow.test.asyncNode.exception; -public class TestException extends Exception{ +public class TestException extends Exception { + } 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 768e27b1..d46afa4c 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 @@ -12,47 +12,49 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/base/application.properties") public class BaseELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testBase1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 最简单的情况 + @Test + public void testBase1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //switch节点最简单的测试用例 - @Test - public void testBase2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // switch节点最简单的测试用例 + @Test + public void testBase2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //then,when,switch混用的稍微复杂点的用例,switch跳到一个then上 - @Test - public void testBase3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // then,when,switch混用的稍微复杂点的用例,switch跳到一个then上 + @Test + public void testBase3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //一个非常复杂的例子,可以看base目录下的img.png这个图示 - @Test - public void testBase4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 一个非常复杂的例子,可以看base目录下的img.png这个图示 + @Test + public void testBase4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 用变量来声明短流程 + @Test + public void testBase5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用变量来声明短流程 - @Test - public void testBase5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java index 4360b4cf..6655fbe4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/base/cmp/ESwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/ESwitchCmp.java index 82f1af15..b4940a11 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/ESwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/ESwitchCmp.java @@ -17,4 +17,5 @@ public class ESwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java index 52ac7d90..796b8b2e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java @@ -17,4 +17,5 @@ public class GSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "then_1001"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java index 60336ff0..16aa3b69 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java @@ -17,4 +17,5 @@ public class XSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "w01"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java index 234ade25..002ea599 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java @@ -19,144 +19,157 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; @RunWith(SolonJUnit4ClassRunner.class) public class BuilderELSpringbootTest1 extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //基于普通组件的builder模式测试 - @Test - public void testBuilder() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") - .build(); + // 基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") + .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + // 基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz(GCmp.class) + .build(); - //基于普通组件的builder模式测试 - @Test - public void testBuilderForClassAndCode() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz(BCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz(DCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz(ECmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz(FCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz(GCmp.class) - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + @Test + public void testBuilderForSameNodeMultiTimes() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a1") + .setName("组件A1") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("a2") + .setName("组件A2") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c1") + .setName("组件C1") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c2") + .setName("组件C2") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(a1,c2,a2,c1)").build(); - @Test - public void testBuilderForSameNodeMultiTimes() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a1") - .setName("组件A1") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("a2") - .setName("组件A2") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c1") - .setName("组件C1") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c2") - .setName("组件C2") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); + } - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a1,c2,a2,c1)" - ).build(); - - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java index 3a4d7f0d..2bfba62b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java @@ -15,18 +15,17 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; @RunWith(SolonJUnit4ClassRunner.class) public class BuilderELSpringbootTest2 extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //通过spring去扫描组件,通过代码去构建chain - @Test - public void testBuilder() throws Exception { - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(h, i, j)" - ).build(); + // 通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(h, i, j)").build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java index 9fbbfba4..553e2334 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/cmpData/CmpDataELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java index 312f5ccd..606e0c52 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 @@ -15,24 +15,26 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/cmpData/application.properties") public class CmpDataELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 最简单的情况 + @Test + public void testCmpData() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + User user = context.getData("user"); + Assert.assertEquals(27, user.getAge()); + Assert.assertEquals("jack", user.getName()); + Assert.assertEquals(0, user.getBirth().compareTo(DateUtil.parseDate("1995-10-01").toJdkDate())); + } - //最简单的情况 - @Test - public void testCmpData() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - User user = context.getData("user"); - Assert.assertEquals(27, user.getAge()); - Assert.assertEquals("jack", user.getName()); - Assert.assertEquals(0, user.getBirth().compareTo(DateUtil.parseDate("1995-10-01").toJdkDate())); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java index 9a1f091d..469c3ac3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java @@ -18,4 +18,5 @@ public class ACmp extends NodeComponent { System.out.println(this.getCmpData(String.class)); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java index 483a78dd..08083f5a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java @@ -4,33 +4,34 @@ import java.util.Date; public class User { - private String name; + private String name; - private int age; + private int age; - private Date birth; + private Date birth; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public int getAge() { - return age; - } + public int getAge() { + return age; + } - public void setAge(int age) { - this.age = age; - } + public void setAge(int age) { + this.age = age; + } - public Date getBirth() { - return birth; - } + public Date getBirth() { + return birth; + } + + public void setBirth(Date birth) { + this.birth = birth; + } - public void setBirth(Date birth) { - this.birth = birth; - } } 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 c13f43ca..9e143dc0 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 @@ -11,9 +11,9 @@ import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; - /** * 测试springboot下的节点执行器 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -21,39 +21,39 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/cmpRetry/application.properties") public class LiteflowRetryELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //全局重试配置测试 - @Test - public void testRetry1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - System.out.println(ONode.stringify(response)); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); - } + // 全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + System.out.println(ONode.stringify(response)); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); + } + // 单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); + } - //单个组件重试配置测试 - @Test - public void testRetry2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); - } + // 单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } - //单个组件指定异常,但抛出的并不是指定异常的场景测试 - @Test - public void testRetry3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - } + // 单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); + } - //单个组件指定异常重试,抛出的是指定异常或者 - @Test - public void testRetry4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java index a1b1b3fb..0e217e4b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/cmpRetry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java index 3c50ded2..a43cfc64 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -18,7 +18,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java index b9232e5a..b523adfe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java index ba3f92d6..694d7fc8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("e") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class ECmp extends NodeComponent { @Override 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 7e8af51b..c1b0d6d8 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 @@ -18,6 +18,7 @@ import java.util.Set; /** * springboot环境step的测试例子 + * * @author Bryan.Zhang * @since 2.7.0 */ @@ -25,47 +26,48 @@ import java.util.Set; @TestPropertySource("classpath:/cmpStep/application.properties") public class CmpStepELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //ab串行 - //cd并行,都抛错,其中c耗时2秒 - @Test - public void testStep1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); - } + // ab串行 + // cd并行,都抛错,其中c耗时2秒 + @Test + public void testStep1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); + } - @Test - public void testStep2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testStep2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testStep3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Map stepMap = response.getExecuteSteps(); - Assert.assertEquals(2, stepMap.size()); - Queue queue = response.getExecuteStepQueue(); - Assert.assertEquals(5, queue.size()); + @Test + public void testStep3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Map stepMap = response.getExecuteSteps(); + Assert.assertEquals(2, stepMap.size()); + Queue queue = response.getExecuteStepQueue(); + Assert.assertEquals(5, queue.size()); - Set tagSet = new HashSet<>(); - response.getExecuteStepQueue().stream().filter( - cmpStep -> cmpStep.getNodeId().equals("a") - ).forEach(cmpStep -> tagSet.add(cmpStep.getTag())); + Set tagSet = new HashSet<>(); + response.getExecuteStepQueue() + .stream() + .filter(cmpStep -> cmpStep.getNodeId().equals("a")) + .forEach(cmpStep -> tagSet.add(cmpStep.getTag())); - Assert.assertEquals(3, tagSet.size()); + Assert.assertEquals(3, tagSet.size()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java index b3f53165..5539d301 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java @@ -14,8 +14,9 @@ import org.noear.solon.annotation.Component; public class ACmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Thread.sleep(5000L); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java index 2db8ed0d..686efe3e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java @@ -14,7 +14,7 @@ import org.noear.solon.annotation.Component; public class CCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); Thread.sleep(2000); throw new RuntimeException("test error c"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java index 70c596b7..b934d5b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java @@ -22,4 +22,5 @@ public class ECmp extends NodeComponent { public boolean isAccess() { return false; } + } 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 90979739..e8f39b83 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 @@ -23,6 +23,7 @@ public class LiteflowNodeELSpringbootTest extends BaseTest { public void testAsyncFlow1() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr())); + Assert.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr())); } + } \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java index 86a93c01..eefa2e1f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.noear.solon.annotation.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java index 6d860cfe..163f8bce 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.noear.solon.annotation.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java index 3652ceb9..8a943af3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.noear.solon.annotation.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { 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 a895e8b1..eb7ac244 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 @@ -12,30 +12,32 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/complex/application1.properties") public class ComplexELSpringbootTest1 extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java index 46ffa923..fcb9a4aa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java index 50ca54db..5c2e41e8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java @@ -15,6 +15,7 @@ public class BCmp extends NodeComponent { @Override public void process() { - + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java index d46c6d9f..a26011cc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java @@ -17,4 +17,5 @@ public class CCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java index 64ac0e29..41037cf1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java @@ -17,4 +17,5 @@ public class DCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java index cb178ef9..f254f5bb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java index bb5c8d10..7b74fe52 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java @@ -17,4 +17,5 @@ public class FCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java index cc132b22..83ed2cfc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java @@ -17,4 +17,5 @@ public class GCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "t1"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java index 78e5d72c..116d29fe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java @@ -17,4 +17,5 @@ public class HCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java index 18bf8d67..919d1e13 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java index 7f7e952b..231cecc0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java @@ -17,4 +17,5 @@ public class JCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java index c8499e7a..c81f0b09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java @@ -17,4 +17,5 @@ public class KCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java index 467813cb..b388c43b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java @@ -17,4 +17,5 @@ public class LCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java index b0b0ec35..69de3193 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java @@ -17,4 +17,5 @@ public class MCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java index 5444a87e..e4113b19 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java @@ -17,4 +17,5 @@ public class NCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java index aa8ab216..6caf77f9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java @@ -17,4 +17,5 @@ public class ZCmp extends NodeComponent { public void process() { } + } 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 4a68c165..be76a718 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 @@ -12,30 +12,32 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/complex/application2.properties") public class ComplexELSpringbootTest2 extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ACmp.java index bf21dd75..b9023996 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/BCmp.java index 9b81319a..fcba7b29 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/BCmp.java @@ -16,4 +16,5 @@ public class BCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "t3"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/CCmp.java index dc9a2a17..44b71db2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/CCmp.java @@ -17,4 +17,5 @@ public class CCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/DCmp.java index 872402da..b47a6c3c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/DCmp.java @@ -17,4 +17,5 @@ public class DCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ECmp.java index 88779bd7..056bc151 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/FCmp.java index 81bb87a2..f3ab167e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/FCmp.java @@ -17,4 +17,5 @@ public class FCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/GCmp.java index 802f830f..687fb619 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/GCmp.java @@ -17,4 +17,5 @@ public class GCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "t2"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/HCmp.java index 45d13415..46428f61 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/HCmp.java @@ -17,4 +17,5 @@ public class HCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ICmp.java index a7f940dc..3fe5dc46 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/JCmp.java index 1c771584..33ad6757 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/JCmp.java @@ -17,4 +17,5 @@ public class JCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/KCmp.java index 005b3513..c5ea2414 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/KCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/KCmp.java @@ -17,4 +17,5 @@ public class KCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/LCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/LCmp.java index 986191d7..4e806255 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/LCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/LCmp.java @@ -17,4 +17,5 @@ public class LCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/MCmp.java index 18670732..3edc09ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/MCmp.java @@ -17,4 +17,5 @@ public class MCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/NCmp.java index b83e2dd5..65fc0322 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/NCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/NCmp.java @@ -17,4 +17,5 @@ public class NCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ZCmp.java index 55886597..a629c55c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/complex2/cmp2/ZCmp.java @@ -17,4 +17,5 @@ public class ZCmp extends NodeComponent { public void process() { } + } 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 1473f22e..5e8aaeb4 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 @@ -13,65 +13,64 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * 组件功能点测试 - * 单元测试 + * 组件功能点测试 单元测试 * * @author donguo.tao */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/component/application.properties") public class FlowExecutorELSpringbootTest extends BaseTest { - private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELSpringbootTest.class); - @Inject - private FlowExecutor flowExecutor; + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELSpringbootTest.class); - //isAccess方法的功能测试 - @Test - public void testIsAccess() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); - Assert.assertTrue(response.isSuccess()); - Assert.assertNotNull(response.getSlot().getResponseData()); - } + @Inject + private FlowExecutor flowExecutor; + // isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } - //isContinueOnError方法的功能点测试 - @Test - public void testIsContinueOnError() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCause()); - } + // isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } - //isEnd方法的功能点测试 - @Test - public void testIsEnd() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d",response.getExecuteStepStr()); - } + // isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d", response.getExecuteStepStr()); + } - //setIsEnd方法的功能点测试 - @Test - public void testSetIsEnd1() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("e",response.getExecuteStepStr()); - } + // setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e", response.getExecuteStepStr()); + } - //条件组件的功能点测试 - @Test - public void testNodeCondComponent() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); - Assert.assertTrue(response.isSuccess()); - } + // 条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } - //测试setIsEnd如果为true,continueError也为true,那不应该continue了 - @Test - public void testSetIsEnd2() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g",response.getExecuteStepStr()); - } + // 测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java index 6c0ac6d4..8a90c6a0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -5,22 +5,23 @@ import org.noear.solon.annotation.Component; import java.util.Objects; - @Component("a") public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("AComp executed!"); - this.getSlot().setResponseData("AComp executed!"); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData) && requestData > 100){ - return true; - } - System.out.println("AComp isAccess false."); - return false; - } + @Override + public void process() { + System.out.println("AComp executed!"); + this.getSlot().setResponseData("AComp executed!"); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100) { + return true; + } + System.out.println("AComp isAccess false."); + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java index 9374c4a0..ca8b4a1c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -5,25 +5,25 @@ import org.noear.solon.annotation.Component; import java.util.Objects; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("BComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java index d9f19f54..8418b6d1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -5,25 +5,26 @@ import org.noear.solon.annotation.Component; import java.util.Objects; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() { - System.out.println("CComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - System.out.println("responseData="+Integer.parseInt(this.getSlot().getResponseData())); - } - @Override - public boolean isContinueOnError() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("CComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + System.out.println("responseData=" + Integer.parseInt(this.getSlot().getResponseData())); + } + + @Override + public boolean isContinueOnError() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java index e1471cd4..b01bd365 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -5,22 +5,23 @@ import org.noear.solon.annotation.Component; import java.util.Objects; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("DComp executed!"); - } - @Override - public boolean isEnd() { - //组件的process执行完之后才会执行isEnd - Object requestData = this.getSlot().getResponseData(); - if (Objects.isNull(requestData)){ - System.out.println("DComp flow isEnd, because of responseData is null."); - return true; - } - return false; - } + @Override + public void process() throws Exception { + System.out.println("DComp executed!"); + } + + @Override + public boolean isEnd() { + // 组件的process执行完之后才会执行isEnd + Object requestData = this.getSlot().getResponseData(); + if (Objects.isNull(requestData)) { + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java index 3cf1ec00..3f69b447 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -6,19 +6,19 @@ import org.noear.solon.annotation.Component; import java.util.Objects; - @Component("e") public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("EComp executed!"); - Object responseData = this.getSlot().getResponseData(); - if (Objects.isNull(responseData)){ - System.out.println("EComp responseData flow must be set end ."); - //执行到某个条件时,手动结束流程。 - this.setIsEnd(true); - } - System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); - } + @Override + public void process() throws Exception { + System.out.println("EComp executed!"); + Object responseData = this.getSlot().getResponseData(); + if (Objects.isNull(responseData)) { + System.out.println("EComp responseData flow must be set end ."); + // 执行到某个条件时,手动结束流程。 + this.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java index 01c1fd2e..0a580929 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -23,4 +23,5 @@ public class GCmp extends NodeComponent { public boolean isContinueOnError() { return true; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java index 8038b422..fccd6094 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -17,4 +17,5 @@ public class HCmp extends NodeComponent { public void process() { System.out.println("HCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java index e7093fd5..e46e1539 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java @@ -5,18 +5,21 @@ import org.noear.solon.annotation.Component; import java.util.Objects; - @Component("f") public class FSwitchCmp extends NodeSwitchComponent { - @Override - public String processSwitch() { - Integer requestData = this.getRequestData(); - if (Objects.isNull(requestData)){ - return "d"; - } else if(requestData == 0){ - return "c"; - } else { - return "b"; - } - } + + @Override + public String processSwitch() { + Integer requestData = this.getRequestData(); + if (Objects.isNull(requestData)) { + return "d"; + } + else if (requestData == 0) { + return "c"; + } + else { + return "b"; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 cc31f45f..400fcd53 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 @@ -13,8 +13,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * springboot环境下自定义声明节点的测试 - * 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * springboot环境下自定义声明节点的测试 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -22,16 +22,17 @@ import org.slf4j.LoggerFactory; @TestPropertySource("classpath:/customNodes/application.properties") public class CustomNodesELSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testCustomNodes() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java index d7cf0644..10ba24a8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/customNodes/domain/DemoDomain.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java index d13d225d..0525ba04 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -5,7 +5,8 @@ import org.noear.solon.annotation.Component; @Component public class DemoDomain { - public void sayHi(){ - System.out.println("hi"); - } + public void sayHi() { + System.out.println("hi"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6f88c4cd..6034ba62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -9,17 +9,15 @@ import java.util.concurrent.ExecutorService; public class CustomThreadExecutor1 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-1-thead-"); - } + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 7d45e4ad..8f9008e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor2 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-2-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index 875dc3d1..dc6f6399 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor3 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-3-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 c990066e..fd6a2f05 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 @@ -23,46 +23,46 @@ import org.slf4j.LoggerFactory; @TestPropertySource("classpath:/customWhenThreadPool/application.properties") public class CustomWhenThreadPoolELSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - /** - * 测试全局线程池配置 - */ - @Test - public void testGlobalThreadPool() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); - } + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); + } - /** - * 测试全局和when上自定义线程池-优先以when上为准 - */ - @Test - public void testGlobalAndCustomWhenThreadPool() { - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response1.getFirstContextBean(); - Assert.assertTrue(response1.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - } + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - /** - * when配置的线程池可以共用 - */ - @Test - public void testCustomWhenThreadPool() { - // 使用when - thread1 - testGlobalAndCustomWhenThreadPool(); - // chain配置同一个thead1 - LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response2.getFirstContextBean(); - Assert.assertTrue(response2.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java index 69a33c52..36b71da7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/event/EventELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java index db9d0f76..afefdbbb 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 @@ -13,6 +13,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境事件回调测试 + * * @author Bryan.Zhang * @since 2.7.1 */ @@ -20,38 +21,38 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/event/application.properties") public class EventELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //测试组件成功事件 - @Test - public void testEvent1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("abc", context.getData("test")); - } + // 测试组件成功事件 + @Test + public void testEvent1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("abc", context.getData("test")); + } - //测试组件失败事件 - @Test - public void testEvent2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("ab", context.getData("test")); - Assert.assertEquals("error:d", context.getData("error")); - } + // 测试组件失败事件 + @Test + public void testEvent2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("ab", context.getData("test")); + Assert.assertEquals("error:d", context.getData("error")); + } - //测试组件失败事件本身抛出异常 - @Test - public void testEvent3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("a", context.getData("test")); - Assert.assertEquals("error:e", context.getData("error")); - } + // 测试组件失败事件本身抛出异常 + @Test + public void testEvent3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("a", context.getData("test")); + Assert.assertEquals("error:e", context.getData("error")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java index bc9ab146..d51291d9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java @@ -17,7 +17,7 @@ public class ACmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",""); + context.setData("test", ""); System.out.println("ACmp executed!"); } @@ -28,4 +28,5 @@ public class ACmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java index d6f69b7f..24b6c520 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java @@ -26,4 +26,5 @@ public class BCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java index 1ec09c25..9ba45684 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java @@ -26,4 +26,5 @@ public class CCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java index e57c0c9c..50feb43c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java @@ -15,7 +15,7 @@ import org.noear.solon.annotation.Component; public class DCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -23,6 +23,7 @@ public class DCmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java index e54b28a6..75dadc2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java @@ -15,7 +15,7 @@ import org.noear.solon.annotation.Component; public class ECmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -23,7 +23,8 @@ public class ECmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); throw new IllegalAccessException("错误事件回调本身抛出异常"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java index 11441ab5..e7b2394c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java @@ -6,7 +6,9 @@ import com.yomahub.liteflow.exception.LiteFlowException; * 用户自定义带状态码的异常 */ public class CustomStatefulException extends LiteFlowException { + public CustomStatefulException(String code, String message) { super(code, message); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java index 5441ca26..0dac705a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java @@ -16,45 +16,44 @@ import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit4ClassRunner; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @RunWith(SolonJUnit4ClassRunner.class) public class Exception1ELSpringBootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - /** - * 验证 chain 节点重复的异常 - */ - @Test(expected = ChainDuplicateException.class) - public void testChainDuplicateException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-exception.el.xml"); - flowExecutor.reloadRule(); - } + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = ChainDuplicateException.class) + public void testChainDuplicateException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = ConfigErrorException.class) - public void testConfigErrorException() { - flowExecutor.setLiteflowConfig(null); - flowExecutor.reloadRule(); - } + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testFlowExecutorNotInitException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("error/flow.txt"); - flowExecutor.reloadRule(); - } + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("error/flow.txt"); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testNoConditionInChainException() throws Exception { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-blank.el.xml"); - flowExecutor.reloadRule(); - } + @Test(expected = FlowExecutorNotInitException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-blank.el.xml"); + flowExecutor.reloadRule(); + } } 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 c582adaf..6b02970b 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 @@ -16,60 +16,60 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/exception/application.properties") public class Exception2ELSpringBootTest extends BaseTest { - - @Inject - private FlowExecutor flowExecutor; - @Inject - private AopContext context; + @Inject + private FlowExecutor flowExecutor; - @Test(expected = ChainNotFoundException.class) - public void testChainNotFoundException() throws Exception { - flowExecutor.execute("chain0", "it's a request"); - } + @Inject + private AopContext context; - @Test(expected = RuntimeException.class) - public void testComponentCustomException() throws Exception { - flowExecutor.execute("chain1", "exception"); - } + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } - @Test - public void testGetSlotFromResponseWhenException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); - Assert.assertFalse(response.isSuccess()); - Assert.assertNotNull(response.getCause()); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } - @Test(expected = NoSwitchTargetNodeException.class) - public void testNoTargetFindException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); - Assert.assertFalse(response.isSuccess()); - throw response.getCause(); - } + @Test + public void testGetSlotFromResponseWhenException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } - @Test - public void testInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("300", response.getCode()); - Assert.assertNotNull(response.getCause()); - Assert.assertTrue(response.getCause() instanceof LiteFlowException); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = NoSwitchTargetNodeException.class) + public void testNoTargetFindException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); + Assert.assertFalse(response.isSuccess()); + throw response.getCause(); + } + + @Test + public void testInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("300", response.getCode()); + Assert.assertNotNull(response.getCause()); + Assert.assertTrue(response.getCause() instanceof LiteFlowException); + Assert.assertNotNull(response.getSlot()); + } + + @Test + public void testNotInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCode()); + } - @Test - public void testNotInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCode()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java index 54110635..fa0647bb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -15,13 +15,13 @@ import org.noear.solon.annotation.Component; @Component("a") public class ACmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new RuntimeException("chain execute execption"); } LOG.info("Acomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java index d09c1f11..c8dccec5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -15,21 +15,23 @@ import org.noear.solon.annotation.Component; @Component("b") public class BCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); @Override public void process() throws InterruptedException { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("when")) { + if (StrUtil.isNotBlank(str) && str.equals("when")) { try { LOG.info("Bcomp sleep begin"); Thread.sleep(3000); LOG.info("Bcomp sleep end"); - } catch (InterruptedException e) { + } + catch (InterruptedException e) { throw e; } } LOG.info("Bcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java index aec2f64b..653b8c5c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -14,11 +14,12 @@ import org.noear.solon.annotation.Component; @Component("c") public class CCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); - + @Override public void process() { LOG.info("Ccomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java index b4ddc3cc..2d6fab04 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -14,14 +14,15 @@ import org.noear.solon.annotation.Component; @Component("d") public class DCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); - + @Override public void process() { - if(1==1){ - int a = 1/0; + if (1 == 1) { + int a = 1 / 0; } LOG.info("Dcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java index a7443cd2..4a8a0fe9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "a"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java index ca9ad309..dddfd2e7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java @@ -16,13 +16,13 @@ import org.noear.solon.annotation.Component; @Component("f") public class FCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(FCmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { + if (StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { throw new CustomStatefulException("300", "chain execute custom stateful execption"); } LOG.info("Fcomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java index 82f53e5a..17391f55 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java @@ -14,11 +14,12 @@ import org.noear.solon.annotation.Component; @Component("g") public class GCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(GCmp.class); - + @Override public void process() { LOG.info("Gcomp executed!"); } + } 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 09f55a12..1825c012 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 @@ -14,6 +14,7 @@ import java.util.concurrent.Future; /** * springboot环境执行返回future的例子 + * * @author Bryan.Zhang * @since 2.6.13 */ @@ -21,14 +22,14 @@ import java.util.concurrent.Future; @TestPropertySource("classpath:/execute2Future/application.properties") public class Executor2FutureELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testFuture() throws Exception{ - Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); - LiteflowResponse response = future.get(); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testFuture() throws Exception { + Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java index db0bc1f4..2a1747ef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/getChainName/GetChainNameELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java index 0fa63807..c409239c 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 @@ -13,41 +13,42 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境获取ChainName的测试 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/getChainName/application.properties") public class GetChainNameELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testGetChainName1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - } + @Test + public void testGetChainName1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } - @Test - public void testGetChainName2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("chain2", context.getData("g")); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - Assert.assertEquals("sub5", context.getData("f")); - Assert.assertEquals("sub5_chain2", context.getData("e")); - Assert.assertEquals("sub6", context.getData("h")); - Assert.assertEquals("sub6", context.getData("j")); - Assert.assertNull(context.getData("k")); - } + @Test + public void testGetChainName2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java index ff9961ec..828c13ca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { DefaultContext context = this.getFirstContextBean(); context.setData(this.getNodeId(), this.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java index 0117d51c..35dc2ed1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -17,9 +17,10 @@ public class ECmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - if (context.hasData(this.getNodeId())){ + if (context.hasData(this.getNodeId())) { context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainId()); - }else{ + } + else { context.setData(this.getNodeId(), this.getCurrChainId()); } } 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 ebd80297..83f5588f 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 @@ -12,69 +12,70 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/ifelse/application.properties") public class IfELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 157a4181..d8af1a88 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 @@ -12,8 +12,10 @@ import org.noear.solon.annotation.Component; @Component("x1") public class X1Cmp extends NodeIfComponent { + @Override public boolean processIf() 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 c21ecb32..e0f656fd 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 @@ -10,9 +10,9 @@ import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; - /** * 测试@LiteflowComponent标注 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -20,13 +20,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/lfCmpAnno/application.properties") public class LiteflowComponentELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); + } - @Test - public void testConfig() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java index 6c4fc23a..9d3a992e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/loop/LoopELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java index 5b3c801f..5debffc3 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 @@ -13,73 +13,77 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL循环的例子测试 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/loop/application.properties") public class LoopELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //测试FOR循环中的index - @Test - public void testLoop6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } + // 测试FOR循环中的index + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } + + // 测试WHILE循环中的index + @Test + public void testLoop7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } - //测试WHILE循环中的index - @Test - public void testLoop7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java index 0c31d13b..46681d7d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java index f1a0d356..fe04067f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java @@ -18,10 +18,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java index da1c622d..da9d4322 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java @@ -19,11 +19,12 @@ public class ECmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = StrUtil.format("{}_{}", "loop", this.getTag()); - if (context.hasData(key)){ + if (context.hasData(key)) { String loopStr = context.getData(key); String loopStrReturn = StrUtil.format("{}{}", loopStr, this.getLoopIndex()); context.setData(key, loopStrReturn); - }else{ + } + else { context.setData(key, this.getLoopIndex().toString()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java index fa9fe7e5..5ca52556 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java @@ -5,8 +5,10 @@ import com.yomahub.liteflow.core.NodeForComponent; @LiteflowComponent("x") public class XCmp extends NodeForComponent { - @Override - public int processFor() throws Exception { - return 3; - } + + @Override + public int processFor() throws Exception { + return 3; + } + } 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 95a744a5..c4bb114c 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 @@ -7,10 +7,12 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") public class YCmp extends NodeBreakComponent { - @Override - public boolean processBreak() throws Exception { - DefaultContext context = this.getFirstContextBean(); - int count = context.getData("test"); - return count > 3; - } + + @Override + public boolean processBreak() 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 e5ef68dc..c7bb40e7 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 @@ -7,15 +7,18 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") public class ZCmp extends NodeWhileComponent { - @Override - public boolean processWhile() throws Exception { - DefaultContext context = this.getFirstContextBean(); - String key = "test"; - if (context.hasData(key)){ - int count = context.getData("test"); - return count < 5; - }else{ - return true; - } - } + + @Override + public boolean processWhile() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } + else { + return true; + } + } + } 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 c19acb3e..7057c731 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 @@ -15,6 +15,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -22,21 +23,21 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/monitor/application.properties") public class MonitorELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); + @Test + public void testMonitor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); - Thread.sleep(10000); - } + Thread.sleep(10000); + } - @AfterClass - public static void clean(){ - MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); - monitorBus.closeScheduler(); - } + @AfterClass + public static void clean() { + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java index 765f5fd6..8480a51a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java @@ -19,10 +19,12 @@ public class ACmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java index 1a9aa457..e70da658 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java @@ -19,7 +19,8 @@ public class BCmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java index cc73e872..3329b26e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java @@ -19,7 +19,8 @@ public class CCmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java index 68ba8dac..1a555dca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -19,17 +19,18 @@ import java.io.File; @TestPropertySource("classpath:/monitorFile/application.properties") public class MonitorFileELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } - @Test - public void testMonitor() throws Exception{ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java index d1785a01..2bcc4b1b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { 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/multiContext/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java index af8bfad4..793d85e1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java @@ -2,23 +2,24 @@ package com.yomahub.liteflow.test.multiContext; public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } 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 74e2c1f8..9d8c8583 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 @@ -15,6 +15,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -22,40 +23,40 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/multiContext/application.properties") public class MultiContextELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testMultiContext1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("987XYZ", checkContext.getSign()); - Assert.assertEquals(95, checkContext.getRandomId()); - Assert.assertEquals("SO12345", orderContext.getOrderNo()); - Assert.assertEquals(2, orderContext.getOrderType()); - Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); - } + @Test + public void testMultiContext1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("987XYZ", checkContext.getSign()); + Assert.assertEquals(95, checkContext.getRandomId()); + Assert.assertEquals("SO12345", orderContext.getOrderNo()); + Assert.assertEquals(2, orderContext.getOrderType()); + Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); + } - @Test(expected = NoSuchContextBeanException.class) - public void testMultiContext2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - DefaultContext context = response.getContextBean(DefaultContext.class); - } + @Test(expected = NoSuchContextBeanException.class) + public void testMultiContext2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + DefaultContext context = response.getContextBean(DefaultContext.class); + } - @Test - public void testPassInitializedContextBean() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("SO11223344"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("987654321d"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext); - Assert.assertTrue(response.isSuccess()); - OrderContext context1 = response.getContextBean(OrderContext.class); - CheckContext context2 = response.getContextBean(CheckContext.class); - Assert.assertEquals("SO11223344", context1.getOrderNo()); - Assert.assertEquals("987654321d", context2.getSign()); - } + @Test + public void testPassInitializedContextBean() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("SO11223344"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("987654321d"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext); + Assert.assertTrue(response.isSuccess()); + OrderContext context1 = response.getContextBean(OrderContext.class); + CheckContext context2 = response.getContextBean(CheckContext.class); + Assert.assertEquals("SO11223344", context1.getOrderNo()); + Assert.assertEquals("987654321d", context2.getSign()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java index c477108b..292db52b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java @@ -4,33 +4,34 @@ import java.util.Date; public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java index 260fad4f..e6afab3c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java @@ -21,4 +21,5 @@ public class ACmp extends NodeComponent { checkContext.setRandomId(95); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java index fea28b55..847ab1ab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java @@ -16,7 +16,7 @@ public class BCmp extends NodeComponent { @Override public void process() { - //getContextBean无参方法是获取到第一个上下文 + // getContextBean无参方法是获取到第一个上下文 OrderContext orderContext = this.getFirstContextBean(); orderContext.setOrderNo("SO12345"); System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java index bb9ee5b8..d0490870 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeComponent { @Override public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java index 720dd626..85144191 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java @@ -16,4 +16,5 @@ public class FCmp extends NodeComponent { @Override public void process() { } + } 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 dba4430f..c62204d9 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 @@ -10,9 +10,9 @@ import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; - /** * 测试springboot下混合格式规则的场景 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -20,16 +20,17 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/multipleType/application.properties") public class LiteflowMultipleTypeELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } - @Test - public void testMultipleType() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); - response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java index 30c90df1..2ce8f2b9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java index 9fb99224..9cce6d74 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -8,11 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义默认的节点执行器 */ public class CustomerDefaultNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerDefaultNodeExecutor进行执行"); - context.setData("customerDefaultNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + context.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java index e4ef70e0..f4d447b6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -8,12 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义节点执行器 */ public class CustomerNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutor进行执行"); - context.setData("customerNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutor进行执行"); + context.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java index 202005b1..130208a7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -10,19 +10,21 @@ import java.util.concurrent.TimeUnit; * 自定义节点执行器 */ public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); - context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); - super.execute(instance); - } - @Override - protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { - TimeUnit.MICROSECONDS.sleep(20L); - DefaultContext context = instance.getFirstContextBean(); - context.setData("retryLogic", this.getClass()); - super.retry(instance, currentRetryCount); - } + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + DefaultContext context = instance.getFirstContextBean(); + context.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 b01ffcf8..55da1960 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 @@ -11,7 +11,6 @@ import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; - /** * 测试springboot下的组件重试 * @@ -22,44 +21,45 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/nodeExecutor/application.properties") public class LiteflowNodeExecutorELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - // 默认执行器测试 - @Test - public void testCustomerDefaultNodeExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("a", response.getExecuteStepStr()); - } + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getExecuteStepStr()); + } - //默认执行器测试+全局重试配置测试 - @Test - public void testDefaultExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); - } + // 默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); + } - //自定义执行器测试 - @Test - public void testCustomerExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("c", response.getExecuteStepStr()); - } + // 自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStr()); + } + + // 自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); + } - //自定义执行器测试+全局重试配置测试 - @Test - public void testCustomExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); - Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java index 8fd765bb..5eec1192 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java @@ -14,9 +14,9 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("a") public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("ACmp executed!"); - } + @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/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java index 6e737879..de68032f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -18,7 +18,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java index f800c08b..77c9ca4c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -23,7 +23,8 @@ public class CCmp extends NodeComponent { } @Override - public Class getNodeExecutorClass() { + public Class getNodeExecutorClass() { return CustomerNodeExecutor.class; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java index bc99b47a..210c1c05 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -15,17 +15,18 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { - @Override - public void process() { - System.out.println("DCmp executed!"); - throw new NullPointerException("demo exception"); - } + @Override + public void process() { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @Override + public Class getNodeExecutorClass() { + return CustomerNodeExecutorAndCustomRetry.class; + } - @Override - public Class getNodeExecutorClass() { - return CustomerNodeExecutorAndCustomRetry.class; - } } 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 0aa6773f..1cd70246 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 @@ -20,16 +20,16 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/nullParam/application.properties") public class NullParamELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - /** - * 支持无参的flow执行,以及param 为null时的异常抛出 - */ - @Test - public void testNullParam() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - } + /** + * 支持无参的flow执行,以及param 为null时的异常抛出 + */ + @Test + public void testNullParam() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java index 5815b584..bd847e2f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { System.out.println("get request data:" + this.getRequestData()); this.getSlot().setInput("BCmp", "param for BCmp"); } + } 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 f6414ac4..d582bbf4 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 @@ -12,6 +12,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境的自定义json parser单元测试 + * * @author dongguo.tao * @since 2.5.0 */ @@ -19,13 +20,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/parsecustom/application-custom-json.properties") public class CustomParserJsonELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testJsonCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 af629f41..36949b2a 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 @@ -11,8 +11,8 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ @@ -20,13 +20,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/parsecustom/application-custom-xml.properties") public class CustomParserXmlELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testXmlCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 c3d4c777..0906c594 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 @@ -11,8 +11,7 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; /** - * springboot环境的自定义yml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义yml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 * * @author junjun */ @@ -20,13 +19,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/parsecustom/application-custom-yml.properties") public class CustomParserYmlELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testYmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testYmlCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java index 62650505..1b8795fc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -5,7 +5,8 @@ import org.noear.solon.annotation.Component; @Component public class TestBean { - public String returnXmlContent(){ - return "THEN(a,b,c,d)"; - } + public String returnXmlContent() { + return "THEN(a,b,c,d)"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java index 221d69b4..35fc960e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -18,9 +18,10 @@ public class ACmp extends NodeComponent { @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new FlowSystemException("chain execute execption"); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java index e4b612d7..d0795d35 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java index 42f5eeed..a164ba09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -4,14 +4,17 @@ import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser; /** * 模拟用户自定义源解析 + * * @author dongguo.tao * @since 2.5.0 */ public class CustomJsonFlowParser extends ClassJsonFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; - return content; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; + return content; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java index 4d16d111..4aa4defa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -5,18 +5,19 @@ import com.yomahub.liteflow.test.parsecustom.bean.TestBean; import org.noear.solon.annotation.Inject; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ public class CustomXmlFlowParser extends ClassXmlFlowELParser { - @Inject - private TestBean testBean; + @Inject + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } - @Override - public String parseCustom() { - return testBean.returnXmlContent(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java index 3431a3d5..b89fcc77 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java @@ -8,12 +8,11 @@ import com.yomahub.liteflow.parser.el.ClassYmlFlowELParser; * @author junjun */ public class CustomYmlFlowParser extends ClassYmlFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - return "flow:\n" + - " chain:\n" + - " - name: chain1\n" + - " value: \"THEN(a, b, c);\""; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + return "flow:\n" + " chain:\n" + " - name: chain1\n" + " value: \"THEN(a, b, c);\""; + } + } 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 f5be16f7..3229fbd1 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 @@ -12,6 +12,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * spring环境的json parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -19,13 +20,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/parser/application-json.properties") public class JsonParserELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的json parser - @Test - public void testJsonParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 41bd8cc9..a9d1afca 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 @@ -14,13 +14,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/parser/application-springEL.properties") public class SpringELSupportELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 测试springEL的解析情况 + @Test + public void testSpringELParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试springEL的解析情况 - @Test - public void testSpringELParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); - Assert.assertTrue(response.isSuccess()); - } } 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 cba7a448..d0d8473d 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 @@ -12,6 +12,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -19,13 +20,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/parser/application-xml.properties") public class XmlParserELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 测试无springboot场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的xml parser - @Test - public void testXmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 8d9db16b..3d31e8ed 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 @@ -12,6 +12,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot下的yml parser测试用例 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -19,13 +20,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/parser/application-yml.properties") public class YmlParserELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 测试无springboot场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的yml parser - @Test - public void testYmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java index 1b348e25..29deae61 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/parser/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java index 8f95c099..bb2a65a1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } 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 758dd45b..66813293 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 @@ -13,6 +13,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下pre节点和finally节点的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -20,62 +21,63 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/preAndFinally/application.properties") public class PreAndFinallyELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //测试普通的pre和finally节点 - @Test - public void testPreAndFinally1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试pre和finally节点不放在开头和结尾的情况 - @Test - public void testPreAndFinally2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 - @Test - public void testPreAndFinally3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); - } + // 测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); + } - //测试在finally节点里是否能获取exception - @Test - public void testPreAndFinally4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(context.getData("hasEx")); - } + // 测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(context.getData("hasEx")); + } - //测试嵌套结构pre和finally是否在各自的chain里打出 - @Test - public void testPreAndFinally5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } + // 测试嵌套结构pre和finally是否在各自的chain里打出 + @Test + public void testPreAndFinally5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } - //测试变量结构pre和finally是否在各自的chain里打出 - @Test - public void testPreAndFinally6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } + // 测试变量结构pre和finally是否在各自的chain里打出 + @Test + public void testPreAndFinally6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } + + // 测试el整体结构的多重pre和finally + @Test + public void testPreAndFinally7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试el整体结构的多重pre和finally - @Test - public void testPreAndFinally7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java index cc08cf0e..06fd909a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/preAndFinally/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java index 49a4515b..a9758dd4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -16,7 +16,7 @@ public class DCmp extends NodeComponent { @Override public void process() { System.out.println("CCmp executed!"); - int i = 1/0; + int i = 1 / 0; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java index d7070796..5057a798 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -17,4 +17,5 @@ public class Finally1Cmp extends NodeComponent { public void process() { System.out.println("Finally1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java index 8931498a..7d93b8a5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -17,4 +17,5 @@ public class Finally2Cmp extends NodeComponent { public void process() { System.out.println("Finally2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java index 6d6954cb..ac899fb4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -17,14 +17,16 @@ import org.noear.solon.annotation.Component; public class Finally3Cmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Slot slot = this.getSlot(); DefaultContext context = slot.getFirstContextBean(); - if (ObjectUtil.isNull(slot.getException())){ + if (ObjectUtil.isNull(slot.getException())) { context.setData("hasEx", false); - }else{ + } + else { context.setData("hasEx", true); } System.out.println("Finally3Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java index 0948ba80..89a4d0fe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -17,4 +17,5 @@ public class Pre1Cmp extends NodeComponent { public void process() { System.out.println("Pre1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java index 36e77323..37e570bc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -17,4 +17,5 @@ public class Pre2Cmp extends NodeComponent { public void process() { System.out.println("Pre2Cmp executed!"); } + } 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 5977cf78..7d0fe732 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 @@ -14,6 +14,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -21,15 +22,16 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/privateDelivery/application.properties") public class PrivateDeliveryELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + ConcurrentHashSet set = context.getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } - @Test - public void testPrivateDelivery() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - ConcurrentHashSet set = context.getData("testSet"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(100, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java index c7cb8c9b..35d07749 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -22,8 +22,8 @@ public class ACmp extends NodeComponent { context.setData("testSet", new ConcurrentHashSet<>()); for (int i = 0; i < 100; i++) { - this.sendPrivateDeliveryData("b",i+1); + this.sendPrivateDeliveryData("b", i + 1); } } -} +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java index 54cf4ce3..cb537efe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -15,13 +15,13 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BCmp executed!"); - Integer value = this.getPrivateDeliveryData(); - DefaultContext context = this.getFirstContextBean(); - ConcurrentHashSet testSet = context.getData("testSet"); - testSet.add(value); - } -} + @Override + public void process() { + System.out.println("BCmp executed!"); + Integer value = this.getPrivateDeliveryData(); + DefaultContext context = this.getFirstContextBean(); + ConcurrentHashSet testSet = context.getData("testSet"); + testSet.add(value); + } +} 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 251d7d68..f939af02 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 @@ -15,6 +15,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -22,41 +23,44 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/refreshRule/application.properties") public class RefreshRuleELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //测试普通刷新流程的场景 - @Test - public void testRefresh1() throws Exception{ - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception { + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试优雅刷新的场景 - @Test - public void testRefresh2() throws Exception{ - new Thread(() -> { - try { - Thread.sleep(3000L); - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - } catch (Exception e) { - e.printStackTrace(); - } + // 测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception { + new Thread(() -> { + try { + Thread.sleep(3000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + } + catch (Exception e) { + e.printStackTrace(); + } - }).start(); + }).start(); - for (int i = 0; i < 500; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - try { - Thread.sleep(10L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java index 91745bc7..81d8634b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/reload/ReloadELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java index df36f8d3..a291043d 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 @@ -12,6 +12,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -19,15 +20,16 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/reload/application.properties") public class ReloadELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + // 这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception { + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml - //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 - @Test - public void testReload() throws Exception{ - flowExecutor.reloadRule(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java index b73b7ce3..31aeebe5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/removeChain/RemoveChainELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java index c0c92265..efef4b4f 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 @@ -13,6 +13,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -20,16 +21,16 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/removeChain/application.properties") public class RemoveChainELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testRemoveChain() throws Exception{ - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response1.isSuccess()); - FlowBus.removeChain("chain1"); - LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response2.isSuccess()); - } + @Test + public void testRemoveChain() throws Exception { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + FlowBus.removeChain("chain1"); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response2.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java index e94e9d43..cc9cee5e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/requestId/LiteflowRequestIdELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java index 2cb87366..01d6ce7e 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 @@ -17,14 +17,14 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/requestId/application.properties") public class LiteflowRequestIdELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testRequestId() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1", response.getRequestId()); - } + @Test + public void testRequestId() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", response.getRequestId()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java index 75a277d1..b80de2e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java @@ -16,8 +16,9 @@ import org.noear.solon.annotation.Component; @Component("a") public class ACmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java index c325a0fc..1f6f755a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.noear.solon.annotation.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java index fcaa9e84..e705db34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java @@ -9,10 +9,11 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class CustomRequestIdGenerator implements RequestIdGenerator { - private final AtomicInteger atomicInteger = new AtomicInteger(0); + private final AtomicInteger atomicInteger = new AtomicInteger(0); + + @Override + public String generate() { + return atomicInteger.incrementAndGet() + ""; + } - @Override - public String generate() { - return atomicInteger.incrementAndGet() + ""; - } } 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 a7cf22dd..fc9a37f3 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 @@ -15,52 +15,53 @@ import java.util.HashSet; import java.util.Set; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author justin.xu */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/subflow/application-implicit.properties") public class ImplicitSubFlowELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; - public static final Set RUN_TIME_SLOT = new HashSet<>(); + @Inject + private FlowExecutor flowExecutor; - //这里GCmp中隐式的调用chain4,从而执行了h,m - @Test - public void testImplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); + public static final Set RUN_TIME_SLOT = new HashSet<>(); - // 传递了slotIndex,则set的size==1 - Assert.assertEquals(1, RUN_TIME_SLOT.size()); - // set中第一次设置的requestId和response中的requestId一致 - Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); - //requestData的取值正确 - Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); - } + // 这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); - //在p里多线程调用q 10次,每个q取到的参数都是不同的。 - @Test - public void testImplicitSubFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + // requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); + } - Set set = context.getData("test"); + // 在p里多线程调用q 10次,每个q取到的参数都是不同的。 + @Test + public void testImplicitSubFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); - //requestData的取值正确 - Assert.assertEquals(10, set.size()); - } + Set set = context.getData("test"); - @Test - public void testImplicitSubFlow3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain_r", "it's a request"); - Assert.assertTrue(response.isSuccess()); + // requestData的取值正确 + Assert.assertEquals(10, set.size()); + } + + @Test + public void testImplicitSubFlow3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain_r", "it's a request"); + Assert.assertTrue(response.isSuccess()); + + } - } } 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 4d46b5c2..c574e853 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 @@ -21,25 +21,27 @@ import org.noear.solon.test.annotation.TestPropertySource; @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/subflow/application-subInDifferentConfig1.properties") public class SubflowInDifferentConfigELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Inject + private FlowExecutor flowExecutor; - @Inject - private AopContext context; + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); + } + + @Inject + private AopContext context; + + // 主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.yml"); + flowExecutor.reloadRule(); + } - //主要测试有不同的配置类型后会不会报出既定的错误 - @Test(expected = MultipleParsersException.class) - public void testExplicitSubFlow2() { - LiteflowConfig config = context.getBean(LiteflowConfig.class); - config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.yml"); - flowExecutor.reloadRule(); - } } 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 9a0be3ed..7ae29410 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 @@ -11,22 +11,23 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; /** - * 测试显示调用子流程(xml) - * 单元测试 + * 测试显示调用子流程(xml) 单元测试 * * @author justin.xu */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/subflow/application-xml.properties") public class SubflowXMLELSpringBootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Inject + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 d3a2acea..0ba515e1 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 @@ -11,22 +11,23 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; /** - * 测试显示调用子流程(yml) - * 单元测试 + * 测试显示调用子流程(yml) 单元测试 * * @author justin.xu */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/subflow/application-yml.properties") public class SubflowYmlELSpringBootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlowYml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Inject + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java index ab9dc377..1337e1da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; 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("Acomp executed!"); - } + + @Override + public void process() { + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java index 12d89ef1..53d838ff 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("Bcomp executed!"); - } + + @Override + public void process() { + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java index fb874d46..a9c5114a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java index de14ae6d..04357769 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java index dc527036..d3f0ee0f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -3,12 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("e") public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ecomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Ecomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java index d17c6b16..585d824a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -6,17 +6,18 @@ import org.noear.solon.annotation.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("f") public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - context.setData("innerRequestData", "inner request"); + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + DefaultContext context = this.getFirstContextBean(); + context.setData("innerRequestData", "inner request"); + + System.out.println("Fcomp executed!"); + } - System.out.println("Fcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java index 6bd52539..747e6b5e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -7,22 +7,20 @@ import org.noear.solon.annotation.Inject; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("g") public class GCmp extends NodeComponent { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Override - public void process() throws Exception { + @Override + public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); - System.out.println("Gcmp executed!"); + System.out.println("Gcmp executed!"); + this.invoke("chain4", "it's implicit subflow."); + } - - this.invoke("chain4", "it's implicit subflow."); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index 8825af58..932fadef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -6,17 +6,18 @@ import org.noear.solon.annotation.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("h") public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqData(); - DefaultContext context = this.getFirstContextBean(); - context.setData("innerRequest", requestData); - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqData(); + DefaultContext context = this.getFirstContextBean(); + context.setData("innerRequest", requestData); + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java index 967d22a4..3c27939e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -5,14 +5,15 @@ import org.noear.solon.annotation.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("m") public class MCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); + } - System.out.println("Mcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java index f4e0a08e..1fbfc993 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java @@ -8,16 +8,18 @@ import org.noear.solon.annotation.Inject; @Component("p") public class PCmp extends NodeComponent { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Override + public void process() throws Exception { + int slotIndex = this.getSlotIndex(); + for (int i = 0; i < 10; i++) { + int finalI = i; + new Thread(() -> flowExecutor.invoke2RespInAsync("c2", "it's implicit subflow " + finalI, slotIndex)) + .start(); + } + Thread.sleep(1000); + } - @Override - public void process() throws Exception { - int slotIndex = this.getSlotIndex(); - for (int i = 0; i < 10; i++) { - int finalI = i; - new Thread(() -> flowExecutor.invoke2RespInAsync("c2", "it's implicit subflow " + finalI, slotIndex)).start(); - } - Thread.sleep(1000); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java index 3cae2456..ae7422b3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java @@ -9,23 +9,25 @@ import java.util.Set; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("q") public class QCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqDataInAsync(); - DefaultContext context = this.getFirstContextBean(); - synchronized (QCmp.class){ - if (context.hasData("test")){ - Set set = context.getData("test"); - set.add(requestData); - }else{ - Set set = new HashSet<>(); - set.add(requestData); - context.setData("test", set); - } - } - } + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqDataInAsync(); + DefaultContext context = this.getFirstContextBean(); + + synchronized (QCmp.class) { + if (context.hasData("test")) { + Set set = context.getData("test"); + set.add(requestData); + } + else { + Set set = new HashSet<>(); + set.add(requestData); + context.setData("test", set); + } + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java index 804bba47..bfaa1ce9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java @@ -5,8 +5,10 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("r") public class R extends NodeComponent { - @Override - public void process() throws Exception { - this.invoke2Resp("chain_s",""); - } + + @Override + public void process() throws Exception { + this.invoke2Resp("chain_s", ""); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java index fbaf1dc9..8743967b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java @@ -5,8 +5,10 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("s") public class S extends NodeComponent { - @Override - public void process() throws Exception { - throw new RuntimeException("test"); - } + + @Override + public void process() throws Exception { + throw new RuntimeException("test"); + } + } 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 b0b3de17..42d414e3 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 @@ -11,22 +11,23 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; import org.noear.solon.test.annotation.TestPropertySource; /** - * 测试显示调用子流程(json) - * 单元测试 + * 测试显示调用子流程(json) 单元测试 * * @author justin.xu */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/subflow/application-json.properties") public class SubflowJsonELSpringBootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Inject + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ACmp.java index 720376df..e86d9905 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ACmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow2.cmp1; 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("Acomp executed!"); - } + + @Override + public void process() { + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/BCmp.java index e72e220f..f1ad0750 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/BCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow2.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("Bcomp executed!"); - } + + @Override + public void process() { + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/CCmp.java index 0bfbee60..08e62aaf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/CCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow2.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/DCmp.java index e2e43805..d6fbd3bd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/DCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow2.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ECmp.java index 36145515..6afb8856 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/subflow2/cmp1/ECmp.java @@ -3,12 +3,12 @@ package com.yomahub.liteflow.test.subflow2.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.noear.solon.annotation.Component; - @Component("e") public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ecomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Ecomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java index 3602f1d4..a1759c62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java @@ -12,33 +12,35 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL替补节点的测试 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/substituteNode/application.properties") public class SubstituteSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testSub1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 最简单的情况 + @Test + public void testSub1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //有替补节点 - @Test - public void testSub2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 有替补节点 + @Test + public void testSub2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试特殊命名的节点 + @Test + public void testSub3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试特殊命名的节点 - @Test - public void testSub3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java index d5e1044b..a314cdd3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/switchcase/SwitchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java index 67b6fc9f..ac9b9d65 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 @@ -12,69 +12,70 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SolonJUnit4ClassRunner.class) @TestPropertySource("classpath:/switchcase/application.properties") public class SwitchELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - //2022-07-12 switch 异常错误.c.y.l.builder.el.operator.ToOperator : parameter error - //run QlExpress Exception at line 1 : - // switch().to(): 只有一个node时出错 - @Test - public void testSwitch1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); - } + // 2022-07-12 switch 异常错误.c.y.l.builder.el.operator.ToOperator : parameter error + // run QlExpress Exception at line 1 : + // switch().to(): 只有一个node时出错 + @Test + public void testSwitch1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d", response.getExecuteStepStr()); + } - @Test - public void testSwitch3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>f==>b",response.getExecuteStepStr()); - } + @Test + public void testSwitch3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>f==>b", response.getExecuteStepStr()); + } - //根据tag来跳转,指定哪个组件的tag - @Test - public void testSwitch4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>g==>d",response.getExecuteStepStr()); - } + // 根据tag来跳转,指定哪个组件的tag + @Test + public void testSwitch4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>g==>d", response.getExecuteStepStr()); + } - //tag的跳转 - @Test - public void testSwitch5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } + // tag的跳转 + @Test + public void testSwitch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } - //相同组件的tag的跳转 - @Test - public void testSwitch6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } + // 相同组件的tag的跳转 + @Test + public void testSwitch6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } - //switch增加default选项 - @Test - public void testSwitch7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>i==>d",response.getExecuteStepStr()); - } + // switch增加default选项 + @Test + public void testSwitch7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>i==>d", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java index 6472afd9..07f02d8f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/switchcase/cmp/ESwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java index 880ff15f..bf20ba3f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java @@ -17,4 +17,5 @@ public class ESwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java index 7711e26b..03f44971 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java @@ -17,4 +17,5 @@ public class FSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return ":td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java index 063deb49..7a471cd9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java @@ -17,4 +17,5 @@ public class GSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java index d316518b..cf8b5043 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java @@ -17,4 +17,5 @@ public class HSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "tag:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java index c462ffec..c72ca0d6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java @@ -17,4 +17,5 @@ public class ISwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "a"; } + } 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 6c9dc347..c2971eae 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 @@ -14,6 +14,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -21,42 +22,43 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/tag/application-json.properties") public class NodeTagELSpringbootJsonTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 f5ce7660..3383fe27 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 @@ -14,6 +14,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -21,51 +22,52 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/tag/application-xml.properties") public class NodeTagELSpringbootXmlTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } + + // 测试tag是否能在WHEN中起效果 + @Test + public void testTag5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", context.getData("test")); + } - //测试tag是否能在WHEN中起效果 - @Test - public void testTag5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1",context.getData("test")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java index 6c092f86..1b54a620 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java @@ -19,12 +19,14 @@ public class ACmp extends NodeComponent { String testKey = "test"; DefaultContext context = this.getFirstContextBean(); - if (context.getData(testKey) == null){ - context.setData(testKey,this.getTag()); - }else{ + if (context.getData(testKey) == null) { + context.setData(testKey, this.getTag()); + } + else { String s = context.getData(testKey); s += this.getTag(); context.setData(testKey, s); } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java index 4e4aba1f..ea3b06c3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -18,6 +18,7 @@ public class B1Cmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",new ConcurrentHashSet()); + context.setData("test", new ConcurrentHashSet()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java index fbc4732d..edebceb5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java @@ -21,4 +21,5 @@ public class BCmp extends NodeComponent { ConcurrentHashSet testSet = context.getData("test"); testSet.add(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java index ceedd8ab..d90bdc3a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java @@ -15,10 +15,12 @@ public class CCmp extends NodeSwitchComponent { @Override public String processSwitch() throws Exception { - if(this.getTag().equals("2")){ + if (this.getTag().equals("2")) { return "e"; - }else{ + } + else { return "d"; } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java index 572980b7..d231b874 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -18,4 +18,5 @@ public class DCmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("DCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java index 11ee96c8..e2687fa3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -18,4 +18,5 @@ public class ECmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("ECmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java index 2f670578..f15f468e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -22,4 +22,5 @@ public class FCmp extends NodeComponent { public boolean isAccess() { return Boolean.parseBoolean(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java index f6180b56..f2d2e3f7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -17,4 +17,5 @@ public class GCmp extends NodeComponent { public void process() { System.out.println("GCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java index cbdb66e1..3edc711f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java @@ -21,7 +21,8 @@ public class HCmp extends NodeComponent { @Override public boolean isAccess() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",this.getTag()); + context.setData("test", this.getTag()); return true; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java index fee0055e..3de938a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -4,13 +4,14 @@ import com.alibaba.ttl.TransmittableThreadLocal; public class TestTL { - public static ThreadLocal tl = new TransmittableThreadLocal<>(); + public static ThreadLocal tl = new TransmittableThreadLocal<>(); - public static String get(){ - return tl.get(); - } + public static String get() { + return tl.get(); + } + + public static void set(String value) { + tl.set(value); + } - public static void set(String value){ - tl.set(value); - } } 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 9dd5a760..a08529b9 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 @@ -13,6 +13,7 @@ import org.noear.solon.test.annotation.TestPropertySource; /** * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * * @author Bryan.Zhang * @since 2.6.3 */ @@ -20,17 +21,18 @@ import org.noear.solon.test.annotation.TestPropertySource; @TestPropertySource("classpath:/useTTLInWhen/application.properties") public class UseTTLInWhenELSpringbootTest extends BaseTest { - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,b", context.getData("b")); + Assert.assertEquals("hello,c", context.getData("c")); + Assert.assertEquals("hello,d", context.getData("d")); + Assert.assertEquals("hello,e", context.getData("e")); + Assert.assertEquals("hello,f", context.getData("f")); + } - @Test - public void testUseTTLInWhen() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,b", context.getData("b")); - Assert.assertEquals("hello,c", context.getData("c")); - Assert.assertEquals("hello,d", context.getData("d")); - Assert.assertEquals("hello,e", context.getData("e")); - Assert.assertEquals("hello,f", context.getData("f")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java index 8fda6d42..cde00a7d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { TestTL.set("hello"); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java index cde0d3de..7692857b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -19,7 +19,7 @@ public class BCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",b"); + context.setData(this.getNodeId(), value + ",b"); System.out.println("BCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java index 71f30885..5a5cbefe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -19,7 +19,7 @@ public class CCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",c"); + context.setData(this.getNodeId(), value + ",c"); System.out.println("CCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java index a6aafe5b..2357bd0d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -19,7 +19,7 @@ public class DCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",d"); + context.setData(this.getNodeId(), value + ",d"); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java index fd96f5bd..7894ad61 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -19,7 +19,7 @@ public class ECmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",e"); + context.setData(this.getNodeId(), value + ",e"); System.out.println("ECmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java index 490abfbf..7f334e99 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -19,7 +19,7 @@ public class FCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",f"); + context.setData(this.getNodeId(), value + ",f"); System.out.println("FCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java index c7ae3ed4..9579d45d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java @@ -15,24 +15,28 @@ import org.noear.solon.test.SolonJUnit4ClassRunner; @RunWith(SolonJUnit4ClassRunner.class) public class ValidateRuleELSpringbootTest extends BaseTest { - @Test - public void testChainELExpressValidate() { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz(BCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, h)")); - Assert.assertTrue(LiteFlowChainELBuilder.validate("THEN(a, b, c)")); - } + @Test + public void testChainELExpressValidate() { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, h)")); + Assert.assertTrue(LiteFlowChainELBuilder.validate("THEN(a, b, c)")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java index 2f094dbc..5693174d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/whenTimeOut/WhenTimeOutELSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java index f5d8e521..227ca822 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 @@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -22,16 +23,17 @@ import org.slf4j.LoggerFactory; @TestPropertySource("classpath:/whenTimeOut/application1.properties") public class WhenTimeOutELSpringbootTest1 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } - //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 621533ae..a725c702 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 @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -21,15 +22,16 @@ import org.slf4j.LoggerFactory; @TestPropertySource("classpath:/whenTimeOut/application2.properties") public class WhenTimeOutELSpringbootTest2 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Inject - private FlowExecutor flowExecutor; + @Inject + private FlowExecutor flowExecutor; + + // 其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java index e6d2d17c..0a640a56 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java index 73c63b84..240c6a66 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -17,7 +17,8 @@ public class BCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java index 0e58e3cc..e8a846ef 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -17,7 +17,8 @@ public class CCmp extends NodeComponent { public void process() { try { Thread.sleep(3500); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java index b4a87fae..3c6927e8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -17,7 +17,8 @@ public class DCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("DCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java index 122930c7..f4a417be 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -17,7 +17,8 @@ public class ECmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("ECmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java index 9eb2243a..463ee4aa 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -17,7 +17,8 @@ public class FCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("FCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java index d2bea027..2604cdad 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringbootTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -25,17 +26,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/absoluteConfigPath/application.properties") @SpringBootTest(classes = AbsoluteConfigPathELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.absoluteConfigPath.cmp" }) public class AbsoluteConfigPathELSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testAbsoluteConfig() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java index 74091479..1f5f6ad0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/aop/CustomAOPELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELSpringbootTest.java index 2991ce3c..7be1ca2f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * 切面场景单元测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @@ -26,31 +27,32 @@ import javax.annotation.Resource; @SpringBootTest(classes = CustomAOPELSpringbootTest.class) @EnableAutoConfiguration @Import(CustomAspect.class) -@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.aop.cmp1", "com.yomahub.liteflow.test.aop.cmp2" }) public class CustomAOPELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试自定义AOP,串行场景 - @Test - public void testCustomAopS() { - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - } + // 测试自定义AOP,串行场景 + @Test + public void testCustomAopS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + } + + // 测试自定义AOP,并行场景 + @Test + public void testCustomAopP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + } - //测试自定义AOP,并行场景 - @Test - public void testCustomAopP() { - LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringbootTest.java index 4e8d921c..9c71f164 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringbootTest.java @@ -21,6 +21,7 @@ import javax.annotation.Resource; /** * 切面场景单元测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @@ -28,52 +29,53 @@ import javax.annotation.Resource; @SpringBootTest(classes = GlobalAOPELSpringbootTest.class) @EnableAutoConfiguration @Import(CmpAspect.class) -@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.aop.cmp1", "com.yomahub.liteflow.test.aop.cmp2" }) public class GlobalAOPELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试全局AOP,串行场景 - @Test - public void testGlobalAopS() { - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,串行场景 + @Test + public void testGlobalAopS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - //测试全局AOP,并行场景 - @Test - public void testGlobalAopP() { - LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,并行场景 + @Test + public void testGlobalAopP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - @Test - public void testGlobalAopException() { - LiteflowResponse response= flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("f")); - } + @Test + public void testGlobalAopException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("f")); + } + + @AfterClass + public static void cleanScanCache() { + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } - @AfterClass - 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/CmpAspect.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java index 3704a146..e3884622 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java @@ -6,15 +6,17 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; public class CmpAspect implements ICmpAroundAspect { - @Override - public void beforeProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, "before"); - } - @Override - public void afterProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); - } + @Override + public void beforeProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, "before"); + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java index c1421dbe..eca5899b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java @@ -11,17 +11,18 @@ import org.aspectj.lang.annotation.Pointcut; @Aspect public class CustomAspect { - @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process())") - public void cut() { - } + @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process())") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId(), "before"); + Object returnObj = jp.proceed(); + context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); + return returnObj; + } - @Around("cut()") - public Object around(ProceedingJoinPoint jp) throws Throwable { - NodeComponent cmp = (NodeComponent) jp.getThis(); - DefaultContext context = cmp.getFirstContextBean(); - context.setData(cmp.getNodeId(), "before"); - Object returnObj = jp.proceed(); - context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); - return returnObj; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java index 0c529fb4..596bcad4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringbootTest.java @@ -18,8 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author ssss */ @@ -27,119 +26,120 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/asyncNode/application.properties") @SpringBootTest(classes = AsyncNodeELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.asyncNode.cmp" }) public class AsyncNodeELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - /***** - * 标准chain 嵌套选择 嵌套子chain进行执行 - * 验证了when情况下 多个node是并行执行 - * 验证了默认参数情况下 when可以加载执行 - * **/ - @Test - public void testAsyncFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - System.out.println(response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; - //这个和test1有点类似,只不过进一步验证了步骤 - @Test - public void testAsyncFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); - Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", - "b==>j==>h==>g==>f","b==>j==>h==>f==>g", - "b==>j==>f==>h==>g","b==>j==>f==>g==>h" - ).contains(response.getExecuteStepStr())); - } + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 验证了when情况下 多个node是并行执行 验证了默认参数情况下 when可以加载执行 + **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getExecuteStepStr()); + } - @Test - public void testAsyncFlow3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - } + // 这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue( + ListUtil + .toList("b==>j==>g==>f==>h", "b==>j==>g==>h==>f", "b==>j==>h==>g==>f", "b==>j==>h==>f==>g", + "b==>j==>f==>h==>g", "b==>j==>f==>g==>h") + .contains(response.getExecuteStepStr())); + } - //测试errorResume,默认的errorResume为false,这里测试默认的 - @Test - public void testAsyncFlow3_1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); - } + @Test + public void testAsyncFlow3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } - //测试errorResume,默认的errorResume为false,这里设置为true - @Test - public void testAsyncFlow3_2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - } + // 测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 - @Test - public void testAsyncFlow4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); - //因为不记录错误,所以最终结果是true - Assert.assertTrue(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为配置了不抛错,所以response里的cause应该为null - Assert.assertNull(response.getCause()); - } + // 测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 - @Test - public void testAsyncFlow5() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); - //整个并行组是报错的,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为第一个when配置了会报错,所以response里的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + // 因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } - //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 - @Test - public void testAsyncFlow6() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); - //第一个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(1), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + // 整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } - //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 - @Test - public void testAsyncFlow7() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); - //第二个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - // 传递了slotIndex,则set的size==2 - DefaultContext context = response.getFirstContextBean(); - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + // 第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(1), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + // 第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + DefaultContext context = response.getFirstContextBean(); + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 测试任意异步一个执行完即继续的场景 + // d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + // 最终执行效果应该是h先返回,然后执行abc,最后gd + // 这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("check").toString().startsWith("habc")); + } - //测试任意异步一个执行完即继续的场景 - //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 - //最终执行效果应该是h先返回,然后执行abc,最后gd - //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 - @Test - public void testAsyncFlow8() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("check").toString().startsWith("habc")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java index db853a3f..93a1347d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java @@ -4,21 +4,23 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; - @Component("a") public class ACmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Acomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java index fe827327..45270495 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java @@ -4,21 +4,23 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Bcomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java index 86173912..b2194ac0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java @@ -4,21 +4,23 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java index 0b764ef6..1773200e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java @@ -4,22 +4,24 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(1000); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + Thread.sleep(1000); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java index caff1beb..fec510e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java @@ -3,13 +3,13 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; import org.springframework.stereotype.Component; - @Component("e") public class ECmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Ecomp executed!"); - return "g"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java index eb9322c8..c6ee31ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java @@ -3,12 +3,12 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("f") public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Fcomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Fcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java index 6044be03..4fae687b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java @@ -4,23 +4,24 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; - @Component("g") public class GCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(500); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Gcomp executed!"); - } + @Override + public void process() throws Exception { + Thread.sleep(500); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java index a4fd8a93..b28d8e03 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java @@ -4,23 +4,24 @@ import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.slot.DefaultContext; import org.springframework.stereotype.Component; - @Component("h") public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java index 32322029..bc890cc7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java @@ -5,22 +5,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.test.asyncNode.exception.TestException; import org.springframework.stereotype.Component; - @Component("i") public class ICmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (ICmp.class){ - if (context.hasData("count")){ - Integer count = context.getData("count"); - context.setData("count", ++count); - } else{ - context.setData("count", 1); - } - } - System.out.println("Icomp executed! throw Exception!"); - throw new TestException(); - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (ICmp.class) { + if (context.hasData("count")) { + Integer count = context.getData("count"); + context.setData("count", ++count); + } + else { + context.setData("count", 1); + } + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java index 66bb9cab..611af09e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java @@ -3,13 +3,13 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; import org.springframework.stereotype.Component; - @Component("j") public class JCmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Jcomp executed!"); - return "chain3"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java index e786e9f8..fa8827df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -1,4 +1,5 @@ package com.yomahub.liteflow.test.asyncNode.exception; -public class TestException extends Exception{ +public class TestException extends Exception { + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java index 894c1a63..7afa6e3b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/BaseELSpringbootTest.java @@ -16,50 +16,52 @@ import javax.annotation.Resource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/base/application.properties") @SpringBootTest(classes = BaseELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.base.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.base.cmp" }) public class BaseELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testBase1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 最简单的情况 + @Test + public void testBase1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //switch节点最简单的测试用例 - @Test - public void testBase2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // switch节点最简单的测试用例 + @Test + public void testBase2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //then,when,switch混用的稍微复杂点的用例,switch跳到一个then上 - @Test - public void testBase3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // then,when,switch混用的稍微复杂点的用例,switch跳到一个then上 + @Test + public void testBase3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //一个非常复杂的例子,可以看base目录下的img.png这个图示 - @Test - public void testBase4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 一个非常复杂的例子,可以看base目录下的img.png这个图示 + @Test + public void testBase4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 用变量来声明短流程 + @Test + public void testBase5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用变量来声明短流程 - @Test - public void testBase5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - } } 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 c3379221..c2361cac 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,4 +17,5 @@ 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/ESwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ESwitchCmp.java index b05adaf5..aac89b7d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ESwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/ESwitchCmp.java @@ -17,4 +17,5 @@ public class ESwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java index e0361714..014654dd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/GSwitchCmp.java @@ -17,4 +17,5 @@ public class GSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "then_1001"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java index c873266e..fca40d9a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/base/cmp/XSwitchCmp.java @@ -17,4 +17,5 @@ public class XSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "w01"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java index 4b221356..49edee05 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest1.java @@ -24,144 +24,157 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class BuilderELSpringbootTest1 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //基于普通组件的builder模式测试 - @Test - public void testBuilder() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") - .build(); + // 基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") + .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + // 基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz(GCmp.class) + .build(); - //基于普通组件的builder模式测试 - @Test - public void testBuilderForClassAndCode() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz(BCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz(DCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz(ECmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz(FCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz(GCmp.class) - .build(); + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); + @Test + public void testBuilderForSameNodeMultiTimes() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a1") + .setName("组件A1") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("a2") + .setName("组件A2") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c1") + .setName("组件C1") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c2") + .setName("组件C2") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(a1,c2,a2,c1)").build(); - @Test - public void testBuilderForSameNodeMultiTimes() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a1") - .setName("组件A1") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("a2") - .setName("组件A2") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c1") - .setName("组件C1") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c2") - .setName("组件C2") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); + } - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a1,c2,a2,c1)" - ).build(); - - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java index 79424414..a6db5d78 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringbootTest2.java @@ -19,21 +19,20 @@ import javax.annotation.Resource; @RunWith(SpringRunner.class) @SpringBootTest(classes = BuilderELSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.builder.cmp2" }) public class BuilderELSpringbootTest2 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //通过spring去扫描组件,通过代码去构建chain - @Test - public void testBuilder() throws Exception { - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(h, i, j)" - ).build(); + // 通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(h, i, j)").build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); + } - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java index 9fbbfba4..553e2334 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -15,4 +15,5 @@ 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/catchcase/CatchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java index efec5a32..fd7bb7ec 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java @@ -16,44 +16,46 @@ import javax.annotation.Resource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/catchcase/application.properties") @SpringBootTest(classes = CatchELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.catchcase.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.catchcase.cmp" }) public class CatchELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testCatch1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); - Assert.assertNull(response.getCause()); - } + @Test + public void testCatch1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); + Assert.assertNull(response.getCause()); + } - @Test - public void testCatch2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("a==>d", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testCatch2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("a==>d", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testCatch3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testCatch3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testCatch4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_3==>a==>b==>a==>b==>a==>b", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testCatch4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_3==>a==>b==>a==>b==>a==>b", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ACmp.java index cf3c9a38..1988ec8a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ACmp.java @@ -16,7 +16,8 @@ public class ACmp extends NodeComponent { @Override public void process() { System.out.println("ACmp executed!"); - int i = 1/0; + int i = 1 / 0; System.out.println(i); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java index 2b323192..ab5c705c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/CmpDataELSpringbootTest.java @@ -23,37 +23,39 @@ import java.util.stream.Collectors; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/cmpData/application.properties") @SpringBootTest(classes = CmpDataELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpData.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpData.cmp" }) public class CmpDataELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testCmpData1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - User user = context.getData("user"); - Assert.assertEquals(27, user.getAge()); - Assert.assertEquals("jack", user.getName()); - Assert.assertEquals(0, user.getBirth().compareTo(DateUtil.parseDate("1995-10-01").toJdkDate())); - } + // 最简单的情况 + @Test + public void testCmpData1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + User user = context.getData("user"); + Assert.assertEquals(27, user.getAge()); + Assert.assertEquals("jack", user.getName()); + Assert.assertEquals(0, user.getBirth().compareTo(DateUtil.parseDate("1995-10-01").toJdkDate())); + } + + @Test + public void testCmpData2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", TestContext.class); + Assert.assertTrue(response.isSuccess()); + TestContext context = response.getFirstContextBean(); + Assert.assertEquals(8, context.getSet().size()); + String result = context.getSet().stream().sorted().collect(Collectors.joining()); + Assert.assertEquals("12345678", result); + } - @Test - public void testCmpData2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg", TestContext.class); - Assert.assertTrue(response.isSuccess()); - TestContext context = response.getFirstContextBean(); - Assert.assertEquals(8, context.getSet().size()); - String result = context.getSet().stream().sorted().collect(Collectors.joining()); - Assert.assertEquals("12345678", result); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/TestContext.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/TestContext.java index 2e4ecdfc..842d0cde 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/TestContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/TestContext.java @@ -6,13 +6,14 @@ import java.util.Set; public class TestContext { - private Set set = new ConcurrentHashSet<>(); + private Set set = new ConcurrentHashSet<>(); - public void add2Set(String str){ - set.add(str); - } + public void add2Set(String str) { + set.add(str); + } + + public Set getSet() { + return set; + } - public Set getSet(){ - return set; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java index 47cdadef..7189fa18 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/cmp/ACmp.java @@ -18,4 +18,5 @@ public class ACmp extends NodeComponent { System.out.println(this.getCmpData(String.class)); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java index 483a78dd..08083f5a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpData/vo/User.java @@ -4,33 +4,34 @@ import java.util.Date; public class User { - private String name; + private String name; - private int age; + private int age; - private Date birth; + private Date birth; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public int getAge() { - return age; - } + public int getAge() { + return age; + } - public void setAge(int age) { - this.age = age; - } + public void setAge(int age) { + this.age = age; + } - public Date getBirth() { - return birth; - } + public Date getBirth() { + return birth; + } + + public void setBirth(Date birth) { + this.birth = birth; + } - public void setBirth(Date birth) { - this.birth = birth; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java index 447d571d..6504bf7a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringbootTest.java @@ -14,9 +14,9 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的节点执行器 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -24,40 +24,41 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/cmpRetry/application.properties") @SpringBootTest(classes = LiteflowRetryELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpRetry.cmp" }) public class LiteflowRetryELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //全局重试配置测试 - @Test - public void testRetry1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); - } + // 全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); + } - //单个组件重试配置测试 - @Test - public void testRetry2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); - } + // 单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); + } - //单个组件指定异常,但抛出的并不是指定异常的场景测试 - @Test - public void testRetry3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - } + // 单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + // 单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); + } - //单个组件指定异常重试,抛出的是指定异常或者 - @Test - public void testRetry4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java index a1b1b3fb..0e217e4b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/cmpRetry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java index 3c50ded2..a43cfc64 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -18,7 +18,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java index b9232e5a..b523adfe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java index ba3f92d6..694d7fc8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("e") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class ECmp extends NodeComponent { @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java index 079f82ff..ed9084d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringbootTest.java @@ -23,6 +23,7 @@ import java.util.function.Predicate; /** * springboot环境step的测试例子 + * * @author Bryan.Zhang * @since 2.7.0 */ @@ -30,50 +31,51 @@ import java.util.function.Predicate; @TestPropertySource(value = "classpath:/cmpStep/application.properties") @SpringBootTest(classes = CmpStepELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.cmpStep.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpStep.cmp" }) public class CmpStepELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //ab串行 - //cd并行,都抛错,其中c耗时2秒 - @Test - public void testStep1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); - } + // ab串行 + // cd并行,都抛错,其中c耗时2秒 + @Test + public void testStep1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); + } - @Test - public void testStep2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testStep2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testStep3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Map stepMap = response.getExecuteSteps(); - Assert.assertEquals(2, stepMap.size()); - Queue queue = response.getExecuteStepQueue(); - Assert.assertEquals(5, queue.size()); + @Test + public void testStep3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Map stepMap = response.getExecuteSteps(); + Assert.assertEquals(2, stepMap.size()); + Queue queue = response.getExecuteStepQueue(); + Assert.assertEquals(5, queue.size()); - Set tagSet = new HashSet<>(); - response.getExecuteStepQueue().stream().filter( - cmpStep -> cmpStep.getNodeId().equals("a") - ).forEach(cmpStep -> tagSet.add(cmpStep.getTag())); + Set tagSet = new HashSet<>(); + response.getExecuteStepQueue() + .stream() + .filter(cmpStep -> cmpStep.getNodeId().equals("a")) + .forEach(cmpStep -> tagSet.add(cmpStep.getTag())); - Assert.assertEquals(3, tagSet.size()); + Assert.assertEquals(3, tagSet.size()); - } + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java index 6c1573f4..ecd0e0c7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java @@ -14,8 +14,9 @@ import org.springframework.stereotype.Component; public class ACmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Thread.sleep(5000L); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java index 34f7792b..2efd2517 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; public class CCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); Thread.sleep(2000); throw new RuntimeException("test error c"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java index f78b4239..cc8b2fe0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java @@ -22,4 +22,5 @@ public class ECmp extends NodeComponent { public boolean isAccess() { return false; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java index cad44ba2..287f2626 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java @@ -19,7 +19,7 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/comments/application.properties") @SpringBootTest(classes = LiteflowNodeELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.comments.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.comments.cmp" }) public class LiteflowNodeELSpringbootTest extends BaseTest { @Resource @@ -30,6 +30,7 @@ public class LiteflowNodeELSpringbootTest extends BaseTest { public void testAsyncFlow1() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr())); + Assert.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr())); } + } \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java index 99e6c277..f50b451a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java @@ -13,10 +13,11 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("a") -public class ACmp{ +public class ACmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java index 1a5864b4..5673981e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java index 692cfeb0..82dd69c0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/comments/cmp/CCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("c") -public class CCmp{ +public class CCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java index c25cb324..ec19d54f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest1.java @@ -16,33 +16,35 @@ import javax.annotation.Resource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/complex/application1.properties") @SpringBootTest(classes = ComplexELSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.complex.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.complex.cmp1" }) public class ComplexELSpringbootTest1 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex1_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子一 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex1_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest2.java index 1ad33bc7..7c15b994 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/ComplexELSpringbootTest2.java @@ -16,33 +16,35 @@ import javax.annotation.Resource; /** * springboot环境EL复杂例子测试1 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/complex/application2.properties") @SpringBootTest(classes = ComplexELSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.complex.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.complex.cmp2" }) public class ComplexELSpringbootTest2 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试复杂例子,优化前 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试复杂例子,优化前 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试复杂例子,优化后 + // 案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 + // 因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 + @Test + public void testComplex2_2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试复杂例子,优化后 - //案例来自于文档中 EL规则写法/复杂编排例子/复杂例子二 - //因为所有的组件都是空执行,你可以在组件里加上Thread.sleep来模拟业务耗时,再来看这个打出结果 - @Test - public void testComplex2_2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java index 5f027f73..77d59d38 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java index 05a17bef..10f6a396 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/BCmp.java @@ -15,6 +15,7 @@ public class BCmp extends NodeComponent { @Override public void process() { - + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java index 4b1b5a35..b8c3b318 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/CCmp.java @@ -17,4 +17,5 @@ public class CCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java index b16cb97e..b51fb291 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/DCmp.java @@ -17,4 +17,5 @@ public class DCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java index f146f653..bcb9c6da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java index 0317a214..1ede2984 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/FCmp.java @@ -17,4 +17,5 @@ public class FCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java index b181bde7..61087e4d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/GCmp.java @@ -17,4 +17,5 @@ public class GCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "t1"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java index 877885b8..58d1b507 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/HCmp.java @@ -17,4 +17,5 @@ public class HCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java index eca509c6..a403dd66 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java index 7d1ef146..95ae5689 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/JCmp.java @@ -17,4 +17,5 @@ public class JCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java index 8ee08d50..4d5c4a8b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/KCmp.java @@ -17,4 +17,5 @@ public class KCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java index 0dce9596..f436e038 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/LCmp.java @@ -17,4 +17,5 @@ public class LCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java index fb39e4a5..e4815006 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/MCmp.java @@ -17,4 +17,5 @@ public class MCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java index 08dcd726..2651e830 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/NCmp.java @@ -17,4 +17,5 @@ public class NCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java index d5117b6c..347c6ac6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp1/ZCmp.java @@ -17,4 +17,5 @@ public class ZCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java index 6ae9ee78..6a11aea2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java index da6be4bf..127a8429 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/BCmp.java @@ -16,4 +16,5 @@ public class BCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "t3"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java index 5ca876b1..433058f8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/CCmp.java @@ -17,4 +17,5 @@ public class CCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java index c1fbe1af..353bbc87 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/DCmp.java @@ -17,4 +17,5 @@ public class DCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java index 3d03b96f..d7ffa851 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java index 24ffe150..a5557403 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/FCmp.java @@ -17,4 +17,5 @@ public class FCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java index 70274409..3cf189f0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/GCmp.java @@ -17,4 +17,5 @@ public class GCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "t2"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java index 75751d43..594d0590 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/HCmp.java @@ -17,4 +17,5 @@ public class HCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java index 08d07119..71f28e45 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ICmp.java @@ -17,4 +17,5 @@ public class ICmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java index ad16e022..3f57128b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/JCmp.java @@ -17,4 +17,5 @@ public class JCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java index 9447a5e2..edb03f77 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/KCmp.java @@ -17,4 +17,5 @@ public class KCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java index a62ff72f..13c43d70 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/LCmp.java @@ -17,4 +17,5 @@ public class LCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java index 6fbff430..27f174c3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/MCmp.java @@ -17,4 +17,5 @@ public class MCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java index c5569eff..5972a8f3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/NCmp.java @@ -17,4 +17,5 @@ public class NCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java index 6e01ccb0..04296060 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/complex/cmp2/ZCmp.java @@ -17,4 +17,5 @@ public class ZCmp extends NodeComponent { public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java index e6b1622c..5ab592c7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorELSpringbootTest.java @@ -18,8 +18,7 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; /** - * 组件功能点测试 - * 单元测试 + * 组件功能点测试 单元测试 * * @author donguo.tao */ @@ -27,67 +26,68 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/component/application.properties") @SpringBootTest(classes = FlowExecutorELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.component.cmp1", "com.yomahub.liteflow.test.component.cmp2" }) public class FlowExecutorELSpringbootTest extends BaseTest { - private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELSpringbootTest.class); - @Resource - private FlowExecutor flowExecutor; + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorELSpringbootTest.class); - //isAccess方法的功能测试 - @Test - public void testIsAccess() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); - Assert.assertTrue(response.isSuccess()); - Assert.assertNotNull(response.getSlot().getResponseData()); - } + @Resource + private FlowExecutor flowExecutor; - //组件抛错的功能点测试 - @Test(expected = ArithmeticException.class) - public void testComponentException() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("/ by zero", response.getMessage()); - ReflectionUtils.rethrowException(response.getCause()); - } + // isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } - //isContinueOnError方法的功能点测试 - @Test - public void testIsContinueOnError() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCause()); - } + // 组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } - //isEnd方法的功能点测试 - @Test - public void testIsEnd() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d",response.getExecuteStepStr()); - } + // isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } - //setIsEnd方法的功能点测试 - @Test - public void testSetIsEnd1() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("e",response.getExecuteStepStr()); - } + // isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d", response.getExecuteStepStr()); + } - //条件组件的功能点测试 - @Test - public void testNodeCondComponent() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); - Assert.assertTrue(response.isSuccess()); - } + // setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e", response.getExecuteStepStr()); + } - //测试setIsEnd如果为true,continueError也为true,那不应该continue了 - @Test - public void testSetIsEnd2() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g",response.getExecuteStepStr()); - } + // 条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + // 测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java index 3f125d17..1f8f3b09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -5,22 +5,23 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("a") public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("AComp executed!"); - this.getSlot().setResponseData("AComp executed!"); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData) && requestData > 100){ - return true; - } - System.out.println("AComp isAccess false."); - return false; - } + @Override + public void process() { + System.out.println("AComp executed!"); + this.getSlot().setResponseData("AComp executed!"); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100) { + return true; + } + System.out.println("AComp isAccess false."); + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java index 6d5db7fc..98994409 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -5,25 +5,25 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("BComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java index dc4620e4..450bf757 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -5,25 +5,26 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() { - System.out.println("CComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - System.out.println("responseData="+Integer.parseInt(this.getSlot().getResponseData())); - } - @Override - public boolean isContinueOnError() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("CComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + System.out.println("responseData=" + Integer.parseInt(this.getSlot().getResponseData())); + } + + @Override + public boolean isContinueOnError() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java index c28a41e3..7913217a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -5,22 +5,23 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("DComp executed!"); - } - @Override - public boolean isEnd() { - //组件的process执行完之后才会执行isEnd - Object requestData = this.getSlot().getResponseData(); - if (Objects.isNull(requestData)){ - System.out.println("DComp flow isEnd, because of responseData is null."); - return true; - } - return false; - } + @Override + public void process() throws Exception { + System.out.println("DComp executed!"); + } + + @Override + public boolean isEnd() { + // 组件的process执行完之后才会执行isEnd + Object requestData = this.getSlot().getResponseData(); + if (Objects.isNull(requestData)) { + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java index 9103080a..bbba1177 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -6,19 +6,19 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("e") public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("EComp executed!"); - Object responseData = this.getSlot().getResponseData(); - if (Objects.isNull(responseData)){ - System.out.println("EComp responseData flow must be set end ."); - //执行到某个条件时,手动结束流程。 - this.setIsEnd(true); - } - System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); - } + @Override + public void process() throws Exception { + System.out.println("EComp executed!"); + Object responseData = this.getSlot().getResponseData(); + if (Objects.isNull(responseData)) { + System.out.println("EComp responseData flow must be set end ."); + // 执行到某个条件时,手动结束流程。 + this.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java index f7917cfa..1a98e6a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -23,4 +23,5 @@ public class GCmp extends NodeComponent { public boolean isContinueOnError() { return true; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java index df41a9c1..dc8063b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -17,4 +17,5 @@ public class HCmp extends NodeComponent { public void process() { System.out.println("HCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java index 5f4951f5..7f7acad2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java @@ -5,18 +5,21 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("f") public class FSwitchCmp extends NodeSwitchComponent { - @Override - public String processSwitch() { - Integer requestData = this.getRequestData(); - if (Objects.isNull(requestData)){ - return "d"; - } else if(requestData == 0){ - return "c"; - } else { - return "b"; - } - } + + @Override + public String processSwitch() { + Integer requestData = this.getRequestData(); + if (Objects.isNull(requestData)) { + return "d"; + } + else if (requestData == 0) { + return "c"; + } + else { + return "b"; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java index 4185c789..b8c84e37 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringbootTest.java @@ -17,8 +17,8 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境下自定义声明节点的测试 - * 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * springboot环境下自定义声明节点的测试 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,19 +26,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customNodes/application.properties") @SpringBootTest(classes = CustomNodesELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +@ComponentScan({ "com.yomahub.liteflow.test.customNodes.domain" }) public class CustomNodesELSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testCustomNodes() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java index d7cf0644..10ba24a8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -15,4 +15,5 @@ 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/customNodes/domain/DemoDomain.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java index d0b10dc0..745da51d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoDomain { - public void sayHi(){ - System.out.println("hi"); - } + public void sayHi() { + System.out.println("hi"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6f88c4cd..6034ba62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -9,17 +9,15 @@ import java.util.concurrent.ExecutorService; public class CustomThreadExecutor1 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-1-thead-"); - } + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 7d45e4ad..8f9008e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor2 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-2-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index 875dc3d1..dc6f6399 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor3 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-3-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java index ab0eb271..45516e80 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java @@ -27,49 +27,49 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/customWhenThreadPool/application.properties") @SpringBootTest(classes = CustomWhenThreadPoolELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.customWhenThreadPool.cmp" }) public class CustomWhenThreadPoolELSpringbootTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 测试全局线程池配置 - */ - @Test - public void testGlobalThreadPool() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); - } + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); + } - /** - * 测试全局和when上自定义线程池-优先以when上为准 - */ - @Test - public void testGlobalAndCustomWhenThreadPool() { - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response1.getFirstContextBean(); - Assert.assertTrue(response1.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - } + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - /** - * when配置的线程池可以共用 - */ - @Test - public void testCustomWhenThreadPool() { - // 使用when - thread1 - testGlobalAndCustomWhenThreadPool(); - // chain配置同一个thead1 - LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response2.getFirstContextBean(); - Assert.assertTrue(response2.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java index f47c972d..01f66e33 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/event/EventELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java index b65379da..64ac4309 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/EventELSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境事件回调测试 + * * @author Bryan.Zhang * @since 2.7.1 */ @@ -24,41 +25,41 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/event/application.properties") @SpringBootTest(classes = EventELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.event.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.event.cmp" }) public class EventELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试组件成功事件 - @Test - public void testEvent1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("abc", context.getData("test")); - } + // 测试组件成功事件 + @Test + public void testEvent1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("abc", context.getData("test")); + } - //测试组件失败事件 - @Test - public void testEvent2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("ab", context.getData("test")); - Assert.assertEquals("error:d", context.getData("error")); - } + // 测试组件失败事件 + @Test + public void testEvent2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("ab", context.getData("test")); + Assert.assertEquals("error:d", context.getData("error")); + } - //测试组件失败事件本身抛出异常 - @Test - public void testEvent3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("a", context.getData("test")); - Assert.assertEquals("error:e", context.getData("error")); - } + // 测试组件失败事件本身抛出异常 + @Test + public void testEvent3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("a", context.getData("test")); + Assert.assertEquals("error:e", context.getData("error")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java index 11c7509b..bf7848df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java @@ -17,7 +17,7 @@ public class ACmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",""); + context.setData("test", ""); System.out.println("ACmp executed!"); } @@ -28,4 +28,5 @@ public class ACmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java index 7fc1b353..38f77d2d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java @@ -26,4 +26,5 @@ public class BCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java index f87eeed1..c56384c8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java @@ -26,4 +26,5 @@ public class CCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java index 1865b83e..5dbbc711 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; public class DCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -23,6 +23,7 @@ public class DCmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java index 600f1632..fe6f51dd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; public class ECmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -23,7 +23,8 @@ public class ECmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); throw new IllegalAccessException("错误事件回调本身抛出异常"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java index 11441ab5..e7b2394c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java @@ -6,7 +6,9 @@ import com.yomahub.liteflow.exception.LiteFlowException; * 用户自定义带状态码的异常 */ public class CustomStatefulException extends LiteFlowException { + public CustomStatefulException(String code, String message) { super(code, message); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java index 100b9043..5d3c6d77 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringBootTest.java @@ -20,8 +20,7 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @@ -30,37 +29,37 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class Exception1ELSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 验证 chain 节点重复的异常 - */ - @Test(expected = ChainDuplicateException.class) - public void testChainDuplicateException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-exception.el.xml"); - flowExecutor.reloadRule(); - } + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = ChainDuplicateException.class) + public void testChainDuplicateException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = ConfigErrorException.class) - public void testConfigErrorException() { - flowExecutor.setLiteflowConfig(null); - flowExecutor.reloadRule(); - } + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testFlowExecutorNotInitException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("error/flow.txt"); - flowExecutor.reloadRule(); - } + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("error/flow.txt"); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testNoConditionInChainException() throws Exception { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-blank.el.xml"); - flowExecutor.reloadRule(); - } + @Test(expected = FlowExecutorNotInitException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-blank.el.xml"); + flowExecutor.reloadRule(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java index 57da710f..4e753d4c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringBootTest.java @@ -22,8 +22,7 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @@ -31,54 +30,55 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/exception/application.properties") @SpringBootTest(classes = Exception2ELSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.exception.cmp" }) public class Exception2ELSpringBootTest extends BaseTest { - - @Resource - private FlowExecutor flowExecutor; - @Autowired - private ApplicationContext context; + @Resource + private FlowExecutor flowExecutor; - @Test(expected = ChainNotFoundException.class) - public void testChainNotFoundException() throws Exception { - flowExecutor.execute("chain0", "it's a request"); - } + @Autowired + private ApplicationContext context; - @Test(expected = RuntimeException.class) - public void testComponentCustomException() throws Exception { - flowExecutor.execute("chain1", "exception"); - } + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } - @Test - public void testGetSlotFromResponseWhenException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); - Assert.assertFalse(response.isSuccess()); - Assert.assertNotNull(response.getCause()); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } - @Test(expected = NoSwitchTargetNodeException.class) - public void testNoTargetFindException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); - Assert.assertFalse(response.isSuccess()); - throw response.getCause(); - } + @Test + public void testGetSlotFromResponseWhenException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } - @Test - public void testInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("300", response.getCode()); - Assert.assertNotNull(response.getCause()); - Assert.assertTrue(response.getCause() instanceof LiteFlowException); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = NoSwitchTargetNodeException.class) + public void testNoTargetFindException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); + Assert.assertFalse(response.isSuccess()); + throw response.getCause(); + } + + @Test + public void testInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("300", response.getCode()); + Assert.assertNotNull(response.getCause()); + Assert.assertTrue(response.getCause() instanceof LiteFlowException); + Assert.assertNotNull(response.getSlot()); + } + + @Test + public void testNotInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCode()); + } - @Test - public void testNotInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCode()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java index d637fab7..e06bdadd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -15,13 +15,13 @@ import org.springframework.stereotype.Component; @Component("a") public class ACmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new RuntimeException("chain execute execption"); } LOG.info("Acomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java index 0f7411c9..00d6f95b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -15,21 +15,23 @@ import org.springframework.stereotype.Component; @Component("b") public class BCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); @Override public void process() throws InterruptedException { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("when")) { + if (StrUtil.isNotBlank(str) && str.equals("when")) { try { LOG.info("Bcomp sleep begin"); Thread.sleep(3000); LOG.info("Bcomp sleep end"); - } catch (InterruptedException e) { + } + catch (InterruptedException e) { throw e; } } LOG.info("Bcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java index ab1759ad..eb8115e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -14,11 +14,12 @@ import org.springframework.stereotype.Component; @Component("c") public class CCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); - + @Override public void process() { LOG.info("Ccomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java index 3aebcc42..4aac8e47 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -14,14 +14,15 @@ import org.springframework.stereotype.Component; @Component("d") public class DCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); - + @Override public void process() { - if(1==1){ - int a = 1/0; + if (1 == 1) { + int a = 1 / 0; } LOG.info("Dcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java index 5911c2e3..17e760a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "a"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java index c0b3917a..ee9a086f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java @@ -16,13 +16,13 @@ import org.springframework.stereotype.Component; @Component("f") public class FCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(FCmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { + if (StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { throw new CustomStatefulException("300", "chain execute custom stateful execption"); } LOG.info("Fcomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java index 0c1120aa..f8bab6c0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java @@ -14,11 +14,12 @@ import org.springframework.stereotype.Component; @Component("g") public class GCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(GCmp.class); - + @Override public void process() { LOG.info("Gcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java index 4a666d25..a65a4e34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringbootTest.java @@ -18,6 +18,7 @@ import java.util.concurrent.Future; /** * springboot环境执行返回future的例子 + * * @author Bryan.Zhang * @since 2.6.13 */ @@ -25,17 +26,17 @@ import java.util.concurrent.Future; @TestPropertySource(value = "classpath:/execute2Future/application.properties") @SpringBootTest(classes = Executor2FutureELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.execute2Future.cmp" }) public class Executor2FutureELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testFuture() throws Exception{ - Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); - LiteflowResponse response = future.get(); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testFuture() throws Exception { + Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java index 05dabbd3..0461c2ca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/getChainName/GetChainNameELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java index 5fa15051..644096d3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringbootTest.java @@ -17,44 +17,45 @@ import javax.annotation.Resource; /** * springboot环境获取ChainName的测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/getChainName/application.properties") @SpringBootTest(classes = GetChainNameELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.getChainName.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.getChainName.cmp" }) public class GetChainNameELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testGetChainName1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - } + @Test + public void testGetChainName1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } - @Test - public void testGetChainName2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("chain2", context.getData("g")); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - Assert.assertEquals("sub5", context.getData("f")); - Assert.assertEquals("sub5_chain2", context.getData("e")); - Assert.assertEquals("sub6", context.getData("h")); - Assert.assertEquals("sub6", context.getData("j")); - Assert.assertNull(context.getData("k")); - } + @Test + public void testGetChainName2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java index 702c0156..3b6aa10f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { DefaultContext context = this.getFirstContextBean(); context.setData(this.getNodeId(), this.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java index 7eaa14eb..076d6b84 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -17,9 +17,10 @@ public class ECmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - if (context.hasData(this.getNodeId())){ + if (context.hasData(this.getNodeId())) { context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainId()); - }else{ + } + else { context.setData(this.getNodeId(), this.getCurrChainId()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java index 4af3289f..65be20f8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/ifelse/IfELSpringbootTest.java @@ -16,80 +16,81 @@ import javax.annotation.Resource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/ifelse/application.properties") @SpringBootTest(classes = IfELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.ifelse.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.ifelse.cmp" }) public class IfELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } - //IF节点中isAccess返回false,这个情况相当于IF整个表达式串没执行 - @Test - public void testIf8() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("c", response.getExecuteStepStrWithoutTime()); - } + // IF节点中isAccess返回false,这个情况相当于IF整个表达式串没执行 + @Test + public void testIf8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStrWithoutTime()); + } } 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 5508800f..ad0f8158 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 @@ -12,8 +12,10 @@ import org.springframework.stereotype.Component; @Component("x1") public class X1Cmp extends NodeIfComponent { + @Override public boolean processIf() 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 ebca577f..70453289 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 @@ -12,6 +12,7 @@ import org.springframework.stereotype.Component; @Component("x2") public class X2Cmp extends NodeIfComponent { + @Override public boolean processIf() throws Exception { return true; @@ -21,4 +22,5 @@ public class X2Cmp extends NodeIfComponent { public boolean isAccess() { return false; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELSpringbootTest.java index dc26c7be..756518c0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELSpringbootTest.java @@ -19,37 +19,39 @@ import java.util.List; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/iterator/application.properties") @SpringBootTest(classes = IteratorELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.iterator.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.iterator.cmp" }) public class IteratorELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testIt1() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("123", str); - } + // 最简单的情况 + @Test + public void testIt1() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("123", str); + } + + // 迭代器带break + @Test + public void testIt2() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("12", str); + } - //迭代器带break - @Test - public void testIt2() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("12", str); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java index 665236a0..e385239b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java @@ -18,12 +18,14 @@ public class ACmp extends NodeComponent { public void process() { String key = "test"; DefaultContext context = this.getFirstContextBean(); - if (!context.hasData(key)){ + if (!context.hasData(key)) { context.setData(key, this.getCurrLoopObj()); - }else{ + } + else { String str = context.getData(key); str += this.getCurrLoopObj(); context.setData(key, str); } } + } 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 74110c69..c0eccdb9 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 @@ -12,4 +12,5 @@ public class BCmp extends NodeBreakComponent { public boolean processBreak() throws Exception { return this.getLoopIndex() == 1; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java index cc36766d..33823698 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java @@ -8,9 +8,11 @@ import java.util.List; @Component("it") public class ITCmp extends NodeIteratorComponent { - @Override - public Iterator processIterator() throws Exception { - List list = this.getRequestData(); - return list.iterator(); - } + + @Override + public Iterator processIterator() throws Exception { + List list = this.getRequestData(); + return list.iterator(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELSpringbootTest.java index 2dc28694..cfc26725 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/LazyELSpringbootTest.java @@ -23,12 +23,12 @@ import javax.annotation.Resource; @ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"})*/ public class LazyELSpringbootTest extends BaseTest { - /*@Resource - private FlowExecutor flowExecutor; + /* + * @Resource private FlowExecutor flowExecutor; + * + * @Test public void testLazy() throws Exception{ LiteflowResponse response = + * flowExecutor.execute2Resp("chain1", "arg"); + * Assert.assertTrue(response.isSuccess()); } + */ - @Test - public void testLazy() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - }*/ } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java index 9d3dacbc..478c1459 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -19,4 +19,5 @@ 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/lfCmpAnno/LiteflowComponentELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringbootTest.java index deeb1c49..9d6747d9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringbootTest.java @@ -13,9 +13,9 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试@LiteflowComponent标注 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -23,16 +23,17 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(value = "classpath:/lfCmpAnno/application.properties") @SpringBootTest(classes = LiteflowComponentELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.lfCmpAnno.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.lfCmpAnno.cmp" }) public class LiteflowComponentELSpringbootTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); + } - @Test - public void testConfig() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java index 6c4fc23a..9d3a992e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/loop/LoopELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java index 2fc7f2bf..25e37914 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringbootTest.java @@ -17,76 +17,80 @@ import javax.annotation.Resource; /** * springboot环境EL循环的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/loop/application.properties") @SpringBootTest(classes = LoopELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.loop.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.loop.cmp" }) public class LoopELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //测试FOR循环中的index - @Test - public void testLoop6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } + // 测试FOR循环中的index + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } + + // 测试WHILE循环中的index + @Test + public void testLoop7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } - //测试WHILE循环中的index - @Test - public void testLoop7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java index fa96a2ae..ae074092 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java index 83be92a4..de42f865 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java @@ -18,10 +18,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java index cf88acc5..0fafa8d0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java @@ -19,11 +19,12 @@ public class ECmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = StrUtil.format("{}_{}", "loop", this.getTag()); - if (context.hasData(key)){ + if (context.hasData(key)) { String loopStr = context.getData(key); String loopStrReturn = StrUtil.format("{}{}", loopStr, this.getLoopIndex()); context.setData(key, loopStrReturn); - }else{ + } + else { context.setData(key, this.getLoopIndex().toString()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java index fa9fe7e5..5ca52556 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java @@ -5,8 +5,10 @@ import com.yomahub.liteflow.core.NodeForComponent; @LiteflowComponent("x") public class XCmp extends NodeForComponent { - @Override - public int processFor() throws Exception { - return 3; - } + + @Override + public int processFor() throws Exception { + return 3; + } + } 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 95a744a5..c4bb114c 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 @@ -7,10 +7,12 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") public class YCmp extends NodeBreakComponent { - @Override - public boolean processBreak() throws Exception { - DefaultContext context = this.getFirstContextBean(); - int count = context.getData("test"); - return count > 3; - } + + @Override + public boolean processBreak() throws Exception { + DefaultContext context = this.getFirstContextBean(); + int count = context.getData("test"); + return count > 3; + } + } 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 e5ef68dc..c7bb40e7 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 @@ -7,15 +7,18 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") public class ZCmp extends NodeWhileComponent { - @Override - public boolean processWhile() throws Exception { - DefaultContext context = this.getFirstContextBean(); - String key = "test"; - if (context.hasData(key)){ - int count = context.getData("test"); - return count < 5; - }else{ - return true; - } - } + + @Override + public boolean processWhile() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } + else { + return true; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java index b0781de4..1fdef50a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,24 +27,24 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/monitor/application.properties") @SpringBootTest(classes = MonitorELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.monitor.cmp" }) public class MonitorELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); + @Test + public void testMonitor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); - Thread.sleep(10000); - } + Thread.sleep(10000); + } - @AfterClass - public static void clean(){ - MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); - monitorBus.closeScheduler(); - } + @AfterClass + public static void clean() { + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java index d5f2438a..4156b95f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java @@ -19,10 +19,12 @@ public class ACmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java index a5a3f44e..8696a42c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java @@ -19,7 +19,8 @@ public class BCmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java index 6a44bb60..1ae56138 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java @@ -19,7 +19,8 @@ public class CCmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java index 24c575d0..2ffdd06e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/MonitorFileELSpringbootTest.java @@ -22,21 +22,21 @@ import java.io.File; @TestPropertySource(value = "classpath:/monitorFile/application.properties") @SpringBootTest(classes = MonitorFileELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.monitorFile.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.monitorFile.cmp" }) public class MonitorFileELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); - String content = FileUtil.readUtf8String(absolutePath); - String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); - FileUtil.writeString(newContent,new File(absolutePath), CharsetUtil.CHARSET_UTF_8); - Thread.sleep(3000); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); - } + @Test + public void testMonitor() throws Exception { + String absolutePath = new ClassPathResource("classpath:/monitorFile/flow.el.xml").getAbsolutePath(); + String content = FileUtil.readUtf8String(absolutePath); + String newContent = content.replace("THEN(a, b, c);", "THEN(a, c, b);"); + FileUtil.writeString(newContent, new File(absolutePath), CharsetUtil.CHARSET_UTF_8); + Thread.sleep(3000); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>c==>b", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java index 37fd4088..b4aee68b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/monitorFile/cmp/ACmp.java @@ -19,4 +19,5 @@ 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/multiContext/CheckContext.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java index af8bfad4..793d85e1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/CheckContext.java @@ -2,23 +2,24 @@ package com.yomahub.liteflow.test.multiContext; public class CheckContext { - private String sign; + private String sign; - private int randomId; + private int randomId; - public String getSign() { - return sign; - } + public String getSign() { + return sign; + } - public void setSign(String sign) { - this.sign = sign; - } + public void setSign(String sign) { + this.sign = sign; + } - public int getRandomId() { - return randomId; - } + public int getRandomId() { + return randomId; + } + + public void setRandomId(int randomId) { + this.randomId = randomId; + } - public void setRandomId(int randomId) { - this.randomId = randomId; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java index 7022f0e6..3835bbdb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/MultiContextELSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,43 +27,43 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/multiContext/application.properties") @SpringBootTest(classes = MultiContextELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.multiContext.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.multiContext.cmp" }) public class MultiContextELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMultiContext1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - OrderContext orderContext = response.getContextBean(OrderContext.class); - CheckContext checkContext = response.getContextBean(CheckContext.class); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("987XYZ", checkContext.getSign()); - Assert.assertEquals(95, checkContext.getRandomId()); - Assert.assertEquals("SO12345", orderContext.getOrderNo()); - Assert.assertEquals(2, orderContext.getOrderType()); - Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); - } + @Test + public void testMultiContext1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + OrderContext orderContext = response.getContextBean(OrderContext.class); + CheckContext checkContext = response.getContextBean(CheckContext.class); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("987XYZ", checkContext.getSign()); + Assert.assertEquals(95, checkContext.getRandomId()); + Assert.assertEquals("SO12345", orderContext.getOrderNo()); + Assert.assertEquals(2, orderContext.getOrderType()); + Assert.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime()); + } - @Test(expected = NoSuchContextBeanException.class) - public void testMultiContext2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); - DefaultContext context = response.getContextBean(DefaultContext.class); - } + @Test(expected = NoSuchContextBeanException.class) + public void testMultiContext2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class); + DefaultContext context = response.getContextBean(DefaultContext.class); + } - @Test - public void testPassInitializedContextBean() throws Exception{ - OrderContext orderContext = new OrderContext(); - orderContext.setOrderNo("SO11223344"); - CheckContext checkContext = new CheckContext(); - checkContext.setSign("987654321d"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext); - Assert.assertTrue(response.isSuccess()); - OrderContext context1 = response.getContextBean(OrderContext.class); - CheckContext context2 = response.getContextBean(CheckContext.class); - Assert.assertEquals("SO11223344", context1.getOrderNo()); - Assert.assertEquals("987654321d", context2.getSign()); - } + @Test + public void testPassInitializedContextBean() throws Exception { + OrderContext orderContext = new OrderContext(); + orderContext.setOrderNo("SO11223344"); + CheckContext checkContext = new CheckContext(); + checkContext.setSign("987654321d"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext); + Assert.assertTrue(response.isSuccess()); + OrderContext context1 = response.getContextBean(OrderContext.class); + CheckContext context2 = response.getContextBean(CheckContext.class); + Assert.assertEquals("SO11223344", context1.getOrderNo()); + Assert.assertEquals("987654321d", context2.getSign()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java index c477108b..292db52b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/OrderContext.java @@ -4,33 +4,34 @@ import java.util.Date; public class OrderContext { - private String orderNo; + private String orderNo; - private int orderType; + private int orderType; - private Date createTime; + private Date createTime; - public String getOrderNo() { - return orderNo; - } + public String getOrderNo() { + return orderNo; + } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } + public void setOrderNo(String orderNo) { + this.orderNo = orderNo; + } - public int getOrderType() { - return orderType; - } + public int getOrderType() { + return orderType; + } - public void setOrderType(int orderType) { - this.orderType = orderType; - } + public void setOrderType(int orderType) { + this.orderType = orderType; + } - public Date getCreateTime() { - return createTime; - } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java index b8e5b675..8219f5de 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ACmp.java @@ -21,4 +21,5 @@ public class ACmp extends NodeComponent { checkContext.setRandomId(95); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java index c5a13ddb..4afcedf6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/BCmp.java @@ -16,7 +16,7 @@ public class BCmp extends NodeComponent { @Override public void process() { - //getContextBean无参方法是获取到第一个上下文 + // getContextBean无参方法是获取到第一个上下文 OrderContext orderContext = this.getFirstContextBean(); orderContext.setOrderNo("SO12345"); System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java index ef3ab3e1..68a82657 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeComponent { @Override public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java index ff404dc3..be0bc2c4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multiContext/cmp/FCmp.java @@ -16,4 +16,5 @@ public class FCmp extends NodeComponent { @Override public void process() { } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java index bdf97c56..95689d51 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringbootTest.java @@ -13,9 +13,9 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试springboot下混合格式规则的场景 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -23,19 +23,20 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(value = "classpath:/multipleType/application.properties") @SpringBootTest(classes = LiteflowMultipleTypeELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.multipleType.cmp" }) public class LiteflowMultipleTypeELSpringbootTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } - @Test - public void testMultipleType() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); - response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java index 343dd85e..a4e4f960 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java index 9fb99224..9cce6d74 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -8,11 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义默认的节点执行器 */ public class CustomerDefaultNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerDefaultNodeExecutor进行执行"); - context.setData("customerDefaultNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + context.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java index e4ef70e0..f4d447b6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -8,12 +8,13 @@ import com.yomahub.liteflow.slot.DefaultContext; * 自定义节点执行器 */ public class CustomerNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutor进行执行"); - context.setData("customerNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutor进行执行"); + context.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java index 202005b1..130208a7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -10,19 +10,21 @@ import java.util.concurrent.TimeUnit; * 自定义节点执行器 */ public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); - context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); - super.execute(instance); - } - @Override - protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { - TimeUnit.MICROSECONDS.sleep(20L); - DefaultContext context = instance.getFirstContextBean(); - context.setData("retryLogic", this.getClass()); - super.retry(instance, currentRetryCount); - } + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + DefaultContext context = instance.getFirstContextBean(); + context.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java index 97f040e1..56c26dee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringbootTest.java @@ -15,7 +15,6 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试springboot下的组件重试 * @@ -26,47 +25,48 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/nodeExecutor/application.properties") @SpringBootTest(classes = LiteflowNodeExecutorELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.nodeExecutor.cmp" }) public class LiteflowNodeExecutorELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - // 默认执行器测试 - @Test - public void testCustomerDefaultNodeExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("a", response.getExecuteStepStr()); - } + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getExecuteStepStr()); + } - //默认执行器测试+全局重试配置测试 - @Test - public void testDefaultExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); - } + // 默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); + } - //自定义执行器测试 - @Test - public void testCustomerExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("c", response.getExecuteStepStr()); - } + // 自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStr()); + } + + // 自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); + } - //自定义执行器测试+全局重试配置测试 - @Test - public void testCustomExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); - Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java index 8fd765bb..5eec1192 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java @@ -14,9 +14,9 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("a") public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("ACmp executed!"); - } + @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/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java index 6e737879..de68032f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -18,7 +18,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java index f800c08b..77c9ca4c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -23,7 +23,8 @@ public class CCmp extends NodeComponent { } @Override - public Class getNodeExecutorClass() { + public Class getNodeExecutorClass() { return CustomerNodeExecutor.class; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java index bc99b47a..210c1c05 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -15,17 +15,18 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { - @Override - public void process() { - System.out.println("DCmp executed!"); - throw new NullPointerException("demo exception"); - } + @Override + public void process() { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @Override + public Class getNodeExecutorClass() { + return CustomerNodeExecutorAndCustomRetry.class; + } - @Override - public Class getNodeExecutorClass() { - return CustomerNodeExecutorAndCustomRetry.class; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java index dd2575ea..97c86474 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamELSpringbootTest.java @@ -22,19 +22,19 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(value = "classpath:/nullParam/application.properties") @SpringBootTest(classes = NullParamELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.nullParam.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.nullParam.cmp" }) public class NullParamELSpringbootTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; - /** - * 支持无参的flow执行,以及param 为null时的异常抛出 - */ - @Test - public void testNullParam() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - } + /** + * 支持无参的flow执行,以及param 为null时的异常抛出 + */ + @Test + public void testNullParam() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java index e518efd8..c3cae20c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { System.out.println("get request data:" + this.getRequestData()); this.getSlot().setInput("BCmp", "param for BCmp"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java index 68f3fbf6..efc8ef0d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境的自定义json parser单元测试 + * * @author dongguo.tao * @since 2.5.0 */ @@ -23,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties") @SpringBootTest(classes = CustomParserJsonELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.parsecustom.cmp" }) public class CustomParserJsonELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testJsonCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java index 1cf2aaf9..63c51e29 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlELSpringbootTest.java @@ -15,8 +15,8 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ @@ -24,16 +24,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties") @SpringBootTest(classes = CustomParserXmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.parsecustom.cmp", "com.yomahub.liteflow.test.parsecustom.bean" }) public class CustomParserXmlELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testXmlCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java index 0ca24257..7742b478 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserYmlELSpringbootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * springboot环境的自定义yml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义yml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 * * @author junjun */ @@ -24,16 +23,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/parsecustom/application-custom-yml.properties") @SpringBootTest(classes = CustomParserYmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +@ComponentScan({ "com.yomahub.liteflow.test.parsecustom.cmp", "com.yomahub.liteflow.test.parsecustom.bean" }) public class CustomParserYmlELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springboot场景的自定义json parser + @Test + public void testYmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试springboot场景的自定义json parser - @Test - public void testYmlCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java index 6e6d9f57..e96fa077 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class TestBean { - public String returnXmlContent(){ - return "THEN(a,b,c,d)"; - } + public String returnXmlContent() { + return "THEN(a,b,c,d)"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java index a6af92af..ea90cd19 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -18,9 +18,10 @@ public class ACmp extends NodeComponent { @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new FlowSystemException("chain execute execption"); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java index 4f3a0d1e..57e75f4b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java index 42f5eeed..a164ba09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -4,14 +4,17 @@ import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser; /** * 模拟用户自定义源解析 + * * @author dongguo.tao * @since 2.5.0 */ public class CustomJsonFlowParser extends ClassJsonFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; - return content; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c, g, f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a, c, WHEN(b, d, SWITCH(e).to(f, g), chain2))\"}]}}"; + return content; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java index 473ad502..3405882d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -6,18 +6,19 @@ import com.yomahub.liteflow.test.parsecustom.bean.TestBean; import javax.annotation.Resource; /** - * springboot环境的自定义xml parser单元测试 - * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * springboot环境的自定义xml parser单元测试 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * * @author bryan.zhang * @since 2.5.7 */ public class CustomXmlFlowParser extends ClassXmlFlowELParser { - @Resource - private TestBean testBean; + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } - @Override - public String parseCustom() { - return testBean.returnXmlContent(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java index 3431a3d5..b89fcc77 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomYmlFlowParser.java @@ -8,12 +8,11 @@ import com.yomahub.liteflow.parser.el.ClassYmlFlowELParser; * @author junjun */ public class CustomYmlFlowParser extends ClassYmlFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - return "flow:\n" + - " chain:\n" + - " - name: chain1\n" + - " value: \"THEN(a, b, c);\""; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + return "flow:\n" + " chain:\n" + " - name: chain1\n" + " value: \"THEN(a, b, c);\""; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java index 43c4a5af..76596594 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/JsonParserELSpringbootTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * spring环境的json parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -24,13 +25,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class JsonParserELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的json parser - @Test - public void testJsonParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java index e7ee6efc..6b33d15a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportELSpringbootTest.java @@ -19,13 +19,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class SpringELSupportELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试springEL的解析情况 + @Test + public void testSpringELParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试springEL的解析情况 - @Test - public void testSpringELParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java index 0bec66a7..c29fa84c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/XmlParserELSpringbootTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * springboot环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -24,13 +25,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class XmlParserELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试无springboot场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的xml parser - @Test - public void testXmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java index c484816f..5d6c84b6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/YmlParserELSpringbootTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * springboot下的yml parser测试用例 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -24,13 +25,14 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class YmlParserELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试无springboot场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试无springboot场景的yml parser - @Test - public void testYmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java index 35f519ec..c9d63440 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/parser/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java index e86aca5d..637ff4c6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java index 4b1605e2..0a6936d3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境下pre节点和finally节点的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,65 +25,66 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/preAndFinally/application.properties") @SpringBootTest(classes = PreAndFinallyELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.preAndFinally.cmp" }) public class PreAndFinallyELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通的pre和finally节点 - @Test - public void testPreAndFinally1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试pre和finally节点不放在开头和结尾的情况 - @Test - public void testPreAndFinally2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 - @Test - public void testPreAndFinally3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); - } + // 测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); + } - //测试在finally节点里是否能获取exception - @Test - public void testPreAndFinally4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(context.getData("hasEx")); - } + // 测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(context.getData("hasEx")); + } - //测试嵌套结构pre和finally是否在各自的chain里打出 - @Test - public void testPreAndFinally5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } + // 测试嵌套结构pre和finally是否在各自的chain里打出 + @Test + public void testPreAndFinally5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } - //测试变量结构pre和finally是否在各自的chain里打出 - @Test - public void testPreAndFinally6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } + // 测试变量结构pre和finally是否在各自的chain里打出 + @Test + public void testPreAndFinally6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } + + // 测试el整体结构的多重pre和finally + @Test + public void testPreAndFinally7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试el整体结构的多重pre和finally - @Test - public void testPreAndFinally7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java index 1dcd7520..55c638b9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/preAndFinally/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java index 3f1216a7..ef7de236 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -16,7 +16,7 @@ public class DCmp extends NodeComponent { @Override public void process() { System.out.println("CCmp executed!"); - int i = 1/0; + int i = 1 / 0; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java index f826fb5e..ef22ba52 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -17,4 +17,5 @@ public class Finally1Cmp extends NodeComponent { public void process() { System.out.println("Finally1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java index 92157678..664e295b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -17,4 +17,5 @@ public class Finally2Cmp extends NodeComponent { public void process() { System.out.println("Finally2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java index 22c4d1d2..0e3c8e9e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -17,14 +17,16 @@ import org.springframework.stereotype.Component; public class Finally3Cmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Slot slot = this.getSlot(); DefaultContext context = slot.getFirstContextBean(); - if (ObjectUtil.isNull(slot.getException())){ + if (ObjectUtil.isNull(slot.getException())) { context.setData("hasEx", false); - }else{ + } + else { context.setData("hasEx", true); } System.out.println("Finally3Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java index 741e15d4..010a783d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -17,4 +17,5 @@ public class Pre1Cmp extends NodeComponent { public void process() { System.out.println("Pre1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java index 43cd71f1..1019fa4e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -17,4 +17,5 @@ public class Pre2Cmp extends NodeComponent { public void process() { System.out.println("Pre2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java index 4079e6b7..70447b20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringbootTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,18 +26,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/privateDelivery/application.properties") @SpringBootTest(classes = PrivateDeliveryELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.privateDelivery.cmp" }) public class PrivateDeliveryELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + ConcurrentHashSet set = context.getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } - @Test - public void testPrivateDelivery() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - ConcurrentHashSet set = context.getData("testSet"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(100, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java index c7cb8c9b..35d07749 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -22,8 +22,8 @@ public class ACmp extends NodeComponent { context.setData("testSet", new ConcurrentHashSet<>()); for (int i = 0; i < 100; i++) { - this.sendPrivateDeliveryData("b",i+1); + this.sendPrivateDeliveryData("b", i + 1); } } -} +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java index 54cf4ce3..cb537efe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -15,13 +15,13 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BCmp executed!"); - Integer value = this.getPrivateDeliveryData(); - DefaultContext context = this.getFirstContextBean(); - ConcurrentHashSet testSet = context.getData("testSet"); - testSet.add(value); - } -} + @Override + public void process() { + System.out.println("BCmp executed!"); + Integer value = this.getPrivateDeliveryData(); + DefaultContext context = this.getFirstContextBean(); + ConcurrentHashSet testSet = context.getData("testSet"); + testSet.add(value); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java index c0673e10..76971e72 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringbootTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,44 +27,47 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/refreshRule/application.properties") @SpringBootTest(classes = RefreshRuleELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.refreshRule.cmp" }) public class RefreshRuleELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通刷新流程的场景 - @Test - public void testRefresh1() throws Exception{ - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception { + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试优雅刷新的场景 - @Test - public void testRefresh2() throws Exception{ - new Thread(() -> { - try { - Thread.sleep(3000L); - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - } catch (Exception e) { - e.printStackTrace(); - } + // 测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception { + new Thread(() -> { + try { + Thread.sleep(3000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + } + catch (Exception e) { + e.printStackTrace(); + } - }).start(); + }).start(); - for (int i = 0; i < 500; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - try { - Thread.sleep(10L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java index 96d599a5..0dffc413 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/reload/ReloadELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java index 40cdca28..c94295a7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringbootTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -23,18 +24,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/reload/application.properties") @SpringBootTest(classes = ReloadELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.reload.cmp" }) public class ReloadELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + // 这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception { + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml - //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 - @Test - public void testReload() throws Exception{ - flowExecutor.reloadRule(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java index fcf6fed4..734956e8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/removeChain/RemoveChainELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java index 4acaa9ac..cfca512b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * springboot环境最普通的例子测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,19 +25,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/removeChain/application.properties") @SpringBootTest(classes = RemoveChainELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.removeChain.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.removeChain.cmp" }) public class RemoveChainELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testRemoveChain() throws Exception{ - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response1.isSuccess()); - FlowBus.removeChain("chain1"); - LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response2.isSuccess()); - } + @Test + public void testRemoveChain() throws Exception { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + FlowBus.removeChain("chain1"); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response2.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java index 8640323d..a7d928c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/requestId/LiteflowRequestIdELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java index 689bdfde..ba27900a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringbootTest.java @@ -21,17 +21,17 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/requestId/application.properties") @SpringBootTest(classes = LiteflowRequestIdELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.requestId.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.requestId.cmp" }) public class LiteflowRequestIdELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testRequestId() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1", response.getRequestId()); - } + @Test + public void testRequestId() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", response.getRequestId()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java index e2369dbd..68916fab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java @@ -16,8 +16,9 @@ import org.springframework.stereotype.Component; @Component("a") public class ACmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java index 5e441aac..19e71b88 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java index fcaa9e84..e705db34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java @@ -9,10 +9,11 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class CustomRequestIdGenerator implements RequestIdGenerator { - private final AtomicInteger atomicInteger = new AtomicInteger(0); + private final AtomicInteger atomicInteger = new AtomicInteger(0); + + @Override + public String generate() { + return atomicInteger.incrementAndGet() + ""; + } - @Override - public String generate() { - return atomicInteger.incrementAndGet() + ""; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/slotOffer/SlotOfferELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/slotOffer/SlotOfferELSpringbootTest.java index 75ad2644..01040f57 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/slotOffer/SlotOfferELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/slotOffer/SlotOfferELSpringbootTest.java @@ -26,6 +26,7 @@ import java.util.function.Supplier; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @@ -33,44 +34,45 @@ import java.util.function.Supplier; @EnableAutoConfiguration public class SlotOfferELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //并发200,一共6w条线程去获取Slot的测试 - @Test - public void testSlotOffer() throws Exception{ - Set set = new ConcurrentHashSet<>(); - Set> futureSet = new ConcurrentHashSet<>(); - Set error = new ConcurrentHashSet<>(); - for (int i = 0; i < 60000; i++) { - futureSet.add(CompletableFuture.supplyAsync(() -> { - int index=0; - try{ - index = DataBus.offerSlotByClass(ListUtil.toList(DefaultContext.class)); - boolean flag = set.add(index); - if (!flag){ - error.add(Integer.toString(index)); - } - }catch (Exception e) { - error.add(e.getMessage()); - }finally { - DataBus.releaseSlot(index); - boolean flag = set.remove(index); - if(!flag){ - error.add(Integer.toString(index)); - } - } - return Boolean.TRUE; - })); - } - CompletableFuture resultFuture = CompletableFuture.allOf(futureSet.toArray(new CompletableFuture[]{})); + // 并发200,一共6w条线程去获取Slot的测试 + @Test + public void testSlotOffer() throws Exception { + Set set = new ConcurrentHashSet<>(); + Set> futureSet = new ConcurrentHashSet<>(); + Set error = new ConcurrentHashSet<>(); + for (int i = 0; i < 60000; i++) { + futureSet.add(CompletableFuture.supplyAsync(() -> { + int index = 0; + try { + index = DataBus.offerSlotByClass(ListUtil.toList(DefaultContext.class)); + boolean flag = set.add(index); + if (!flag) { + error.add(Integer.toString(index)); + } + } + catch (Exception e) { + error.add(e.getMessage()); + } + finally { + DataBus.releaseSlot(index); + boolean flag = set.remove(index); + if (!flag) { + error.add(Integer.toString(index)); + } + } + return Boolean.TRUE; + })); + } + CompletableFuture resultFuture = CompletableFuture.allOf(futureSet.toArray(new CompletableFuture[] {})); - resultFuture.get(); - - Assert.assertEquals(0, set.size()); - Assert.assertEquals(0, error.size()); - Assert.assertEquals(0, DataBus.OCCUPY_COUNT.get()); - } + resultFuture.get(); + Assert.assertEquals(0, set.size()); + Assert.assertEquals(0, error.size()); + Assert.assertEquals(0, DataBus.OCCUPY_COUNT.get()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java index c089041a..69251564 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringbootTest.java @@ -19,8 +19,7 @@ import java.util.HashSet; import java.util.Set; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author justin.xu */ @@ -28,46 +27,48 @@ import java.util.Set; @TestPropertySource(value = "classpath:/subflow/application-implicit.properties") @SpringBootTest(classes = ImplicitSubFlowELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp2" }) public class ImplicitSubFlowELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - public static final Set RUN_TIME_SLOT = new HashSet<>(); + @Resource + private FlowExecutor flowExecutor; - //这里GCmp中隐式的调用chain4,从而执行了h,m - @Test - public void testImplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); + public static final Set RUN_TIME_SLOT = new HashSet<>(); - // 传递了slotIndex,则set的size==1 - Assert.assertEquals(1, RUN_TIME_SLOT.size()); - // set中第一次设置的requestId和response中的requestId一致 - Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); - //requestData的取值正确 - Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); - } + // 这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); - //在p里多线程调用q 10次,每个q取到的参数都是不同的。 - @Test - public void testImplicitSubFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + // requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); + } - Set set = context.getData("test"); + // 在p里多线程调用q 10次,每个q取到的参数都是不同的。 + @Test + public void testImplicitSubFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); - //requestData的取值正确 - Assert.assertEquals(10, set.size()); - } + Set set = context.getData("test"); - @Test - public void testImplicitSubFlow3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain_r", "it's a request"); - Assert.assertTrue(response.isSuccess()); + // requestData的取值正确 + Assert.assertEquals(10, set.size()); + } + + @Test + public void testImplicitSubFlow3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain_r", "it's a request"); + Assert.assertTrue(response.isSuccess()); + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java index 28bdb9fb..8d34c447 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringbootTest.java @@ -27,27 +27,29 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-subInDifferentConfig1.properties") @SpringBootTest(classes = SubflowInDifferentConfigELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1","com.yomahub.liteflow.test.subflow.cmp2"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1", "com.yomahub.liteflow.test.subflow.cmp2" }) public class SubflowInDifferentConfigELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; - @Autowired - private ApplicationContext context; + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); + } + + @Autowired + private ApplicationContext context; + + // 主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.yml"); + flowExecutor.reloadRule(); + } - //主要测试有不同的配置类型后会不会报出既定的错误 - @Test(expected = MultipleParsersException.class) - public void testExplicitSubFlow2() { - LiteflowConfig config = context.getBean(LiteflowConfig.class); - config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.yml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringBootTest.java index a3486c02..2e8e88a8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(json) - * 单元测试 + * 测试显示调用子流程(json) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-json.properties") @SpringBootTest(classes = SubflowJsonELSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowJsonELSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java index f14bd072..c164cc2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(xml) - * 单元测试 + * 测试显示调用子流程(xml) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-xml.properties") @SpringBootTest(classes = SubflowXMLELSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowXMLELSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java index fc624051..5197c6d0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringBootTest.java @@ -15,8 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(yml) - * 单元测试 + * 测试显示调用子流程(yml) 单元测试 * * @author justin.xu */ @@ -24,16 +23,18 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/subflow/application-yml.properties") @SpringBootTest(classes = SubflowYmlELSpringBootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +@ComponentScan({ "com.yomahub.liteflow.test.subflow.cmp1" }) public class SubflowYmlELSpringBootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlowYml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java index 75a7fb49..11697dc0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; 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("Acomp executed!"); - } + + @Override + public void process() { + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java index 9fb3c932..06459fc5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; 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("Bcomp executed!"); - } + + @Override + public void process() { + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java index ce8ea149..aa1668e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java index 309196e9..1b0cfb90 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java index b855a1ae..9dce7ccf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -3,12 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("e") public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ecomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Ecomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java index 2faf9b7c..b3ea86b4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -6,17 +6,18 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("f") public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - context.setData("innerRequestData", "inner request"); + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + DefaultContext context = this.getFirstContextBean(); + context.setData("innerRequestData", "inner request"); + + System.out.println("Fcomp executed!"); + } - System.out.println("Fcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java index 22f7a1fc..27877e4a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -7,22 +7,20 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("g") public class GCmp extends NodeComponent { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; - @Override - public void process() throws Exception { + @Override + public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); - System.out.println("Gcmp executed!"); + System.out.println("Gcmp executed!"); + this.invoke("chain4", "it's implicit subflow."); + } - - this.invoke("chain4", "it's implicit subflow."); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index a9f79290..74c13bd8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -6,17 +6,18 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("h") public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqData(); - DefaultContext context = this.getFirstContextBean(); - context.setData("innerRequest", requestData); - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqData(); + DefaultContext context = this.getFirstContextBean(); + context.setData("innerRequest", requestData); + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java index 5ef0f629..0fa9e0b7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -5,14 +5,15 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("m") public class MCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); + } - System.out.println("Mcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java index 39d75247..b599bb07 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java @@ -7,20 +7,21 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("p") public class PCmp extends NodeComponent { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Override + public void process() throws Exception { + int slotIndex = this.getSlotIndex(); + for (int i = 0; i < 10; i++) { + int finalI = i; + new Thread(() -> flowExecutor.invoke2RespInAsync("c2", "it's implicit subflow " + finalI, slotIndex)) + .start(); + } + Thread.sleep(1000); + } - @Override - public void process() throws Exception { - int slotIndex = this.getSlotIndex(); - for (int i = 0; i < 10; i++) { - int finalI = i; - new Thread(() -> flowExecutor.invoke2RespInAsync("c2", "it's implicit subflow " + finalI, slotIndex)).start(); - } - Thread.sleep(1000); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java index 8f9475fc..ed89408a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java @@ -9,23 +9,25 @@ import java.util.Set; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringbootTest.RUN_TIME_SLOT; - @Component("q") public class QCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqDataInAsync(); - DefaultContext context = this.getFirstContextBean(); - synchronized (QCmp.class){ - if (context.hasData("test")){ - Set set = context.getData("test"); - set.add(requestData); - }else{ - Set set = new HashSet<>(); - set.add(requestData); - context.setData("test", set); - } - } - } + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqDataInAsync(); + DefaultContext context = this.getFirstContextBean(); + + synchronized (QCmp.class) { + if (context.hasData("test")) { + Set set = context.getData("test"); + set.add(requestData); + } + else { + Set set = new HashSet<>(); + set.add(requestData); + context.setData("test", set); + } + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java index 804bba47..bfaa1ce9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/R.java @@ -5,8 +5,10 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("r") public class R extends NodeComponent { - @Override - public void process() throws Exception { - this.invoke2Resp("chain_s",""); - } + + @Override + public void process() throws Exception { + this.invoke2Resp("chain_s", ""); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java index fbaf1dc9..8743967b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/S.java @@ -5,8 +5,10 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("s") public class S extends NodeComponent { - @Override - public void process() throws Exception { - throw new RuntimeException("test"); - } + + @Override + public void process() throws Exception { + throw new RuntimeException("test"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java index a5d3df90..72a13873 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/SubstituteSpringbootTest.java @@ -16,36 +16,38 @@ import javax.annotation.Resource; /** * springboot环境EL替补节点的测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/substituteNode/application.properties") @SpringBootTest(classes = SubstituteSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.substituteNode.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.substituteNode.cmp" }) public class SubstituteSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testSub1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 最简单的情况 + @Test + public void testSub1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //有替补节点 - @Test - public void testSub2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 有替补节点 + @Test + public void testSub2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + // 测试特殊命名的节点 + @Test + public void testSub3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试特殊命名的节点 - @Test - public void testSub3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java index 5b95b6d3..b6e1d7d8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/substituteNode/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/switchcase/SwitchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java index c773bba9..510f4aea 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringbootTest.java @@ -16,95 +16,96 @@ import javax.annotation.Resource; /** * springboot环境EL常规的例子测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @TestPropertySource(value = "classpath:/switchcase/application.properties") @SpringBootTest(classes = SwitchELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.switchcase.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.switchcase.cmp" }) public class SwitchELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //2022-07-12 switch 异常错误.c.y.l.builder.el.operator.ToOperator : parameter error - //run QlExpress Exception at line 1 : - // switch().to(): 只有一个node时出错 - @Test - public void testSwitch1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); - } + // 2022-07-12 switch 异常错误.c.y.l.builder.el.operator.ToOperator : parameter error + // run QlExpress Exception at line 1 : + // switch().to(): 只有一个node时出错 + @Test + public void testSwitch1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d", response.getExecuteStepStr()); + } - @Test - public void testSwitch3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>f==>b",response.getExecuteStepStr()); - } + @Test + public void testSwitch3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>f==>b", response.getExecuteStepStr()); + } - //根据tag来跳转,指定哪个组件的tag - @Test - public void testSwitch4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>g==>d",response.getExecuteStepStr()); - } + // 根据tag来跳转,指定哪个组件的tag + @Test + public void testSwitch4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>g==>d", response.getExecuteStepStr()); + } - //tag的跳转 - @Test - public void testSwitch5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } + // tag的跳转 + @Test + public void testSwitch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } - //相同组件的tag的跳转 - @Test - public void testSwitch6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } + // 相同组件的tag的跳转 + @Test + public void testSwitch6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } - //switch增加default选项 - @Test - public void testSwitch7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>i==>d",response.getExecuteStepStr()); - } + // switch增加default选项 + @Test + public void testSwitch7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>i==>d", response.getExecuteStepStr()); + } - //switch返回如果是空,会走default选项 - @Test - public void testSwitch8() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>j==>d",response.getExecuteStepStr()); - } + // switch返回如果是空,会走default选项 + @Test + public void testSwitch8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>j==>d", response.getExecuteStepStr()); + } - //测试跳转到某个链路上 - @Test - public void testSwitch9() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("k==>a==>b",response.getExecuteStepStr()); - } + // 测试跳转到某个链路上 + @Test + public void testSwitch9() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("k==>a==>b", response.getExecuteStepStr()); + } - //相同组件复用的用例 - @Test - public void testSwitch10() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 相同组件复用的用例 + @Test + public void testSwitch10() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg"); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java index 73c1b5d4..58f7e6b9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java @@ -18,4 +18,5 @@ public class ACmp extends NodeComponent { System.out.println("ACmp executed!"); System.out.println(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java index b3e03d8f..275e3c98 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java @@ -17,4 +17,5 @@ public class ESwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java index ac83ec67..e32efdd2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java @@ -17,4 +17,5 @@ public class FSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return ":td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java index a956a5ec..8ee8cc9d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java @@ -17,4 +17,5 @@ public class GSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java index 68838816..12a8482a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java @@ -17,4 +17,5 @@ public class HSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "tag:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java index 34e58318..18c2982b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ISwitchCmp.java @@ -17,4 +17,5 @@ public class ISwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "a"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/JSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/JSwitchCmp.java index 0e70272e..e93518db 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/JSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/JSwitchCmp.java @@ -17,4 +17,5 @@ public class JSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return ""; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/KSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/KSwitchCmp.java index efea50e3..6039bae5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/KSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/KSwitchCmp.java @@ -17,4 +17,5 @@ public class KSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "chain10"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/LSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/LSwitchCmp.java index 7363535d..c44eed11 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/LSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/LSwitchCmp.java @@ -6,9 +6,11 @@ import com.yomahub.liteflow.core.NodeSwitchComponent; @LiteflowComponent("l") public class LSwitchCmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - String tag = this.getTag(); - return StrUtil.format("tag:{}",tag); - } + + @Override + public String processSwitch() throws Exception { + String tag = this.getTag(); + return StrUtil.format("tag:{}", tag); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java index 1b4263cd..2dd64e18 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootJsonTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,45 +26,46 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/tag/application-json.properties") @SpringBootTest(classes = NodeTagELSpringbootJsonTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.tag.cmp" }) public class NodeTagELSpringbootJsonTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java index 8469c53e..e0a3c406 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringbootXmlTest.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -25,54 +26,55 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/tag/application-xml.properties") @SpringBootTest(classes = NodeTagELSpringbootXmlTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.tag.cmp" }) public class NodeTagELSpringbootXmlTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } + + // 测试tag是否能在WHEN中起效果 + @Test + public void testTag5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", context.getData("test")); + } - //测试tag是否能在WHEN中起效果 - @Test - public void testTag5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1",context.getData("test")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java index 6c092f86..1b54a620 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java @@ -19,12 +19,14 @@ public class ACmp extends NodeComponent { String testKey = "test"; DefaultContext context = this.getFirstContextBean(); - if (context.getData(testKey) == null){ - context.setData(testKey,this.getTag()); - }else{ + if (context.getData(testKey) == null) { + context.setData(testKey, this.getTag()); + } + else { String s = context.getData(testKey); s += this.getTag(); context.setData(testKey, s); } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java index 4e4aba1f..ea3b06c3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -18,6 +18,7 @@ public class B1Cmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",new ConcurrentHashSet()); + context.setData("test", new ConcurrentHashSet()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java index fbc4732d..edebceb5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java @@ -21,4 +21,5 @@ public class BCmp extends NodeComponent { ConcurrentHashSet testSet = context.getData("test"); testSet.add(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java index ceedd8ab..d90bdc3a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java @@ -15,10 +15,12 @@ public class CCmp extends NodeSwitchComponent { @Override public String processSwitch() throws Exception { - if(this.getTag().equals("2")){ + if (this.getTag().equals("2")) { return "e"; - }else{ + } + else { return "d"; } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java index 572980b7..d231b874 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -18,4 +18,5 @@ public class DCmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("DCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java index 11ee96c8..e2687fa3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -18,4 +18,5 @@ public class ECmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("ECmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java index 2f670578..f15f468e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -22,4 +22,5 @@ public class FCmp extends NodeComponent { public boolean isAccess() { return Boolean.parseBoolean(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java index f6180b56..f2d2e3f7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -17,4 +17,5 @@ public class GCmp extends NodeComponent { public void process() { System.out.println("GCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java index cbdb66e1..3edc711f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/tag/cmp/HCmp.java @@ -21,7 +21,8 @@ public class HCmp extends NodeComponent { @Override public boolean isAccess() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",this.getTag()); + context.setData("test", this.getTag()); return true; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java index fee0055e..3de938a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -4,13 +4,14 @@ import com.alibaba.ttl.TransmittableThreadLocal; public class TestTL { - public static ThreadLocal tl = new TransmittableThreadLocal<>(); + public static ThreadLocal tl = new TransmittableThreadLocal<>(); - public static String get(){ - return tl.get(); - } + public static String get() { + return tl.get(); + } + + public static void set(String value) { + tl.set(value); + } - public static void set(String value){ - tl.set(value); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java index 19188a53..9c761546 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringbootTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * * @author Bryan.Zhang * @since 2.6.3 */ @@ -24,20 +25,21 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/useTTLInWhen/application.properties") @SpringBootTest(classes = UseTTLInWhenELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.useTTLInWhen.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.useTTLInWhen.cmp" }) public class UseTTLInWhenELSpringbootTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,b", context.getData("b")); + Assert.assertEquals("hello,c", context.getData("c")); + Assert.assertEquals("hello,d", context.getData("d")); + Assert.assertEquals("hello,e", context.getData("e")); + Assert.assertEquals("hello,f", context.getData("f")); + } - @Test - public void testUseTTLInWhen() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,b", context.getData("b")); - Assert.assertEquals("hello,c", context.getData("c")); - Assert.assertEquals("hello,d", context.getData("d")); - Assert.assertEquals("hello,e", context.getData("e")); - Assert.assertEquals("hello,f", context.getData("f")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java index bab445a4..7fbd16da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { TestTL.set("hello"); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java index 7597ad59..d9f48956 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -19,7 +19,7 @@ public class BCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",b"); + context.setData(this.getNodeId(), value + ",b"); System.out.println("BCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java index bc5c7ca6..82d1d051 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -19,7 +19,7 @@ public class CCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",c"); + context.setData(this.getNodeId(), value + ",c"); System.out.println("CCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java index 1410921d..a8b64dd4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -19,7 +19,7 @@ public class DCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",d"); + context.setData(this.getNodeId(), value + ",d"); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java index 6217dd6a..8cb7eab8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -19,7 +19,7 @@ public class ECmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",e"); + context.setData(this.getNodeId(), value + ",e"); System.out.println("ECmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java index 06380e58..4b85cac4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -19,7 +19,7 @@ public class FCmp extends NodeComponent { public void process() { String value = TestTL.get(); DefaultContext context = this.getFirstContextBean(); - context.setData(this.getNodeId(),value+",f"); + context.setData(this.getNodeId(), value + ",f"); System.out.println("FCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java index 058dc977..66b87af1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/ValidateRuleELSpringbootTest.java @@ -28,24 +28,28 @@ import javax.annotation.Resource; @EnableAutoConfiguration public class ValidateRuleELSpringbootTest extends BaseTest { - @Test - public void testChainELExpressValidate() { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz(BCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, h)")); - Assert.assertTrue(LiteFlowChainELBuilder.validate("THEN(a, b, c)")); - } + @Test + public void testChainELExpressValidate() { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, h)")); + Assert.assertTrue(LiteFlowChainELBuilder.validate("THEN(a, b, c)")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java index 916bda29..3c913c07 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/validateRule/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/whenTimeOut/WhenTimeOutELSpringbootTest1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java index 40a49f08..108b4fe6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest1.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -26,19 +27,20 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/whenTimeOut/application1.properties") @SpringBootTest(classes = WhenTimeOutELSpringbootTest1.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.whenTimeOut.cmp" }) public class WhenTimeOutELSpringbootTest1 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } - //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java index e151f890..2f06f6f3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringbootTest2.java @@ -18,6 +18,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -25,18 +26,19 @@ import javax.annotation.Resource; @TestPropertySource(value = "classpath:/whenTimeOut/application2.properties") @SpringBootTest(classes = WhenTimeOutELSpringbootTest2.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.whenTimeOut.cmp" }) public class WhenTimeOutELSpringbootTest2 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java index 19b0bc06..c8a474b4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java @@ -17,4 +17,5 @@ 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/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java index fb8cd2a1..f5778fcd 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 @@ -17,7 +17,8 @@ public class BCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("BCmp executed!"); 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 ee9fe977..e50c9689 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 @@ -17,7 +17,8 @@ public class CCmp extends NodeComponent { public void process() { try { Thread.sleep(3500); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java index 5f3c4b3f..1a3a7d42 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -17,7 +17,8 @@ public class DCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("DCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java index 0e18aee7..5ab23c86 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -17,7 +17,8 @@ public class ECmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("ECmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java index fad1d2d6..d0def9de 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -17,7 +17,8 @@ public class FCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("FCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java index 1ecaf2cc..da836cba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathELSpringTest.java @@ -13,6 +13,7 @@ import javax.annotation.Resource; /** * spring环境下,规则配置文件通过绝对路径获取 + * * @author zendwang * @since 2.8.0 */ @@ -20,12 +21,13 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/absoluteConfigPath/application.xml") public class AbsoluteConfigPathELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testAbsoluteConfig(){ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java index 74091479..1f5f6ad0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/aop/CustomAOPELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELSpringTest.java index 6db327dc..38f32a12 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPELSpringTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * 切面场景单元测试 + * * @author zendwang * @since 2.8.0 */ @@ -21,28 +22,29 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/aop/application-custom.xml") public class CustomAOPELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试自定义AOP,串行场景 - @Test - public void testCustomAopS() { - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - } + // 测试自定义AOP,串行场景 + @Test + public void testCustomAopS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + } + + // 测试自定义AOP,并行场景 + @Test + public void testCustomAopP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + } - //测试自定义AOP,并行场景 - @Test - public void testCustomAopP() { - LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringTest.java index 8c6f889d..9fee62d4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPELSpringTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * 切面场景单元测试 + * * @author zendwang * @since 2.8.0 */ @@ -24,49 +25,50 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/aop/application-global.xml") public class GlobalAOPELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试全局AOP,串行场景 - @Test - public void testGlobalAopS() { - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,串行场景 + @Test + public void testGlobalAopS() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - //测试全局AOP,并行场景 - @Test - public void testGlobalAopP() { - LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("d")); - Assert.assertEquals("before_after", context.getData("e")); - } + // 测试全局AOP,并行场景 + @Test + public void testGlobalAopP() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("d")); + Assert.assertEquals("before_after", context.getData("e")); + } - @Test - public void testGlobalAopException() { - LiteflowResponse response= flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("before_after", context.getData("a")); - Assert.assertEquals("before_after", context.getData("b")); - Assert.assertEquals("before_after", context.getData("c")); - Assert.assertEquals("before_after", context.getData("f")); - } + @Test + public void testGlobalAopException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("before_after", context.getData("a")); + Assert.assertEquals("before_after", context.getData("b")); + Assert.assertEquals("before_after", context.getData("c")); + Assert.assertEquals("before_after", context.getData("f")); + } + + @AfterClass + public static void cleanScanCache() { + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } - @AfterClass - public static void cleanScanCache(){ - BaseTest.cleanScanCache(); - ComponentScanner.cmpAroundAspect = null; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java index 3704a146..e3884622 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java @@ -6,15 +6,17 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; public class CmpAspect implements ICmpAroundAspect { - @Override - public void beforeProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, "before"); - } - @Override - public void afterProcess(String nodeId, Slot slot) { - DefaultContext context = slot.getFirstContextBean(); - context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); - } + @Override + public void beforeProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, "before"); + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + DefaultContext context = slot.getFirstContextBean(); + context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after")); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java index c1421dbe..eca5899b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java @@ -11,17 +11,18 @@ import org.aspectj.lang.annotation.Pointcut; @Aspect public class CustomAspect { - @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process())") - public void cut() { - } + @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process())") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + DefaultContext context = cmp.getFirstContextBean(); + context.setData(cmp.getNodeId(), "before"); + Object returnObj = jp.proceed(); + context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); + return returnObj; + } - @Around("cut()") - public Object around(ProceedingJoinPoint jp) throws Throwable { - NodeComponent cmp = (NodeComponent) jp.getThis(); - DefaultContext context = cmp.getFirstContextBean(); - context.setData(cmp.getNodeId(), "before"); - Object returnObj = jp.proceed(); - context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after")); - return returnObj; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringTest.java index b1c895ea..faf11210 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeELSpringTest.java @@ -15,119 +15,119 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author ssss */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/asyncNode/application.xml") public class AsyncNodeELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - /***** - * 标准chain 嵌套选择 嵌套子chain进行执行 - * 验证了when情况下 多个node是并行执行 - * 验证了默认参数情况下 when可以加载执行 - * **/ - @Test - public void testAsyncFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - System.out.println(response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; - //这个和test1有点类似,只不过进一步验证了步骤 - @Test - public void testAsyncFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); - Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", - "b==>j==>h==>g==>f","b==>j==>h==>f==>g", - "b==>j==>f==>h==>g","b==>j==>f==>g==>h" - ).contains(response.getExecuteStepStr())); - } + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 验证了when情况下 多个node是并行执行 验证了默认参数情况下 when可以加载执行 + **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getExecuteStepStr()); + } - //测试errorResume,默认的errorResume为false,这里测试默认的 - @Test - public void testAsyncFlow3_1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); - } + // 这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue( + ListUtil + .toList("b==>j==>g==>f==>h", "b==>j==>g==>h==>f", "b==>j==>h==>g==>f", "b==>j==>h==>f==>g", + "b==>j==>f==>h==>g", "b==>j==>f==>g==>h") + .contains(response.getExecuteStepStr())); + } - //测试errorResume,默认的errorResume为false,这里设置为true - @Test - public void testAsyncFlow3_2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); - Assert.assertTrue(response.isSuccess()); - } + // 测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 - @Test - public void testAsyncFlow4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //因为不记录错误,所以最终结果是true - Assert.assertTrue(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为配置了不抛错,所以response里的cause应该为null - Assert.assertNull(response.getCause()); - } + // 测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } - //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 - @Test - public void testAsyncFlow5() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //整个并行组是报错的,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //因为第一个when配置了会报错,所以response里的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } - //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 - @Test - public void testAsyncFlow6() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第一个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(1), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } - //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 - @Test - public void testAsyncFlow7() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - //第二个when会抛错,所以最终结果是false - Assert.assertFalse(response.isSuccess()); - // 传递了slotIndex,则set的size==2 - Integer count = context.getData("count"); - Assert.assertEquals(new Integer(2), count); - //第一个when会报错,所以最终response的cause里应该会有TestException - Assert.assertEquals(TestException.class, response.getCause().getClass()); - } + // 不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(1), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + // 第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Integer count = context.getData("count"); + Assert.assertEquals(new Integer(2), count); + // 第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + // 测试任意异步一个执行完即继续的场景 + // d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + // 最终执行效果应该是h先返回,然后执行abc,最后gd + // 这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("check").toString().startsWith("habc")); + } - //测试任意异步一个执行完即继续的场景 - //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 - //最终执行效果应该是h先返回,然后执行abc,最后gd - //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 - @Test - public void testAsyncFlow8() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("check").toString().startsWith("habc")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java index 01afc585..39d38eb9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java @@ -5,21 +5,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; import org.springframework.stereotype.Component; - @Component("a") public class ACmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Acomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java index 73c27c74..58b33bdd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java @@ -5,21 +5,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; import org.springframework.stereotype.Component; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Bcomp executed!"); - } + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java index 253447f8..7e3c0f6d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java @@ -5,21 +5,23 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; import org.springframework.stereotype.Component; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java index 6203d92d..bae09af7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java @@ -5,22 +5,24 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; import org.springframework.stereotype.Component; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(1000); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + Thread.sleep(1000); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java index caff1beb..fec510e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java @@ -3,13 +3,13 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; import org.springframework.stereotype.Component; - @Component("e") public class ECmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Ecomp executed!"); - return "g"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java index eb9322c8..c6ee31ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java @@ -3,12 +3,12 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("f") public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Fcomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Fcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java index 66fd659c..3ac840f8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; import org.springframework.stereotype.Component; - @Component("g") public class GCmp extends NodeComponent { - @Override - public void process() throws Exception { - Thread.sleep(500); - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } - System.out.println("Gcomp executed!"); - } + @Override + public void process() throws Exception { + Thread.sleep(500); + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java index dd211dfa..330c0ebc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java @@ -5,23 +5,24 @@ import com.yomahub.liteflow.slot.DefaultContext; import com.yomahub.liteflow.slot.Slot; import org.springframework.stereotype.Component; - @Component("h") public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (NodeComponent.class){ - if (context.hasData("check")){ - String str = context.getData("check"); - str += this.getNodeId(); - context.setData("check", str); - }else{ - context.setData("check", this.getNodeId()); - } - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (NodeComponent.class) { + if (context.hasData("check")) { + String str = context.getData("check"); + str += this.getNodeId(); + context.setData("check", str); + } + else { + context.setData("check", this.getNodeId()); + } + } + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java index d85b775e..5d09de85 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java @@ -6,22 +6,23 @@ import com.yomahub.liteflow.slot.Slot; import com.yomahub.liteflow.test.asyncNode.exception.TestException; import org.springframework.stereotype.Component; - @Component("i") public class ICmp extends NodeComponent { - @Override - public void process() throws Exception { - DefaultContext context = this.getFirstContextBean(); - synchronized (ICmp.class){ - if (context.hasData("count")){ - Integer count = context.getData("count"); - context.setData("count", ++count); - } else{ - context.setData("count", 1); - } - } - System.out.println("Icomp executed! throw Exception!"); - throw new TestException(); - } + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + synchronized (ICmp.class) { + if (context.hasData("count")) { + Integer count = context.getData("count"); + context.setData("count", ++count); + } + else { + context.setData("count", 1); + } + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java index 66bb9cab..611af09e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java @@ -3,13 +3,13 @@ package com.yomahub.liteflow.test.asyncNode.cmp; import com.yomahub.liteflow.core.NodeSwitchComponent; import org.springframework.stereotype.Component; - @Component("j") public class JCmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - System.out.println("Jcomp executed!"); - return "chain3"; - } + @Override + public String processSwitch() throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java index e786e9f8..fa8827df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -1,4 +1,5 @@ package com.yomahub.liteflow.test.asyncNode.exception; -public class TestException extends Exception{ +public class TestException extends Exception { + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/BaseCommonELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/BaseCommonELSpringTest.java index 9cbc27b2..933d8f0e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/BaseCommonELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/BaseCommonELSpringTest.java @@ -15,13 +15,14 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/base/application.xml") public class BaseCommonELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testBaseCommon() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>d", response.getExecuteStepStr()); + } - @Test - public void testBaseCommon(){ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java index c3379221..c2361cac 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/builder/BuilderELSpringTest1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringTest1.java index 14b5def1..3beb0ef0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringTest1.java @@ -27,113 +27,124 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/builder/application1.xml") public class BuilderELSpringTest1 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") + .build(); + + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); + + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + } + + // 基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("e") + .setName("组件E") + .setType(NodeTypeEnum.SWITCH) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz(GCmp.class) + .build(); + + LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL("THEN(c, d)").build(); + + LiteFlowChainELBuilder.createChain() + .setChainName("chain1") + .setEL("THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))") + .build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); + + } - //基于普通组件的builder模式测试 - @Test - public void testBuilder() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") - .build(); - - - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); - - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); - - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - } - - //基于普通组件的builder模式测试 - @Test - public void testBuilderForClassAndCode() throws Exception { - LiteFlowNodeBuilder.createNode().setId("a") - .setName("组件A") - .setType(NodeTypeEnum.COMMON) - .setClazz(ACmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("b") - .setName("组件B") - .setType(NodeTypeEnum.COMMON) - .setClazz(BCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("c") - .setName("组件C") - .setType(NodeTypeEnum.COMMON) - .setClazz(CCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("d") - .setName("组件D") - .setType(NodeTypeEnum.COMMON) - .setClazz(DCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("e") - .setName("组件E") - .setType(NodeTypeEnum.SWITCH) - .setClazz(ECmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("f") - .setName("组件F") - .setType(NodeTypeEnum.COMMON) - .setClazz(FCmp.class) - .build(); - LiteFlowNodeBuilder.createNode().setId("g") - .setName("组件G") - .setType(NodeTypeEnum.COMMON) - .setClazz(GCmp.class) - .build(); - - - LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL( - "THEN(c, d)" - ).build(); - - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))" - ).build(); - - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr()); - - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringTest2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringTest2.java index 3594481e..b72c8cde 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/BuilderELSpringTest2.java @@ -18,18 +18,17 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/builder/application2.xml") public class BuilderELSpringTest2 extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL("THEN(h, i, j)").build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); + } - //通过spring去扫描组件,通过代码去构建chain - @Test - public void testBuilder() throws Exception { - LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL( - "THEN(h, i, j)" - ).build(); - - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("h==>i==>j", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java index ed0e7458..ccfef83e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println(getTag() + ",ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringTest.java index 5e2cc9e8..0b060ef6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetryELSpringTest.java @@ -12,48 +12,49 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试spring下的节点重试 + * * @author Bryan.Zhang * @since 2.5.10 */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/cmpRetry/application.xml") -@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.cmpRetry.cmp" }) public class LiteflowRetryELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //全局重试配置测试 - @Test - public void testRetry1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); - } + // 全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr()); + } - //单个组件重试配置测试 - @Test - public void testRetry2() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); - } + // 单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr()); + } - //单个组件指定异常,但抛出的并不是指定异常的场景测试 - @Test - public void testRetry3() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - } + // 单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + // 单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); + } - //单个组件指定异常重试,抛出的是指定异常或者 - @Test - public void testRetry4() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java index a1b1b3fb..0e217e4b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/cmpRetry/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java index 3c50ded2..a43cfc64 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -18,7 +18,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java index b9232e5a..b523adfe 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java index ba3f92d6..694d7fc8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -12,7 +12,7 @@ import com.yomahub.liteflow.annotation.LiteflowRetry; import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("e") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class ECmp extends NodeComponent { @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringTest.java index bceba7fc..5a5536e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/CmpStepELSpringTest.java @@ -20,44 +20,46 @@ import java.util.Set; @ContextConfiguration("classpath:/cmpStep/application.xml") public class CmpStepELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testStep1(){ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); - Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); - Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); - Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); - } + @Test + public void testStep1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess()); + Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess()); + Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass()); + Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass()); + } - @Test - public void testStep2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); - } + @Test + public void testStep2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime()); + } - @Test - public void testStep3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Map stepMap = response.getExecuteSteps(); - Assert.assertEquals(2, stepMap.size()); - Queue queue = response.getExecuteStepQueue(); - Assert.assertEquals(5, queue.size()); + @Test + public void testStep3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Map stepMap = response.getExecuteSteps(); + Assert.assertEquals(2, stepMap.size()); + Queue queue = response.getExecuteStepQueue(); + Assert.assertEquals(5, queue.size()); - Set tagSet = new HashSet<>(); - response.getExecuteStepQueue().stream().filter( - cmpStep -> cmpStep.getNodeId().equals("a") - ).forEach(cmpStep -> tagSet.add(cmpStep.getTag())); + Set tagSet = new HashSet<>(); + response.getExecuteStepQueue() + .stream() + .filter(cmpStep -> cmpStep.getNodeId().equals("a")) + .forEach(cmpStep -> tagSet.add(cmpStep.getTag())); - Assert.assertEquals(3, tagSet.size()); + Assert.assertEquals(3, tagSet.size()); + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java index 6c1573f4..ecd0e0c7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ACmp.java @@ -14,8 +14,9 @@ import org.springframework.stereotype.Component; public class ACmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Thread.sleep(5000L); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java index 34f7792b..2efd2517 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/CCmp.java @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; public class CCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); Thread.sleep(2000); throw new RuntimeException("test error c"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java index f78b4239..cc8b2fe0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/cmpStep/cmp/ECmp.java @@ -22,4 +22,5 @@ public class ECmp extends NodeComponent { public boolean isAccess() { return false; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java index 9cf41698..7399ff84 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/LiteflowNodeELSpringbootTest.java @@ -24,6 +24,7 @@ public class LiteflowNodeELSpringbootTest extends BaseTest { public void testAsyncFlow1() { LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(ListUtil.toList("a==>b==>c==>b","a==>b==>b==>c").contains(response.getExecuteStepStr())); + Assert.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr())); } + } \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java index aacacbbb..d0c82905 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/comments/cmp/ACmp.java @@ -11,7 +11,7 @@ import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("a") -public class ACmp extends NodeComponent{ +public class ACmp extends NodeComponent { @Override public void process() { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/ComponentELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/ComponentELSpringTest.java index d488fda2..76e6e1cf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/ComponentELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/ComponentELSpringTest.java @@ -15,73 +15,73 @@ import org.springframework.util.ReflectionUtils; import javax.annotation.Resource; /** - * 组件功能点测试 - * 单元测试 + * 组件功能点测试 单元测试 * * @author donguo.tao */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/component/application.xml") public class ComponentELSpringTest extends BaseTest { - private static final Logger LOG = LoggerFactory.getLogger(ComponentELSpringTest.class); - @Resource - private FlowExecutor flowExecutor; + private static final Logger LOG = LoggerFactory.getLogger(ComponentELSpringTest.class); - //isAccess方法的功能测试 - @Test - public void testIsAccess() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); - Assert.assertTrue(response.isSuccess()); - Assert.assertNotNull(response.getSlot().getResponseData()); - } + @Resource + private FlowExecutor flowExecutor; - //组件抛错的功能点测试 - @Test(expected = ArithmeticException.class) - public void testComponentException() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("/ by zero", response.getMessage()); - ReflectionUtils.rethrowException(response.getCause()); - } + // isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } - //isContinueOnError方法的功能点测试 - @Test - public void testIsContinueOnError() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCause()); - } + // 组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } - //isEnd方法的功能点测试 - @Test - public void testIsEnd() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("d",response.getExecuteStepStr()); - } + // isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } - //setIsEnd方法的功能点测试 - @Test - public void testSetIsEnd1() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("e",response.getExecuteStepStr()); - } + // isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d", response.getExecuteStepStr()); + } - //条件组件的功能点测试 - @Test - public void testNodeCondComponent() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); - Assert.assertTrue(response.isSuccess()); - } + // setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e", response.getExecuteStepStr()); + } - //测试setIsEnd如果为true,continueError也为true,那不应该continue了 - @Test - public void testSetIsEnd2() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g",response.getExecuteStepStr()); - } + // 条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + // 测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java index 3f125d17..1f8f3b09 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -5,22 +5,23 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("a") public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("AComp executed!"); - this.getSlot().setResponseData("AComp executed!"); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData) && requestData > 100){ - return true; - } - System.out.println("AComp isAccess false."); - return false; - } + @Override + public void process() { + System.out.println("AComp executed!"); + this.getSlot().setResponseData("AComp executed!"); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100) { + return true; + } + System.out.println("AComp isAccess false."); + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java index 6d5db7fc..98994409 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -5,25 +5,25 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - } - @Override - public boolean isAccess() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("BComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + } + + @Override + public boolean isAccess() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java index dc4620e4..450bf757 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -5,25 +5,26 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() { - System.out.println("CComp executed!"); - Integer requestData = this.getRequestData(); - Integer divisor = 130; - Integer result = divisor / requestData; - this.getSlot().setResponseData(result); - System.out.println("responseData="+Integer.parseInt(this.getSlot().getResponseData())); - } - @Override - public boolean isContinueOnError() { - Integer requestData = this.getRequestData(); - if (Objects.nonNull(requestData)){ - return true; - } - return false; - } + @Override + public void process() { + System.out.println("CComp executed!"); + Integer requestData = this.getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + this.getSlot().setResponseData(result); + System.out.println("responseData=" + Integer.parseInt(this.getSlot().getResponseData())); + } + + @Override + public boolean isContinueOnError() { + Integer requestData = this.getRequestData(); + if (Objects.nonNull(requestData)) { + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java index c28a41e3..7913217a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -5,22 +5,23 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("DComp executed!"); - } - @Override - public boolean isEnd() { - //组件的process执行完之后才会执行isEnd - Object requestData = this.getSlot().getResponseData(); - if (Objects.isNull(requestData)){ - System.out.println("DComp flow isEnd, because of responseData is null."); - return true; - } - return false; - } + @Override + public void process() throws Exception { + System.out.println("DComp executed!"); + } + + @Override + public boolean isEnd() { + // 组件的process执行完之后才会执行isEnd + Object requestData = this.getSlot().getResponseData(); + if (Objects.isNull(requestData)) { + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java index 9103080a..bbba1177 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -6,19 +6,19 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("e") public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("EComp executed!"); - Object responseData = this.getSlot().getResponseData(); - if (Objects.isNull(responseData)){ - System.out.println("EComp responseData flow must be set end ."); - //执行到某个条件时,手动结束流程。 - this.setIsEnd(true); - } - System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); - } + @Override + public void process() throws Exception { + System.out.println("EComp executed!"); + Object responseData = this.getSlot().getResponseData(); + if (Objects.isNull(responseData)) { + System.out.println("EComp responseData flow must be set end ."); + // 执行到某个条件时,手动结束流程。 + this.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JsonUtil.toJsonString(responseData)); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java index f7917cfa..1a98e6a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -23,4 +23,5 @@ public class GCmp extends NodeComponent { public boolean isContinueOnError() { return true; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java index df41a9c1..dc8063b2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -17,4 +17,5 @@ public class HCmp extends NodeComponent { public void process() { System.out.println("HCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java index 5f4951f5..7f7acad2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/component/cmp2/FSwitchCmp.java @@ -5,18 +5,21 @@ import org.springframework.stereotype.Component; import java.util.Objects; - @Component("f") public class FSwitchCmp extends NodeSwitchComponent { - @Override - public String processSwitch() { - Integer requestData = this.getRequestData(); - if (Objects.isNull(requestData)){ - return "d"; - } else if(requestData == 0){ - return "c"; - } else { - return "b"; - } - } + + @Override + public String processSwitch() { + Integer requestData = this.getRequestData(); + if (Objects.isNull(requestData)) { + return "d"; + } + else if (requestData == 0) { + return "c"; + } + else { + return "b"; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java index 7a7fe63a..e3647352 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java @@ -16,30 +16,34 @@ import javax.annotation.Resource; /** * spring环境下参数单元测试 + * * @author zendwang * @since 2.5.0 */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/config/application-local.xml") public class LiteflowConfigELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - - @Autowired - private ApplicationContext context; - - @Test - public void testConfig() throws Exception { - LiteflowConfig config = context.getBean(LiteflowConfig.class); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("config/flow.el.json", config.getRuleSource()); - Assert.assertEquals(15, config.getWhenMaxWaitSeconds().intValue()); - Assert.assertEquals(200, config.getQueueLimit().intValue()); - Assert.assertEquals(300000L, config.getDelay().longValue()); - Assert.assertEquals(300000L, config.getPeriod().longValue()); - Assert.assertFalse(config.getEnableLog()); - // Assert.assertEquals(Runtime.getRuntime().availableProcessors() * 2, config.getWhenMaxWorkers().longValue()); - Assert.assertEquals(512, config.getWhenQueueLimit().longValue()); - } + + @Resource + private FlowExecutor flowExecutor; + + @Autowired + private ApplicationContext context; + + @Test + public void testConfig() throws Exception { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("config/flow.el.json", config.getRuleSource()); + Assert.assertEquals(15, config.getWhenMaxWaitSeconds().intValue()); + Assert.assertEquals(200, config.getQueueLimit().intValue()); + Assert.assertEquals(300000L, config.getDelay().longValue()); + Assert.assertEquals(300000L, config.getPeriod().longValue()); + Assert.assertFalse(config.getEnableLog()); + // Assert.assertEquals(Runtime.getRuntime().availableProcessors() * 2, + // config.getWhenMaxWorkers().longValue()); + Assert.assertEquals(512, config.getWhenQueueLimit().longValue()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LocalRuleSourcePatternMatchELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LocalRuleSourcePatternMatchELSpringTest.java index 385c77d0..6648fa19 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LocalRuleSourcePatternMatchELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LocalRuleSourcePatternMatchELSpringTest.java @@ -13,26 +13,26 @@ import javax.annotation.Resource; /** * spring环境下 rule-source 参数支持通配符,支持模式匹配 + * * @author zendwang * @since 2.5.0 */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/config/local-rule-source-pattern-match.xml") public class LocalRuleSourcePatternMatchELSpringTest extends BaseTest { - - @Resource - private FlowExecutor executor; - - /** - * 匹配的文件 - * config/springgroup0/flow0.json - * config/springgroup1/flow0.json - */ - @Test - public void testLocalJsonRuleSourcePatternMatch() { - LiteflowResponse response0 = executor.execute2Resp("chain1", "arg"); - Assert.assertEquals("a==>b==>c", response0.getExecuteStepStr()); - LiteflowResponse response1 = executor.execute2Resp("chain3", "arg"); - Assert.assertEquals("a==>c==>f==>g", response1.getExecuteStepStr()); - } + + @Resource + private FlowExecutor executor; + + /** + * 匹配的文件 config/springgroup0/flow0.json config/springgroup1/flow0.json + */ + @Test + public void testLocalJsonRuleSourcePatternMatch() { + LiteflowResponse response0 = executor.execute2Resp("chain1", "arg"); + Assert.assertEquals("a==>b==>c", response0.getExecuteStepStr()); + LiteflowResponse response1 = executor.execute2Resp("chain3", "arg"); + Assert.assertEquals("a==>c==>f==>g", response1.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java index 89be97ac..937e1c66 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/config/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/cmp/ECmp.java index eceb073c..0382ee6c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringTest.java index 82f1e455..a599c528 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesELSpringTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * spring环境下自定义声明节点的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -22,16 +23,17 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/customNodes/application.xml") public class CustomNodesELSpringTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } - @Test - public void testCustomNodes() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java index d7cf0644..10ba24a8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -15,4 +15,5 @@ public class ACmp extends NodeComponent { 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/customNodes/domain/DemoDomain.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java index d0b10dc0..745da51d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -5,7 +5,8 @@ import org.springframework.stereotype.Component; @Component public class DemoDomain { - public void sayHi(){ - System.out.println("hi"); - } + public void sayHi() { + System.out.println("hi"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index eef8b3d3..be8a3ffc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -9,17 +9,15 @@ import java.util.concurrent.ExecutorService; public class CustomThreadExecutor1 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-1-thead-"); - } + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index a05de79e..f70d4ddd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor2 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-2-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index 71aac982..95c13e95 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -8,17 +8,16 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; public class CustomThreadExecutor3 implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); - //只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor( - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), - "customer-when-3-thead-"); - } + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java index 3b3a56e1..c32ecce8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java @@ -24,46 +24,46 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/customWhenThreadPool/application.xml") public class CustomWhenThreadPoolELSpringTest extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - /** - * 测试全局线程池配置 - */ - @Test - public void testGlobalThreadPool() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); - } + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead")); + } - /** - * 测试全局和when上自定义线程池-优先以when上为准 - */ - @Test - public void testGlobalAndCustomWhenThreadPool() { - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response1.getFirstContextBean(); - Assert.assertTrue(response1.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - } + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response2.getFirstContextBean(); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); - /** - * when配置的线程池可以共用 - */ - @Test - public void testCustomWhenThreadPool() { - // 使用when - thread1 - testGlobalAndCustomWhenThreadPool(); - // chain配置同一个thead1 - LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response2.getFirstContextBean(); - Assert.assertTrue(response2.isSuccess()); - Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead")); + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java index f47c972d..01f66e33 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/enable/LiteflowEnableELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableELSpringTest.java index 0071247e..27f9b70c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/enable/LiteflowEnableELSpringTest.java @@ -23,19 +23,21 @@ import javax.annotation.Resource; @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/enable/application-local.xml") public class LiteflowEnableELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - @Test - public void testEnable() throws Exception { - LiteflowConfig config = LiteflowConfigGetter.get(); - Boolean enable = config.getEnable(); - if (enable) { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - return; - } + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testEnable() throws Exception { + LiteflowConfig config = LiteflowConfigGetter.get(); + Boolean enable = config.getEnable(); + if (enable) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + return; + } + + Assert.assertFalse(enable); + } - Assert.assertFalse(enable); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java index 1028beae..9eff0d0e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/enable/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/event/EventELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/EventELSpringTest.java index 36bc860c..61c3c37e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/EventELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/EventELSpringTest.java @@ -16,37 +16,38 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/event/application.xml") public class EventELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试组件成功事件 - @Test - public void testEvent1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("abc", context.getData("test")); - } + // 测试组件成功事件 + @Test + public void testEvent1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("abc", context.getData("test")); + } - //测试组件失败事件 - @Test - public void testEvent2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("ab", context.getData("test")); - Assert.assertEquals("error:d", context.getData("error")); - } + // 测试组件失败事件 + @Test + public void testEvent2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("ab", context.getData("test")); + Assert.assertEquals("error:d", context.getData("error")); + } + + // 测试组件失败事件本身抛出异常 + @Test + public void testEvent3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); + Assert.assertEquals("a", context.getData("test")); + Assert.assertEquals("error:e", context.getData("error")); + } - //测试组件失败事件本身抛出异常 - @Test - public void testEvent3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(NullPointerException.class, response.getCause().getClass()); - Assert.assertEquals("a", context.getData("test")); - Assert.assertEquals("error:e", context.getData("error")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java index 11c7509b..bf7848df 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ACmp.java @@ -17,7 +17,7 @@ public class ACmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",""); + context.setData("test", ""); System.out.println("ACmp executed!"); } @@ -28,4 +28,5 @@ public class ACmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java index 7fc1b353..38f77d2d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/BCmp.java @@ -26,4 +26,5 @@ public class BCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java index f87eeed1..c56384c8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/CCmp.java @@ -26,4 +26,5 @@ public class CCmp extends NodeComponent { str += this.getNodeId(); context.setData("test", str); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java index 1865b83e..5dbbc711 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/DCmp.java @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; public class DCmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -23,6 +23,7 @@ public class DCmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java index 600f1632..fe6f51dd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/event/cmp/ECmp.java @@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; public class ECmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { System.out.println("CCmp executed!"); throw new NullPointerException(); } @@ -23,7 +23,8 @@ public class ECmp extends NodeComponent { @Override public void onError() throws Exception { DefaultContext context = this.getFirstContextBean(); - context.setData("error","error:"+this.getNodeId()); + context.setData("error", "error:" + this.getNodeId()); throw new IllegalAccessException("错误事件回调本身抛出异常"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java index 11441ab5..e7b2394c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/CustomStatefulException.java @@ -6,7 +6,9 @@ import com.yomahub.liteflow.exception.LiteFlowException; * 用户自定义带状态码的异常 */ public class CustomStatefulException extends LiteFlowException { + public CustomStatefulException(String code, String message) { super(code, message); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringTest.java index cb8e0148..1233ef6c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception1ELSpringTest.java @@ -15,45 +15,45 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/exception/application1.xml") public class Exception1ELSpringTest extends BaseTest { - - @Resource - private FlowExecutor flowExecutor; - /** - * 验证 chain 节点重复的异常 - */ - @Test(expected = ChainDuplicateException.class) - public void testChainDuplicateException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-exception.el.xml"); - flowExecutor.reloadRule(); - } + @Resource + private FlowExecutor flowExecutor; - @Test(expected = ConfigErrorException.class) - public void testConfigErrorException() { - flowExecutor.setLiteflowConfig(null); - flowExecutor.reloadRule(); - } + /** + * 验证 chain 节点重复的异常 + */ + @Test(expected = ChainDuplicateException.class) + public void testChainDuplicateException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-exception.el.xml"); + flowExecutor.reloadRule(); + } + + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.reloadRule(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("error/flow.txt"); + flowExecutor.reloadRule(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("exception/flow-blank.el.xml"); + flowExecutor.reloadRule(); + } - @Test(expected = FlowExecutorNotInitException.class) - public void testFlowExecutorNotInitException() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("error/flow.txt"); - flowExecutor.reloadRule(); - } - - @Test(expected = FlowExecutorNotInitException.class) - public void testNoConditionInChainException() throws Exception { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("exception/flow-blank.el.xml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringTest.java index 3ecc3b49..49e333f8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/Exception2ELSpringTest.java @@ -15,57 +15,57 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 流程执行异常 - * 单元测试 + * 流程执行异常 单元测试 * * @author zendwang */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/exception/application2.xml") public class Exception2ELSpringTest extends BaseTest { - - @Resource - private FlowExecutor flowExecutor; - @Test(expected = ChainNotFoundException.class) - public void testChainNotFoundException() throws Exception { - flowExecutor.execute("chain0", "it's a request"); - } + @Resource + private FlowExecutor flowExecutor; - @Test(expected = RuntimeException.class) - public void testComponentCustomException() throws Exception { - flowExecutor.execute("chain1", "exception"); - } - - @Test - public void testGetSlotFromResponseWhenException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); - Assert.assertFalse(response.isSuccess()); - Assert.assertNotNull(response.getCause()); - Assert.assertNotNull(response.getSlot()); - } + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } - @Test(expected = NoSwitchTargetNodeException.class) - public void testNoTargetFindException() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); - Assert.assertFalse(response.isSuccess()); - throw response.getCause(); - } + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } - @Test - public void testInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("300", response.getCode()); - Assert.assertNotNull(response.getCause()); - Assert.assertTrue(response.getCause() instanceof LiteFlowException); - Assert.assertNotNull(response.getSlot()); - } + @Test + public void testGetSlotFromResponseWhenException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } + + @Test(expected = NoSwitchTargetNodeException.class) + public void testNoTargetFindException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test"); + Assert.assertFalse(response.isSuccess()); + throw response.getCause(); + } + + @Test + public void testInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("300", response.getCode()); + Assert.assertNotNull(response.getCause()); + Assert.assertTrue(response.getCause() instanceof LiteFlowException); + Assert.assertNotNull(response.getSlot()); + } + + @Test + public void testNotInvokeCustomStatefulException() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCode()); + } - @Test - public void testNotInvokeCustomStatefulException() { - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test"); - Assert.assertTrue(response.isSuccess()); - Assert.assertNull(response.getCode()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java index d637fab7..e06bdadd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -15,13 +15,13 @@ import org.springframework.stereotype.Component; @Component("a") public class ACmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new RuntimeException("chain execute execption"); } LOG.info("Acomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java index 0f7411c9..00d6f95b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -15,21 +15,23 @@ import org.springframework.stereotype.Component; @Component("b") public class BCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); @Override public void process() throws InterruptedException { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("when")) { + if (StrUtil.isNotBlank(str) && str.equals("when")) { try { LOG.info("Bcomp sleep begin"); Thread.sleep(3000); LOG.info("Bcomp sleep end"); - } catch (InterruptedException e) { + } + catch (InterruptedException e) { throw e; } } LOG.info("Bcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java index ab1759ad..eb8115e0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -14,11 +14,12 @@ import org.springframework.stereotype.Component; @Component("c") public class CCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); - + @Override public void process() { LOG.info("Ccomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java index 3aebcc42..4aac8e47 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -14,14 +14,15 @@ import org.springframework.stereotype.Component; @Component("d") public class DCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); - + @Override public void process() { - if(1==1){ - int a = 1/0; + if (1 == 1) { + int a = 1 / 0; } LOG.info("Dcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java index 5911c2e3..17e760a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "a"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java index c0b3917a..ee9a086f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/FCmp.java @@ -16,13 +16,13 @@ import org.springframework.stereotype.Component; @Component("f") public class FCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(FCmp.class); - + @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { + if (StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) { throw new CustomStatefulException("300", "chain execute custom stateful execption"); } LOG.info("Fcomp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java index 0c1120aa..f8bab6c0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/exception/cmp/GCmp.java @@ -14,11 +14,12 @@ import org.springframework.stereotype.Component; @Component("g") public class GCmp extends NodeComponent { - + private static final Logger LOG = LoggerFactory.getLogger(GCmp.class); - + @Override public void process() { LOG.info("Gcomp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringTest.java index d313ef00..dea605f2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureELSpringTest.java @@ -15,6 +15,7 @@ import java.util.concurrent.Future; /** * spring环境执行返回future的例子 + * * @author Bryan.Zhang * @since 2.6.13 */ @@ -22,14 +23,14 @@ import java.util.concurrent.Future; @ContextConfiguration("classpath:/execute2Future/application.xml") public class Executor2FutureELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testFuture() throws Exception{ - Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); - LiteflowResponse response = future.get(); - Assert.assertTrue(response.isSuccess()); - } + @Test + public void testFuture() throws Exception { + Future future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java index 05dabbd3..0461c2ca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/flowmeta/FlowMetaELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaELSpringTest.java index 610cb7b5..69791808 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaELSpringTest.java @@ -19,15 +19,16 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/flowmeta/application.xml") public class FlowMetaELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试动态添加元信息节点 + @Test + public void testFlowMeta() { + FlowBus.addNode("d", "d组件", NodeTypeEnum.COMMON, DCmp.class); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>d[d组件]", response.getExecuteStepStr()); + } - //测试动态添加元信息节点 - @Test - public void testFlowMeta() { - FlowBus.addNode("d", "d组件", NodeTypeEnum.COMMON, DCmp.class); - LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>d[d组件]", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java index 4df6c78f..1ffb94eb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/getChainName/GetChainNameELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringTest.java index 74fea4fd..f2d18d14 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/GetChainNameELSpringTest.java @@ -14,41 +14,42 @@ import javax.annotation.Resource; /** * spring环境获取ChainName的测试 + * * @author Bryan.Zhang */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/getChainName/application.xml") public class GetChainNameELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testGetChainName1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - } + @Test + public void testGetChainName1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + } - @Test - public void testGetChainName2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("chain2", context.getData("g")); - Assert.assertEquals("sub1", context.getData("a")); - Assert.assertEquals("sub2", context.getData("b")); - Assert.assertEquals("sub3", context.getData("c")); - Assert.assertEquals("sub4", context.getData("d")); - Assert.assertEquals("sub5", context.getData("f")); - Assert.assertEquals("sub5_chain2", context.getData("e")); - Assert.assertEquals("sub6", context.getData("h")); - Assert.assertEquals("sub6", context.getData("j")); - Assert.assertNull(context.getData("k")); - } + @Test + public void testGetChainName2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("chain2", context.getData("g")); + Assert.assertEquals("sub1", context.getData("a")); + Assert.assertEquals("sub2", context.getData("b")); + Assert.assertEquals("sub3", context.getData("c")); + Assert.assertEquals("sub4", context.getData("d")); + Assert.assertEquals("sub5", context.getData("f")); + Assert.assertEquals("sub5_chain2", context.getData("e")); + Assert.assertEquals("sub6", context.getData("h")); + Assert.assertEquals("sub6", context.getData("j")); + Assert.assertNull(context.getData("k")); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java index 702c0156..3b6aa10f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { DefaultContext context = this.getFirstContextBean(); context.setData(this.getNodeId(), this.getCurrChainId()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java index 7eaa14eb..076d6b84 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/getChainName/cmp/ECmp.java @@ -17,9 +17,10 @@ public class ECmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - if (context.hasData(this.getNodeId())){ + if (context.hasData(this.getNodeId())) { context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainId()); - }else{ + } + else { context.setData(this.getNodeId(), this.getCurrChainId()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELSpringTest.java index 4b64b0cb..0e643e62 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/ifelse/IfElseELSpringTest.java @@ -15,62 +15,63 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/ifelse/application.xml") public class IfElseELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //IF只有2个参数 - @Test - public void testIf1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); - } + // IF只有2个参数 + @Test + public void testIf1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime()); + } - //IF只有3个参数 - @Test - public void testIf2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF只有3个参数 + @Test + public void testIf2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有3个参数,进行嵌套 - @Test - public void testIf3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有3个参数,进行嵌套 + @Test + public void testIf3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,加上ELSE - @Test - public void testIf4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,加上ELSE + @Test + public void testIf4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime()); + } - //IF有2个参数,ELSE里再嵌套一个IF - @Test - public void testIf5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); - } + // IF有2个参数,ELSE里再嵌套一个IF + @Test + public void testIf5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime()); + } - //标准的IF ELIF ELSE - @Test - public void testIf6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); - } + // 标准的IF ELIF ELSE + @Test + public void testIf6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + // IF ELIF... ELSE 的形式 + @Test + public void testIf7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); + } - //IF ELIF... ELSE 的形式 - @Test - public void testIf7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-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 5508800f..ad0f8158 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 @@ -12,8 +12,10 @@ import org.springframework.stereotype.Component; @Component("x1") public class X1Cmp extends NodeIfComponent { + @Override public boolean processIf() 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/IteratorELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELSpringTest.java index 207a4898..2847e83b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/IteratorELSpringTest.java @@ -18,28 +18,29 @@ import java.util.List; @ContextConfiguration("classpath:/iterator/application.xml") public class IteratorELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //最简单的情况 - @Test - public void testIt1() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("123", str); - } + // 最简单的情况 + @Test + public void testIt1() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("123", str); + } + + // 迭代器带break + @Test + public void testIt2() throws Exception { + List list = ListUtil.toList("1", "2", "3"); + LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); + Assert.assertTrue(response.isSuccess()); + DefaultContext context = response.getFirstContextBean(); + String str = context.getData("test"); + Assert.assertEquals("12", str); + } - //迭代器带break - @Test - public void testIt2() throws Exception{ - List list = ListUtil.toList("1","2","3"); - LiteflowResponse response = flowExecutor.execute2Resp("chain2", list); - Assert.assertTrue(response.isSuccess()); - DefaultContext context = response.getFirstContextBean(); - String str = context.getData("test"); - Assert.assertEquals("12", str); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java index 665236a0..e385239b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ACmp.java @@ -18,12 +18,14 @@ public class ACmp extends NodeComponent { public void process() { String key = "test"; DefaultContext context = this.getFirstContextBean(); - if (!context.hasData(key)){ + if (!context.hasData(key)) { context.setData(key, this.getCurrLoopObj()); - }else{ + } + else { String str = context.getData(key); str += this.getCurrLoopObj(); context.setData(key, str); } } + } 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 cc7d0e74..e6dcd45a 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 @@ -11,4 +11,5 @@ public class BCmp extends NodeBreakComponent { public boolean processBreak() throws Exception { return this.getLoopIndex() == 1; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java index cc36766d..33823698 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/iterator/cmp/ITCmp.java @@ -8,9 +8,11 @@ import java.util.List; @Component("it") public class ITCmp extends NodeIteratorComponent { - @Override - public Iterator processIterator() throws Exception { - List list = this.getRequestData(); - return list.iterator(); - } + + @Override + public Iterator processIterator() throws Exception { + List list = this.getRequestData(); + return list.iterator(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringTest.java index a794cc0d..d2df5be6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/LiteflowComponentELSpringTest.java @@ -11,9 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试@LiteflowComponent标注 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -21,13 +21,14 @@ import org.springframework.test.context.junit4.SpringRunner; @ContextConfiguration("classpath:/lfCmpAnno/application.xml") public class LiteflowComponentELSpringTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); + } - @Test - public void testConfig() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java index 6c4fc23a..9d3a992e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/lfCmpAnno/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/loop/LoopELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringTest.java index 822fa5de..3c9b7d24 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/LoopELSpringTest.java @@ -16,67 +16,70 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/loop/application.xml") public class LoopELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //FOR循环数字直接在el中定义 - @Test - public void testLoop1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FOR循环数字直接在el中定义 + @Test + public void testLoop1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("LOOP_2==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FPR循环由For组件定义 - @Test - public void testLoop2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); - } + // FPR循环由For组件定义 + @Test + public void testLoop2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("x==>a==>b==>c==>a==>b==>c==>a==>b==>c", response.getExecuteStepStr()); + } - //FOR循环中加入BREAK组件 - @Test - public void testLoop3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // FOR循环中加入BREAK组件 + @Test + public void testLoop3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //WHILE循环 - @Test - public void testLoop4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", response.getExecuteStepStr()); - } + // WHILE循环 + @Test + public void testLoop4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z", + response.getExecuteStepStr()); + } - //WHILE循环加入BREAK - @Test - public void testLoop5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr()); - } + // WHILE循环加入BREAK + @Test + public void testLoop5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", + response.getExecuteStepStr()); + } - //测试FOR循环中的index - @Test - public void testLoop6() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } + // 测试FOR循环中的index + @Test + public void testLoop6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } + + // 测试WHILE循环中的index + @Test + public void testLoop7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("01234", context.getData("loop_e1")); + Assert.assertEquals("01234", context.getData("loop_e2")); + Assert.assertEquals("01234", context.getData("loop_e3")); + } - //测试WHILE循环中的index - @Test - public void testLoop7() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("01234", context.getData("loop_e1")); - Assert.assertEquals("01234", context.getData("loop_e2")); - Assert.assertEquals("01234", context.getData("loop_e3")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java index fa96a2ae..ae074092 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/loop/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java index 83be92a4..de42f865 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/DCmp.java @@ -18,10 +18,11 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = "test"; - if (context.hasData(key)){ + if (context.hasData(key)) { int count = context.getData(key); context.setData(key, ++count); - }else{ + } + else { context.setData(key, 1); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java index cf88acc5..0fafa8d0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/ECmp.java @@ -19,11 +19,12 @@ public class ECmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String key = StrUtil.format("{}_{}", "loop", this.getTag()); - if (context.hasData(key)){ + if (context.hasData(key)) { String loopStr = context.getData(key); String loopStrReturn = StrUtil.format("{}{}", loopStr, this.getLoopIndex()); context.setData(key, loopStrReturn); - }else{ + } + else { context.setData(key, this.getLoopIndex().toString()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java index fa9fe7e5..5ca52556 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/loop/cmp/XCmp.java @@ -5,8 +5,10 @@ import com.yomahub.liteflow.core.NodeForComponent; @LiteflowComponent("x") public class XCmp extends NodeForComponent { - @Override - public int processFor() throws Exception { - return 3; - } + + @Override + public int processFor() throws Exception { + return 3; + } + } 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 12673962..6a820a63 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 @@ -6,10 +6,12 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("y") public class YCmp extends NodeBreakComponent { - @Override - public boolean processBreak() throws Exception { - DefaultContext context = this.getFirstContextBean(); - int count = context.getData("test"); - return count > 3; - } + + @Override + public boolean processBreak() 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 fe157fb0..78c621f2 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 @@ -6,15 +6,18 @@ import com.yomahub.liteflow.slot.DefaultContext; @LiteflowComponent("z") public class ZCmp extends NodeWhileComponent { - @Override - public boolean processWhile() throws Exception { - DefaultContext context = this.getFirstContextBean(); - String key = "test"; - if (context.hasData(key)){ - int count = context.getData("test"); - return count < 5; - }else{ - return true; - } - } + + @Override + public boolean processWhile() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } + else { + return true; + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringTest.java index af206f96..422b01f1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/MonitorELSpringTest.java @@ -17,6 +17,7 @@ import javax.annotation.Resource; /** * spring环境下监控的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -24,21 +25,21 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/monitor/application.xml") public class MonitorELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testMonitor() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); + @Test + public void testMonitor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); - Thread.sleep(10000); - } + Thread.sleep(10000); + } - @AfterClass - public static void clean(){ - MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); - monitorBus.closeScheduler(); - } + @AfterClass + public static void clean() { + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java index d5f2438a..4156b95f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java @@ -19,10 +19,12 @@ public class ACmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java index a5a3f44e..8696a42c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java @@ -19,7 +19,8 @@ public class BCmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java index 6a44bb60..1ae56138 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java @@ -19,7 +19,8 @@ public class CCmp extends NodeComponent { public void process() { try { Thread.sleep(new Random().nextInt(2000)); - }catch (Exception e){ + } + catch (Exception e) { e.printStackTrace(); } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringTest.java index 8b727864..53ca0d5b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeELSpringTest.java @@ -11,9 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; - /** * 测试spring下混合格式规则的场景 + * * @author Bryan.Zhang * @since 2.5.10 */ @@ -21,16 +21,17 @@ import org.springframework.test.context.junit4.SpringRunner; @ContextConfiguration("classpath:/multipleType/application.xml") public class LiteflowMultipleTypeELSpringTest extends BaseTest { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } - @Test - public void testMultipleType() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr()); - response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java index 343dd85e..a4e4f960 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java index 0ced9da9..5572a472 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -10,11 +10,13 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; * 自定义默认的节点执行器 */ public class CustomerDefaultNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerDefaultNodeExecutor进行执行"); - context.setData("customerDefaultNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + context.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java index 5a9f2e58..16f32a7c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -10,12 +10,13 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; * 自定义节点执行器 */ public class CustomerNodeExecutor extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutor进行执行"); - context.setData("customerNodeExecutor", this.getClass()); - super.execute(instance); - } + + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutor进行执行"); + context.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java index 003d3331..81c6604f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -12,19 +12,21 @@ import java.util.concurrent.TimeUnit; * 自定义节点执行器 */ public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { - @Override - public void execute(NodeComponent instance) throws Exception { - DefaultContext context = instance.getFirstContextBean(); - LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); - context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); - super.execute(instance); - } - @Override - protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { - TimeUnit.MICROSECONDS.sleep(20L); - DefaultContext context = instance.getFirstContextBean(); - context.setData("retryLogic", this.getClass()); - super.retry(instance, currentRetryCount); - } + @Override + public void execute(NodeComponent instance) throws Exception { + DefaultContext context = instance.getFirstContextBean(); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + context.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + DefaultContext context = instance.getFirstContextBean(); + context.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringTest.java index e7313a11..5600f168 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorELSpringTest.java @@ -12,7 +12,6 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; - /** * 测试spring下的组件重试 * @@ -23,44 +22,45 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/nodeExecutor/application.xml") public class LiteflowNodeExecutorELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - // 默认执行器测试 - @Test - public void testCustomerDefaultNodeExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("a", response.getExecuteStepStr()); - } + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getExecuteStepStr()); + } - //默认执行器测试+全局重试配置测试 - @Test - public void testDefaultExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); - Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); - } + // 默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getExecuteStepStr()); + } - //自定义执行器测试 - @Test - public void testCustomerExecutor() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("c", response.getExecuteStepStr()); - } + // 自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getExecuteStepStr()); + } + + // 自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); + } - //自定义执行器测试+全局重试配置测试 - @Test - public void testCustomExecutorForRetry() { - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic")); - Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java index 8fd765bb..5eec1192 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java @@ -14,9 +14,9 @@ import com.yomahub.liteflow.core.NodeComponent; @LiteflowComponent("a") public class ACmp extends NodeComponent { - @Override - public void process() { - System.out.println("ACmp executed!"); - } + @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/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java index 6e737879..de68032f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -18,7 +18,7 @@ public class BCmp extends NodeComponent { @Override public void process() { System.out.println("BCmp executed!"); - if (flag < 2){ + if (flag < 2) { flag++; throw new RuntimeException("demo exception"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java index f800c08b..77c9ca4c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -23,7 +23,8 @@ public class CCmp extends NodeComponent { } @Override - public Class getNodeExecutorClass() { + public Class getNodeExecutorClass() { return CustomerNodeExecutor.class; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java index bc99b47a..210c1c05 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -15,17 +15,18 @@ import com.yomahub.liteflow.flow.executor.NodeExecutor; import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; @LiteflowComponent("d") -@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowRetry(retry = 5, forExceptions = { NullPointerException.class }) public class DCmp extends NodeComponent { - @Override - public void process() { - System.out.println("DCmp executed!"); - throw new NullPointerException("demo exception"); - } + @Override + public void process() { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @Override + public Class getNodeExecutorClass() { + return CustomerNodeExecutorAndCustomRetry.class; + } - @Override - public Class getNodeExecutorClass() { - return CustomerNodeExecutorAndCustomRetry.class; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java index 05a6b352..45a862a9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/NullParamTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * 单元测试:传递null param导致NPE的优化代码 + * * @author LeoLee * @since 2.6.6 **/ @@ -21,15 +22,16 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/nullParam/application-local.xml") public class NullParamTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + /** + * 支持无参的flow执行,以及param 为null时的异常抛出 + */ + @Test + public void testNullParam() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + } - /** - * 支持无参的flow执行,以及param 为null时的异常抛出 - */ - @Test - public void testNullParam() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java index e518efd8..c3cae20c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/nullParam/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { System.out.println("get request data:" + this.getRequestData()); this.getSlot().setInput("BCmp", "param for BCmp"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java index f42f9af2..3796e041 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java @@ -4,14 +4,17 @@ import com.yomahub.liteflow.parser.el.ClassJsonFlowELParser; /** * 模拟用户自定义源解析 + * * @author dongguo.tao * @date 2021/4/7 */ public class CustomJsonFlowParser extends ClassJsonFlowELParser { - @Override - public String parseCustom() { - //模拟自定义解析结果 - String content = "{\"flow\":{\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c,g,f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a,c,WHEN(b,d,SWITCH(e).to(f,g)), chain2)\"}]}}"; - return content; - } + + @Override + public String parseCustom() { + // 模拟自定义解析结果 + String content = "{\"flow\":{\"chain\":[{\"name\":\"chain2\",\"value\":\"THEN(c,g,f)\"},{\"name\":\"chain1\",\"value\":\"THEN(a,c,WHEN(b,d,SWITCH(e).to(f,g)), chain2)\"}]}}"; + return content; + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringTest.java index c2d0fac5..62021667 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonELSpringTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * spring环境的自定义json parser单元测试 + * * @author dongguo.tao * @since 2.5.0 */ @@ -21,13 +22,14 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/parsecustom/application.xml") public class CustomParserJsonELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试spring场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的自定义json parser - @Test - public void testJsonCustomParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java index 071d4385..592d25ea 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -18,9 +18,10 @@ public class ACmp extends NodeComponent { @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new FlowSystemException("chain execute execption"); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java index 44d672a9..e6fda9eb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonELSpringTest.java index 49b0cc47..d5ad93d2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonELSpringTest.java @@ -13,6 +13,7 @@ import javax.annotation.Resource; /** * spring环境的json parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -20,13 +21,14 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/parser/application-json.xml") public class LFParserJsonELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试spring场景的xml parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的xml parser - @Test - public void testJsonParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java index e1ea7b8c..ae6c61a3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserJsonNoSpringTest.java @@ -9,18 +9,20 @@ import org.junit.Test; /** * 无spring环境的json parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class LFParserJsonNoSpringTest extends BaseTest { - //测试无spring场景的json parser - @Test - public void testNoSpring() { - LiteflowConfig liteflowConfig = new LiteflowConfig(); - liteflowConfig.setRuleSource("parser/flow.el.json"); - FlowExecutor executor = new FlowExecutor(liteflowConfig); - LiteflowResponse response = executor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试无spring场景的json parser + @Test + public void testNoSpring() { + LiteflowConfig liteflowConfig = new LiteflowConfig(); + liteflowConfig.setRuleSource("parser/flow.el.json"); + FlowExecutor executor = new FlowExecutor(liteflowConfig); + LiteflowResponse response = executor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlELSpringTest.java index 0b8a5df0..d6c1caeb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlELSpringTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * spring环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -21,13 +22,14 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/parser/application-xml.xml") public class LFParserXmlELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试spring场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的xml parser - @Test - public void testXmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java index cfcdf884..9d09592a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserXmlNoSpringTest.java @@ -9,18 +9,20 @@ import org.junit.Test; /** * 无spring环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class LFParserXmlNoSpringTest extends BaseTest { - //测试无spring场景的xml parser - @Test - public void testNoSpring() { - LiteflowConfig liteflowConfig = new LiteflowConfig(); - liteflowConfig.setRuleSource("parser/flow.el.xml"); - FlowExecutor executor = new FlowExecutor(liteflowConfig); - LiteflowResponse response = executor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试无spring场景的xml parser + @Test + public void testNoSpring() { + LiteflowConfig liteflowConfig = new LiteflowConfig(); + liteflowConfig.setRuleSource("parser/flow.el.xml"); + FlowExecutor executor = new FlowExecutor(liteflowConfig); + LiteflowResponse response = executor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlELSpringTest.java index f2324882..15743488 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlELSpringTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * spring环境的xml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -21,13 +22,14 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/parser/application-yml.xml") public class LFParserYmlELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 测试spring场景的xml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试spring场景的xml parser - @Test - public void testYmlParser() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java index e415f04d..bcd53970 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/LFParserYmlNoSpringTest.java @@ -9,18 +9,20 @@ import org.junit.Test; /** * 无spring环境的yml parser单元测试 + * * @author Bryan.Zhang * @since 2.5.0 */ public class LFParserYmlNoSpringTest extends BaseTest { - //测试无spring场景的yml parser - @Test - public void testNoSpring() { - LiteflowConfig liteflowConfig = new LiteflowConfig(); - liteflowConfig.setRuleSource("parser/flow.el.yml"); - FlowExecutor executor = new FlowExecutor(liteflowConfig); - LiteflowResponse response = executor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试无spring场景的yml parser + @Test + public void testNoSpring() { + LiteflowConfig liteflowConfig = new LiteflowConfig(); + liteflowConfig.setRuleSource("parser/flow.el.yml"); + FlowExecutor executor = new FlowExecutor(liteflowConfig); + LiteflowResponse response = executor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java index 61056f6b..30159322 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java @@ -18,9 +18,10 @@ public class ACmp extends NodeComponent { @Override public void process() { String str = this.getRequestData(); - if(StrUtil.isNotBlank(str) && str.equals("exception")) { + if (StrUtil.isNotBlank(str) && str.equals("exception")) { throw new FlowSystemException("chain execute execption"); } System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java index e86aca5d..637ff4c6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -17,4 +17,5 @@ public class ECmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "g"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringTest.java index f9f421cb..c56453ff 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallyELSpringTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * spring环境下pre节点和finally节点的测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -21,47 +22,48 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/preAndFinally/application.xml") public class PreAndFinallyELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通的pre和finally节点 - @Test - public void testPreAndFinally1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试pre和finally节点不放在开头和结尾的情况 - @Test - public void testPreAndFinally2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getExecuteStepStr()); - } + // 测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2", response.getExecuteStepStr()); + } - //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 - @Test - public void testPreAndFinally3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); - } + // 测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr()); + } - //测试在finally节点里是否能获取exception - @Test - public void testPreAndFinally4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertFalse(response.isSuccess()); - Assert.assertTrue(context.getData("hasEx")); - } + // 测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(context.getData("hasEx")); + } + + // 测试嵌套结构pre和finally是否在各自的chain里打出 + @Test + public void testPreAndFinally5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); + } - //测试嵌套结构pre和finally是否在各自的chain里打出 - @Test - public void testPreAndFinally5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java index 1dcd7520..55c638b9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/preAndFinally/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java index 3f1216a7..ef7de236 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -16,7 +16,7 @@ public class DCmp extends NodeComponent { @Override public void process() { System.out.println("CCmp executed!"); - int i = 1/0; + int i = 1 / 0; } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java index f826fb5e..ef22ba52 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -17,4 +17,5 @@ public class Finally1Cmp extends NodeComponent { public void process() { System.out.println("Finally1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java index 92157678..664e295b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -17,4 +17,5 @@ public class Finally2Cmp extends NodeComponent { public void process() { System.out.println("Finally2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java index 22c4d1d2..0e3c8e9e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -17,14 +17,16 @@ import org.springframework.stereotype.Component; public class Finally3Cmp extends NodeComponent { @Override - public void process() throws Exception{ + public void process() throws Exception { Slot slot = this.getSlot(); DefaultContext context = slot.getFirstContextBean(); - if (ObjectUtil.isNull(slot.getException())){ + if (ObjectUtil.isNull(slot.getException())) { context.setData("hasEx", false); - }else{ + } + else { context.setData("hasEx", true); } System.out.println("Finally3Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java index 741e15d4..010a783d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -17,4 +17,5 @@ public class Pre1Cmp extends NodeComponent { public void process() { System.out.println("Pre1Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java index 43cd71f1..1019fa4e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -17,4 +17,5 @@ public class Pre2Cmp extends NodeComponent { public void process() { System.out.println("Pre2Cmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringTest.java index 4292fe36..934f9656 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliveryELSpringTest.java @@ -16,6 +16,7 @@ import java.util.Set; /** * spring环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -23,15 +24,16 @@ import java.util.Set; @ContextConfiguration("classpath:/privateDelivery/application.xml") public class PrivateDeliveryELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + ConcurrentHashSet set = context.getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } - @Test - public void testPrivateDelivery() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - ConcurrentHashSet set = context.getData("testSet"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals(100, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java index 25390104..57aaeeed 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -25,8 +25,8 @@ public class ACmp extends NodeComponent { context.setData("testSet", new ConcurrentHashSet<>()); for (int i = 0; i < 100; i++) { - this.sendPrivateDeliveryData("b",i+1); + this.sendPrivateDeliveryData("b", i + 1); } } -} +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java index 2bd78c29..c1d1810f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -17,13 +17,13 @@ import java.util.Set; @LiteflowComponent("b") public class BCmp extends NodeComponent { - @Override - public void process() { - System.out.println("BCmp executed!"); - DefaultContext context = this.getFirstContextBean(); - Integer value = this.getPrivateDeliveryData(); - ConcurrentHashSet testSet = context.getData("testSet"); - testSet.add(value); - } -} + @Override + public void process() { + System.out.println("BCmp executed!"); + DefaultContext context = this.getFirstContextBean(); + Integer value = this.getPrivateDeliveryData(); + ConcurrentHashSet testSet = context.getData("testSet"); + testSet.add(value); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringTest.java index 1c03bcfa..9c5df35f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleELSpringTest.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * spring环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,41 +24,44 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/refreshRule/application.xml") public class RefreshRuleELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - //测试普通刷新流程的场景 - @Test - public void testRefresh1() throws Exception{ - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } + // 测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception { + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //测试优雅刷新的场景 - @Test - public void testRefresh2() throws Exception{ - new Thread(() -> { - try { - Thread.sleep(3000L); - String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); - FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); - } catch (Exception e) { - e.printStackTrace(); - } + // 测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception { + new Thread(() -> { + try { + Thread.sleep(3000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.el.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_EL_XML, content); + } + catch (Exception e) { + e.printStackTrace(); + } - }).start(); + }).start(); - for (int i = 0; i < 500; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - try { - Thread.sleep(10L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java index 96d599a5..0dffc413 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/reload/ReloadELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringTest.java index 1cf07e8d..678b83ea 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/reload/ReloadELSpringTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * spring环境下重新加载规则测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -21,15 +22,16 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/reload/application.xml") public class ReloadELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + // 这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception { + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml - //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 - @Test - public void testReload() throws Exception{ - flowExecutor.reloadRule(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java index fcf6fed4..734956e8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/removeChain/RemoveChainELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringTest.java index ce08c915..a655fa91 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/RemoveChainELSpringTest.java @@ -17,15 +17,16 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/removeChain/application.xml") public class RemoveChainELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testRemoveChain() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + FlowBus.removeChain("chain1"); + LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response2.isSuccess()); + } - @Test - public void testRemoveChain(){ - LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response1.isSuccess()); - FlowBus.removeChain("chain1"); - LiteflowResponse response2 = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response2.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java index 8640323d..a7d928c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/removeChain/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/requestId/LiteflowRequestIdELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringTest.java index 1957fd5a..3971e34e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/LiteflowRequestIdELSpringTest.java @@ -18,14 +18,14 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/requestId/application.xml") public class LiteflowRequestIdELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testRequestId() throws Exception { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("1", response.getSlot().getRequestId()); - } + @Test + public void testRequestId() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("1", response.getSlot().getRequestId()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java index e2369dbd..68916fab 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/ACmp.java @@ -16,8 +16,9 @@ import org.springframework.stereotype.Component; @Component("a") public class ACmp { - @LiteflowMethod(LiteFlowMethodEnum.PROCESS) - public void process(NodeComponent bindCmp) { - System.out.println("ACmp executed!"); - } + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java index 5e441aac..19e71b88 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/cmp/BCmp.java @@ -13,7 +13,7 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum; import org.springframework.stereotype.Component; @Component("b") -public class BCmp{ +public class BCmp { @LiteflowMethod(LiteFlowMethodEnum.PROCESS) public void process(NodeComponent bindCmp) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java index fcaa9e84..e705db34 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/requestId/config/CustomRequestIdGenerator.java @@ -9,10 +9,11 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class CustomRequestIdGenerator implements RequestIdGenerator { - private final AtomicInteger atomicInteger = new AtomicInteger(0); + private final AtomicInteger atomicInteger = new AtomicInteger(0); + + @Override + public String generate() { + return atomicInteger.incrementAndGet() + ""; + } - @Override - public String generate() { - return atomicInteger.incrementAndGet() + ""; - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotELSpringTest.java index cdc3f26b..42b5eee4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotELSpringTest.java @@ -22,6 +22,7 @@ import java.util.concurrent.Future; /** * springboot环境下slot扩容测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -29,30 +30,31 @@ import java.util.concurrent.Future; @ContextConfiguration("classpath:/resizeSlot/application.xml") public class ResizeSlotELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testResize() throws Exception{ - ExecutorService pool = Executors.newCachedThreadPool(); + @Test + public void testResize() throws Exception { + ExecutorService pool = Executors.newCachedThreadPool(); - List> futureList = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - Future future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); - futureList.add(future); - } + List> futureList = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + Future future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); + futureList.add(future); + } - for(Future future : futureList){ - Assert.assertTrue(future.get().isSuccess()); - } + for (Future future : futureList) { + Assert.assertTrue(future.get().isSuccess()); + } - //取到static的对象QUEUE - Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); - ConcurrentLinkedQueue queue = (ConcurrentLinkedQueue) ReflectUtil.getStaticFieldValue(field); + // 取到static的对象QUEUE + Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); + ConcurrentLinkedQueue queue = (ConcurrentLinkedQueue) ReflectUtil.getStaticFieldValue(field); + + // 因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114 + // 为什么不是直接114呢? + // 因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的 + Assert.assertTrue(queue.size() > 4); + } - //因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114 - //为什么不是直接114呢? - //因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的 - Assert.assertTrue(queue.size() > 4); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java index 4f466e1c..074eb297 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/subflow/ImplicitSubFlowELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringTest.java index f56d2667..dc1b2c60 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowELSpringTest.java @@ -15,45 +15,46 @@ import java.util.HashSet; import java.util.Set; /** - * 测试隐式调用子流程 - * 单元测试 + * 测试隐式调用子流程 单元测试 * * @author justin.xu */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/subflow/application-implicit.xml") public class ImplicitSubFlowELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - public static final Set RUN_TIME_SLOT = new HashSet<>(); + @Resource + private FlowExecutor flowExecutor; - //这里GCmp中隐式的调用chain4,从而执行了h,m - @Test - public void testImplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); + public static final Set RUN_TIME_SLOT = new HashSet<>(); - // 传递了slotIndex,则set的size==1 - Assert.assertEquals(1, RUN_TIME_SLOT.size()); - // set中第一次设置的requestId和response中的requestId一致 - Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); - //requestData的取值正确 - Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); - } + // 这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getExecuteStepStr()); - //在p里多线程调用q 10次,每个q取到的参数都是不同的。 - @Test - public void testImplicitSubFlow2() { - LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + // requestData的取值正确 + Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest")); + } - Set set = context.getData("test"); + // 在p里多线程调用q 10次,每个q取到的参数都是不同的。 + @Test + public void testImplicitSubFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + + Set set = context.getData("test"); + + // requestData的取值正确 + Assert.assertEquals(10, set.size()); + } - //requestData的取值正确 - Assert.assertEquals(10, set.size()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringTest.java index 57264d54..30e35bb3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigELSpringTest.java @@ -22,22 +22,24 @@ import javax.annotation.Resource; @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/subflow/application-subInDifferentConfig1.xml") public class SubflowInDifferentConfigELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr()); + } + + // 主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = LiteflowConfigGetter.get(); + config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.yml"); + flowExecutor.reloadRule(); + } - //主要测试有不同的配置类型后会不会报出既定的错误 - @Test(expected = MultipleParsersException.class) - public void testExplicitSubFlow2() { - LiteflowConfig config = LiteflowConfigGetter.get(); - config.setRuleSource("subflow/flow-main.el.xml,subflow/flow-sub1.el.xml,subflow/flow-sub2.el.yml"); - flowExecutor.reloadRule(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringTest.java index 6ca1388c..46374d30 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonELSpringTest.java @@ -13,22 +13,23 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(json) - * 单元测试 + * 测试显示调用子流程(json) 单元测试 * * @author justin.xu */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/subflow/application-json.xml") public class SubflowJsonELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringTest.java index 3fb95566..bedf4edc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLELSpringTest.java @@ -13,22 +13,23 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(xml) - * 单元测试 + * 测试显示调用子流程(xml) 单元测试 * * @author justin.xu */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/subflow/application-xml.xml") public class SubflowXMLELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlow() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringTest.java index f82f2636..a36095ea 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlELSpringTest.java @@ -13,22 +13,23 @@ import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; /** - * 测试显示调用子流程(yml) - * 单元测试 + * 测试显示调用子流程(yml) 单元测试 * * @author justin.xu */ @RunWith(SpringRunner.class) @ContextConfiguration("classpath:/subflow/application-yml.xml") public class SubflowYmlELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; - //是否按照流程定义配置执行 - @Test - public void testExplicitSubFlowYml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); - } + @Resource + private FlowExecutor flowExecutor; + + // 是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr()); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java index 75a7fb49..11697dc0 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; 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("Acomp executed!"); - } + + @Override + public void process() { + System.out.println("Acomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java index 9fb3c932..06459fc5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; 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("Bcomp executed!"); - } + + @Override + public void process() { + System.out.println("Bcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java index ce8ea149..aa1668e2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("c") public class CCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ccomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Ccomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java index 309196e9..1b0cfb90 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -3,11 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("d") public class DCmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Dcomp executed!"); - } + + @Override + public void process() throws Exception { + System.out.println("Dcomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java index b855a1ae..9dce7ccf 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -3,12 +3,12 @@ package com.yomahub.liteflow.test.subflow.cmp1; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; - @Component("e") public class ECmp extends NodeComponent { - @Override - public void process() throws Exception { - System.out.println("Ecomp executed!"); - } + @Override + public void process() throws Exception { + System.out.println("Ecomp executed!"); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java index ed062498..f773bd5c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -5,14 +5,15 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringTest.RUN_TIME_SLOT; - @Component("f") public class FCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Fcomp executed!"); + } - System.out.println("Fcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java index a21058a1..308e75c3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -5,17 +5,17 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringTest.RUN_TIME_SLOT; - @Component("g") public class GCmp extends NodeComponent { - @Override - public void process() throws Exception { + @Override + public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); - System.out.println("Gcmp executed!"); + System.out.println("Gcmp executed!"); + + this.invoke("chain4", "it's implicit subflow."); + } - this.invoke("chain4", "it's implicit subflow."); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java index 00192e3f..e9b6fc54 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -6,17 +6,18 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringTest.RUN_TIME_SLOT; - @Component("h") public class HCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqData(); - DefaultContext context = this.getFirstContextBean(); - context.setData("innerRequest", requestData); - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqData(); + DefaultContext context = this.getFirstContextBean(); + context.setData("innerRequest", requestData); + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); + } - System.out.println("Hcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java index 2586732c..7d7115bb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -5,14 +5,15 @@ import org.springframework.stereotype.Component; import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowELSpringTest.RUN_TIME_SLOT; - @Component("m") public class MCmp extends NodeComponent { - @Override - public void process() throws Exception { - RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + @Override + public void process() throws Exception { + + RUN_TIME_SLOT.add(this.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); + } - System.out.println("Mcomp executed!"); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java index 390cfaaa..d6d9ceec 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/PCmp.java @@ -5,26 +5,27 @@ import com.yomahub.liteflow.core.NodeComponent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - @Component("p") public class PCmp extends NodeComponent { - @Autowired - private FlowExecutor flowExecutor; + @Autowired + private FlowExecutor flowExecutor; + + @Override + public void process() throws Exception { + int slotIndex = this.getSlotIndex(); + for (int i = 0; i < 10; i++) { + int finalI = i; + new Thread(() -> { + try { + flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); + } + catch (Exception e) { + throw new RuntimeException(e); + } + }).start(); + } + Thread.sleep(1000); + } - @Override - public void process() throws Exception { - int slotIndex = this.getSlotIndex(); - for (int i = 0; i < 10; i++) { - int finalI = i; - new Thread(() -> { - try { - flowExecutor.invokeInAsync("c2", "it's implicit subflow " + finalI, slotIndex); - } catch (Exception e) { - throw new RuntimeException(e); - } - }).start(); - } - Thread.sleep(1000); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java index ac1350cd..7399dc2d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/QCmp.java @@ -7,23 +7,25 @@ import org.springframework.stereotype.Component; import java.util.HashSet; import java.util.Set; - @Component("q") public class QCmp extends NodeComponent { - @Override - public void process() throws Exception { - String requestData = this.getSubChainReqDataInAsync(); - DefaultContext context = this.getFirstContextBean(); - synchronized (QCmp.class){ - if (context.hasData("test")){ - Set set = context.getData("test"); - set.add(requestData); - }else{ - Set set = new HashSet<>(); - set.add(requestData); - context.setData("test", set); - } - } - } + @Override + public void process() throws Exception { + String requestData = this.getSubChainReqDataInAsync(); + DefaultContext context = this.getFirstContextBean(); + + synchronized (QCmp.class) { + if (context.hasData("test")) { + Set set = context.getData("test"); + set.add(requestData); + } + else { + Set set = new HashSet<>(); + set.add(requestData); + context.setData("test", set); + } + } + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringTest.java index cc83086b..9f91d2b7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/SwitchELSpringTest.java @@ -15,40 +15,42 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/switchcase/application.xml") public class SwitchELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testSwitch1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); - } + @Test + public void testSwitch1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>e==>d",response.getExecuteStepStr()); - } + @Test + public void testSwitch2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>e==>d", response.getExecuteStepStr()); + } - @Test - public void testSwitch3() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>f==>b",response.getExecuteStepStr()); - } + @Test + public void testSwitch3() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>f==>b", response.getExecuteStepStr()); + } + + @Test + public void testSwitch4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>g==>d", response.getExecuteStepStr()); + } + + @Test + public void testSwitch5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>h==>b", response.getExecuteStepStr()); + } - @Test - public void testSwitch4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>g==>d",response.getExecuteStepStr()); - } - @Test - public void testSwitch5() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>h==>b",response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java index 6472afd9..07f02d8f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/switchcase/cmp/ESwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java index b3e03d8f..275e3c98 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/ESwitchCmp.java @@ -17,4 +17,5 @@ public class ESwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java index ac83ec67..e32efdd2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/FSwitchCmp.java @@ -17,4 +17,5 @@ public class FSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return ":td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java index a956a5ec..8ee8cc9d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/GSwitchCmp.java @@ -17,4 +17,5 @@ public class GSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "d:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java index 68838816..12a8482a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/switchcase/cmp/HSwitchCmp.java @@ -17,4 +17,5 @@ public class HSwitchCmp extends NodeSwitchComponent { public String processSwitch() throws Exception { return "tag:td"; } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringJsonTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringJsonTest.java index 4f67e9d7..6fbc39f5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringJsonTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringJsonTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -22,42 +23,43 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/tag/application-json.xml") public class NodeTagELSpringJsonTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringXmlTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringXmlTest.java index 39601086..93f2ee4a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringXmlTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/NodeTagELSpringXmlTest.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * springboot环境下隐私投递的测试 + * * @author Bryan.Zhang * @since 2.5.0 */ @@ -22,42 +23,43 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/tag/application-xml.xml") public class NodeTagELSpringXmlTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; - @Test - public void testTag1() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("123",context.getData("test")); - } + @Test + public void testTag1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123", context.getData("test")); + } - @Test - public void testTag2() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); - } + @Test + public void testTag2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr()); + } - //测试多线程when情况下的tag取值是否正确 - //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 - @Test - public void testTag3() throws Exception{ - for (int i = 0; i < 50; i++) { - LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - ConcurrentHashSet testSet = context.getData("test"); - Assert.assertEquals(3, testSet.size()); - } - } + // 测试多线程when情况下的tag取值是否正确 + // 这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception { + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = context.getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + // 测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getExecuteStepStr()); + } - //测试tag是否能在isAccess中起效 - @Test - public void testTag4() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("g", response.getExecuteStepStr()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java index 57868b28..55d2dd8c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java @@ -19,12 +19,14 @@ public class ACmp extends NodeComponent { public void process() { String testKey = "test"; DefaultContext context = this.getFirstContextBean(); - if (context.getData(testKey) == null){ - context.setData(testKey,this.getTag()); - }else{ + if (context.getData(testKey) == null) { + context.setData(testKey, this.getTag()); + } + else { String s = context.getData(testKey); s += this.getTag(); context.setData(testKey, s); } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java index de3d6aba..f5b2c4bb 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -19,6 +19,7 @@ public class B1Cmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("test",new ConcurrentHashSet()); + context.setData("test", new ConcurrentHashSet()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java index 58841874..7ba80649 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java @@ -22,4 +22,5 @@ public class BCmp extends NodeComponent { ConcurrentHashSet testSet = context.getData("test"); testSet.add(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java index ceedd8ab..d90bdc3a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java @@ -15,10 +15,12 @@ public class CCmp extends NodeSwitchComponent { @Override public String processSwitch() throws Exception { - if(this.getTag().equals("2")){ + if (this.getTag().equals("2")) { return "e"; - }else{ + } + else { return "d"; } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java index 572980b7..d231b874 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -18,4 +18,5 @@ public class DCmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("DCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java index 11ee96c8..e2687fa3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -18,4 +18,5 @@ public class ECmp extends NodeComponent { System.out.println(this.getTag()); System.out.println("ECmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java index 2f670578..f15f468e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -22,4 +22,5 @@ public class FCmp extends NodeComponent { public boolean isAccess() { return Boolean.parseBoolean(this.getTag()); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java index f6180b56..f2d2e3f7 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -17,4 +17,5 @@ public class GCmp extends NodeComponent { public void process() { System.out.println("GCmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java index fee0055e..3de938a6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -4,13 +4,14 @@ import com.alibaba.ttl.TransmittableThreadLocal; public class TestTL { - public static ThreadLocal tl = new TransmittableThreadLocal<>(); + public static ThreadLocal tl = new TransmittableThreadLocal<>(); - public static String get(){ - return tl.get(); - } + public static String get() { + return tl.get(); + } + + public static void set(String value) { + tl.set(value); + } - public static void set(String value){ - tl.set(value); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringTest.java index a38012c8..7498c525 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenELSpringTest.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; /** * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * * @author Bryan.Zhang * @since 2.6.3 */ @@ -21,17 +22,18 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/useTTLInWhen/application.xml") public class UseTTLInWhenELSpringTest extends BaseTest { - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertEquals("hello,b", context.getData("b")); + Assert.assertEquals("hello,c", context.getData("c")); + Assert.assertEquals("hello,d", context.getData("d")); + Assert.assertEquals("hello,e", context.getData("e")); + Assert.assertEquals("hello,f", context.getData("f")); + } - @Test - public void testUseTTLInWhen() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertEquals("hello,b", context.getData("b")); - Assert.assertEquals("hello,c", context.getData("c")); - Assert.assertEquals("hello,d", context.getData("d")); - Assert.assertEquals("hello,e", context.getData("e")); - Assert.assertEquals("hello,f", context.getData("f")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java index bab445a4..7fbd16da 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java @@ -19,4 +19,5 @@ public class ACmp extends NodeComponent { TestTL.set("hello"); System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java index b0e7b15f..b80df86a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -19,7 +19,7 @@ public class BCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String value = TestTL.get(); - context.setData(this.getNodeId(),value+",b"); + context.setData(this.getNodeId(), value + ",b"); System.out.println("BCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java index 90a29474..3d3581d2 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -19,7 +19,7 @@ public class CCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String value = TestTL.get(); - context.setData(this.getNodeId(),value+",c"); + context.setData(this.getNodeId(), value + ",c"); System.out.println("CCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java index c81a734a..ba7d1fa9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -19,7 +19,7 @@ public class DCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String value = TestTL.get(); - context.setData(this.getNodeId(),value+",d"); + context.setData(this.getNodeId(), value + ",d"); System.out.println("DCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java index 7384747f..1d2625a3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -19,7 +19,7 @@ public class ECmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String value = TestTL.get(); - context.setData(this.getNodeId(),value+",e"); + context.setData(this.getNodeId(), value + ",e"); System.out.println("ECmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java index 0fb50eff..273967dc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -19,7 +19,7 @@ public class FCmp extends NodeComponent { public void process() { DefaultContext context = this.getFirstContextBean(); String value = TestTL.get(); - context.setData(this.getNodeId(),value+",f"); + context.setData(this.getNodeId(), value + ",f"); System.out.println("FCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest1.java index a15c5680..2be2c847 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest1.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -23,16 +24,17 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/whenTimeOut/application1.xml") public class WhenTimeOutELSpringTest1 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } - //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertFalse(response.isSuccess()); - Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest2.java index 61c30a5d..2658ddf3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutELSpringTest2.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; /** * springboot环境下异步线程超时日志打印测试 + * * @author Bryan.Zhang * @since 2.6.4 */ @@ -22,15 +23,16 @@ import javax.annotation.Resource; @ContextConfiguration("classpath:/whenTimeOut/application2.xml") public class WhenTimeOutELSpringTest2 extends BaseTest { - private final Logger log = LoggerFactory.getLogger(this.getClass()); + private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Resource - private FlowExecutor flowExecutor; + @Resource + private FlowExecutor flowExecutor; + + // 其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } - //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 - @Test - public void testWhenTimeOut() throws Exception{ - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java index 19b0bc06..c8a474b4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { 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/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java index fb8cd2a1..f5778fcd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -17,7 +17,8 @@ public class BCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("BCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java index ee9fe977..e50c9689 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -17,7 +17,8 @@ public class CCmp extends NodeComponent { public void process() { try { Thread.sleep(3500); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("CCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java index 5f3c4b3f..1a3a7d42 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -17,7 +17,8 @@ public class DCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("DCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java index 0e18aee7..5ab23c86 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -17,7 +17,8 @@ public class ECmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("ECmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java index fad1d2d6..d0def9de 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -17,7 +17,8 @@ public class FCmp extends NodeComponent { public void process() { try { Thread.sleep(4000); - }catch (Exception ignored){ + } + catch (Exception ignored) { } System.out.println("FCmp executed!"); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index f7a3405b..4b0e1e5c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -12,9 +12,10 @@ import org.junit.AfterClass; * @author tangkc * @since 2.8.6 */ -public class BaseTest { +public class BaseTest { + @AfterClass - public static void cleanScanCache(){ + public static void cleanScanCache() { ComponentScanner.cleanCache(); FlowBus.cleanCache(); ExecutorHelper.loadInstance().clearExecutorServiceMap(); @@ -22,4 +23,5 @@ public class BaseTest { LiteflowConfigGetter.clean(); FlowInitHook.cleanHook(); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java index 46ac7164..f000048c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java @@ -31,8 +31,9 @@ import java.sql.Statement; @TestPropertySource(value = "classpath:/application-xml.properties") @SpringBootTest(classes = SQLWithXmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.sql.cmp" }) public class SQLWithXmlELSpringbootTest extends BaseTest { + @Resource private FlowExecutor flowExecutor; @@ -50,7 +51,7 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { } @Test - public void testSQLWithScriptXml() { + public void testSQLWithScriptXml() { LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); Assert.assertTrue(response.isSuccess()); Assert.assertEquals("x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime()); @@ -70,10 +71,12 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), sqlParserVO.getPassword()); + connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), + sqlParserVO.getPassword()); Statement statement = connection.createStatement(); statement.executeUpdate("UPDATE EL_TABLE SET EL_DATA='THEN(a, c, b);' WHERE chain_name='chain1'"); - } catch (SQLException e) { + } + catch (SQLException e) { throw new ELSQLException(e.getMessage()); } } @@ -86,11 +89,15 @@ public class SQLWithXmlELSpringbootTest extends BaseTest { SQLParserVO sqlParserVO = JsonUtil.parseObject(liteflowConfig.getRuleSourceExtData(), SQLParserVO.class); Connection connection; try { - connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), sqlParserVO.getPassword()); + connection = DriverManager.getConnection(sqlParserVO.getUrl(), sqlParserVO.getUsername(), + sqlParserVO.getPassword()); Statement statement = connection.createStatement(); - statement.executeUpdate("UPDATE SCRIPT_NODE_TABLE SET SCRIPT_NODE_DATA='return false;' WHERE SCRIPT_NODE_ID='x0'"); - } catch (SQLException e) { + statement.executeUpdate( + "UPDATE SCRIPT_NODE_TABLE SET SCRIPT_NODE_DATA='return false;' WHERE SCRIPT_NODE_ID='x0'"); + } + catch (SQLException e) { throw new ELSQLException(e.getMessage()); } } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java index 4b7958ec..558d82bd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java index 02e76f92..8411b0c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -10,13 +10,14 @@ import org.junit.AfterClass; public class BaseTest { - @AfterClass - public static void cleanScanCache(){ - ComponentScanner.cleanCache(); - FlowBus.cleanCache(); - ExecutorHelper.loadInstance().clearExecutorServiceMap(); - SpiFactoryCleaner.clean(); - LiteflowConfigGetter.clean(); - FlowInitHook.cleanHook(); - } + @AfterClass + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + } diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java index bad35e5f..1944ec53 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkClusterWithXmlELSpringbootTest.java @@ -34,58 +34,58 @@ import java.nio.charset.StandardCharsets; @TestPropertySource(value = "classpath:/zookeeper/application-xml-cluster.properties") @SpringBootTest(classes = ZkClusterWithXmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.zookeeper.cmp" }) public class ZkClusterWithXmlELSpringbootTest extends BaseTest { - - private static final String ZK_CHAIN_PATH = "/liteflow/chain"; - private static final String ZK_SCRIPT_PATH = "/liteflow/script"; + private static final String ZK_CHAIN_PATH = "/liteflow/chain"; - private static TestingCluster zkCluster; - - @Resource - private FlowExecutor flowExecutor; + private static final String ZK_SCRIPT_PATH = "/liteflow/script"; - @BeforeClass - public static void setUpBeforeClass() throws Exception { - System.setProperty("zookeeper.admin.enableServer", "false"); + private static TestingCluster zkCluster; + @Resource + private FlowExecutor flowExecutor; - zkCluster = new TestingCluster(new InstanceSpec(null, 21810, -1, -1, true, -1, -1, -1), - new InstanceSpec(null, 21811, -1, -1, true, -1, -1, -1), - new InstanceSpec(null, 21812, -1, -1, true, -1, -1, -1)); - zkCluster.start(); - String connectStr = zkCluster.getConnectString(); + @BeforeClass + public static void setUpBeforeClass() throws Exception { + System.setProperty("zookeeper.admin.enableServer", "false"); - ZkClient zkClient = new ZkClient(connectStr); - zkClient.setZkSerializer(new ZkSerializer() { - @Override - public byte[] serialize(final Object o) throws ZkMarshallingError { - return o.toString().getBytes(StandardCharsets.UTF_8); - } + zkCluster = new TestingCluster(new InstanceSpec(null, 21810, -1, -1, true, -1, -1, -1), + new InstanceSpec(null, 21811, -1, -1, true, -1, -1, -1), + new InstanceSpec(null, 21812, -1, -1, true, -1, -1, -1)); + zkCluster.start(); + String connectStr = zkCluster.getConnectString(); - @Override - public Object deserialize(final byte[] bytes) throws ZkMarshallingError { - return new String(bytes, StandardCharsets.UTF_8); - } - }); + ZkClient zkClient = new ZkClient(connectStr); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(StandardCharsets.UTF_8); + } - String chain1Path = ZK_CHAIN_PATH+"/chain1"; - zkClient.createPersistent(chain1Path, true); - zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, StandardCharsets.UTF_8); + } + }); - String script1Path = ZK_SCRIPT_PATH+"/s1:script:脚本s1"; - zkClient.createPersistent(script1Path, true); - zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); + String chain1Path = ZK_CHAIN_PATH + "/chain1"; + zkClient.createPersistent(chain1Path, true); + zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + + String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1"; + zkClient.createPersistent(script1Path, true); + zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); + + Thread.sleep(2000L); + } + + @Test + public void testZkNodeWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("hello", context.getData("test")); + } - Thread.sleep(2000L); - } - - @Test - public void testZkNodeWithXml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assert.assertTrue(response.isSuccess()); - Assert.assertEquals("hello", context.getData("test")); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java index 9dc234fd..da0bccd8 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlELSpringbootTest.java @@ -24,8 +24,8 @@ import java.nio.charset.Charset; import java.util.concurrent.CountDownLatch; /** - * springboot环境下的zk配置源功能测试 - * ZK节点存储数据的格式为xml文件 + * springboot环境下的zk配置源功能测试 ZK节点存储数据的格式为xml文件 + * * @author zendwang * @since 2.5.0 */ @@ -33,50 +33,51 @@ import java.util.concurrent.CountDownLatch; @TestPropertySource(value = "classpath:/zookeeper/application-xml.properties") @SpringBootTest(classes = ZkNodeWithXmlELSpringbootTest.class) @EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +@ComponentScan({ "com.yomahub.liteflow.test.zookeeper.cmp" }) public class ZkNodeWithXmlELSpringbootTest extends BaseTest { - private static final String ZK_CHAIN_PATH = "/liteflow/chain"; + private static final String ZK_CHAIN_PATH = "/liteflow/chain"; - private static final String ZK_SCRIPT_PATH = "/liteflow/script"; + private static final String ZK_SCRIPT_PATH = "/liteflow/script"; - private static TestingServer zkServer; - - @Resource - private FlowExecutor flowExecutor; + private static TestingServer zkServer; - @BeforeClass - public static void setUpBeforeClass() throws Exception { - zkServer = new TestingServer(21810); - ZkClient zkClient = new ZkClient("127.0.0.1:21810"); - zkClient.setZkSerializer(new ZkSerializer() { - @Override - public byte[] serialize(final Object o) throws ZkMarshallingError { - return o.toString().getBytes(Charset.forName("UTF-8")); - } + @Resource + private FlowExecutor flowExecutor; - @Override - public Object deserialize(final byte[] bytes) throws ZkMarshallingError { - return new String(bytes, Charset.forName("UTF-8")); - } - }); - String chain1Path = ZK_CHAIN_PATH+"/chain1"; - zkClient.createPersistent(chain1Path, true); - zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + String chain1Path = ZK_CHAIN_PATH + "/chain1"; + zkClient.createPersistent(chain1Path, true); + zkClient.writeData(chain1Path, "THEN(a, b, c, s1);"); + + String script1Path = ZK_SCRIPT_PATH + "/s1:script:脚本s1"; + zkClient.createPersistent(script1Path, true); + zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); + } + + @Test + public void testZkNodeWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } - String script1Path = ZK_SCRIPT_PATH+"/s1:script:脚本s1"; - zkClient.createPersistent(script1Path, true); - zkClient.writeData(script1Path, "defaultContext.setData(\"test\",\"hello\");"); - } - - @Test - public void testZkNodeWithXml() { - LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); - Assert.assertTrue(response.isSuccess()); - } - - @AfterClass - public static void tearDown() throws Exception { - zkServer.stop(); - } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java index f4fcf186..eb4438ee 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-zk-springboot/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java @@ -17,4 +17,5 @@ public class ACmp extends NodeComponent { public void process() { System.out.println("ACmp executed!"); } + }