feature #I5RG4H 选择组件支持组件标签选择

This commit is contained in:
everywhere.z
2022-10-03 19:30:57 +08:00
parent 527102eece
commit fdae528311
43 changed files with 842 additions and 21 deletions

View File

@@ -17,6 +17,8 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
/**
* 选择Condition
@@ -27,6 +29,8 @@ public class SwitchCondition extends Condition{
private final Map<String, Executable> targetMap = new HashMap<>();
private final String TAG_PREFIX = "tag:";
@Override
public void execute(Integer slotIndex) throws Exception {
if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())){
@@ -40,7 +44,23 @@ public class SwitchCondition extends Condition{
Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getSwitchNode().getInstance().getClass());
String targetId = slot.getSwitchResult(originalClass.getName());
if (StrUtil.isNotBlank(targetId)) {
Executable targetExecutor = targetMap.get(targetId);
Executable targetExecutor;
//这里要判断是否跳转到tag
if (targetId.startsWith(TAG_PREFIX)){
String targetTag = targetId.replaceAll(TAG_PREFIX, "");
targetExecutor = targetMap.values().stream().filter(executable -> {
if (executable instanceof Node){
Node node = (Node) executable;
return targetTag.equals(node.getTag());
}else{
return false;
}
}).findFirst().orElse(null);
}else{
targetExecutor = targetMap.get(targetId);
}
if (ObjectUtil.isNotNull(targetExecutor)) {
//switch的目标不能是Pre节点或者Finally节点
if (targetExecutor instanceof PreCondition || targetExecutor instanceof FinallyCondition){

View File

@@ -0,0 +1,53 @@
package com.yomahub.liteflow.test.switchcase;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
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环境最普通的例子测试
* @author Bryan.Zhang
* @since 2.6.4
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/switchcase/application.properties")
@SpringBootTest(classes = SwitchELDeclMultiSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.switchcase.cmp"})
public class SwitchELDeclMultiSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testSwitch1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr());
}
@Test
public void testSwitch2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch3() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>f==>b",response.getExecuteStepStr());
}
}

View File

@@ -0,0 +1,49 @@
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.AnnotationNodeTypeEnum;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.test.base.cmp.TestDomain;
import javax.annotation.Resource;
@LiteflowComponent
public class CmpConfig {
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
public void processA(NodeComponent bindCmp) {
System.out.println("ACmp executed!");
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b")
public void processB(NodeComponent bindCmp) {
System.out.println("BCmp executed!");
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "c")
public void processC(NodeComponent bindCmp) {
System.out.println("CCmp executed!");
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,nodeId = "d")
public void processD(NodeComponent bindCmp) {
System.out.println("CCmp executed!");
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "e",nodeType = AnnotationNodeTypeEnum.SWITCH)
public String processE(NodeComponent bindCmp) {
return "d";
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH,nodeId = "f",nodeType = AnnotationNodeTypeEnum.SWITCH)
public String processF(NodeComponent bindCmp) {
return "tag:td";
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=switchcase/flow.el.xml

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
THEN(
a,
SWITCH(e).to(d),
b
);
</chain>
<chain name="chain2">
THEN(
a,
SWITCH(e).to(b, d)
);
</chain>
<chain name="chain3">
THEN(
a,
SWITCH(f).to(b.tag("td"), d)
);
</chain>
</flow>

View File

@@ -0,0 +1,52 @@
package com.yomahub.liteflow.test.switchcase;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
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环境最普通的例子测试
* @author Bryan.Zhang
* @since 2.6.4
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/switchcase/application.properties")
@SpringBootTest(classes = SwitchELDeclSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.switchcase.cmp"})
public class SwitchELDeclSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testSwitch1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr());
}
@Test
public void testSwitch2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch3() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>f==>b",response.getExecuteStepStr());
}
}

View File

@@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
@LiteflowComponent("a")
@LiteflowCmpDefine
public class ACmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
@LiteflowComponent("b")
@LiteflowCmpDefine
public class BCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("BCmp executed!");
}
}

View File

@@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
@LiteflowComponent("c")
@LiteflowCmpDefine
public class CCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("CCmp executed!");
}
}

View File

@@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
@LiteflowComponent("d")
@LiteflowCmpDefine
public class DCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
System.out.println("DCmp executed!");
}
}

View File

@@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("e")
@LiteflowSwitchCmpDefine
public class ESwitchCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS_SWITCH)
public String processSwitch(NodeComponent bindCmp) throws Exception {
return "d";
}
}

View File

@@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import org.springframework.stereotype.Component;
@Component("f")
@LiteflowSwitchCmpDefine
public class FSwitchCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS_SWITCH)
public String processSwitch(NodeComponent bindCmp) throws Exception {
return "tag:td";
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=switchcase/flow.el.xml

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
THEN(
a,
SWITCH(e).to(d),
b
);
</chain>
<chain name="chain2">
THEN(
a,
SWITCH(e).to(b, d)
);
</chain>
<chain name="chain3">
THEN(
a,
SWITCH(f).to(b.tag("td"), d)
);
</chain>
</flow>

View File

@@ -0,0 +1,43 @@
package com.yomahub.liteflow.test.switchcase;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class SwitchTest extends BaseTest{
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("switchcase/flow.el.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testSwitch1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr());
}
@Test
public void testSwitch2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch3() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>f==>b",response.getExecuteStepStr());
}
}

View File

@@ -0,0 +1,18 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
}

View File

@@ -0,0 +1,18 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
public class ESwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "d";
}
}

View File

@@ -0,0 +1,18 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
public class FSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "tag:td";
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=switchcase/flow.el.xml

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.switchcase.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.switchcase.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.switchcase.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.switchcase.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.switchcase.cmp.ESwitchCmp"/>
<node id="f" class="com.yomahub.liteflow.test.switchcase.cmp.FSwitchCmp"/>
</nodes>
<chain name="chain1">
THEN(
a,
SWITCH(e).to(d),
b
);
</chain>
<chain name="chain2">
THEN(
a,
SWITCH(e).to(b, d)
);
</chain>
<chain name="chain3">
THEN(
a,
SWITCH(f).to(b.tag("td"), d)
);
</chain>
</flow>

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.switchError;
package com.yomahub.liteflow.test.switchcase;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
@@ -19,10 +19,10 @@ import javax.annotation.Resource;
* @author Bryan.Zhang
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/switchError/application.properties")
@TestPropertySource(value = "classpath:/switchcase/application.properties")
@SpringBootTest(classes = SwitchELSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.switchError.cmp"})
@ComponentScan({"com.yomahub.liteflow.test.switchcase.cmp"})
public class SwitchELSpringbootTest extends BaseTest {
@Resource
@@ -32,8 +32,23 @@ public class SwitchELSpringbootTest extends BaseTest {
//run QlExpress Exception at line 1 :
// switch().to(): 只有一个node时出错
@Test
public void testSwitchError() throws Exception{
public void testSwitch1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr());
}
@Test
public void testSwitch2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch3() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>f==>b",response.getExecuteStepStr());
}
}

View File

@@ -5,7 +5,7 @@
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.switchError.cmp;
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
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.switchError.cmp;
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
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.switchError.cmp;
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
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.switchError.cmp;
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
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.switchError.cmp;
package com.yomahub.liteflow.test.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;

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.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("f")
public class FSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "tag:td";
}
}

View File

@@ -1 +0,0 @@
liteflow.rule-source=switchError/flow.el.xml

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
THEN(
a,
SWITCH(e).to(d),
b
);
</chain>
</flow>

View File

@@ -0,0 +1 @@
liteflow.rule-source=switchcase/flow.el.xml

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
THEN(
a,
SWITCH(e).to(d),
b
);
</chain>
<chain name="chain2">
THEN(
a,
SWITCH(e).to(b, d)
);
</chain>
<chain name="chain3">
THEN(
a,
SWITCH(f).to(b.tag("td"), d)
);
</chain>
</flow>

View File

@@ -0,0 +1,41 @@
package com.yomahub.liteflow.test.switchcase;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
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:/switchcase/application.xml")
public class SwitchELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testSwitch1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d==>b", response.getExecuteStepStr());
}
@Test
public void testSwitch2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>e==>d",response.getExecuteStepStr());
}
@Test
public void testSwitch3() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>f==>b",response.getExecuteStepStr());
}
}

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.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("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.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("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.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp 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.switchcase.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("d")
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
}

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.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class ESwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "d";
}
}

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.switchcase.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("f")
public class FSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "tag:td";
}
}

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.switchcase.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.spi.spring.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="switchcase/flow.el.xml"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<constructor-arg name="liteflowConfig" ref="liteflowConfig"/>
</bean>
</beans>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
THEN(
a,
SWITCH(e).to(d),
b
);
</chain>
<chain name="chain2">
THEN(
a,
SWITCH(e).to(b, d)
);
</chain>
<chain name="chain3">
THEN(
a,
SWITCH(f).to(b.tag("td"), d)
);
</chain>
</flow>