补充测试用例

This commit is contained in:
bryan31
2022-03-06 00:28:36 +08:00
parent 59d440092d
commit bbe1e8f73a
11 changed files with 238 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
package com.yomahub.liteflow.test.parsecustom;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 非spring环境的自定义json parser单元测试
* @author dongguo.tao
* @since 2.5.0
*/
public class CustomParserJsonTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser");
flowExecutor = FlowExecutor.loadInstance(config);
}
//测试springboot场景的自定义json parser
@Test
public void testJsonCustomParser() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "args");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,34 @@
package com.yomahub.liteflow.test.parsecustom;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 非spring环境的自定义xml parser单元测试
* @author bryan.zhang
* @since 2.5.7
*/
public class CustomParserXmlTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser");
flowExecutor = FlowExecutor.loadInstance(config);
}
//测试springboot场景的自定义json parser
@Test
public void testXmlCustomParser() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "args");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.exception.FlowSystemException;
public class ACmp extends NodeComponent {
@Override
public void process() {
String str = this.getSlot().getRequestData();
if(StrUtil.isNotBlank(str) && str.equals("exception")) {
throw new FlowSystemException("chain execute execption");
}
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
}

View File

@@ -0,0 +1,18 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeCondComponent;
public class ECmp extends NodeCondComponent {
@Override
public String processCond() throws Exception {
return "g";
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class FCmp extends NodeComponent {
@Override
public void process() {
System.out.println("FCmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.parsecustom.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class GCmp extends NodeComponent {
@Override
public void process() {
System.out.println("GCmp executed!");
}
}

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.parsecustom.parser;
import com.yomahub.liteflow.parser.ClassJsonFlowParser;
/**
* 模拟用户自定义源解析
* @author dongguo.tao
* @since 2.5.0
*/
public class CustomJsonFlowParser extends ClassJsonFlowParser {
@Override
public String parseCustom() {
//模拟自定义解析结果
return "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"condition\":[{\"type\":\"then\",\"value\":\"c,g,f\"}]},{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,c\"},{\"type\":\"when\",\"value\":\"b,d,e(f|g)\"},{\"type\":\"then\",\"value\":\"chain2\"}]}]}}";
}
}

View File

@@ -0,0 +1,17 @@
package com.yomahub.liteflow.test.parsecustom.parser;
import com.yomahub.liteflow.parser.ClassXmlFlowParser;
/**
* 非spring环境的自定义xml parser单元测试
* 主要测试自定义配置源类是否能引入springboot中的其他依赖
* @author bryan.zhang
* @since 2.5.7
*/
public class CustomXmlFlowParser extends ClassXmlFlowParser {
@Override
public String parseCustom() {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><nodes><node id=\"a\" class=\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"/><node id=\"b\" class=\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"/><node id=\"c\" class=\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"/><node id=\"d\" class=\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"/><node id=\"e\" class=\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"/><node id=\"f\" class=\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"/><node id=\"g\" class=\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"/></nodes><chain name=\"chain1\"><then value=\"a,b,c,d\"/></chain></flow>";
}
}