【测试用例】liteflow开启和关闭
This commit is contained in:
请叫我猿叔叔
2021-09-28 20:56:40 +08:00
parent 5cb2932188
commit 07e4909f7d
8 changed files with 177 additions and 3 deletions

View File

@@ -1,10 +1,14 @@
package com.yomahub.liteflow.test.enable;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
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.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@@ -12,6 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner;
/**
* 测试springboot下的enable参数
*
* @author Bryan.Zhang
* @since 2.5.10
*/
@@ -22,8 +27,18 @@ 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 testConfig() {
System.out.println("成功启动,并且打印");
public void testEnable() {
LiteflowConfig config = context.getBean(LiteflowConfig.class);
Boolean enable = config.getEnable();
if (enable) {
System.out.println("成功启动,并且打印");
return;
}
Assert.assertFalse(enable);
}
}

View File

@@ -1,2 +1,2 @@
liteflow.enable=false
liteflow.rule-source=enable/flow.xml
liteflow.rule-source=enable/flow.xml

View File

@@ -0,0 +1,45 @@
package com.yomahub.liteflow.test.enable;
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.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境下enable参数
*
* @author qjwyss
* @since 2.6.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/enable/application-local.xml")
public class LiteflowEnableSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Autowired
private ApplicationContext context;
@Test
public void testEnable() throws Exception {
LiteflowConfig config = context.getBean(LiteflowConfig.class);
Boolean enable = config.getEnable();
if (enable) {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
return;
}
Assert.assertFalse(enable);
}
}

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.enable.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

@@ -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.enable.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

@@ -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.enable.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

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.yomahub.liteflow.test.enable.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="enable/flow.json"/>
<property name="enable" value="true"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<property name="liteflowConfig" ref="liteflowConfig"/>
</bean>
</beans>

View File

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