补充测试用例

This commit is contained in:
bryan31
2022-03-08 00:39:26 +08:00
parent 2114394baa
commit 64aff87fb8
12 changed files with 395 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
package com.yomahub.liteflow.test.tag;
import cn.hutool.core.collection.ConcurrentHashSet;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
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环境下组件标签的测试
* @author Bryan.Zhang
* @since 2.5.0
*/
public class NodeTagJsonTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("tag/flow.json");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testTag1() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("123",response.getSlot().getData("test"));
}
@Test
public void testTag2() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().getExecuteStepStr());
}
//测试多线程when情况下的tag取值是否正确
//这里循环多次的原因是因为when多线程有时候因为凑巧可能正确。所以多次情况下在2.6.4版本肯定出错
@Test
public void testTag3() throws Exception{
for (int i = 0; i < 50; i++) {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
ConcurrentHashSet<String> testSet = response.getSlot().getData("test");
Assert.assertEquals(3, testSet.size());
}
}
//测试tag是否能在isAccess中起效
@Test
public void testTag4() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("g", response.getSlot().getExecuteStepStr());
}
}

View File

@@ -0,0 +1,63 @@
package com.yomahub.liteflow.test.tag;
import cn.hutool.core.collection.ConcurrentHashSet;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
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环境下组件标签的测试
* @author Bryan.Zhang
* @since 2.5.0
*/
public class NodeTagXmlTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("tag/flow.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testTag1() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("123",response.getSlot().getData("test"));
}
@Test
public void testTag2() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().getExecuteStepStr());
}
//测试多线程when情况下的tag取值是否正确
//这里循环多次的原因是因为when多线程有时候因为凑巧可能正确。所以多次情况下在2.6.4版本肯定出错
@Test
public void testTag3() throws Exception{
for (int i = 0; i < 50; i++) {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
ConcurrentHashSet<String> testSet = response.getSlot().getData("test");
Assert.assertEquals(3, testSet.size());
}
}
//测试tag是否能在isAccess中起效
@Test
public void testTag4() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("g", response.getSlot().getExecuteStepStr());
}
}

View File

@@ -0,0 +1,28 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.tag.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.Slot;
public class ACmp extends NodeComponent {
@Override
public void process() {
String testKey = "test";
Slot slot = this.getSlot();
if (slot.getData(testKey) == null){
slot.setData(testKey,this.getTag());
}else{
String s = slot.getData(testKey);
s += this.getTag();
slot.setData(testKey, s);
}
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.tag.cmp;
import cn.hutool.core.collection.ConcurrentHashSet;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.Slot;
public class B1Cmp extends NodeComponent {
@Override
public void process() {
Slot slot = this.getSlot();
slot.setData("test",new ConcurrentHashSet<String>());
}
}

View File

@@ -0,0 +1,22 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.tag.cmp;
import cn.hutool.core.collection.ConcurrentHashSet;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.Slot;
public class BCmp extends NodeComponent {
@Override
public void process() {
Slot slot = this.getSlot();
ConcurrentHashSet<String> testSet = slot.getData("test");
testSet.add(this.getTag());
}
}

View File

@@ -0,0 +1,22 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.tag.cmp;
import com.yomahub.liteflow.core.NodeCondComponent;
public class CCmp extends NodeCondComponent {
@Override
public String processCond() throws Exception {
if(this.getTag().equals("2")){
return "e";
}else{
return "d";
}
}
}

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

View File

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

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.tag.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,67 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "a",
"class": "com.yomahub.liteflow.test.tag.cmp.ACmp"
},
{
"id": "b",
"class": "com.yomahub.liteflow.test.tag.cmp.BCmp"
},
{
"id": "b1",
"class": "com.yomahub.liteflow.test.tag.cmp.B1Cmp"
},
{
"id": "c",
"class": "com.yomahub.liteflow.test.tag.cmp.CCmp"
},
{
"id": "d",
"class": "com.yomahub.liteflow.test.tag.cmp.DCmp"
},
{
"id": "e",
"class": "com.yomahub.liteflow.test.tag.cmp.ECmp"
},
{
"id": "f",
"class": "com.yomahub.liteflow.test.tag.cmp.FCmp"
},
{
"id": "g",
"class": "com.yomahub.liteflow.test.tag.cmp.GCmp"
}
]
},
"chain": [
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a[1],a[2],a[3]"}
]
},
{
"name": "chain2",
"condition": [
{"type": "then", "value": "a[1],a[2],a[3],c[2](d[5]|e[6])"}
]
},
{
"name": "chain3",
"condition": [
{"type": "then", "value": "b1"},
{"type": "when", "value": "b[1],b[2],b[3]"}
]
},
{
"name": "chain4",
"condition": [
{"type": "then", "value": "f[false],g"}
]
}
]
}
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.tag.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.tag.cmp.BCmp"/>
<node id="b1" class="com.yomahub.liteflow.test.tag.cmp.B1Cmp"/>
<node id="c" class="com.yomahub.liteflow.test.tag.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.tag.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.tag.cmp.ECmp"/>
<node id="f" class="com.yomahub.liteflow.test.tag.cmp.FCmp"/>
<node id="g" class="com.yomahub.liteflow.test.tag.cmp.GCmp"/>
</nodes>
<chain name="chain1">
<then value="a[1],a[2],a[3]"/>
</chain>
<chain name="chain2">
<then value="a[1],a[2],a[3],c[2](d[5]|e[6])"/>
</chain>
<chain name="chain3">
<then value="b1"/>
<when value="b[1],b[2],b[3]"/>
</chain>
<chain name="chain4">
<then value="f[false],g"/>
</chain>
</flow>