补充测试用例

This commit is contained in:
bryan31
2022-03-06 00:11:29 +08:00
parent 9aeb10d40f
commit 59d440092d
6 changed files with 113 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
package com.yomahub.liteflow.test.nullParam;
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 org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 单元测试:传递null param导致NPE的优化代码
*
* @author LeoLee
* @since 2.6.6
*/
public class NullParamTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("nullParam/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
}
/**
* 支持无参的flow执行以及param 为null时的异常抛出
*/
@Test
public void testNullParam() throws Exception {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,20 @@
/**
* <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;
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");
}
}

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.nullParam.cmp;
import com.yomahub.liteflow.core.NodeComponent;
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");
}
}

View File

@@ -0,0 +1,20 @@
/**
* <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;
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
System.out.println("CCmp param:" + this.getSlot().getOutput("CCmp"));
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.nullParam.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.nullParam.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.nullParam.cmp.CCmp"/>
</nodes>
<chain name="chain1">
<then value="a,b"/>
<when value="c"/>
</chain>
</flow>

View File

@@ -21,10 +21,10 @@ import org.springframework.test.context.junit4.SpringRunner;
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/nullParam/application.properties")
@SpringBootTest(classes = NullParamTest.class)
@SpringBootTest(classes = NullParamSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.nullParam.cmp"})
public class NullParamTest {
public class NullParamSpringbootTest {
@Autowired
private FlowExecutor flowExecutor;