mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
单元测试提交
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.yomahub.liteflow.test.nullParam;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 单元测试:传递null param导致NPE的优化代码
|
||||
*
|
||||
* @Author LeoLee
|
||||
* @Date 2021/12/9 16:58
|
||||
* @Version 1.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/nullParam/application.properties")
|
||||
@SpringBootTest(classes = NullParamTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.nullParam.cmp"})
|
||||
public class NullParamTest {
|
||||
|
||||
@Autowired
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
/**
|
||||
* 支持无参的flow执行,以及param 为null时的异常抛出
|
||||
* @Author LeoLee
|
||||
* @Date 17:25 2021/12/9
|
||||
*/
|
||||
@Test
|
||||
public void testNullParam() throws Exception {
|
||||
//flowExecutor.execute("chain1", null);//NullParamException: data slot can't accept null param
|
||||
flowExecutor.execute("chain1");
|
||||
//flowExecutor.execute2Resp("chain1", null);//NullParamException: data slot can't accept null param
|
||||
flowExecutor.execute2Resp("chain1");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.nullParam.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!");
|
||||
System.out.println("get request data:" + this.getSlot().getRequestData());
|
||||
this.getSlot().setInput("BCmp", "param for BCmp");
|
||||
}
|
||||
}
|
||||
@@ -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.nullParam.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!");
|
||||
System.out.println("BCmp param:" + this.getSlot().getInput("BCmp"));
|
||||
this.getSlot().setOutput("CCmp", "param for CCmp");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.nullParam.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
System.out.println("CCmp param:" + this.getSlot().getOutput("CCmp"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
liteflow.rule-source=nullParam/flow.xml
|
||||
liteflow.print-banner=true
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
<!--同步执行-->
|
||||
<then value="a,b"/>
|
||||
<when value="c"/>
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user