mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
补充测试用例
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package com.yomahub.liteflow.test.component;
|
||||
|
||||
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;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
||||
/**
|
||||
* 组件功能点测试
|
||||
* 单元测试
|
||||
*
|
||||
* @author donguo.tao
|
||||
*/
|
||||
public class FlowExecutorTest extends BaseTest {
|
||||
|
||||
private static FlowExecutor flowExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void init(){
|
||||
LiteflowConfig config = new LiteflowConfig();
|
||||
config.setRuleSource("component/flow.xml");
|
||||
flowExecutor = FlowExecutor.loadInstance(config);
|
||||
}
|
||||
|
||||
//isAccess方法的功能测试
|
||||
@Test
|
||||
public void testIsAccess() {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", 101);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertNotNull(response.getSlot().getResponseData());
|
||||
}
|
||||
|
||||
//组件抛错的功能点测试
|
||||
@Test(expected = ArithmeticException.class)
|
||||
public void testComponentException() throws Throwable {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", 0);
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertEquals("/ by zero", response.getMessage());
|
||||
throw response.getCause();
|
||||
}
|
||||
|
||||
//isContinueOnError方法的功能点测试
|
||||
@Test
|
||||
public void testIsContinueOnError() throws Throwable {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", 0);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertNull(response.getCause());
|
||||
}
|
||||
|
||||
//isEnd方法的功能点测试
|
||||
@Test
|
||||
public void testIsEnd() throws Exception {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", 10);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("d",response.getSlot().getExecuteStepStr());
|
||||
}
|
||||
|
||||
//setIsEnd方法的功能点测试
|
||||
@Test
|
||||
public void testSetIsEnd1() throws Exception {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain5", 10);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("e",response.getSlot().getExecuteStepStr());
|
||||
}
|
||||
|
||||
//条件组件的功能点测试
|
||||
@Test
|
||||
public void testNodeCondComponent() {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain6", 0);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//测试setIsEnd如果为true,continueError也为true,那不应该continue了
|
||||
@Test
|
||||
public void testSetIsEnd2() throws Exception {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain7", 10);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("g",response.getSlot().getExecuteStepStr());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yomahub.liteflow.test.component.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class ACmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("AComp executed!");
|
||||
this.getSlot().setResponseData("AComp executed!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
Integer requestData = this.getSlot().getRequestData();
|
||||
if (Objects.nonNull(requestData) && requestData > 100){
|
||||
return true;
|
||||
}
|
||||
System.out.println("AComp isAccess false.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.component.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class BCmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BComp executed!");
|
||||
Integer requestData = this.getSlot().getRequestData();
|
||||
Integer divisor = 130;
|
||||
Integer result = divisor / requestData;
|
||||
this.getSlot().setResponseData(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccess() {
|
||||
Integer requestData = this.getSlot().getRequestData();
|
||||
if (Objects.nonNull(requestData)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.component.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class CCmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CComp executed!");
|
||||
Integer requestData = this.getSlot().getRequestData();
|
||||
Integer divisor = 130;
|
||||
Integer result = divisor / requestData;
|
||||
this.getSlot().setResponseData(result);
|
||||
System.out.println("responseData="+Integer.parseInt(this.getSlot().getResponseData()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinueOnError() {
|
||||
Integer requestData = this.getSlot().getRequestData();
|
||||
if (Objects.nonNull(requestData)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yomahub.liteflow.test.component.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class DCmp extends NodeComponent {
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
System.out.println("DComp executed!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnd() {
|
||||
//组件的process执行完之后才会执行isEnd
|
||||
Object requestData = this.getSlot().getResponseData();
|
||||
if (Objects.isNull(requestData)){
|
||||
System.out.println("DComp flow isEnd, because of responseData is null.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.yomahub.liteflow.test.component.cmp1;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class ECmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
System.out.println("EComp executed!");
|
||||
Object responseData = this.getSlot().getResponseData();
|
||||
if (Objects.isNull(responseData)){
|
||||
System.out.println("EComp responseData flow must be set end .");
|
||||
//执行到某个条件时,手动结束流程。
|
||||
this.setIsEnd(true);
|
||||
}
|
||||
System.out.println("EComp responseData responseData=" + JSON.toJSONString(responseData));
|
||||
}
|
||||
}
|
||||
@@ -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.component.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class GCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("GCmp executed!");
|
||||
this.setIsEnd(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinueOnError() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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.component.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class HCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("HCmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.yomahub.liteflow.test.component.cmp2;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeCondComponent;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FCondCmp extends NodeCondComponent {
|
||||
@Override
|
||||
public String processCond() {
|
||||
Integer requestData = this.getSlot().getRequestData();
|
||||
if (Objects.isNull(requestData)){
|
||||
return "d";
|
||||
} else if(requestData == 0){
|
||||
return "c";
|
||||
} else {
|
||||
return "b";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="a" class="com.yomahub.liteflow.test.component.cmp1.ACmp"/>
|
||||
<node id="b" class="com.yomahub.liteflow.test.component.cmp1.BCmp"/>
|
||||
<node id="c" class="com.yomahub.liteflow.test.component.cmp1.CCmp"/>
|
||||
<node id="d" class="com.yomahub.liteflow.test.component.cmp1.DCmp"/>
|
||||
<node id="e" class="com.yomahub.liteflow.test.component.cmp1.ECmp"/>
|
||||
<node id="f" class="com.yomahub.liteflow.test.component.cmp2.FCondCmp"/>
|
||||
<node id="g" class="com.yomahub.liteflow.test.component.cmp1.GCmp"/>
|
||||
<node id="h" class="com.yomahub.liteflow.test.component.cmp1.HCmp"/>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
<then value="a"/>
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
<then value="b"/>
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
<then value="c"/>
|
||||
</chain>
|
||||
|
||||
<chain name="chain4">
|
||||
<then value="a,d,c"/>
|
||||
</chain>
|
||||
|
||||
<chain name="chain5">
|
||||
<then value="a,e,c"/>
|
||||
</chain>
|
||||
|
||||
<chain name="chain6">
|
||||
<then value="f(d | c | b)" />
|
||||
</chain>
|
||||
|
||||
<chain name="chain7">
|
||||
<then value="g,h"/>
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -3,7 +3,6 @@ package com.yomahub.liteflow.test.component;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.entity.data.DefaultSlot;
|
||||
import com.yomahub.liteflow.entity.data.LiteflowResponse;
|
||||
import com.yomahub.liteflow.exception.ChainEndException;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -28,11 +27,11 @@ import java.lang.reflect.UndeclaredThrowableException;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/component/application.properties")
|
||||
@SpringBootTest(classes = FlowExecutorTest.class)
|
||||
@SpringBootTest(classes = FlowExecutorSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"})
|
||||
public class FlowExecutorTest extends BaseTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorTest.class);
|
||||
public class FlowExecutorSpringbootTest extends BaseTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorSpringbootTest.class);
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
@@ -55,11 +54,11 @@ public class FlowExecutorTest extends BaseTest {
|
||||
}
|
||||
|
||||
//isContinueOnError方法的功能点测试
|
||||
@Test(expected = UndeclaredThrowableException.class)
|
||||
@Test
|
||||
public void testIsContinueOnError() throws Exception {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", 0);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
ReflectionUtils.rethrowException(response.getCause());
|
||||
Assert.assertNull(response.getCause());
|
||||
}
|
||||
|
||||
//isEnd方法的功能点测试
|
||||
@@ -48,11 +48,11 @@ public class ComponentSpringTest extends BaseTest {
|
||||
}
|
||||
|
||||
//isContinueOnError方法的功能点测试
|
||||
@Test(expected = UndeclaredThrowableException.class)
|
||||
@Test
|
||||
public void testIsContinueOnError() throws Exception {
|
||||
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", 0);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
ReflectionUtils.rethrowException(response.getCause());
|
||||
Assert.assertNull(response.getCause());
|
||||
}
|
||||
|
||||
//isEnd方法的功能点测试
|
||||
|
||||
Reference in New Issue
Block a user