补充测试用例

This commit is contained in:
bryan31
2022-03-06 23:57:15 +08:00
parent bbe1e8f73a
commit b99f2a837e
24 changed files with 608 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
package com.yomahub.liteflow.test.parser;
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 Bryan.Zhang
* @since 2.5.0
*/
public class JsonParserTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("parser/flow.json");
flowExecutor = FlowExecutor.loadInstance(config);
}
//测试spring场景的json parser
@Test
public void testJsonParser() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,34 @@
package com.yomahub.liteflow.test.parser;
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.0
*/
public class XmlParserTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("parser/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
}
//测试无springboot场景的xml parser
@Test
public void testXmlParser() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,34 @@
package com.yomahub.liteflow.test.parser;
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;
/**
* springboot下的yml parser测试用例
* @author Bryan.Zhang
* @since 2.5.0
*/
public class YmlParserTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("parser/flow.yml");
flowExecutor = FlowExecutor.loadInstance(config);
}
//测试无springboot场景的yml parser
@Test
public void testYmlParser() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
}
}

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.parser.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class ACmp extends NodeComponent {
@Override
public void process() {
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.parser.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.parser.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.parser.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.parser.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.parser.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.parser.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,59 @@
package com.yomahub.liteflow.test.preAndFinally;
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环境下pre节点和finally节点的测试
* @author Bryan.Zhang
* @since 2.6.4
*/
public class PreAndFinallyTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("preAndFinally/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
}
//测试普通的pre和finally节点
@Test
public void testPreAndFinally1() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getSlot().getExecuteStepStr());
}
//测试pre和finally节点不放在开头和结尾的情况
@Test
public void testPreAndFinally2() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getSlot().getExecuteStepStr());
}
//测试有节点报错是否还执行finally节点的情况其中d节点会报错但依旧执行f1,f2节点
@Test
public void testPreAndFinally3() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getSlot().getExecuteStepStr());
}
//测试在finally节点里是否能获取exception
@Test
public void testPreAndFinally4() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertTrue(response.getSlot().getData("hasEx"));
}
}

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

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.preAndFinally.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class Finally1Cmp extends NodeComponent {
@Override
public void process() {
System.out.println("Finally1Cmp 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.preAndFinally.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class Finally2Cmp extends NodeComponent {
@Override
public void process() {
System.out.println("Finally2Cmp executed!");
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.preAndFinally.cmp;
import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.Slot;
public class Finally3Cmp extends NodeComponent {
@Override
public void process() throws Exception{
Slot slot = this.getSlot();
if (ObjectUtil.isNull(slot.getException())){
slot.setData("hasEx", false);
}else{
slot.setData("hasEx", true);
}
System.out.println("Finally3Cmp 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.preAndFinally.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class Pre1Cmp extends NodeComponent {
@Override
public void process() {
System.out.println("Pre1Cmp 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.preAndFinally.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class Pre2Cmp extends NodeComponent {
@Override
public void process() {
System.out.println("Pre2Cmp executed!");
}
}

View File

@@ -0,0 +1,52 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "a",
"class": "com.yomahub.liteflow.test.parser.cmp.ACmp"
},
{
"id": "b",
"class": "com.yomahub.liteflow.test.parser.cmp.BCmp"
},
{
"id": "c",
"class": "com.yomahub.liteflow.test.parser.cmp.CCmp"
},
{
"id": "d",
"class": "com.yomahub.liteflow.test.parser.cmp.DCmp"
},
{
"id": "e",
"class": "com.yomahub.liteflow.test.parser.cmp.ECmp"
},
{
"id": "f",
"class": "com.yomahub.liteflow.test.parser.cmp.FCmp"
},
{
"id": "g",
"class": "com.yomahub.liteflow.test.parser.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,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.parser.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.parser.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.parser.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.parser.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.parser.cmp.ECmp"/>
<node id="f" class="com.yomahub.liteflow.test.parser.cmp.FCmp"/>
<node id="g" class="com.yomahub.liteflow.test.parser.cmp.GCmp"/>
</nodes>
<chain name="chain1">
<then value="a,c"/>
<when value="b,d,e(f|g)"/>
<then value="chain2"/>
</chain>
<chain name="chain2">
<then value="c,g,f"/>
</chain>
</flow>

View File

@@ -0,0 +1,30 @@
flow:
nodes:
node:
- id: a
class: com.yomahub.liteflow.test.parser.cmp.ACmp
- id: b
class: com.yomahub.liteflow.test.parser.cmp.BCmp
- id: c
class: com.yomahub.liteflow.test.parser.cmp.CCmp
- id: d
class: com.yomahub.liteflow.test.parser.cmp.DCmp
- id: e
class: com.yomahub.liteflow.test.parser.cmp.ECmp
- id: f
class: com.yomahub.liteflow.test.parser.cmp.FCmp
- id: g
class: com.yomahub.liteflow.test.parser.cmp.GCmp
chain:
- name: chain1
condition:
- type: then
value: 'a,c'
- type: when
value: 'b,d,e(f|g)'
- type: then
value: 'chain2'
- name: chain2
condition:
- type: then
value: 'c,g,f'

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.preAndFinally.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.preAndFinally.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.preAndFinally.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.preAndFinally.cmp.DCmp"/>
<node id="f1" class="com.yomahub.liteflow.test.preAndFinally.cmp.Finally1Cmp"/>
<node id="f2" class="com.yomahub.liteflow.test.preAndFinally.cmp.Finally2Cmp"/>
<node id="f3" class="com.yomahub.liteflow.test.preAndFinally.cmp.Finally3Cmp"/>
<node id="p1" class="com.yomahub.liteflow.test.preAndFinally.cmp.Pre1Cmp"/>
<node id="p2" class="com.yomahub.liteflow.test.preAndFinally.cmp.Pre2Cmp"/>
</nodes>
<chain name="chain1">
<pre value="p1,p2"/>
<then value="a,b,c"/>
<finally value="f1,f2"/>
</chain>
<chain name="chain2">
<then value="a"/>
<pre value="p1,p2"/>
<finally value="f1,f2"/>
<then value="b,c"/>
</chain>
<chain name="chain3">
<pre value="p1,p2"/>
<then value="a,d,c"/>
<finally value="f1,f2"/>
</chain>
<chain name="chain4">
<then value="a,d,c"/>
<finally value="f3"/>
</chain>
</flow>