mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
feature #I5KTST IF三元符语法的添加以及IF ELIF ELSE语法的添加
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package com.yomahub.liteflow.test.ifelse;
|
||||
|
||||
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 IfElseTest extends BaseTest{
|
||||
|
||||
private static FlowExecutor flowExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void init(){
|
||||
LiteflowConfig config = new LiteflowConfig();
|
||||
config.setRuleSource("ifelse/flow.el.xml");
|
||||
flowExecutor = FlowExecutorHolder.loadInstance(config);
|
||||
}
|
||||
|
||||
//IF只有2个参数
|
||||
@Test
|
||||
public void testIf1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>a==>b", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
//IF只有3个参数
|
||||
@Test
|
||||
public void testIf2() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
//IF有3个参数,进行嵌套
|
||||
@Test
|
||||
public void testIf3() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
//IF有2个参数,加上ELSE
|
||||
@Test
|
||||
public void testIf4() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>c==>d", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
//IF有2个参数,ELSE里再嵌套一个IF
|
||||
@Test
|
||||
public void testIf5() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>x1==>c==>c==>b", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
//标准的IF ELIF ELSE
|
||||
@Test
|
||||
public void testIf6() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>x1==>c==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
//IF ELIF... ELSE 的形式
|
||||
@Test
|
||||
public void testIf7() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
}
|
||||
@@ -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.ifelse.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.ifelse.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.ifelse.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.ifelse.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class DCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("DCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.ifelse.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeIfComponent;
|
||||
|
||||
public class X1Cmp extends NodeIfComponent {
|
||||
@Override
|
||||
public boolean processIf() throws Exception {
|
||||
return Boolean.parseBoolean(this.getTag());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="a" class="com.yomahub.liteflow.test.ifelse.cmp.ACmp"/>
|
||||
<node id="b" class="com.yomahub.liteflow.test.ifelse.cmp.BCmp"/>
|
||||
<node id="c" class="com.yomahub.liteflow.test.ifelse.cmp.CCmp"/>
|
||||
<node id="d" class="com.yomahub.liteflow.test.ifelse.cmp.DCmp"/>
|
||||
<node id="x1" class="com.yomahub.liteflow.test.ifelse.cmp.X1Cmp"/>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
IF(x1.tag("true"), THEN(a, b));
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
IF(x1.tag("false"), THEN(a, b), THEN(c, d));
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
item = IF(x1.tag("false"), a, THEN(c, c, b));
|
||||
IF(
|
||||
x1.tag("false"),
|
||||
a,
|
||||
item
|
||||
);
|
||||
</chain>
|
||||
|
||||
<chain name="chain4">
|
||||
IF(x1.tag("false"), THEN(a, b)).ELSE(THEN(c, d));
|
||||
</chain>
|
||||
|
||||
<chain name="chain5">
|
||||
item = IF(x1.tag("false"), a, THEN(c, c, b));
|
||||
|
||||
IF(x1.tag("false"), THEN(a, b)).ELSE(item);
|
||||
</chain>
|
||||
|
||||
<chain name="chain6">
|
||||
IF(x1.tag("false"), THEN(a, b)).ELIF(x1.tag("true"), THEN(c, c)).ELSE(d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain7">
|
||||
IF(x1.tag("false"), a).ELIF(x1.tag("false"), b)
|
||||
.ELIF(x1.tag("false"), c)
|
||||
.ELIF(x1.tag("false"), d)
|
||||
.ELSE(THEN(d, b, a));
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user