!18 帮liteflow增加单元测试

Merge pull request !18 from justin.xu/v2.5.0-SNAPSHOT
This commit is contained in:
铂赛东
2021-04-06 17:01:09 +08:00
committed by Gitee
22 changed files with 416 additions and 8 deletions

View File

@@ -0,0 +1,46 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
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.util.HashSet;
import java.util.Set;
/**
* 测试隐式调用子流程
* 单元测试
*
* @author justin.xu
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/subflow/application-implicit.properties")
@SpringBootTest(classes = ImplicitSubFlowTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"})
public class ImplicitSubFlowTest {
@Resource
private FlowExecutor flowExecutor;
public static final Set<Integer> RUN_TIME_SLOT = new HashSet<>();
//这里GCmp中隐式的调用chain4从而执行了hm
@Test
public void testImplicitSubFlow() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain3", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("f==>g==>h==>m", response.getData().printStep());
// 传递了slotIndex则set的size==1
Assert.assertEquals(1, RUN_TIME_SLOT.size());
}
}

View File

@@ -0,0 +1,39 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
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;
/**
* 测试显示调用子流程(json)
* 单元测试
*
* @author justin.xu
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/subflow/application-json.properties")
@SpringBootTest(classes = SubflowJsonSpringBootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"})
public class SubflowJsonSpringBootTest {
@Resource
private FlowExecutor flowExecutor;
//是否按照流程定义配置执行
@Test
public void testExplicitSubFlow() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getData().printStep());
}
}

View File

@@ -0,0 +1,39 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
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;
/**
* 测试显示调用子流程(xml)
* 单元测试
*
* @author justin.xu
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/subflow/application-xml.properties")
@SpringBootTest(classes = SubflowXMLSpringBootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"})
public class SubflowXMLSpringBootTest {
@Resource
private FlowExecutor flowExecutor;
//是否按照流程定义配置执行
@Test
public void testExplicitSubFlow() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getData().printStep());
}
}

View File

@@ -0,0 +1,42 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.test.parser.LFParserXmlSpringbootTest;
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;
/**
* 测试显示调用子流程(yml)
* 单元测试
*
* @author justin.xu
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/subflow/application-yml.properties")
@SpringBootTest(classes = SubflowYmlSpringBootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"})
public class SubflowYmlSpringBootTest {
@Resource
private FlowExecutor flowExecutor;
//是否按照流程定义配置执行
@Test
public void testExplicitSubFlowYml() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "it's a request");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getData().printStep());
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("Acomp executed!");
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("Bcomp executed!");
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("Ccomp executed!");
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("d")
public class DCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("Dcomp executed!");
}
}

View File

@@ -0,0 +1,14 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class ECmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("Ecomp executed!");
}
}

View File

@@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
@Component("f")
public class FCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlotIndex());
System.out.println("Fcomp executed!");
}
}

View File

@@ -0,0 +1,28 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
@Component("g")
public class GCmp extends NodeComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlotIndex());
System.out.println("Gcomp executed!");
flowExecutor.invoke("chain4", "it's implicit subflow.", DefaultSlot.class, this.getSlotIndex());
}
}

View File

@@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
@Component("h")
public class HCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlotIndex());
System.out.println("Hcomp executed!");
}
}

View File

@@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
@Component("m")
public class MCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlotIndex());
System.out.println("Mcomp executed!");
}
}

View File

@@ -54,14 +54,14 @@
- [ ] isEnd方法和this.setIsEnd(true)的功能点测试
- [ ] 条件组件功能点测试(基于springboot环境)
- [ ] 条件组件的功能点测试
- [ ] 显式子流程测试(基于springboot环境)
- [ ] 子流程功能点测试,是否能进入子流程
- [ ] 多个子流程是否能串联衔接
- [ ] 同名节点和同名chain是否chain为优先级最高
- [ ] 多个子流程配置顺序是否和最终执行结果无关(这个需要结合xmljsonyml来测分3种配置方式因为这个和parser有一定的关系)
- [ ] 隐式子流程测试(基于springboot环境)
- [ ] 隐式子流程的功能点测试
- [ ] 多个隐式子流程是否能共享同一个上下文
- [x] 显式子流程测试(基于springboot环境)
- [x] 子流程功能点测试,是否能进入子流程
- [x] 多个子流程是否能串联衔接
- [x] 同名节点和同名chain是否节点为优先级最高
- [x] 多个子流程配置顺序是否和最终执行结果无关(这个需要结合xmljsonyml来测分3种配置方式因为这个和parser有一定的关系)
- [x] 隐式子流程测试(基于springboot环境)
- [x] 隐式子流程的功能点测试
- [x] 多个隐式子流程是否能共享同一个上下文
- [ ] when condition下的线程池功能测试(基于springboot环境)
- [ ] 线程池的基本功能点测试
- [ ] 线程池满了情况下基于errorResume参数的功能点测试

View File

@@ -0,0 +1 @@
liteflow.rule-source=subflow/flow-implicit.xml

View File

@@ -0,0 +1 @@
liteflow.rule-source=subflow/flow.json

View File

@@ -0,0 +1 @@
liteflow.rule-source=subflow/flow.xml

View File

@@ -0,0 +1 @@
liteflow.rule-source=subflow/flow.yml

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain3">
<then value="f,g"/> <!-- g隐式调用chain4 -->
</chain>
<chain name="chain4">
<then value="h,m"/>
</chain>
<!-- f,g,h,m -->
</flow>

View File

@@ -0,0 +1,33 @@
{
"flow": {
"chain": [
{
"name": "chain3",
"condition": [
{"type": "then", "value": "e,d"}
]
},
{
"name": "chain2",
"condition": [
{"type": "then", "value": "b,a"},
{"type": "then", "value": "chain3"}
]
},
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a,b"},
{"type": "then", "value": "c"},
{"type": "then", "value": "chain2"}
]
},
{
"name": "c",
"condition": [
{"type": "then", "value": "d,e"}
]
}
]
}
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
<then value="a,b"/>
<then value="c"/> <!-- 显式的调用了chain(c)当这里存在Node(c)时测试是否为优先调用了Node(c)-->
<then value="chain2"/> <!-- 测试调用c流程后是否正常调用chain2 -->
</chain>
<chain name="c">
<then value="d,e"/>
</chain>
<chain name="chain2">
<then value="b,a"/>
<then value="chain3"/>
</chain>
<chain name="chain3">
<then value="e,d"/>
</chain>
<!-- a,b,c,b,a,e,d -->
</flow>

View File

@@ -0,0 +1,24 @@
flow:
chain:
- name: chain3
condition:
- type: then
value: 'e,d'
- name: chain1
condition:
- type: then
value: 'a,b'
- type: then
value: 'c'
- type: then
value: 'chain2'
- name: c
condition:
- type: then
value: 'd,e'
- name: chain2
condition:
- type: then
value: 'b,a'
- type: then
value: 'chain3'