补充测试用例

This commit is contained in:
bryan31
2022-02-24 17:22:10 +08:00
parent 2f41623769
commit 9e01dbfcca
63 changed files with 1157 additions and 139 deletions

View File

@@ -24,7 +24,6 @@ import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BuilderSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.builder.cmp"})
public class BuilderSpringbootTest extends BaseTest {
@Resource

View File

@@ -18,7 +18,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* springboot环境下异步线程超时日志打印测试
* springboot环境下自定义声明节点的测试
* @author Bryan.Zhang
* @since 2.6.4
*/

View File

@@ -1,13 +0,0 @@
package com.yomahub.liteflow.test.customThreadPool;
import com.yomahub.liteflow.thread.ExecutorBuilder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class CustomThreadExecutor implements ExecutorBuilder {
@Override
public ExecutorService buildExecutor() {
return Executors.newCachedThreadPool();
}
}

View File

@@ -1,43 +0,0 @@
package com.yomahub.liteflow.test.customThreadPool;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
/**
* springboot环境下异步线程超时日志打印测试
* @author Bryan.Zhang
* @since 2.6.4
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/customThreadPool/application.properties")
@SpringBootTest(classes = CustomThreadPoolSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.customThreadPool.cmp"})
public class CustomThreadPoolSpringbootTest extends BaseTest {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
private FlowExecutor flowExecutor;
@Test
public void testCustomThreadPool() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertFalse(response.getSlot().getData("threadName").toString().startsWith("lf-when-thead"));
}
}

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.customThreadPool.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,22 +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.customThreadPool.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
this.getSlot().setData("threadName", Thread.currentThread().getName());
System.out.println("BCmp 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.customThreadPool.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!");
}
}

View File

@@ -1,6 +1,8 @@
package com.yomahub.liteflow.test.enable;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
@@ -27,13 +29,9 @@ import org.springframework.test.context.junit4.SpringRunner;
@ComponentScan({"com.yomahub.liteflow.test.enable.cmp"})
public class LiteflowEnableSpringbootTest extends BaseTest {
@Autowired
private ApplicationContext context;
@Test
public void testEnable() {
LiteflowConfig config = context.getBean(LiteflowConfig.class);
LiteflowConfig config = LiteflowConfigGetter.get();
Boolean enable = config.getEnable();
if (enable) {
System.out.println("成功启动,并且打印");

View File

@@ -3,7 +3,6 @@ package com.yomahub.liteflow.test.exception;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.exception.ChainNotFoundException;
import com.yomahub.liteflow.exception.ConfigErrorException;
import com.yomahub.liteflow.exception.FlowExecutorNotInitException;
@@ -32,10 +31,10 @@ import javax.annotation.Resource;
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/exception/application.properties")
@SpringBootTest(classes = FlowExecutorSpringBootTest.class)
@SpringBootTest(classes = ExceptionSpringBootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.exception.cmp1"})
public class FlowExecutorSpringBootTest extends BaseTest {
@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"})
public class ExceptionSpringBootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@@ -65,7 +64,7 @@ public class FlowExecutorSpringBootTest extends BaseTest {
public void testComponentCustomException() throws Exception {
flowExecutor.execute("chain1", "exception");
}
@Test(expected = FlowSystemException.class)
public void testNoConditionInChainException() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "test");
@@ -81,11 +80,4 @@ public class FlowExecutorSpringBootTest extends BaseTest {
Assert.assertNotNull(response.getCause());
Assert.assertNotNull(response.getSlot());
}
// @Test(expected = WhenExecuteException.class)
// public void testWhenExecuteTimeoutException() throws Exception {
// LiteflowResponse response = flowExecutor.execute("chain3", "when");
// Assert.assertFalse(response.isSuccess());
// ReflectionUtils.rethrowException(response.getCause());
// }
}

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.exception.cmp1;
package com.yomahub.liteflow.test.exception.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.exception.cmp1;
package com.yomahub.liteflow.test.exception.cmp;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.NodeComponent;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.exception.cmp1;
package com.yomahub.liteflow.test.exception.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.slf4j.Logger;

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.exception.cmp1;
package com.yomahub.liteflow.test.exception.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.slf4j.Logger;

View File

@@ -1,2 +0,0 @@
liteflow.rule-source=customThreadPool/flow.xml
liteflow.thread-executor-class=com.yomahub.liteflow.test.customThreadPool.CustomThreadExecutor

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
<when value="a,b,c"/>
</chain>
</flow>