更新单元测试

This commit is contained in:
zendwang
2021-04-09 11:49:44 +08:00
parent 4b2c197628
commit f267212ff1
6 changed files with 0 additions and 176 deletions

View File

@@ -1,15 +0,0 @@
package com.yomahub.liteflow.test.flow;
import com.yomahub.liteflow.entity.data.AbsSlot;
public class CustomSlot extends AbsSlot {
private String name;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
}

View File

@@ -1,58 +0,0 @@
package com.yomahub.liteflow.test.flow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.property.LiteflowConfig;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.util.ReflectionUtils;
public class FlowExecutorTest {
@Test
public void testMethodExecute() {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("flow/flow.json");
FlowExecutor executor = new FlowExecutor();
executor.setLiteflowConfig(config);
executor.init();
LiteflowResponse<CustomSlot> response = executor.execute("chain1", "test0", CustomSlot.class);
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("custom", response.getSlot().getName());
}
@Test(expected=RuntimeException.class)
public void testMethodExecuteWithException() throws Exception{
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("flow/flow.json");
FlowExecutor executor = new FlowExecutor();
executor.setLiteflowConfig(config);
executor.init();
LiteflowResponse<CustomSlot> response = executor.execute("chain1", "test1", CustomSlot.class);
Assert.assertFalse(response.isSuccess());
ReflectionUtils.rethrowException(response.getCause());
}
@Test
public void testMethodInvoke() throws Exception {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("flow/flow.json");
FlowExecutor executor = new FlowExecutor();
executor.setLiteflowConfig(config);
executor.init();
CustomSlot slot = executor.invoke("chain1", "test0", CustomSlot.class);
Assert.assertEquals("custom", slot.getName());
}
@Test(expected=RuntimeException.class)
public void testMethodInvokeWithException() throws Exception {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("flow/flow.json");
FlowExecutor executor = new FlowExecutor();
executor.setLiteflowConfig(config);
executor.init();
Slot slot = executor.invoke("chain1", "test1", CustomSlot.class);
}
}

View File

@@ -1,20 +0,0 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.flow.cmp;
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("ACmp executed!");
}
}

View File

@@ -1,21 +0,0 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.flow.cmp;
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("BCmp executed!");
}
}

View File

@@ -1,34 +0,0 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.flow.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.test.flow.CustomSlot;
import org.springframework.stereotype.Component;
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
if(this.getSlot() instanceof CustomSlot) {
CustomSlot slot = this.getSlot();
String str = slot.getRequestData();
if(StrUtil.isNotBlank(str) && str.equals("test0")) {
slot.setName("custom");
}
if(StrUtil.isNotBlank(str) && str.equals("test1")) {
slot.setName("custom");
throw new RuntimeException("customException");
}
}
System.out.println("CCmp executed!");
}
}

View File

@@ -1,28 +0,0 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "a",
"class": "com.yomahub.liteflow.test.flow.cmp.ACmp"
},
{
"id": "b",
"class": "com.yomahub.liteflow.test.flow.cmp.BCmp"
},
{
"id": "c",
"class": "com.yomahub.liteflow.test.flow.cmp.CCmp"
}
]
},
"chain": [
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a,b,c"}
]
}
]
}
}