merge master
This commit is contained in:
commit
c0e4d922f3
|
@ -11,7 +11,7 @@ LiteFlow是一个轻量且强大的国产规则引擎框架,可用于复杂的
|
|||
|
||||
LiteFlow于2020年正式开源,2021年获得开源中国年度最受欢迎开源软件殊荣。于2022年获得Gitee最有价值开源项目(GVP)荣誉。是一个正处在高速发展中的开源项目。
|
||||
|
||||
LiteFlow是一个由社区驱动的项目,我们非常重视社区建设,拥有一个2500多人的使用者社区,在使用中碰到任何问题或者建议都可以在社区中反应。
|
||||
LiteFlow是一个由社区驱动的项目,我们非常重视社区建设,拥有一个3000多人的使用者社区,在使用中碰到任何问题或者建议都可以在社区中反应。
|
||||
|
||||
你在官网中可以找到加入社区的方式!
|
||||
|
||||
|
@ -59,7 +59,7 @@ LiteFlow期待你的了解!
|
|||
|
||||
**微信公众号**
|
||||
|
||||
由于社区群超过200人,需要邀请入群。关注公众号后点击`个人微信`加我,我可以拉你入群
|
||||
社区群需要邀请入群。关注公众号后点击`个人微信`加我,我可以拉你入群
|
||||
|
||||
![offIical-wx](static/img/offical-wx.jpg)
|
||||
|
||||
|
|
|
@ -18,10 +18,16 @@ public @interface LiteflowMethod {
|
|||
|
||||
/**
|
||||
* 节点ID,用于区分节点 默认为空 则按照Spring模式下BeanName为准。
|
||||
* @return
|
||||
* @return nodeId
|
||||
*/
|
||||
String nodeId() default "";
|
||||
|
||||
/**
|
||||
* 节点Name
|
||||
* @return nodeName
|
||||
*/
|
||||
String nodeName() default "";
|
||||
|
||||
/**
|
||||
* CMP类型定义
|
||||
* @return AnnotationNodeTypeEnum
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
package com.yomahub.liteflow.aop;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
|
||||
/**
|
||||
|
@ -17,18 +18,8 @@ import com.yomahub.liteflow.slot.Slot;
|
|||
*/
|
||||
public interface ICmpAroundAspect {
|
||||
|
||||
/**
|
||||
* 前置处理
|
||||
* @param nodeId 节点ID
|
||||
* @param slot
|
||||
*/
|
||||
void beforeProcess(String nodeId, Slot slot);
|
||||
void beforeProcess(NodeComponent cmp);
|
||||
|
||||
/**
|
||||
* 后置处理
|
||||
* @param nodeId 节点ID
|
||||
* @param slot
|
||||
*/
|
||||
void afterProcess(String nodeId, Slot slot);
|
||||
void afterProcess(NodeComponent cmp);
|
||||
|
||||
}
|
||||
|
|
|
@ -343,13 +343,10 @@ public class FlowExecutor {
|
|||
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);
|
||||
|
@ -357,14 +354,6 @@ public class FlowExecutor {
|
|||
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);
|
||||
}
|
||||
|
||||
//如果传入了用户的RequestId,则用这个请求Id,如果没传入,则进行生成
|
||||
if (StrUtil.isNotBlank(requestId)){
|
||||
slot.putRequestId(requestId);
|
||||
|
@ -375,6 +364,19 @@ public class FlowExecutor {
|
|||
LOG.info("requestId has generated");
|
||||
}
|
||||
|
||||
if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
|
||||
LOG.info("slot[{}] offered", slotIndex);
|
||||
}
|
||||
|
||||
// 如果是隐式流程,事先把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);
|
||||
|
|
|
@ -112,11 +112,11 @@ public abstract class NodeComponent {
|
|||
// 执行失败后回调方法
|
||||
// 这里要注意,失败方法本身抛出错误,只打出堆栈,往外抛出的还是主要的异常
|
||||
try {
|
||||
self.onError();
|
||||
self.onError(e);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
String errMsg = StrUtil.format("component[{}] onError method happens exception", this.getDisplayName());
|
||||
LOG.error(errMsg);
|
||||
LOG.error(errMsg, ex);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public abstract class NodeComponent {
|
|||
|
||||
stopWatch.stop();
|
||||
final long timeSpent = stopWatch.getTotalTimeMillis();
|
||||
LOG.debug("component[{}] finished in {} milliseconds", this.getDisplayName(), timeSpent);
|
||||
LOG.info("component[{}] finished in {} milliseconds", this.getDisplayName(), timeSpent);
|
||||
|
||||
// 往CmpStep中放入时间消耗信息
|
||||
cmpStep.setTimeSpent(timeSpent);
|
||||
|
@ -142,7 +142,7 @@ public abstract class NodeComponent {
|
|||
public void beforeProcess() {
|
||||
// 全局切面只在spring体系下生效,这里用了spi机制取到相应环境下的实现类
|
||||
// 非spring环境下,全局切面为空实现
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().beforeProcess(nodeId, this.getSlot());
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().beforeProcess(this.self);
|
||||
}
|
||||
|
||||
public abstract void process() throws Exception;
|
||||
|
@ -151,12 +151,12 @@ public abstract class NodeComponent {
|
|||
// 如果需要在成功后回调某一个方法,请覆盖这个方法
|
||||
}
|
||||
|
||||
public void onError() throws Exception {
|
||||
public void onError(Exception e) throws Exception {
|
||||
// 如果需要在抛错后回调某一段逻辑,请覆盖这个方法
|
||||
}
|
||||
|
||||
public void afterProcess() {
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().afterProcess(nodeId, this.getSlot());
|
||||
CmpAroundAspectHolder.loadCmpAroundAspect().afterProcess(this.self);
|
||||
}
|
||||
|
||||
// 是否进入该节点
|
||||
|
|
|
@ -2,10 +2,7 @@ package com.yomahub.liteflow.core.proxy;
|
|||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Tuple;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.*;
|
||||
import com.yomahub.liteflow.annotation.LiteflowMethod;
|
||||
import com.yomahub.liteflow.annotation.LiteflowRetry;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
@ -13,8 +10,10 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
|
|||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.exception.ComponentMethodDefineErrorException;
|
||||
import com.yomahub.liteflow.exception.LiteFlowException;
|
||||
import com.yomahub.liteflow.exception.ProxyException;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.spi.holder.LiteflowComponentSupportHolder;
|
||||
import com.yomahub.liteflow.util.LiteFlowProxyUtil;
|
||||
import com.yomahub.liteflow.util.SerialsUtil;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
|
@ -30,6 +29,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -96,8 +96,23 @@ public class ComponentProxy {
|
|||
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);
|
||||
+ activeNodeId + ",cmpClass:" + clazz);
|
||||
}
|
||||
|
||||
|
||||
String activeNodeName;
|
||||
if (isMethodCreate){
|
||||
// 获取process上的LiteflowMethod
|
||||
LiteflowMethod mainliteflowMethod = methodList.stream().filter(liteflowMethod -> liteflowMethod.value().isMainMethod()).findFirst().orElse(null);
|
||||
if (mainliteflowMethod == null){
|
||||
String errMsg = StrUtil.format("you have not defined @LiteFlowMethod on the processXXX method in class {}", clazz.getName());
|
||||
throw new LiteFlowException(errMsg);
|
||||
}
|
||||
activeNodeName = mainliteflowMethod.nodeName();
|
||||
}else{
|
||||
activeNodeName = LiteflowComponentSupportHolder.loadLiteflowComponentSupport().getCmpName(bean);
|
||||
}
|
||||
|
||||
// 当前节点实际LiteflowRetry注解
|
||||
AtomicReference<LiteflowRetry> liteflowRetryAtomicReference = new AtomicReference<>(null);
|
||||
// 相同nodeId只能有一个LiteflowRetry定义方法,且必须再Process方法上
|
||||
|
@ -153,10 +168,12 @@ public class ComponentProxy {
|
|||
NodeComponent nodeComponent = (NodeComponent) instance;
|
||||
// 重设nodeId
|
||||
nodeComponent.setNodeId(activeNodeId);
|
||||
// 重设nodeName
|
||||
nodeComponent.setName(activeNodeName);
|
||||
return nodeComponent;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new LiteFlowException(e);
|
||||
throw new ProxyException(e);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
@ -198,19 +215,24 @@ public class ComponentProxy {
|
|||
.orElse(null);
|
||||
|
||||
// 如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法
|
||||
// 进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数
|
||||
boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1
|
||||
&& Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class);
|
||||
// 进行检查,检查被代理的bean里是否第一个参数为NodeComponent这个类型的
|
||||
boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length > 0
|
||||
&& liteFlowMethodBean.getMethod().getParameterTypes()[0].equals(NodeComponent.class);
|
||||
if (!checkFlag) {
|
||||
String errMsg = StrUtil.format(
|
||||
"Method[{}.{}] must have NodeComponent parameter(and only one parameter)",
|
||||
"Method[{}.{}] must have NodeComponent parameter(first parameter is NodeComponent)",
|
||||
bean.getClass().getName(), liteFlowMethodBean.getMethod().getName());
|
||||
LOG.error(errMsg);
|
||||
throw new ComponentMethodDefineErrorException(errMsg);
|
||||
}
|
||||
|
||||
try {
|
||||
return liteFlowMethodBean.getMethod().invoke(bean, proxy);
|
||||
if (args.length > 0){
|
||||
Object[] wrapArgs = ArrayUtil.insert(args, 0, proxy);
|
||||
return liteFlowMethodBean.getMethod().invoke(bean, wrapArgs);
|
||||
}else{
|
||||
return liteFlowMethodBean.getMethod().invoke(bean, proxy);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
InvocationTargetException targetEx = (InvocationTargetException) e;
|
||||
|
|
|
@ -2,14 +2,19 @@ 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("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),
|
||||
|
||||
IS_ACCESS("isAccess", false),
|
||||
|
||||
IS_END("isEnd", false), IS_CONTINUE_ON_ERROR("isContinueOnError", false),
|
||||
IS_END("isEnd", false),
|
||||
IS_CONTINUE_ON_ERROR("isContinueOnError", false),
|
||||
|
||||
GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass", false),
|
||||
|
||||
|
@ -19,7 +24,10 @@ public enum LiteFlowMethodEnum {
|
|||
|
||||
BEFORE_PROCESS("beforeProcess", false),
|
||||
|
||||
AFTER_PROCESS("afterProcess", false);
|
||||
AFTER_PROCESS("afterProcess", false),
|
||||
|
||||
GET_DISPLAY_NAME("getDisplayName", false)
|
||||
;
|
||||
|
||||
private String methodName;
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
/**
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class ProxyException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 异常信息 */
|
||||
private String message;
|
||||
|
||||
public ProxyException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ProxyException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
|
@ -93,7 +93,7 @@ public class FlowBus {
|
|||
}
|
||||
|
||||
nodeMap.put(nodeId,
|
||||
new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, null, nodeId)));
|
||||
new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, type, nodeComponent.getName(), nodeId)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.yomahub.liteflow.flow;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.yomahub.liteflow.exception.LiteFlowException;
|
||||
import com.yomahub.liteflow.flow.entity.CmpStep;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 执行结果封装类
|
||||
|
@ -101,9 +101,15 @@ public class LiteflowResponse {
|
|||
return this.getSlot().getContextBean(contextBeanClazz);
|
||||
}
|
||||
|
||||
public Map<String, CmpStep> getExecuteSteps() {
|
||||
Map<String, CmpStep> map = new HashMap<>();
|
||||
this.getSlot().getExecuteSteps().forEach(cmpStep -> map.put(cmpStep.getNodeId(), cmpStep));
|
||||
public Map<String, List<CmpStep>> getExecuteSteps() {
|
||||
Map<String, List<CmpStep>> map = new LinkedHashMap<>();
|
||||
this.getSlot().getExecuteSteps().forEach(cmpStep -> {
|
||||
if (map.containsKey(cmpStep.getNodeId())){
|
||||
map.get(cmpStep.getNodeId()).add(cmpStep);
|
||||
}else{
|
||||
map.put(cmpStep.getNodeId(), ListUtil.toList(cmpStep));
|
||||
}
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
@ -133,10 +133,7 @@ public class Node implements Executable, Cloneable{
|
|||
|
||||
// 判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性
|
||||
if (instance.isAccess()) {
|
||||
// 根据配置判断是否打印执行中的日志
|
||||
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
|
||||
LOG.info("[O]start component[{}] execution", instance.getDisplayName());
|
||||
}
|
||||
LOG.info("[O]start component[{}] execution", instance.getDisplayName());
|
||||
|
||||
// 这里开始进行重试的逻辑和主逻辑的运行
|
||||
NodeExecutor nodeExecutor = NodeExecutorHelper.loadInstance()
|
||||
|
@ -145,9 +142,7 @@ public class Node implements Executable, Cloneable{
|
|||
nodeExecutor.execute(instance);
|
||||
}
|
||||
else {
|
||||
if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
|
||||
LOG.info("[X]skip component[{}] execution", instance.getDisplayName());
|
||||
}
|
||||
LOG.info("[X]skip component[{}] execution", instance.getDisplayName());
|
||||
}
|
||||
// 如果组件覆盖了isEnd方法,或者在在逻辑中主要调用了setEnd(true)的话,流程就会立马结束
|
||||
if (instance.isEnd()) {
|
||||
|
|
|
@ -1,41 +1,33 @@
|
|||
package com.yomahub.liteflow.flow.element.condition;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
import com.yomahub.liteflow.exception.AndOrConditionException;
|
||||
import com.yomahub.liteflow.flow.element.Condition;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.slot.DataBus;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class AndOrCondition extends Condition {
|
||||
|
||||
private final LFLog LOG = LFLoggerManager.getLogger(this.getClass());
|
||||
|
||||
private BooleanConditionTypeEnum booleanConditionType;
|
||||
|
||||
@Override
|
||||
public void executeCondition(Integer slotIndex) throws Exception {
|
||||
List<Executable> itemList = this.getItem();
|
||||
|
||||
|
||||
if (CollUtil.isEmpty(itemList)){
|
||||
throw new AndOrConditionException("boolean item list is null");
|
||||
}
|
||||
|
||||
boolean[] booleanArray = new boolean[itemList.size()];
|
||||
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
Executable item = itemList.get(i);
|
||||
item.setCurrChainId(this.getCurrChainId());
|
||||
item.execute(slotIndex);
|
||||
booleanArray[i] = item.getItemResultMetaValue(slotIndex);
|
||||
}
|
||||
|
||||
BooleanConditionTypeEnum booleanConditionType = this.getBooleanConditionType();
|
||||
|
||||
Slot slot = DataBus.getSlot(slotIndex);
|
||||
|
@ -43,16 +35,37 @@ public class AndOrCondition extends Condition {
|
|||
String resultKey = StrUtil.format("{}_{}",this.getClass().getName(),this.hashCode());
|
||||
switch (booleanConditionType) {
|
||||
case AND:
|
||||
slot.setAndOrResult(resultKey, BooleanUtil.and(booleanArray));
|
||||
slot.setAndOrResult(resultKey, itemList.stream().allMatch(new AndOrConditionPredicate(slotIndex)));
|
||||
break;
|
||||
case OR:
|
||||
slot.setAndOrResult(resultKey, BooleanUtil.or(booleanArray));
|
||||
slot.setAndOrResult(resultKey, itemList.stream().anyMatch(new AndOrConditionPredicate(slotIndex)));
|
||||
break;
|
||||
default:
|
||||
throw new AndOrConditionException("condition type must be 'AND' or 'OR'");
|
||||
}
|
||||
}
|
||||
|
||||
private class AndOrConditionPredicate implements Predicate<Executable> {
|
||||
|
||||
private final Integer slotIndex;
|
||||
|
||||
public AndOrConditionPredicate(Integer slotIndex) {
|
||||
this.slotIndex = slotIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Executable condition) {
|
||||
try {
|
||||
condition.setCurrChainId(getCurrChainId());
|
||||
condition.execute(slotIndex);
|
||||
return condition.getItemResultMetaValue(slotIndex);
|
||||
} catch (Exception e) {
|
||||
throw new AndOrConditionException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -4,11 +4,15 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
||||
import com.yomahub.liteflow.flow.element.Condition;
|
||||
import com.yomahub.liteflow.flow.element.Executable;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import com.yomahub.liteflow.slot.DataBus;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
|
||||
public class NotCondition extends Condition {
|
||||
|
||||
private final LFLog LOG = LFLoggerManager.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public void executeCondition(Integer slotIndex) throws Exception {
|
||||
Executable item = this.getItem();
|
||||
|
@ -17,6 +21,8 @@ public class NotCondition extends Condition {
|
|||
item.execute(slotIndex);
|
||||
boolean flag = item.getItemResultMetaValue(slotIndex);
|
||||
|
||||
LOG.info("the result of boolean component [{}] is [{}]", item.getId(), flag);
|
||||
|
||||
Slot slot = DataBus.getSlot(slotIndex);
|
||||
|
||||
String resultKey = StrUtil.format("{}_{}",this.getClass().getName(),this.hashCode());
|
||||
|
|
|
@ -30,71 +30,66 @@ 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<Executable> targetList = this.getTargetList();
|
||||
// 获取switch node
|
||||
Node switchNode = this.getSwitchNode();
|
||||
// 获取target List
|
||||
List<Executable> targetList = this.getTargetList();
|
||||
|
||||
// 先去判断isAccess方法,如果isAccess方法都返回false,整个SWITCH表达式不执行
|
||||
if (!switchNode.isAccess(slotIndex)) {
|
||||
return;
|
||||
}
|
||||
// 先去判断isAccess方法,如果isAccess方法都返回false,整个SWITCH表达式不执行
|
||||
if (!switchNode.isAccess(slotIndex)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 先执行switch节点
|
||||
switchNode.setCurrChainId(this.getCurrChainId());
|
||||
switchNode.execute(slotIndex);
|
||||
// 先执行switch节点
|
||||
switchNode.setCurrChainId(this.getCurrChainId());
|
||||
switchNode.execute(slotIndex);
|
||||
|
||||
// 拿到switch节点的结果
|
||||
String targetId = switchNode.getItemResultMetaValue(slotIndex);
|
||||
// 拿到switch节点的结果
|
||||
String targetId = switchNode.getItemResultMetaValue(slotIndex);
|
||||
|
||||
Slot slot = DataBus.getSlot(slotIndex);
|
||||
Slot slot = DataBus.getSlot(slotIndex);
|
||||
|
||||
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 -> {
|
||||
return (StrUtil.startWith(_targetId, TAG_PREFIX) && _targetTag.equals(executable.getTag()))
|
||||
|| ((StrUtil.isEmpty(_targetId) || _targetId.equals(executable.getId()))
|
||||
&& (StrUtil.isEmpty(_targetTag) || _targetTag.equals(executable.getTag())));
|
||||
}).findFirst().orElse(null);
|
||||
}
|
||||
else {
|
||||
targetExecutor = targetList.stream()
|
||||
.filter(executable -> executable.getId().equals(targetId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNull(targetExecutor)) {
|
||||
// 没有匹配到执行节点,则走默认的执行节点
|
||||
targetExecutor = this.getDefaultExecutor();
|
||||
}
|
||||
|
||||
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);
|
||||
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 -> {
|
||||
return (StrUtil.startWith(_targetId, TAG_PREFIX) && _targetTag.equals(executable.getTag()))
|
||||
|| ((StrUtil.isEmpty(_targetId) || _targetId.equals(executable.getId()))
|
||||
&& (StrUtil.isEmpty(_targetTag) || _targetTag.equals(executable.getTag())));
|
||||
}).findFirst().orElse(null);
|
||||
}
|
||||
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);
|
||||
targetExecutor = targetList.stream()
|
||||
.filter(executable -> executable.getId().equals(targetId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNull(targetExecutor)) {
|
||||
// 没有匹配到执行节点,则走默认的执行节点
|
||||
targetExecutor = this.getDefaultExecutor();
|
||||
}
|
||||
|
||||
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 {
|
||||
throw new SwitchTypeErrorException("switch instance must be NodeSwitchComponent");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -342,27 +342,38 @@ public class LFLog implements Logger{
|
|||
|
||||
@Override
|
||||
public void error(String s) {
|
||||
this.log.error(getRId() + s);
|
||||
if (isPrint()) {
|
||||
this.log.error(getRId() + s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String s, Object o) {
|
||||
this.log.error(getRId() + s, o);
|
||||
if (isPrint()) {
|
||||
this.log.error(getRId() + s, o);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String s, Object o, Object o1) {
|
||||
this.log.error(getRId() + s, o, o1);
|
||||
if (isPrint()) {
|
||||
this.log.error(getRId() + s, o, o1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String s, Object... objects) {
|
||||
this.log.error(getRId() + s, objects);
|
||||
if (isPrint()) {
|
||||
this.log.error(getRId() + s, objects);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String s, Throwable throwable) {
|
||||
this.log.error(getRId() + s, throwable);
|
||||
if (isPrint()) {
|
||||
this.log.error(getRId() + s, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -372,26 +383,36 @@ public class LFLog implements Logger{
|
|||
|
||||
@Override
|
||||
public void error(Marker marker, String s) {
|
||||
this.log.error(marker, getRId() + s);
|
||||
if (isPrint()) {
|
||||
this.log.error(marker, getRId() + s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Marker marker, String s, Object o) {
|
||||
this.log.error(marker, getRId() + s, o);
|
||||
if (isPrint()) {
|
||||
this.log.error(marker, getRId() + s, o);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Marker marker, String s, Object o, Object o1) {
|
||||
this.log.error(marker, getRId() + s, o, o1);
|
||||
if (isPrint()) {
|
||||
this.log.error(marker, getRId() + s, o, o1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Marker marker, String s, Object... objects) {
|
||||
this.log.error(marker, getRId() + s, objects);
|
||||
if (isPrint()) {
|
||||
this.log.error(marker, getRId() + s, objects);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Marker marker, String s, Throwable throwable) {
|
||||
this.log.error(marker, getRId() + s, throwable);
|
||||
if (isPrint()) {
|
||||
this.log.error(marker, getRId() + s, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,13 +63,21 @@ public class MonitorFile {
|
|||
@Override
|
||||
public void onFileChange(File file) {
|
||||
LOG.info("file modify,filePath={}", file.getAbsolutePath());
|
||||
FlowExecutorHolder.loadInstance().reloadRule();
|
||||
this.reloadRule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDelete(File file) {
|
||||
LOG.info("file delete,filePath={}", file.getAbsolutePath());
|
||||
FlowExecutorHolder.loadInstance().reloadRule();
|
||||
this.reloadRule();
|
||||
}
|
||||
|
||||
private void reloadRule() {
|
||||
try {
|
||||
FlowExecutorHolder.loadInstance().reloadRule();
|
||||
} catch (Exception e) {
|
||||
LOG.error("reload rule error", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 创建文件变化监听器
|
||||
|
|
|
@ -140,6 +140,8 @@ public class ParserHelper {
|
|||
// 校验加载的 chainName 是否有重复的
|
||||
// TODO 这里是否有个问题,当混合格式加载的时候,2个同名的Chain在不同的文件里,就不行了
|
||||
String chainName = Optional.ofNullable(e.attributeValue(ID)).orElse(e.attributeValue(NAME));
|
||||
// 检查 chainName
|
||||
checkChainId(chainName, e.getText());
|
||||
if (!chainNameSet.add(chainName)) {
|
||||
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
|
||||
}
|
||||
|
@ -202,9 +204,11 @@ public class ParserHelper {
|
|||
JsonNode innerJsonObject = iterator.next();
|
||||
// 校验加载的 chainName 是否有重复的
|
||||
// TODO 这里是否有个问题,当混合格式加载的时候,2个同名的Chain在不同的文件里,就不行了
|
||||
String chainName = Optional.ofNullable(innerJsonObject.get(ID))
|
||||
.orElse(innerJsonObject.get(NAME))
|
||||
.textValue();
|
||||
JsonNode chainNameJsonNode = Optional.ofNullable(innerJsonObject.get(ID))
|
||||
.orElse(innerJsonObject.get(NAME));
|
||||
String chainName = Optional.ofNullable(chainNameJsonNode).map(JsonNode::textValue).orElse(null);
|
||||
// 检查 chainName
|
||||
checkChainId(chainName, innerJsonObject.toPrettyString());
|
||||
if (!chainNameSet.add(chainName)) {
|
||||
throw new ChainDuplicateException(String.format("[chain name duplicate] chainName=%s", chainName));
|
||||
}
|
||||
|
@ -250,6 +254,17 @@ public class ParserHelper {
|
|||
chainELBuilder.setEL(el).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 chainId
|
||||
* @param chainId chainId
|
||||
* @param elData elData
|
||||
*/
|
||||
private static void checkChainId(String chainId, String elData) {
|
||||
if (StrUtil.isBlank(chainId)) {
|
||||
throw new ParseException("missing chain id in expression \r\n" + elData);
|
||||
}
|
||||
}
|
||||
|
||||
private static class RegexUtil {
|
||||
|
||||
// java 注释的正则表达式
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.yomahub.liteflow.script.proxy;
|
|||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.*;
|
||||
import com.yomahub.liteflow.exception.LiteFlowException;
|
||||
import com.yomahub.liteflow.exception.ProxyException;
|
||||
import com.yomahub.liteflow.exception.ScriptBeanMethodInvokeException;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
|
@ -10,8 +11,18 @@ import com.yomahub.liteflow.script.annotation.ScriptBean;
|
|||
import com.yomahub.liteflow.util.LiteFlowProxyUtil;
|
||||
import com.yomahub.liteflow.util.SerialsUtil;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.description.method.ParameterDescription;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
|
||||
import net.bytebuddy.implementation.FixedValue;
|
||||
import net.bytebuddy.implementation.InvocationHandlerAdapter;
|
||||
import net.bytebuddy.implementation.MethodCall;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
import net.bytebuddy.implementation.bytecode.constant.DefaultValue;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
@ -56,19 +67,18 @@ public class ScriptBeanProxy {
|
|||
}
|
||||
|
||||
try {
|
||||
return new ByteBuddy().subclass(orignalClass)
|
||||
.name(StrUtil.format("{}.ByteBuddy${}", ClassUtil.getPackage(orignalClass),
|
||||
SerialsUtil.generateShortUUID()))
|
||||
Class<?> c = 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();
|
||||
.getLoaded();
|
||||
|
||||
return ReflectUtil.newInstanceIfPossible(c);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new LiteFlowException(e);
|
||||
throw new ProxyException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -136,9 +136,7 @@ public class DataBus {
|
|||
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", slotIndex);
|
||||
}
|
||||
LOG.info("slot[{}] released", slotIndex);
|
||||
SLOTS.remove(slotIndex);
|
||||
QUEUE.add(slotIndex);
|
||||
OCCUPY_COUNT.decrementAndGet();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.yomahub.liteflow.spi;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
|
||||
/**
|
||||
|
@ -10,8 +11,8 @@ import com.yomahub.liteflow.slot.Slot;
|
|||
*/
|
||||
public interface CmpAroundAspect extends SpiPriority {
|
||||
|
||||
void beforeProcess(String nodeId, Slot slot);
|
||||
void beforeProcess(NodeComponent cmp);
|
||||
|
||||
void afterProcess(String nodeId, Slot slot);
|
||||
void afterProcess(NodeComponent cmp);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.yomahub.liteflow.spi;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 环境容器SPI接口
|
||||
*
|
||||
|
@ -8,18 +10,27 @@ package com.yomahub.liteflow.spi;
|
|||
*/
|
||||
public interface ContextAware extends SpiPriority {
|
||||
|
||||
<T> T getBean(String name);
|
||||
<T> T getBean(String name);
|
||||
|
||||
<T> T getBean(Class<T> clazz);
|
||||
<T> T getBean(Class<T> clazz);
|
||||
|
||||
<T> T registerBean(String beanName, Class<T> clazz);
|
||||
<T> T registerBean(String beanName, Class<T> clazz);
|
||||
|
||||
<T> T registerBean(Class<T> clazz);
|
||||
<T> T registerBean(Class<T> clazz);
|
||||
|
||||
<T> T registerBean(String beanName, Object bean);
|
||||
<T> T registerBean(String beanName, Object bean);
|
||||
|
||||
<T> T registerOrGet(String beanName, Class<T> clazz);
|
||||
<T> T registerOrGet(String beanName, Class<T> clazz);
|
||||
|
||||
boolean hasBean(String beanName);
|
||||
/**
|
||||
* 获取指定类型对应的所有Bean,包括子类
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param type 类、接口,null表示获取所有bean
|
||||
* @return 类型对应的bean,key是bean注册的name,value是Bean
|
||||
*/
|
||||
<T> Map<String, T> getBeansOfType(Class<T> type);
|
||||
|
||||
boolean hasBean(String beanName);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,6 @@ import com.yomahub.liteflow.core.NodeComponent;
|
|||
*/
|
||||
public interface LiteflowComponentSupport extends SpiPriority {
|
||||
|
||||
String getCmpName(NodeComponent nodeComponent);
|
||||
String getCmpName(Object nodeComponent);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.yomahub.liteflow.spi.local;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
import com.yomahub.liteflow.spi.CmpAroundAspect;
|
||||
|
||||
|
@ -12,12 +13,12 @@ import com.yomahub.liteflow.spi.CmpAroundAspect;
|
|||
public class LocalCmpAroundAspect implements CmpAroundAspect {
|
||||
|
||||
@Override
|
||||
public void beforeProcess(String nodeId, Slot slot) {
|
||||
public void beforeProcess(NodeComponent cmp) {
|
||||
// 无spring环境下为空实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(String nodeId, Slot slot) {
|
||||
public void afterProcess(NodeComponent cmp) {
|
||||
// 无spring环境下为空实现
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.yomahub.liteflow.spi.local;
|
|||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.yomahub.liteflow.spi.ContextAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 非Spring环境容器实现 其实非Spring没有环境容器,所以这是个空实现
|
||||
*
|
||||
|
@ -11,44 +13,49 @@ import com.yomahub.liteflow.spi.ContextAware;
|
|||
*/
|
||||
public class LocalContextAware implements ContextAware {
|
||||
|
||||
@Override
|
||||
public <T> T getBean(String name) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public <T> T getBean(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getBean(Class<T> clazz) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public <T> T getBean(Class<T> clazz) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Class<T> clazz) {
|
||||
return ReflectUtil.newInstance(clazz);
|
||||
}
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Class<T> clazz) {
|
||||
return ReflectUtil.newInstance(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(Class<T> clazz) {
|
||||
return registerBean(null, clazz);
|
||||
}
|
||||
@Override
|
||||
public <T> T registerBean(Class<T> clazz) {
|
||||
return registerBean(null, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Object bean) {
|
||||
return (T) bean;
|
||||
}
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Object bean) {
|
||||
return (T) bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerOrGet(String beanName, Class<T> clazz) {
|
||||
return registerBean(beanName, clazz);
|
||||
}
|
||||
@Override
|
||||
public <T> T registerOrGet(String beanName, Class<T> clazz) {
|
||||
return registerBean(beanName, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBean(String beanName) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public <T> Map<String, T> getBeansOfType(Class<T> type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 2;
|
||||
}
|
||||
@Override
|
||||
public boolean hasBean(String beanName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport;
|
|||
public class LocalLiteflowComponentSupport implements LiteflowComponentSupport {
|
||||
|
||||
@Override
|
||||
public String getCmpName(NodeComponent nodeComponent) {
|
||||
public String getCmpName(Object nodeComponent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.yomahub.liteflow.log.LFLoggerManager;
|
|||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +16,6 @@ public class LiteFlowExecutorPoolShutdown {
|
|||
|
||||
private static final LFLog LOG = LFLoggerManager.getLogger(LiteFlowExecutorPoolShutdown.class);
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() throws Exception {
|
||||
ExecutorService executorService = ContextAwareHolder.loadContextAware().getBean("whenExecutors");
|
||||
|
||||
|
|
|
@ -71,6 +71,9 @@ public class SQLXmlELParser extends ClassXmlFlowELParser {
|
|||
* @param sqlParserVO sqlParserVO
|
||||
*/
|
||||
private void checkParserVO(SQLParserVO sqlParserVO) {
|
||||
if (sqlParserVO.isDefaultDataSource()) {
|
||||
return;
|
||||
}
|
||||
if (StrUtil.isEmpty(sqlParserVO.getUrl())) {
|
||||
throw new ELSQLException(StrFormatter.format(ERROR_MSG_PATTERN, "url"));
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.yomahub.liteflow.parser.sql.exception.ELSQLException;
|
|||
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
@ -25,331 +24,279 @@ 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 SCRIPT_WITH_LANGUAG_SQL_PATTERN = "SELECT {},{},{},{},{} FROM {} WHERE {}=?";
|
||||
private static final String SCRIPT_WITH_LANGUAG_SQL_PATTERN = "SELECT {},{},{},{},{} FROM {} WHERE {}=?";
|
||||
|
||||
private static final String CHAIN_XML_PATTERN = "<chain name=\"{}\">{}</chain>";
|
||||
private static final String CHAIN_XML_PATTERN = "<chain name=\"{}\">{}</chain>";
|
||||
|
||||
private static final String NODE_XML_PATTERN = "<nodes>{}</nodes>";
|
||||
private static final String NODE_XML_PATTERN = "<nodes>{}</nodes>";
|
||||
|
||||
private static final String NODE_ITEM_XML_PATTERN = "<node id=\"{}\" name=\"{}\" type=\"{}\"><![CDATA[{}]]></node>";
|
||||
private static final String NODE_ITEM_XML_PATTERN = "<node id=\"{}\" name=\"{}\" type=\"{}\"><![CDATA[{}]]></node>";
|
||||
|
||||
private static final String NODE_ITEM_WITH_LANGUAGE_XML_PATTERN = "<node id=\"{}\" name=\"{}\" type=\"{}\" language=\"{}\"><![CDATA[{}]]></node>";
|
||||
private static final String NODE_ITEM_WITH_LANGUAGE_XML_PATTERN = "<node id=\"{}\" name=\"{}\" type=\"{}\" language=\"{}\"><![CDATA[{}]]></node>";
|
||||
|
||||
private static final String XML_PATTERN = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow>{}{}</flow>";
|
||||
private static final String XML_PATTERN = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow>{}{}</flow>";
|
||||
|
||||
private static final Integer FETCH_SIZE_MAX = 1000;
|
||||
private static final Integer FETCH_SIZE_MAX = 1000;
|
||||
|
||||
private SQLParserVO sqlParserVO;
|
||||
private SQLParserVO sqlParserVO;
|
||||
|
||||
private static JDBCHelper INSTANCE;
|
||||
private static JDBCHelper INSTANCE;
|
||||
|
||||
/**
|
||||
* 初始化 INSTANCE
|
||||
*/
|
||||
public static void init(SQLParserVO sqlParserVO) {
|
||||
try {
|
||||
INSTANCE = new JDBCHelper();
|
||||
Class.forName(sqlParserVO.getDriverClassName());
|
||||
INSTANCE.setSqlParserVO(sqlParserVO);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new ELSQLException(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 初始化 INSTANCE
|
||||
*/
|
||||
public static void init(SQLParserVO sqlParserVO) {
|
||||
try {
|
||||
INSTANCE = new JDBCHelper();
|
||||
if (StrUtil.isNotBlank(sqlParserVO.getDriverClassName())) {
|
||||
Class.forName(sqlParserVO.getDriverClassName());
|
||||
}
|
||||
INSTANCE.setSqlParserVO(sqlParserVO);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ELSQLException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 INSTANCE
|
||||
*/
|
||||
public static JDBCHelper getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
/**
|
||||
* 获取 INSTANCE
|
||||
*/
|
||||
public static JDBCHelper getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接
|
||||
*/
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 获取 ElData 数据内容
|
||||
*/
|
||||
public String getContent() {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
/**
|
||||
* 获取 ElData 数据内容
|
||||
*/
|
||||
public String getContent() {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String chainTableName = sqlParserVO.getChainTableName();
|
||||
String elDataField = sqlParserVO.getElDataField();
|
||||
String chainNameField = sqlParserVO.getChainNameField();
|
||||
String chainApplicationNameField = sqlParserVO.getChainApplicationNameField();
|
||||
String applicationName = sqlParserVO.getApplicationName();
|
||||
|
||||
String chainTableName = sqlParserVO.getChainTableName();
|
||||
String elDataField = sqlParserVO.getElDataField();
|
||||
String chainNameField = sqlParserVO.getChainNameField();
|
||||
String chainApplicationNameField = sqlParserVO.getChainApplicationNameField();
|
||||
String applicationName = sqlParserVO.getApplicationName();
|
||||
if (StrUtil.isBlank(chainTableName)) {
|
||||
throw new ELSQLException("You did not define the chainTableName property");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(chainTableName)) {
|
||||
throw new ELSQLException("You did not define the chainTableName property");
|
||||
}
|
||||
if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(chainApplicationNameField)) {
|
||||
throw new ELSQLException("You did not define the applicationName or chainApplicationNameField property");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(chainApplicationNameField)) {
|
||||
throw new ELSQLException("You did not define the applicationName or chainApplicationNameField property");
|
||||
}
|
||||
String sqlCmd = StrUtil.format(SQL_PATTERN, chainNameField, elDataField, chainTableName,
|
||||
chainApplicationNameField);
|
||||
|
||||
String sqlCmd = StrUtil.format(SQL_PATTERN, chainNameField, elDataField, chainTableName,
|
||||
chainApplicationNameField);
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
conn = LiteFlowJdbcUtil.getConn(sqlParserVO);
|
||||
stmt = conn.prepareStatement(sqlCmd, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
// 设置游标拉取数量
|
||||
stmt.setFetchSize(FETCH_SIZE_MAX);
|
||||
stmt.setString(1, applicationName);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
List<String> 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();
|
||||
while (rs.next()) {
|
||||
String elData = getStringFromResultSet(rs, elDataField);
|
||||
String chainName = getStringFromResultSet(rs, chainNameField);
|
||||
|
||||
while (rs.next()) {
|
||||
String elData = getStringFromResultSet(rs, elDataField);
|
||||
String chainName = getStringFromResultSet(rs, chainNameField);
|
||||
result.add(StrUtil.format(CHAIN_XML_PATTERN, XmlUtil.escape(chainName), elData));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ELSQLException(e.getMessage());
|
||||
} finally {
|
||||
// 关闭连接
|
||||
LiteFlowJdbcUtil.close(conn, stmt, rs);
|
||||
}
|
||||
|
||||
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 chainsContent = CollUtil.join(result, StrUtil.EMPTY);
|
||||
|
||||
String chainsContent = CollUtil.join(result, StrUtil.EMPTY);
|
||||
String nodesContent;
|
||||
if (hasScriptData()) {
|
||||
nodesContent = getScriptNodes();
|
||||
} else {
|
||||
nodesContent = StrUtil.EMPTY;
|
||||
}
|
||||
|
||||
String nodesContent;
|
||||
if (hasScriptData()) {
|
||||
nodesContent = getScriptNodes();
|
||||
}
|
||||
else {
|
||||
nodesContent = StrUtil.EMPTY;
|
||||
}
|
||||
return StrUtil.format(XML_PATTERN, nodesContent, chainsContent);
|
||||
}
|
||||
|
||||
return StrUtil.format(XML_PATTERN, nodesContent, chainsContent);
|
||||
}
|
||||
/**
|
||||
* 获取脚本节点内容
|
||||
*/
|
||||
public String getScriptNodes() {
|
||||
String scriptLanguageField = sqlParserVO.getScriptLanguageField();
|
||||
if (StrUtil.isNotBlank(scriptLanguageField)) {
|
||||
return getScriptNodesWithLanguage();
|
||||
}
|
||||
|
||||
public String getScriptNodes() {
|
||||
String scriptLanguageField = sqlParserVO.getScriptLanguageField();
|
||||
if (StrUtil.isNotBlank(scriptLanguageField)) {
|
||||
return getScriptNodesWithLanguage();
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
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 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();
|
||||
if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) {
|
||||
throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) {
|
||||
throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property");
|
||||
}
|
||||
String sqlCmd = StrUtil.format(SCRIPT_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField,
|
||||
scriptTypeField, scriptTableName, scriptApplicationNameField);
|
||||
try {
|
||||
conn = LiteFlowJdbcUtil.getConn(sqlParserVO);
|
||||
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 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();
|
||||
while (rs.next()) {
|
||||
String id = getStringFromResultSet(rs, scriptIdField);
|
||||
String data = getStringFromResultSet(rs, scriptDataField);
|
||||
String name = getStringFromResultSet(rs, scriptNameField);
|
||||
String type = getStringFromResultSet(rs, scriptTypeField);
|
||||
|
||||
while (rs.next()) {
|
||||
String id = getStringFromResultSet(rs, scriptIdField);
|
||||
String data = getStringFromResultSet(rs, scriptDataField);
|
||||
String name = getStringFromResultSet(rs, scriptNameField);
|
||||
String type = getStringFromResultSet(rs, scriptTypeField);
|
||||
NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type);
|
||||
if (Objects.isNull(nodeTypeEnum)) {
|
||||
throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type));
|
||||
}
|
||||
|
||||
NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type);
|
||||
if (Objects.isNull(nodeTypeEnum)) {
|
||||
throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type));
|
||||
}
|
||||
if (!nodeTypeEnum.isScript()) {
|
||||
throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type));
|
||||
}
|
||||
|
||||
if (!nodeTypeEnum.isScript()) {
|
||||
throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type));
|
||||
}
|
||||
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 {
|
||||
// 关闭连接
|
||||
LiteFlowJdbcUtil.close(conn, stmt, rs);
|
||||
}
|
||||
return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
/**
|
||||
* 获取脚本节点(带语言)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getScriptNodesWithLanguage() {
|
||||
|
||||
public String getScriptNodesWithLanguage() {
|
||||
List<String> result = new ArrayList<>();
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
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 scriptLanguageField = sqlParserVO.getScriptLanguageField();
|
||||
|
||||
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 scriptLanguageField = sqlParserVO.getScriptLanguageField();
|
||||
if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) {
|
||||
throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(applicationName) || StrUtil.isBlank(scriptApplicationNameField)) {
|
||||
throw new ELSQLException("You did not define the applicationName or scriptApplicationNameField property");
|
||||
}
|
||||
String sqlCmd = StrUtil.format(SCRIPT_WITH_LANGUAG_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField,
|
||||
scriptTypeField, scriptLanguageField, scriptTableName, scriptApplicationNameField);
|
||||
try {
|
||||
conn = LiteFlowJdbcUtil.getConn(sqlParserVO);
|
||||
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 sqlCmd = StrUtil.format(SCRIPT_WITH_LANGUAG_SQL_PATTERN, scriptIdField, scriptDataField, scriptNameField,
|
||||
scriptTypeField, scriptLanguageField, 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();
|
||||
while (rs.next()) {
|
||||
String id = getStringFromResultSet(rs, scriptIdField);
|
||||
String data = getStringFromResultSet(rs, scriptDataField);
|
||||
String name = getStringFromResultSet(rs, scriptNameField);
|
||||
String type = getStringFromResultSet(rs, scriptTypeField);
|
||||
String language = getStringFromResultSet(rs, scriptLanguageField);
|
||||
|
||||
while (rs.next()) {
|
||||
String id = getStringFromResultSet(rs, scriptIdField);
|
||||
String data = getStringFromResultSet(rs, scriptDataField);
|
||||
String name = getStringFromResultSet(rs, scriptNameField);
|
||||
String type = getStringFromResultSet(rs, scriptTypeField);
|
||||
String language = getStringFromResultSet(rs, scriptLanguageField);
|
||||
NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type);
|
||||
if (Objects.isNull(nodeTypeEnum)) {
|
||||
throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type));
|
||||
}
|
||||
|
||||
NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getEnumByCode(type);
|
||||
if (Objects.isNull(nodeTypeEnum)) {
|
||||
throw new ELSQLException(StrUtil.format("Invalid type value[{}]", type));
|
||||
}
|
||||
if (!nodeTypeEnum.isScript()) {
|
||||
throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type));
|
||||
}
|
||||
|
||||
if (!nodeTypeEnum.isScript()) {
|
||||
throw new ELSQLException(StrUtil.format("The type value[{}] is not a script type", type));
|
||||
}
|
||||
if (!ScriptTypeEnum.checkScriptType(language)) {
|
||||
throw new ELSQLException(StrUtil.format("The language value[{}] is error", language));
|
||||
}
|
||||
|
||||
if (!ScriptTypeEnum.checkScriptType(language)) {
|
||||
throw new ELSQLException(StrUtil.format("The language value[{}] is error", language));
|
||||
}
|
||||
result.add(StrUtil.format(NODE_ITEM_WITH_LANGUAGE_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name),
|
||||
type, language, data));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ELSQLException(e.getMessage());
|
||||
} finally {
|
||||
// 关闭连接
|
||||
LiteFlowJdbcUtil.close(conn, stmt, rs);
|
||||
}
|
||||
return StrUtil.format(NODE_XML_PATTERN, CollUtil.join(result, StrUtil.EMPTY));
|
||||
}
|
||||
|
||||
result.add(StrUtil.format(NODE_ITEM_WITH_LANGUAGE_XML_PATTERN, XmlUtil.escape(id), XmlUtil.escape(name),
|
||||
type, language, 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));
|
||||
}
|
||||
private boolean hasScriptData() {
|
||||
if (StrUtil.isBlank(sqlParserVO.getScriptTableName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭连接
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sqlCmd = StrUtil.format(SCRIPT_SQL_CHECK_PATTERN, sqlParserVO.getScriptTableName(),
|
||||
sqlParserVO.getScriptApplicationNameField());
|
||||
try {
|
||||
conn = LiteFlowJdbcUtil.getConn(sqlParserVO);
|
||||
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 {
|
||||
// 关闭连接
|
||||
LiteFlowJdbcUtil.close(conn, stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasScriptData() {
|
||||
if (StrUtil.isBlank(sqlParserVO.getScriptTableName())) {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
private SQLParserVO getSqlParserVO() {
|
||||
return sqlParserVO;
|
||||
}
|
||||
|
||||
// #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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
package com.yomahub.liteflow.parser.sql.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.parser.sql.exception.ELSQLException;
|
||||
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.*;
|
||||
import java.util.Map;
|
||||
|
||||
public class LiteFlowJdbcUtil {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LiteFlowJdbcUtil.class);
|
||||
private static final String CHECK_SQL_PATTERN = "SELECT {},{} FROM {} WHERE {}='{}'";
|
||||
|
||||
/**
|
||||
* 获取链接
|
||||
* 此方法会根据配置,判读使用指定数据源,还是IOC容器中已有的数据源
|
||||
*
|
||||
* @param sqlParserVO
|
||||
* @return
|
||||
*/
|
||||
public static Connection getConn(SQLParserVO sqlParserVO) {
|
||||
Connection connection = null;
|
||||
String url = sqlParserVO.getUrl();
|
||||
String username = sqlParserVO.getUsername();
|
||||
String password = sqlParserVO.getPassword();
|
||||
|
||||
try {
|
||||
// 如果不配置 jdbc 连接相关配置,代表使用项目数据源
|
||||
if (sqlParserVO.isDefaultDataSource()) {
|
||||
String executeSql = buildCheckSql(sqlParserVO);
|
||||
Map<String, DataSource> dataSourceMap = ContextAwareHolder.loadContextAware().getBeansOfType(DataSource.class);
|
||||
// 遍历数据源,多数据源场景下,判断哪个数据源有 liteflow 配置
|
||||
for (Map.Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
|
||||
String dataSourceName = entry.getKey();
|
||||
DataSource dataSource = entry.getValue();
|
||||
|
||||
if (checkConnectionCanExecuteSql(dataSource.getConnection(), executeSql)) {
|
||||
connection = dataSource.getConnection();
|
||||
LOG.info("use dataSourceName[{}],has found liteflow config", dataSourceName);
|
||||
} else {
|
||||
LOG.info("check dataSourceName[{}],but not has liteflow config", dataSourceName);
|
||||
}
|
||||
}
|
||||
if (connection == null) {
|
||||
throw new ELSQLException("can not found liteflow config in dataSourceName " + dataSourceMap.keySet());
|
||||
}
|
||||
}
|
||||
// 如果配置 jdbc 连接相关配置,代表使用指定链接信息
|
||||
else {
|
||||
connection = DriverManager.getConnection(url, username, password);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ELSQLException(e.getMessage());
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断连接是否可以执行指定 sql
|
||||
*
|
||||
* @param conn 连接
|
||||
* @param sql 执行 sql
|
||||
*/
|
||||
public static boolean checkConnectionCanExecuteSql(Connection conn, String sql) {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setFetchSize(1);
|
||||
rs = stmt.executeQuery();
|
||||
return rs.next();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
} finally {
|
||||
// 关闭连接
|
||||
close(conn, stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭
|
||||
*
|
||||
* @param conn conn
|
||||
* @param conn conn
|
||||
* @param rs rs
|
||||
*/
|
||||
public static 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建检查 sql
|
||||
*
|
||||
* @param sqlParserVO
|
||||
* @return
|
||||
*/
|
||||
private static String buildCheckSql(SQLParserVO sqlParserVO) {
|
||||
String chainTableName = sqlParserVO.getChainTableName();
|
||||
String elDataField = sqlParserVO.getElDataField();
|
||||
String chainNameField = sqlParserVO.getChainNameField();
|
||||
String chainApplicationNameField = sqlParserVO.getChainApplicationNameField();
|
||||
String applicationName = sqlParserVO.getApplicationName();
|
||||
return StrUtil.format(CHECK_SQL_PATTERN, chainNameField, elDataField, chainTableName, chainApplicationNameField, applicationName);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.yomahub.liteflow.parser.sql.vo;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 用于解析 RuleSourceExtData 的 VO 类,用于 sql 模式中
|
||||
*
|
||||
|
@ -8,212 +10,219 @@ package com.yomahub.liteflow.parser.sql.vo;
|
|||
*/
|
||||
public class SQLParserVO {
|
||||
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 驱动
|
||||
*/
|
||||
private String driverClassName;
|
||||
/**
|
||||
* 驱动
|
||||
*/
|
||||
private String driverClassName;
|
||||
|
||||
/**
|
||||
* 账号名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 账号名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
private String applicationName;
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
private String applicationName;
|
||||
|
||||
/**
|
||||
* chain表名
|
||||
*/
|
||||
private String chainTableName;
|
||||
/**
|
||||
* chain表名
|
||||
*/
|
||||
private String chainTableName;
|
||||
|
||||
/**
|
||||
* chain表里的应用名字段
|
||||
*/
|
||||
private String chainApplicationNameField = "application_name";
|
||||
/**
|
||||
* chain表里的应用名字段
|
||||
*/
|
||||
private String chainApplicationNameField = "application_name";
|
||||
|
||||
/**
|
||||
* chainName
|
||||
*/
|
||||
private String chainNameField = "chain_name";
|
||||
/**
|
||||
* chainName
|
||||
*/
|
||||
private String chainNameField = "chain_name";
|
||||
|
||||
/**
|
||||
* el 表达式相关数据
|
||||
*/
|
||||
private String elDataField = "el_data";
|
||||
/**
|
||||
* el 表达式相关数据
|
||||
*/
|
||||
private String elDataField = "el_data";
|
||||
|
||||
/**
|
||||
* 脚本 node 表名
|
||||
*/
|
||||
private String scriptTableName;
|
||||
/**
|
||||
* 脚本 node 表名
|
||||
*/
|
||||
private String scriptTableName;
|
||||
|
||||
/**
|
||||
* script表里的应用名字段
|
||||
*/
|
||||
private String scriptApplicationNameField = "application_name";
|
||||
/**
|
||||
* script表里的应用名字段
|
||||
*/
|
||||
private String scriptApplicationNameField = "application_name";
|
||||
|
||||
/**
|
||||
* 脚本 node id 字段
|
||||
*/
|
||||
private String scriptIdField = "script_id";
|
||||
/**
|
||||
* 脚本 node id 字段
|
||||
*/
|
||||
private String scriptIdField = "script_id";
|
||||
|
||||
/**
|
||||
* 脚本 node name 字段
|
||||
*/
|
||||
private String scriptNameField = "script_name";
|
||||
/**
|
||||
* 脚本 node name 字段
|
||||
*/
|
||||
private String scriptNameField = "script_name";
|
||||
|
||||
/**
|
||||
* 脚本 node data 字段
|
||||
*/
|
||||
private String scriptDataField = "script_data";
|
||||
/**
|
||||
* 脚本 node data 字段
|
||||
*/
|
||||
private String scriptDataField = "script_data";
|
||||
|
||||
/**
|
||||
* 脚本 node type 字段
|
||||
*/
|
||||
private String scriptTypeField = "script_type";
|
||||
/**
|
||||
* 脚本 node type 字段
|
||||
*/
|
||||
private String scriptTypeField = "script_type";
|
||||
|
||||
/**
|
||||
* 脚本 node language 字段
|
||||
*/
|
||||
private String scriptLanguageField;
|
||||
/**
|
||||
* 脚本 node language 字段
|
||||
*/
|
||||
private String scriptLanguageField;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getDriverClassName() {
|
||||
return driverClassName;
|
||||
}
|
||||
public String getDriverClassName() {
|
||||
return driverClassName;
|
||||
}
|
||||
|
||||
public void setDriverClassName(String driverClassName) {
|
||||
this.driverClassName = driverClassName;
|
||||
}
|
||||
public void setDriverClassName(String driverClassName) {
|
||||
this.driverClassName = driverClassName;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
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 getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
public void setApplicationName(String applicationName) {
|
||||
this.applicationName = applicationName;
|
||||
}
|
||||
public void setApplicationName(String applicationName) {
|
||||
this.applicationName = applicationName;
|
||||
}
|
||||
|
||||
public String getChainTableName() {
|
||||
return chainTableName;
|
||||
}
|
||||
public String getChainTableName() {
|
||||
return chainTableName;
|
||||
}
|
||||
|
||||
public void setChainTableName(String chainTableName) {
|
||||
this.chainTableName = chainTableName;
|
||||
}
|
||||
public void setChainTableName(String chainTableName) {
|
||||
this.chainTableName = chainTableName;
|
||||
}
|
||||
|
||||
public String getChainApplicationNameField() {
|
||||
return chainApplicationNameField;
|
||||
}
|
||||
public String getChainApplicationNameField() {
|
||||
return chainApplicationNameField;
|
||||
}
|
||||
|
||||
public void setChainApplicationNameField(String chainApplicationNameField) {
|
||||
this.chainApplicationNameField = chainApplicationNameField;
|
||||
}
|
||||
public void setChainApplicationNameField(String chainApplicationNameField) {
|
||||
this.chainApplicationNameField = chainApplicationNameField;
|
||||
}
|
||||
|
||||
public String getChainNameField() {
|
||||
return chainNameField;
|
||||
}
|
||||
public String getChainNameField() {
|
||||
return chainNameField;
|
||||
}
|
||||
|
||||
public void setChainNameField(String chainNameField) {
|
||||
this.chainNameField = chainNameField;
|
||||
}
|
||||
public void setChainNameField(String chainNameField) {
|
||||
this.chainNameField = chainNameField;
|
||||
}
|
||||
|
||||
public String getElDataField() {
|
||||
return elDataField;
|
||||
}
|
||||
public String getElDataField() {
|
||||
return elDataField;
|
||||
}
|
||||
|
||||
public void setElDataField(String elDataField) {
|
||||
this.elDataField = elDataField;
|
||||
}
|
||||
public void setElDataField(String elDataField) {
|
||||
this.elDataField = elDataField;
|
||||
}
|
||||
|
||||
public String getScriptTableName() {
|
||||
return scriptTableName;
|
||||
}
|
||||
public String getScriptTableName() {
|
||||
return scriptTableName;
|
||||
}
|
||||
|
||||
public void setScriptTableName(String scriptTableName) {
|
||||
this.scriptTableName = scriptTableName;
|
||||
}
|
||||
public void setScriptTableName(String scriptTableName) {
|
||||
this.scriptTableName = scriptTableName;
|
||||
}
|
||||
|
||||
public String getScriptApplicationNameField() {
|
||||
return scriptApplicationNameField;
|
||||
}
|
||||
public String getScriptApplicationNameField() {
|
||||
return scriptApplicationNameField;
|
||||
}
|
||||
|
||||
public void setScriptApplicationNameField(String scriptApplicationNameField) {
|
||||
this.scriptApplicationNameField = scriptApplicationNameField;
|
||||
}
|
||||
public void setScriptApplicationNameField(String scriptApplicationNameField) {
|
||||
this.scriptApplicationNameField = scriptApplicationNameField;
|
||||
}
|
||||
|
||||
public String getScriptIdField() {
|
||||
return scriptIdField;
|
||||
}
|
||||
public String getScriptIdField() {
|
||||
return scriptIdField;
|
||||
}
|
||||
|
||||
public void setScriptIdField(String scriptIdField) {
|
||||
this.scriptIdField = scriptIdField;
|
||||
}
|
||||
public void setScriptIdField(String scriptIdField) {
|
||||
this.scriptIdField = scriptIdField;
|
||||
}
|
||||
|
||||
public String getScriptNameField() {
|
||||
return scriptNameField;
|
||||
}
|
||||
public String getScriptNameField() {
|
||||
return scriptNameField;
|
||||
}
|
||||
|
||||
public void setScriptNameField(String scriptNameField) {
|
||||
this.scriptNameField = scriptNameField;
|
||||
}
|
||||
public void setScriptNameField(String scriptNameField) {
|
||||
this.scriptNameField = scriptNameField;
|
||||
}
|
||||
|
||||
public String getScriptDataField() {
|
||||
return scriptDataField;
|
||||
}
|
||||
public String getScriptDataField() {
|
||||
return scriptDataField;
|
||||
}
|
||||
|
||||
public void setScriptDataField(String scriptDataField) {
|
||||
this.scriptDataField = scriptDataField;
|
||||
}
|
||||
public void setScriptDataField(String scriptDataField) {
|
||||
this.scriptDataField = scriptDataField;
|
||||
}
|
||||
|
||||
public String getScriptTypeField() {
|
||||
return scriptTypeField;
|
||||
}
|
||||
public String getScriptTypeField() {
|
||||
return scriptTypeField;
|
||||
}
|
||||
|
||||
public void setScriptTypeField(String scriptTypeField) {
|
||||
this.scriptTypeField = scriptTypeField;
|
||||
}
|
||||
public void setScriptTypeField(String scriptTypeField) {
|
||||
this.scriptTypeField = scriptTypeField;
|
||||
}
|
||||
|
||||
public String getScriptLanguageField() {
|
||||
return scriptLanguageField;
|
||||
}
|
||||
public String getScriptLanguageField() {
|
||||
return scriptLanguageField;
|
||||
}
|
||||
|
||||
public void setScriptLanguageField(String scriptLanguageField) {
|
||||
this.scriptLanguageField = scriptLanguageField;
|
||||
}
|
||||
public void setScriptLanguageField(String scriptLanguageField) {
|
||||
this.scriptLanguageField = scriptLanguageField;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断配资是否使用 IOC 已有数据源
|
||||
*/
|
||||
public boolean isDefaultDataSource() {
|
||||
return StrUtil.isBlank(url) && StrUtil.isBlank(username) && StrUtil.isBlank(password) && StrUtil.isBlank(driverClassName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class NodeComponentOfMethod extends NodeComponent {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onError() throws Exception {
|
||||
public void onError(Exception e) throws Exception {
|
||||
if (methodEnum != LiteFlowMethodEnum.ON_ERROR) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.yomahub.liteflow.spi.solon;
|
|||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yomahub.liteflow.aop.ICmpAroundAspect;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
import com.yomahub.liteflow.spi.CmpAroundAspect;
|
||||
import org.noear.solon.Solon;
|
||||
|
@ -23,16 +24,16 @@ public class SolonCmpAroundAspect implements CmpAroundAspect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess(String nodeId, Slot slot) {
|
||||
public void beforeProcess(NodeComponent cmp) {
|
||||
if (ObjectUtil.isNotNull(cmpAroundAspect)) {
|
||||
cmpAroundAspect.beforeProcess(nodeId, slot);
|
||||
cmpAroundAspect.beforeProcess(cmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(String nodeId, Slot slot) {
|
||||
public void afterProcess(NodeComponent cmp) {
|
||||
if (ObjectUtil.isNotNull(cmpAroundAspect)) {
|
||||
cmpAroundAspect.afterProcess(nodeId, slot);
|
||||
cmpAroundAspect.afterProcess(cmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package com.yomahub.liteflow.spi.solon;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yomahub.liteflow.spi.ContextAware;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.core.BeanWrap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基于代码形式的 Solon 上下文工具类
|
||||
*
|
||||
|
@ -12,73 +17,76 @@ import org.noear.solon.core.BeanWrap;
|
|||
*/
|
||||
public class SolonContextAware implements ContextAware {
|
||||
|
||||
@Override
|
||||
public <T> T getBean(String name) {
|
||||
try {
|
||||
return Solon.context().getBean(name);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public <T> T getBean(String name) {
|
||||
try {
|
||||
return Solon.context().getBean(name);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getBean(Class<T> clazz) {
|
||||
try {
|
||||
return Solon.context().getBean(clazz);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public <T> T getBean(Class<T> clazz) {
|
||||
try {
|
||||
return Solon.context().getBean(clazz);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getBean(String beanName, Class<T> clazz) {
|
||||
try {
|
||||
return Solon.context().getBean(beanName);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private <T> T getBean(String beanName, Class<T> clazz) {
|
||||
try {
|
||||
return Solon.context().getBean(beanName);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Class<T> c) {
|
||||
BeanWrap beanWrap = new BeanWrap(Solon.context(), c, null, beanName);
|
||||
Solon.context().putWrap(beanName, beanWrap);
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Class<T> c) {
|
||||
BeanWrap beanWrap = new BeanWrap(Solon.context(), c, null, beanName);
|
||||
Solon.context().putWrap(beanName, beanWrap);
|
||||
|
||||
return beanWrap.get();
|
||||
}
|
||||
return beanWrap.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(Class<T> c) {
|
||||
return registerBean(c.getName(), c);
|
||||
}
|
||||
@Override
|
||||
public <T> T registerBean(Class<T> c) {
|
||||
return registerBean(c.getName(), c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Object bean) {
|
||||
BeanWrap beanWrap = new BeanWrap(Solon.context(), bean.getClass(), bean, beanName);
|
||||
Solon.context().putWrap(beanName, beanWrap);
|
||||
@Override
|
||||
public <T> 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> T registerOrGet(String beanName, Class<T> clazz) {
|
||||
T t = getBean(beanName, clazz);
|
||||
if (ObjectUtil.isNull(t)) {
|
||||
t = registerBean(beanName, clazz);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
@Override
|
||||
public <T> T registerOrGet(String beanName, Class<T> 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 <T> Map<String, T> getBeansOfType(Class<T> type) {
|
||||
List<BeanWrap> wrapsOfType = Solon.context().getWrapsOfType(type);
|
||||
return CollUtil.toMap(wrapsOfType, new HashMap<String, T>(), BeanWrap::name, BeanWrap::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public boolean hasBean(String beanName) {
|
||||
return Solon.context().hasWrap(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport;
|
|||
public class SolonLiteflowComponentSupport implements LiteflowComponentSupport {
|
||||
|
||||
@Override
|
||||
public String getCmpName(NodeComponent nodeComponent) {
|
||||
public String getCmpName(Object nodeComponent) {
|
||||
// 判断NodeComponent是否是标识了@LiteflowComponent的标注
|
||||
// 如果标注了,那么要从中取到name字段
|
||||
LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class);
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package com.yomahub.liteflow.spi.spring;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.yomahub.liteflow.spi.ContextAware;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
|
@ -12,6 +10,8 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基于代码形式的spring上下文工具类
|
||||
*
|
||||
|
@ -19,83 +19,87 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||
*/
|
||||
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> T getBean(String name) {
|
||||
T t = (T) applicationContext.getBean(name);
|
||||
return t;
|
||||
}
|
||||
@Override
|
||||
public <T> T getBean(String name) {
|
||||
T t = (T) applicationContext.getBean(name);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getBean(Class<T> clazz) {
|
||||
T t = applicationContext.getBean(clazz);
|
||||
return t;
|
||||
}
|
||||
@Override
|
||||
public <T> Map<String, T> getBeansOfType(Class<T> type) {
|
||||
return applicationContext.getBeansOfType(type);
|
||||
}
|
||||
|
||||
private <T> T getBean(String beanName, Class<T> clazz) {
|
||||
T t = applicationContext.getBean(beanName, clazz);
|
||||
return t;
|
||||
}
|
||||
@Override
|
||||
public <T> T getBean(Class<T> clazz) {
|
||||
T t = applicationContext.getBean(clazz);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Class<T> c) {
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext
|
||||
.getAutowireCapableBeanFactory();
|
||||
BeanDefinition beanDefinition = new GenericBeanDefinition();
|
||||
beanDefinition.setBeanClassName(c.getName());
|
||||
beanFactory.setAllowBeanDefinitionOverriding(true);
|
||||
beanFactory.registerBeanDefinition(beanName, beanDefinition);
|
||||
return getBean(beanName);
|
||||
}
|
||||
private <T> T getBean(String beanName, Class<T> clazz) {
|
||||
T t = applicationContext.getBean(beanName, clazz);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerBean(Class<T> c) {
|
||||
return registerBean(c.getName(), c);
|
||||
}
|
||||
@Override
|
||||
public <T> T registerBean(String beanName, Class<T> 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> 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> T registerBean(Class<T> c) {
|
||||
return registerBean(c.getName(), c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T registerOrGet(String beanName, Class<T> clazz) {
|
||||
if (ObjectUtil.isNull(applicationContext)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return getBean(beanName, clazz);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return registerBean(beanName, clazz);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public <T> 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 boolean hasBean(String beanName) {
|
||||
return applicationContext.containsBean(beanName);
|
||||
}
|
||||
@Override
|
||||
public <T> T registerOrGet(String beanName, Class<T> clazz) {
|
||||
if (ObjectUtil.isNull(applicationContext)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return getBean(beanName, clazz);
|
||||
} catch (Exception e) {
|
||||
return registerBean(beanName, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public boolean hasBean(String beanName) {
|
||||
return applicationContext.containsBean(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int priority() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.yomahub.liteflow.spi.spring;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
import com.yomahub.liteflow.spi.CmpAroundAspect;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
|
@ -14,16 +15,16 @@ import com.yomahub.liteflow.spring.ComponentScanner;
|
|||
public class SpringCmpAroundAspect implements CmpAroundAspect {
|
||||
|
||||
@Override
|
||||
public void beforeProcess(String nodeId, Slot slot) {
|
||||
public void beforeProcess(NodeComponent cmp) {
|
||||
if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) {
|
||||
ComponentScanner.cmpAroundAspect.beforeProcess(nodeId, slot);
|
||||
ComponentScanner.cmpAroundAspect.beforeProcess(cmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(String nodeId, Slot slot) {
|
||||
public void afterProcess(NodeComponent cmp) {
|
||||
if (ObjectUtil.isNotNull(ComponentScanner.cmpAroundAspect)) {
|
||||
ComponentScanner.cmpAroundAspect.afterProcess(nodeId, slot);
|
||||
ComponentScanner.cmpAroundAspect.afterProcess(cmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.yomahub.liteflow.spi.LiteflowComponentSupport;
|
|||
public class SpringLiteflowComponentSupport implements LiteflowComponentSupport {
|
||||
|
||||
@Override
|
||||
public String getCmpName(NodeComponent nodeComponent) {
|
||||
public String getCmpName(Object nodeComponent) {
|
||||
// 判断NodeComponent是否是标识了@LiteflowComponent的标注
|
||||
// 如果标注了,那么要从中取到name字段
|
||||
LiteflowComponent liteflowComponent = nodeComponent.getClass().getAnnotation(LiteflowComponent.class);
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
|||
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
|
@ -15,7 +15,7 @@ import org.junit.AfterClass;
|
|||
*/
|
||||
public class BaseTest {
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanScanCache() {
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
|
|
|
@ -1,27 +1,25 @@
|
|||
package com.yomahub.liteflow.test.apollo;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ctrip.framework.apollo.Config;
|
||||
import com.ctrip.framework.apollo.ConfigService;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.event.annotation.AfterTestClass;
|
||||
import org.springframework.test.context.event.annotation.BeforeTestClass;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
@ -31,7 +29,7 @@ import static org.mockito.Mockito.*;
|
|||
* @Author: zhanghua
|
||||
* @Date: 2022/12/3 15:22
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/apollo/application-xml.properties")
|
||||
@SpringBootTest(classes = ApolloWithXmlELSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -47,16 +45,10 @@ public class ApolloWithXmlELSpringbootTest {
|
|||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
FlowBus.cleanCache();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApolloWithXml1() {
|
||||
Set<String> chainNameList = Sets.newHashSet("chain1");
|
||||
|
@ -70,7 +62,6 @@ public class ApolloWithXmlELSpringbootTest {
|
|||
when(scriptConfig.getProperty(anyString(), anyString())).thenReturn(scriptNodeValue);
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStrWithoutTime());
|
||||
Assertions.assertEquals("a==>b==>c==>s1[脚本s1]", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,11 +6,13 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
|||
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.springframework.test.context.event.annotation.AfterTestClass;
|
||||
|
||||
public class BaseTest {
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanScanCache() {
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.absoluteConfigPath;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/absoluteConfigPath/application.properties")
|
||||
@SpringBootTest(classes = AbsoluteConfigPathELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -37,7 +38,7 @@ public class AbsoluteConfigPathELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testAbsoluteConfig() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@ import com.yomahub.liteflow.slot.DefaultContext;
|
|||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.aop.aspect.CmpAspect;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.event.annotation.AfterTestClass;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -24,7 +26,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/aop/application.properties")
|
||||
@SpringBootTest(classes = GlobalAOPELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -40,12 +42,12 @@ public class GlobalAOPELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("before_after", context.getData("a"));
|
||||
Assertions.assertEquals("before_after", context.getData("b"));
|
||||
Assertions.assertEquals("before_after", context.getData("c"));
|
||||
Assertions.assertEquals("before_after", context.getData("d"));
|
||||
Assertions.assertEquals("before_after", context.getData("e"));
|
||||
}
|
||||
|
||||
// 测试全局AOP,并行场景
|
||||
|
@ -53,26 +55,26 @@ public class GlobalAOPELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("before_after", context.getData("a"));
|
||||
Assertions.assertEquals("before_after", context.getData("b"));
|
||||
Assertions.assertEquals("before_after", context.getData("c"));
|
||||
Assertions.assertEquals("before_after", context.getData("d"));
|
||||
Assertions.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"));
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("before_after", context.getData("a"));
|
||||
Assertions.assertEquals("before_after", context.getData("b"));
|
||||
Assertions.assertEquals("before_after", context.getData("c"));
|
||||
Assertions.assertEquals("before_after", context.getData("f"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void cleanScanCache() {
|
||||
BaseTest.cleanScanCache();
|
||||
ComponentScanner.cmpAroundAspect = null;
|
||||
|
|
|
@ -2,21 +2,22 @@ package com.yomahub.liteflow.test.aop.aspect;
|
|||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.aop.ICmpAroundAspect;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
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");
|
||||
public void beforeProcess(NodeComponent cmp) {
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
context.setData(cmp.getNodeId(), "before");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(String nodeId, Slot slot) {
|
||||
DefaultContext context = slot.getFirstContextBean();
|
||||
context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after"));
|
||||
public void afterProcess(NodeComponent cmp) {
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ import com.yomahub.liteflow.flow.LiteflowResponse;
|
|||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.asyncNode.exception.TestException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author ssss
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/asyncNode/application.properties")
|
||||
@SpringBootTest(classes = AsyncNodeELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -38,7 +39,7 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testAsyncFlow1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
System.out.println(response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
|
@ -46,7 +47,7 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testAsyncFlow2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request");
|
||||
Assert.assertTrue(
|
||||
Assertions.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")
|
||||
|
@ -57,15 +58,15 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
@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);
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
// 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错
|
||||
|
@ -74,12 +75,12 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 因为不记录错误,所以最终结果是true
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
// 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(2), count);
|
||||
Assertions.assertEquals(2, count);
|
||||
// 因为配置了不抛错,所以response里的cause应该为null
|
||||
Assert.assertNull(response.getCause());
|
||||
Assertions.assertNull(response.getCause());
|
||||
}
|
||||
|
||||
// 相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错
|
||||
|
@ -88,12 +89,12 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 整个并行组是报错的,所以最终结果是false
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
// 因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(2), count);
|
||||
Assertions.assertEquals(2, count);
|
||||
// 因为第一个when配置了会报错,所以response里的cause里应该会有TestException
|
||||
Assert.assertEquals(TestException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals(TestException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
// 不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行
|
||||
|
@ -102,12 +103,12 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 第一个when会抛错,所以最终结果是false
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
// 因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(1), count);
|
||||
Assertions.assertEquals(1, count);
|
||||
// 第一个when会报错,所以最终response的cause里应该会有TestException
|
||||
Assert.assertEquals(TestException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals(TestException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
// 不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错
|
||||
|
@ -116,12 +117,12 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
// 第二个when会抛错,所以最终结果是false
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
// 传递了slotIndex,则set的size==2
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(2), count);
|
||||
Assertions.assertEquals(2, count);
|
||||
// 第一个when会报错,所以最终response的cause里应该会有TestException
|
||||
Assert.assertEquals(TestException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals(TestException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
// 测试任意异步一个执行完即继续的场景
|
||||
|
@ -132,8 +133,8 @@ public class AsyncNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(context.getData("check").toString().startsWith("habc"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.base;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/base/application.properties")
|
||||
@SpringBootTest(classes = BaseELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -33,7 +34,7 @@ public class BaseELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testBase() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import javax.annotation.Resource;
|
|||
@LiteflowComponent
|
||||
public class CmpConfig {
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a", nodeName = "A组件")
|
||||
public void processA(NodeComponent bindCmp) {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@ import com.yomahub.liteflow.enums.NodeTypeEnum;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.builder.cmp1.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
@ -19,7 +20,7 @@ import javax.annotation.Resource;
|
|||
//基于builder模式的单元测试
|
||||
//这里只是最基本的builder模式的测试,只是为了验证在springboot模式下的正常性
|
||||
//更详细的builder模式测试用例会单独拉testcase去做
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = BuilderELDeclMultiSpringbootTest1.class)
|
||||
@EnableAutoConfiguration
|
||||
public class BuilderELDeclMultiSpringbootTest1 extends BaseTest {
|
||||
|
@ -81,8 +82,8 @@ public class BuilderELDeclMultiSpringbootTest1 extends BaseTest {
|
|||
.build();
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 基于普通组件的builder模式测试
|
||||
|
@ -139,8 +140,8 @@ public class BuilderELDeclMultiSpringbootTest1 extends BaseTest {
|
|||
.build();
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -173,8 +174,8 @@ public class BuilderELDeclMultiSpringbootTest1 extends BaseTest {
|
|||
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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -16,7 +17,7 @@ import javax.annotation.Resource;
|
|||
|
||||
//基于builder模式的单元测试
|
||||
//这里测试的是通过spring去扫描,但是通过代码去构建chain的用例
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = BuilderELDeclMultiSpringbootTest2.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({ "com.yomahub.liteflow.test.builder.cmp2" })
|
||||
|
@ -31,8 +32,8 @@ public class BuilderELDeclMultiSpringbootTest2 extends BaseTest {
|
|||
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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("h==>i==>j", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.cmpRetry;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.10
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/cmpRetry/application.properties")
|
||||
@SpringBootTest(classes = LiteflowRetryELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,31 +35,31 @@ public class LiteflowRetryELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testRetry1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 单个组件指定异常,但抛出的并不是指定异常的场景测试
|
||||
@Test
|
||||
public void testRetry3() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.flow.entity.CmpStep;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -14,10 +15,7 @@ import org.springframework.test.context.TestPropertySource;
|
|||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* springboot环境最普通的例子测试
|
||||
|
@ -25,7 +23,7 @@ import java.util.Set;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/cmpStep/application.properties")
|
||||
@SpringBootTest(classes = CmpStepELDeclSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -38,31 +36,31 @@ public class CmpStepELDeclSpringbootTest extends BaseTest {
|
|||
@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());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertTrue(response.getExecuteSteps().get("a").get(0).isSuccess());
|
||||
Assertions.assertTrue(response.getExecuteSteps().get("b").get(0).isSuccess());
|
||||
Assertions.assertFalse(response.getExecuteSteps().get("c").get(0).isSuccess());
|
||||
Assertions.assertFalse(response.getExecuteSteps().get("d").get(0).isSuccess());
|
||||
Assertions.assertTrue(response.getExecuteSteps().get("c").get(0).getTimeSpent() >= 2000);
|
||||
Assertions.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").get(0).getException().getClass());
|
||||
Assertions.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").get(0).getException().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStep2() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStep3() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Map<String, CmpStep> stepMap = response.getExecuteSteps();
|
||||
Assert.assertEquals(2, stepMap.size());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Map<String, List<CmpStep>> stepMap = response.getExecuteSteps();
|
||||
Assertions.assertEquals(2, stepMap.size());
|
||||
Queue<CmpStep> queue = response.getExecuteStepQueue();
|
||||
Assert.assertEquals(5, queue.size());
|
||||
Assertions.assertEquals(5, queue.size());
|
||||
|
||||
Set<String> tagSet = new HashSet<>();
|
||||
response.getExecuteStepQueue()
|
||||
|
@ -70,7 +68,7 @@ public class CmpStepELDeclSpringbootTest extends BaseTest {
|
|||
.filter(cmpStep -> cmpStep.getNodeId().equals("a"))
|
||||
.forEach(cmpStep -> tagSet.add(cmpStep.getTag()));
|
||||
|
||||
Assert.assertEquals(3, tagSet.size());
|
||||
Assertions.assertEquals(3, tagSet.size());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,10 @@ import cn.hutool.core.collection.ListUtil;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -15,7 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/comments/application.properties")
|
||||
@SpringBootTest(classes = LiteflowNodeELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -29,8 +30,8 @@ public class LiteflowNodeELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testAsyncFlow1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr()));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(ListUtil.toList("a==>b==>c==>b", "a==>b==>b==>c").contains(response.getExecuteStepStr()));
|
||||
}
|
||||
|
||||
}
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.complex;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -19,7 +20,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/complex/application1.properties")
|
||||
@SpringBootTest(classes = ComplexELDeclMultiSpringbootTest1.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -35,7 +36,7 @@ public class ComplexELDeclMultiSpringbootTest1 extends BaseTest {
|
|||
@Test
|
||||
public void testComplex1_1() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1_1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
// 测试复杂例子,优化后
|
||||
|
@ -44,7 +45,7 @@ public class ComplexELDeclMultiSpringbootTest1 extends BaseTest {
|
|||
@Test
|
||||
public void testComplex1_2() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1_2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.complex;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -19,7 +20,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/complex/application2.properties")
|
||||
@SpringBootTest(classes = ComplexELDeclMultiSpringbootTest2.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -35,7 +36,7 @@ public class ComplexELDeclMultiSpringbootTest2 extends BaseTest {
|
|||
@Test
|
||||
public void testComplex2_1() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2_1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
// 测试复杂例子,优化后
|
||||
|
@ -44,7 +45,7 @@ public class ComplexELDeclMultiSpringbootTest2 extends BaseTest {
|
|||
@Test
|
||||
public void testComplex2_2() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2_2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package com.yomahub.liteflow.test.component;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
@ -22,7 +24,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author donguo.tao
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/component/application.properties")
|
||||
@SpringBootTest(classes = FlowExecutorELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -38,56 +40,58 @@ public class FlowExecutorELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testIsAccess() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertNotNull(response.getSlot().getResponseData());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertNotNull(response.getSlot().getResponseData());
|
||||
}
|
||||
|
||||
// 组件抛错的功能点测试
|
||||
@Test(expected = ArithmeticException.class)
|
||||
@Test
|
||||
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());
|
||||
Assertions.assertThrows(ArithmeticException.class, () -> {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0);
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("/ by zero", response.getMessage());
|
||||
ReflectionUtils.rethrowException(response.getCause());
|
||||
});
|
||||
}
|
||||
|
||||
// isContinueOnError方法的功能点测试
|
||||
@Test
|
||||
public void testIsContinueOnError() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertNull(response.getCause());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("e", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 条件组件的功能点测试
|
||||
@Test
|
||||
public void testNodeCondComponent() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("g", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.customMethodName;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.7.2
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/customMethodName/application.properties")
|
||||
@SpringBootTest(classes = CustomMethodNameELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -33,7 +34,7 @@ public class CustomMethodNameELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testCustomMethodName() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.customNodes;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/customNodes/application.properties")
|
||||
@SpringBootTest(classes = CustomNodesELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -37,9 +38,9 @@ public class CustomNodesELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testCustomNodes() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
@ -23,7 +24,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/customWhenThreadPool/application.properties")
|
||||
@SpringBootTest(classes = CustomWhenThreadPoolELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -42,8 +43,8 @@ public class CustomWhenThreadPoolELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,8 +54,8 @@ public class CustomWhenThreadPoolELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response1.isSuccess());
|
||||
Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,8 +68,8 @@ public class CustomWhenThreadPoolELDeclMultiSpringbootTest extends BaseTest {
|
|||
// 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"));
|
||||
Assertions.assertTrue(response2.isSuccess());
|
||||
Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead"));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -21,7 +22,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/event/application.properties")
|
||||
@SpringBootTest(classes = EventELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -36,8 +37,8 @@ public class EventELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("abc", context.getData("test"));
|
||||
}
|
||||
|
||||
// 测试组件失败事件
|
||||
|
@ -45,10 +46,10 @@ public class EventELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(NullPointerException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("ab", context.getData("test"));
|
||||
Assertions.assertEquals("error:d", context.getData("error"));
|
||||
}
|
||||
|
||||
// 测试组件失败事件本身抛出异常
|
||||
|
@ -56,10 +57,10 @@ public class EventELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(NullPointerException.class, response.getCause().getClass());
|
||||
Assertions.assertEquals("a", context.getData("test"));
|
||||
Assertions.assertEquals("error:e", context.getData("error"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class CmpConfig {
|
|||
}
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR, nodeId = "d")
|
||||
public void onErrorD(NodeComponent bindCmp) throws Exception {
|
||||
public void onErrorD(NodeComponent bindCmp, Exception e) throws Exception {
|
||||
DefaultContext context = bindCmp.getFirstContextBean();
|
||||
context.setData("error", "error:" + bindCmp.getNodeId());
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class CmpConfig {
|
|||
}
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.ON_ERROR, nodeId = "e")
|
||||
public void onErrorE(NodeComponent bindCmp) throws Exception {
|
||||
public void onErrorE(NodeComponent bindCmp,Exception e) throws Exception {
|
||||
DefaultContext context = bindCmp.getFirstContextBean();
|
||||
context.setData("error", "error:" + bindCmp.getNodeId());
|
||||
throw new IllegalAccessException("错误事件回调本身抛出异常");
|
||||
|
|
|
@ -4,14 +4,18 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.exception.ChainDuplicateException;
|
||||
import com.yomahub.liteflow.exception.ConfigErrorException;
|
||||
import com.yomahub.liteflow.exception.FlowExecutorNotInitException;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
@ -20,7 +24,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author zendwang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = Exception1ELDeclMultiSpringBootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class Exception1ELDeclMultiSpringBootTest extends BaseTest {
|
||||
|
@ -31,31 +35,38 @@ public class Exception1ELDeclMultiSpringBootTest extends BaseTest {
|
|||
/**
|
||||
* 验证 chain 节点重复的异常
|
||||
*/
|
||||
@Test(expected = ChainDuplicateException.class)
|
||||
@Test
|
||||
public void testChainDuplicateException() {
|
||||
LiteflowConfig config = LiteflowConfigGetter.get();
|
||||
config.setRuleSource("exception/flow-exception.el.xml");
|
||||
flowExecutor.reloadRule();
|
||||
Assertions.assertThrows(ChainDuplicateException.class, () -> {
|
||||
LiteflowConfig config = LiteflowConfigGetter.get();
|
||||
config.setRuleSource("exception/flow-exception.el.xml");
|
||||
flowExecutor.reloadRule();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = ConfigErrorException.class)
|
||||
@Test
|
||||
public void testConfigErrorException() {
|
||||
flowExecutor.setLiteflowConfig(null);
|
||||
flowExecutor.reloadRule();
|
||||
Assertions.assertThrows(ConfigErrorException.class, () -> {
|
||||
flowExecutor.setLiteflowConfig(null);
|
||||
flowExecutor.reloadRule();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = FlowExecutorNotInitException.class)
|
||||
@Test
|
||||
public void testFlowExecutorNotInitException() {
|
||||
LiteflowConfig config = LiteflowConfigGetter.get();
|
||||
config.setRuleSource("error/flow.txt");
|
||||
flowExecutor.reloadRule();
|
||||
Assertions.assertThrows(FlowExecutorNotInitException.class, () -> {
|
||||
LiteflowConfig config = LiteflowConfigGetter.get();
|
||||
config.setRuleSource("error/flow.txt");
|
||||
flowExecutor.reloadRule();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = FlowExecutorNotInitException.class)
|
||||
@Test
|
||||
public void testNoConditionInChainException() throws Exception {
|
||||
LiteflowConfig config = LiteflowConfigGetter.get();
|
||||
config.setRuleSource("exception/flow-blank.el.xml");
|
||||
flowExecutor.reloadRule();
|
||||
Assertions.assertThrows(FlowExecutorNotInitException.class, () -> {
|
||||
LiteflowConfig config = LiteflowConfigGetter.get();
|
||||
config.setRuleSource("exception/flow-blank.el.xml");
|
||||
flowExecutor.reloadRule();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ import com.yomahub.liteflow.exception.LiteFlowException;
|
|||
import com.yomahub.liteflow.exception.NoSwitchTargetNodeException;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author zendwang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/exception/application.properties")
|
||||
@SpringBootTest(classes = Exception2ELDeclMultiSpringBootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -32,46 +33,49 @@ public class Exception2ELDeclMultiSpringBootTest extends BaseTest {
|
|||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test(expected = ChainNotFoundException.class)
|
||||
@Test
|
||||
public void testChainNotFoundException() throws Exception {
|
||||
flowExecutor.execute("chain0", "it's a request");
|
||||
Assertions.assertThrows(ChainNotFoundException.class, () -> flowExecutor.execute("chain0", "it's a request"));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
@Test
|
||||
public void testComponentCustomException() throws Exception {
|
||||
flowExecutor.execute("chain1", "exception");
|
||||
Assertions.assertThrows(RuntimeException.class, () -> 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());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertNotNull(response.getCause());
|
||||
Assertions.assertNotNull(response.getSlot());
|
||||
}
|
||||
|
||||
@Test(expected = NoSwitchTargetNodeException.class)
|
||||
@Test
|
||||
public void testNoTargetFindException() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test");
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
throw response.getCause();
|
||||
Assertions.assertThrows(NoSwitchTargetNodeException.class, () -> {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "test");
|
||||
Assertions.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());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("300", response.getCode());
|
||||
Assertions.assertNotNull(response.getCause());
|
||||
Assertions.assertTrue(response.getCause() instanceof LiteFlowException);
|
||||
Assertions.assertNotNull(response.getSlot());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotInvokeCustomStatefulException() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertNull(response.getCode());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertNull(response.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -22,7 +23,7 @@ import java.util.concurrent.Future;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.13
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/execute2Future/application.properties")
|
||||
@SpringBootTest(classes = Executor2FutureELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -36,7 +37,7 @@ public class Executor2FutureELDeclMultiSpringbootTest extends BaseTest {
|
|||
public void testFuture() throws Exception {
|
||||
Future<LiteflowResponse> future = flowExecutor.execute2Future("chain1", "arg", DefaultContext.class);
|
||||
LiteflowResponse response = future.get();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.extend;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.7.1
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/extend/application.properties")
|
||||
@SpringBootTest(classes = CmpExtendELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -33,7 +34,7 @@ public class CmpExtendELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testExtend() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/getChainName/application.properties")
|
||||
@SpringBootTest(classes = GetChainNameELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,28 +35,28 @@ public class GetChainNameELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("sub1", context.getData("a"));
|
||||
Assertions.assertEquals("sub2", context.getData("b"));
|
||||
Assertions.assertEquals("sub3", context.getData("c"));
|
||||
Assertions.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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("chain2", context.getData("g"));
|
||||
Assertions.assertEquals("sub1", context.getData("a"));
|
||||
Assertions.assertEquals("sub2", context.getData("b"));
|
||||
Assertions.assertEquals("sub3", context.getData("c"));
|
||||
Assertions.assertEquals("sub4", context.getData("d"));
|
||||
Assertions.assertEquals("sub5", context.getData("f"));
|
||||
Assertions.assertEquals("sub5_chain2", context.getData("e"));
|
||||
Assertions.assertEquals("sub6", context.getData("h"));
|
||||
Assertions.assertEquals("sub6", context.getData("j"));
|
||||
Assertions.assertNull(context.getData("k"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.ifelse;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/ifelse/application.properties")
|
||||
@SpringBootTest(classes = IfElseELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,56 +35,56 @@ public class IfElseELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testIf1() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -23,7 +24,7 @@ import java.util.List;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/iterator/application.properties")
|
||||
@SpringBootTest(classes = IteratorELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -38,10 +39,10 @@ public class IteratorELDeclMultiSpringbootTest extends BaseTest {
|
|||
public void testIt1() throws Exception {
|
||||
List<String> list = ListUtil.toList("1", "2", "3");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", list);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
String str = context.getData("test");
|
||||
Assert.assertEquals("123", str);
|
||||
Assertions.assertEquals("123", str);
|
||||
}
|
||||
|
||||
// 迭代器带break
|
||||
|
@ -49,10 +50,10 @@ public class IteratorELDeclMultiSpringbootTest extends BaseTest {
|
|||
public void testIt2() throws Exception {
|
||||
List<String> list = ListUtil.toList("1", "2", "3");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", list);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
String str = context.getData("test");
|
||||
Assert.assertEquals("12", str);
|
||||
Assertions.assertEquals("12", str);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.yomahub.liteflow.test.lazy;
|
|||
import com.yomahub.liteflow.test.BaseTest;
|
||||
|
||||
//spring的延迟加载在el表达形式模式下不起作用
|
||||
/*@RunWith(SpringRunner.class)
|
||||
/*@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/lazy/application.properties")
|
||||
@SpringBootTest(classes = LazyELDeclSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -15,7 +15,7 @@ public class LazyELDeclMultiSpringbootTest extends BaseTest {
|
|||
*
|
||||
* @Test public void testLazy() throws Exception{ LiteflowResponse response =
|
||||
* flowExecutor.execute2Resp("chain1", "arg");
|
||||
* Assert.assertTrue(response.isSuccess()); }
|
||||
* Assertions.assertTrue(response.isSuccess()); }
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.lfCmpAnno;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -19,7 +20,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.10
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/lfCmpAnno/application.properties")
|
||||
@SpringBootTest(classes = LiteflowComponentELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -32,8 +33,8 @@ public class LiteflowComponentELDeclMultiSpringbootTest extends BaseTest {
|
|||
@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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -21,7 +22,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/loop/application.properties")
|
||||
@SpringBootTest(classes = LoopELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -35,31 +36,31 @@ public class LoopELDeclMultiSpringbootTest extends BaseTest {
|
|||
@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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.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",
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z==>a==>d==>z",
|
||||
response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
|
@ -67,8 +68,8 @@ public class LoopELDeclMultiSpringbootTest extends BaseTest {
|
|||
@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",
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y",
|
||||
response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
|
@ -77,10 +78,10 @@ public class LoopELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("01234", context.getData("loop_e1"));
|
||||
Assertions.assertEquals("01234", context.getData("loop_e2"));
|
||||
Assertions.assertEquals("01234", context.getData("loop_e3"));
|
||||
}
|
||||
|
||||
// 测试WHILE循环中的index
|
||||
|
@ -88,10 +89,10 @@ public class LoopELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("01234", context.getData("loop_e1"));
|
||||
Assertions.assertEquals("01234", context.getData("loop_e2"));
|
||||
Assertions.assertEquals("01234", context.getData("loop_e3"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.mixDefine;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/mixDefine/application.properties")
|
||||
@SpringBootTest(classes = MixDefineELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,7 +35,7 @@ public class MixDefineELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testMixDefine1() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,10 +5,12 @@ import com.yomahub.liteflow.flow.LiteflowResponse;
|
|||
import com.yomahub.liteflow.monitor.MonitorBus;
|
||||
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.event.annotation.AfterTestClass;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -23,7 +25,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/monitor/application.properties")
|
||||
@SpringBootTest(classes = MonitorELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -36,13 +38,14 @@ public class MonitorELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testMonitor() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void clean() {
|
||||
BaseTest.cleanScanCache();
|
||||
MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class);
|
||||
monitorBus.closeScheduler();
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package com.yomahub.liteflow.test.monitorFile;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/monitorFile/application.properties")
|
||||
@SpringBootTest(classes = MonitorFileELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@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());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.yomahub.liteflow.test.monitorFile.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.annotation.LiteflowMethod;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@LiteflowComponent
|
||||
public class CmpConfig {
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
|
||||
public void processA(NodeComponent bindCmp) {
|
||||
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!");
|
||||
}
|
||||
|
||||
}
|
|
@ -6,9 +6,10 @@ import com.yomahub.liteflow.exception.NoSuchContextBeanException;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -23,7 +24,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/multiContext/application.properties")
|
||||
@SpringBootTest(classes = MultiContextELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -38,18 +39,19 @@ public class MultiContextELDeclMultiSpringbootTest extends BaseTest {
|
|||
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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("987XYZ", checkContext.getSign());
|
||||
Assertions.assertEquals(95, checkContext.getRandomId());
|
||||
Assertions.assertEquals("SO12345", orderContext.getOrderNo());
|
||||
Assertions.assertEquals(2, orderContext.getOrderType());
|
||||
Assertions.assertEquals(DateUtil.parseDate("2022-06-15"), orderContext.getCreateTime());
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchContextBeanException.class)
|
||||
@Test
|
||||
public void testMultiContext2() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class);
|
||||
DefaultContext context = response.getContextBean(DefaultContext.class);
|
||||
Assertions.assertThrows(NoSuchContextBeanException.class, () -> {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class);
|
||||
DefaultContext context = response.getContextBean(DefaultContext.class);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.multipleType;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -19,7 +20,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.10
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/multipleType/application.properties")
|
||||
@SpringBootTest(classes = LiteflowMultipleTypeELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -32,11 +33,11 @@ public class LiteflowMultipleTypeELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testMultipleType() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>c==>b==>a", response.getExecuteStepStr());
|
||||
response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>b==>c", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -21,7 +22,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.10
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/nodeExecutor/application.properties")
|
||||
@SpringBootTest(classes = LiteflowNodeExecutorELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -36,9 +37,9 @@ public class LiteflowNodeExecutorELDeclMultiSpringbootTest extends BaseTest {
|
|||
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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor"));
|
||||
Assertions.assertEquals("a", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 默认执行器测试+全局重试配置测试
|
||||
|
@ -46,17 +47,17 @@ public class LiteflowNodeExecutorELDeclMultiSpringbootTest extends BaseTest {
|
|||
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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals(CustomerDefaultNodeExecutor.class, context.getData("customerDefaultNodeExecutor"));
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("c", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 自定义执行器测试+全局重试配置测试
|
||||
|
@ -64,9 +65,9 @@ public class LiteflowNodeExecutorELDeclMultiSpringbootTest extends BaseTest {
|
|||
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());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(CustomerNodeExecutorAndCustomRetry.class, context.getData("retryLogic"));
|
||||
Assertions.assertEquals("d==>d==>d==>d==>d==>d", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.parsecustom;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author dongguo.tao
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties")
|
||||
@SpringBootTest(classes = CustomParserJsonELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,7 +35,7 @@ public class CustomParserJsonELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testJsonCustomParser() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.parsecustom;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author bryan.zhang
|
||||
* @since 2.5.7
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties")
|
||||
@SpringBootTest(classes = CustomParserXmlELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,7 +35,7 @@ public class CustomParserXmlELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testXmlCustomParser() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.parser;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parser/application-json.properties")
|
||||
@SpringBootTest(classes = JsonParserELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,7 +35,7 @@ public class JsonParserELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testJsonParser() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.parser;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -14,7 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parser/application-springEL.properties")
|
||||
@SpringBootTest(classes = SpringELSupportELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -28,7 +29,7 @@ public class SpringELSupportELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testSpringELParser() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.parser;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parser/application-xml.properties")
|
||||
@SpringBootTest(classes = XmlParserELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,7 +35,7 @@ public class XmlParserELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testXmlParser() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.parser;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/parser/application-yml.properties")
|
||||
@SpringBootTest(classes = YmlParserELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -34,7 +35,7 @@ public class YmlParserELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testYmlParser() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -21,7 +22,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/preAndFinally/application.properties")
|
||||
@SpringBootTest(classes = PreAndFinallyELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -35,24 +36,24 @@ public class PreAndFinallyELDeclMultiSpringbootTest extends BaseTest {
|
|||
@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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 测试在finally节点里是否能获取exception
|
||||
|
@ -60,15 +61,15 @@ public class PreAndFinallyELDeclMultiSpringbootTest extends BaseTest {
|
|||
public void testPreAndFinally4() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertTrue(context.getData("hasEx"));
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertTrue((Boolean) 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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("p1==>p2==>p1==>p2==>a==>b==>c==>f1==>f2==>f1", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/privateDelivery/application.properties")
|
||||
@SpringBootTest(classes = PrivateDeliveryELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -37,8 +38,8 @@ public class PrivateDeliveryELDeclMultiSpringbootTest extends BaseTest {
|
|||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
ConcurrentHashSet<Integer> set = context.getData("testSet");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals(100, set.size());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals(100, set.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ import com.yomahub.liteflow.enums.FlowParserTypeEnum;
|
|||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -23,7 +24,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/refreshRule/application.properties")
|
||||
@SpringBootTest(classes = RefreshRuleELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -39,7 +40,7 @@ public class RefreshRuleELDeclMultiSpringbootTest extends BaseTest {
|
|||
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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
// 测试优雅刷新的场景
|
||||
|
@ -59,7 +60,7 @@ public class RefreshRuleELDeclMultiSpringbootTest extends BaseTest {
|
|||
|
||||
for (int i = 0; i < 500; i++) {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
try {
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.reload;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/reload/application.properties")
|
||||
@SpringBootTest(classes = ReloadELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -36,7 +37,7 @@ public class ReloadELDeclMultiSpringbootTest extends BaseTest {
|
|||
public void testReload() throws Exception {
|
||||
flowExecutor.reloadRule();
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.requestId;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -17,7 +18,7 @@ import javax.annotation.Resource;
|
|||
/**
|
||||
* @author tangkc
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/requestId/application.properties")
|
||||
@SpringBootTest(classes = LiteflowRequestIdELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -30,8 +31,8 @@ public class LiteflowRequestIdELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testRequestId() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("1", response.getSlot().getRequestId());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("1", response.getSlot().getRequestId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -22,7 +23,7 @@ import java.util.Set;
|
|||
*
|
||||
* @author justin.xu
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/subflow/application-implicit.properties")
|
||||
@SpringBootTest(classes = ImplicitSubFlowELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -39,15 +40,15 @@ public class ImplicitSubFlowELDeclMultiSpringbootTest extends BaseTest {
|
|||
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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("f==>g==>h==>m", response.getExecuteStepStr());
|
||||
|
||||
// 传递了slotIndex,则set的size==1
|
||||
Assert.assertEquals(1, RUN_TIME_SLOT.size());
|
||||
Assertions.assertEquals(1, RUN_TIME_SLOT.size());
|
||||
// set中第一次设置的requestId和response中的requestId一致
|
||||
Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId()));
|
||||
Assertions.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId()));
|
||||
// requestData的取值正确
|
||||
Assert.assertEquals("it's implicit subflow.", context.getData("innerRequest"));
|
||||
Assertions.assertEquals("it's implicit subflow.", context.getData("innerRequest"));
|
||||
}
|
||||
|
||||
// 在p里多线程调用q 10次,每个q取到的参数都是不同的。
|
||||
|
@ -55,12 +56,12 @@ public class ImplicitSubFlowELDeclMultiSpringbootTest extends BaseTest {
|
|||
public void testImplicitSubFlow2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("c1", "it's a request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
|
||||
Set<String> set = context.getData("test");
|
||||
|
||||
// requestData的取值正确
|
||||
Assert.assertEquals(10, set.size());
|
||||
Assertions.assertEquals(10, set.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import com.yomahub.liteflow.exception.MultipleParsersException;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -23,7 +24,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/subflow/application-subInDifferentConfig1.properties")
|
||||
@SpringBootTest(classes = SubflowInDifferentConfigELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -37,19 +38,21 @@ public class SubflowInDifferentConfigELDeclMultiSpringbootTest extends BaseTest
|
|||
@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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>b==>a==>e==>d", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
// 主要测试有不同的配置类型后会不会报出既定的错误
|
||||
@Test(expected = MultipleParsersException.class)
|
||||
@Test
|
||||
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();
|
||||
Assertions.assertThrows(MultipleParsersException.class, () -> {
|
||||
LiteflowConfig config = context.getBean(LiteflowConfig.class);
|
||||
config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml");
|
||||
flowExecutor.reloadRule();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.subflow;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -19,7 +20,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author justin.xu
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/subflow/application-json.properties")
|
||||
@SpringBootTest(classes = SubflowJsonELDeclMultiSpringBootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -33,8 +34,8 @@ public class SubflowJsonELDeclMultiSpringBootTest extends BaseTest {
|
|||
@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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.subflow;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -19,7 +20,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author justin.xu
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/subflow/application-xml.properties")
|
||||
@SpringBootTest(classes = SubflowXMLELDeclMultiSpringBootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -33,8 +34,8 @@ public class SubflowXMLELDeclMultiSpringBootTest extends BaseTest {
|
|||
@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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.subflow;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -19,7 +20,7 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author justin.xu
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/subflow/application-yml.properties")
|
||||
@SpringBootTest(classes = SubflowYmlELDeclMultiSpringBootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -33,8 +34,8 @@ public class SubflowYmlELDeclMultiSpringBootTest extends BaseTest {
|
|||
@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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.switchcase;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -20,7 +21,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/switchcase/application.properties")
|
||||
@SpringBootTest(classes = SwitchELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -33,36 +34,36 @@ public class SwitchELDeclMultiSpringbootTest extends BaseTest {
|
|||
@Test
|
||||
public void testSwitch1() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>h==>b", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/tag/application-json.properties")
|
||||
@SpringBootTest(classes = NodeTagELDeclMultiSpringbootJsonTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -36,15 +37,15 @@ public class NodeTagELDeclMultiSpringbootJsonTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 测试多线程when情况下的tag取值是否正确
|
||||
|
@ -54,9 +55,9 @@ public class NodeTagELDeclMultiSpringbootJsonTest extends BaseTest {
|
|||
for (int i = 0; i < 50; i++) {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
ConcurrentHashSet<String> testSet = context.getData("test");
|
||||
Assert.assertEquals(3, testSet.size());
|
||||
Assertions.assertEquals(3, testSet.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,8 +65,8 @@ public class NodeTagELDeclMultiSpringbootJsonTest extends BaseTest {
|
|||
@Test
|
||||
public void testTag4() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("g", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("g", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/tag/application-xml.properties")
|
||||
@SpringBootTest(classes = NodeTagELDeclMultiSpringbootXmlTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -36,15 +37,15 @@ public class NodeTagELDeclMultiSpringbootXmlTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.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());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>a==>a==>c==>e", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
// 测试多线程when情况下的tag取值是否正确
|
||||
|
@ -54,9 +55,9 @@ public class NodeTagELDeclMultiSpringbootXmlTest extends BaseTest {
|
|||
for (int i = 0; i < 50; i++) {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
ConcurrentHashSet<String> testSet = context.getData("test");
|
||||
Assert.assertEquals(3, testSet.size());
|
||||
Assertions.assertEquals(3, testSet.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,8 +65,8 @@ public class NodeTagELDeclMultiSpringbootXmlTest extends BaseTest {
|
|||
@Test
|
||||
public void testTag4() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("g", response.getExecuteStepStr());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("g", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -21,7 +22,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.3
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/useTTLInWhen/application.properties")
|
||||
@SpringBootTest(classes = UseTTLInWhenELDeclMultiSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -35,11 +36,11 @@ public class UseTTLInWhenELDeclMultiSpringbootTest extends BaseTest {
|
|||
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"));
|
||||
Assertions.assertEquals("hello,b", context.getData("b"));
|
||||
Assertions.assertEquals("hello,c", context.getData("c"));
|
||||
Assertions.assertEquals("hello,d", context.getData("d"));
|
||||
Assertions.assertEquals("hello,e", context.getData("e"));
|
||||
Assertions.assertEquals("hello,f", context.getData("f"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
|||
import com.yomahub.liteflow.exception.WhenTimeoutException;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
@ -23,7 +24,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/whenTimeOut/application1.properties")
|
||||
@SpringBootTest(classes = WhenTimeOutELDeclMultiSpringbootTest1.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -39,8 +40,8 @@ public class WhenTimeOutELDeclMultiSpringbootTest1 extends BaseTest {
|
|||
@Test
|
||||
public void testWhenTimeOut() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
|
||||
Assertions.assertFalse(response.isSuccess());
|
||||
Assertions.assertEquals(WhenTimeoutException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.yomahub.liteflow.test.whenTimeOut;
|
|||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.Resource;
|
|||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestPropertySource(value = "classpath:/whenTimeOut/application2.properties")
|
||||
@SpringBootTest(classes = WhenTimeOutELDeclMultiSpringbootTest2.class)
|
||||
@EnableAutoConfiguration
|
||||
|
@ -38,7 +39,7 @@ public class WhenTimeOutELDeclMultiSpringbootTest2 extends BaseTest {
|
|||
@Test
|
||||
public void testWhenTimeOut() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
liteflow.rule-source=monitorFile/flow.el.xml
|
||||
liteflow.enable-monitor-file=true
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
THEN(a, b, c);
|
||||
</chain>
|
||||
|
||||
</flow>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue