修改测试用例

This commit is contained in:
bryan31
2021-04-04 23:33:48 +08:00
parent ec1467f8c1
commit f37c6f6462
12 changed files with 197 additions and 33 deletions

View File

@@ -8,8 +8,9 @@ import org.junit.Assert;
import org.junit.Test;
/**
* 切面场景单元测试
* 无spring环境的json parser单元测试
* @author Bryan.Zhang
* @since 2.5.0
*/
public class LFParserJsonNoSpringTest {

View File

@@ -0,0 +1,27 @@
package com.yomahub.liteflow.test.parser;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/parser/application-json.xml")
public class LFParserJsonSpringTest {
@Resource
private FlowExecutor flowExecutor;
//测试spring场景的xml parser
@Test
public void testSpring() throws Exception{
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -15,8 +15,9 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 切面场景单元测试
* spring环境的json parser单元测试
* @author Bryan.Zhang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/parser/application-json.properties")
@@ -28,7 +29,7 @@ public class LFParserJsonSpringbootTest {
@Resource
private FlowExecutor flowExecutor;
//测试springboot场景的json parser
//测试spring场景的json parser
@Test
public void testSpringboot() throws Exception{
LiteflowResponse<Slot> response = flowExecutor.execute("chain2", "arg");

View File

@@ -8,8 +8,9 @@ import org.junit.Assert;
import org.junit.Test;
/**
* 切面场景单元测试
* 无spring环境的xml parser单元测试
* @author Bryan.Zhang
* @since 2.5.0
*/
public class LFParserXmlNoSpringTest {

View File

@@ -11,6 +11,11 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境的xml parser单元测试
* @author Bryan.Zhang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/parser/application-xml.xml")
public class LFParserXmlSpringTest {

View File

@@ -16,8 +16,9 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 切面场景单元测试
* springboot环境的xml parser单元测试
* @author Bryan.Zhang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/parser/application-xml.properties")

View File

@@ -0,0 +1,28 @@
package com.yomahub.liteflow.test.parser;
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;
/**
* 无spring环境的yml parser单元测试
* @author Bryan.Zhang
* @since 2.5.0
*/
public class LFParserYmlNoSpringTest {
//测试无spring场景的yml parser
@Test
public void testNoSpring() throws Exception{
FlowExecutor executor = new FlowExecutor();
LiteflowConfig liteflowConfig = new LiteflowConfig();
liteflowConfig.setRuleSource("parser/flow.yml");
executor.setLiteflowConfig(liteflowConfig);
executor.init();
LiteflowResponse<Slot> response = executor.execute("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,32 @@
package com.yomahub.liteflow.test.parser;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境的xml parser单元测试
* @author Bryan.Zhang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/parser/application-yml.xml")
public class LFParserYmlSpringTest {
@Resource
private FlowExecutor flowExecutor;
//测试spring场景的xml parser
@Test
public void testSpring() throws Exception{
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,38 @@
package com.yomahub.liteflow.test.parser;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
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下的yml parser测试用例
* @author Bryan.Zhang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/parser/application-yml.properties")
@SpringBootTest(classes = LFParserYmlSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.parser.cmp"})
public class LFParserYmlSpringbootTest {
@Resource
private FlowExecutor flowExecutor;
//测试无springboot场景的yml parser
@Test
public void testSpringboot() throws Exception{
LiteflowResponse<Slot> response = flowExecutor.execute("chain2", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,23 @@
<?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.parser.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScaner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="parser/flow.json"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<property name="liteflowConfig" ref="liteflowConfig"/>
</bean>
</beans>

View File

@@ -0,0 +1,23 @@
<?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.parser.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScaner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="parser/flow.yml"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<property name="liteflowConfig" ref="liteflowConfig"/>
</bean>
</beans>

View File

@@ -2,45 +2,29 @@ flow:
nodes:
node:
- id: a
class: com.yomahub.liteflow.test.component.AComponent
class: com.yomahub.liteflow.test.parser.cmp.ACmp
- id: b
class: com.yomahub.liteflow.test.component.BComponent
class: com.yomahub.liteflow.test.parser.cmp.BCmp
- id: c
class: com.yomahub.liteflow.test.component.CComponent
class: com.yomahub.liteflow.test.parser.cmp.CCmp
- id: d
class: com.yomahub.liteflow.test.component.DComponent
class: com.yomahub.liteflow.test.parser.cmp.DCmp
- id: e
class: com.yomahub.liteflow.test.component.EComponent
class: com.yomahub.liteflow.test.parser.cmp.ECmp
- id: f
class: com.yomahub.liteflow.test.component.FComponent
class: com.yomahub.liteflow.test.parser.cmp.FCmp
- id: g
class: com.yomahub.liteflow.test.component.GComponent
- id: cond
class: com.yomahub.liteflow.test.component.CondComponent
class: com.yomahub.liteflow.test.parser.cmp.GCmp
chain:
- name: chain1
condition:
- type: then
value: 'a,cond(b|d)'
value: 'a,c'
- type: when
value: 'b,d,e(f|g)'
- type: then
value: 'e,f,g'
value: 'chain2'
- name: chain2
condition:
- type: then
value: 'a,c'
- type: when
value: 'b,d,e,f,g'
- type: then
value: 'c'
- name: chain3
condition:
- type: then
value: 'a,c,strategy1,g'
- name: strategy1
condition:
- type: then
value: m(m1|m2|strategy2)
- name: strategy2
condition:
- type: then
value: 'q,p(p1|p2)'
value: 'c,g,f'