enhancement #I61EMZ 增加一个验证EL规则的api,供检查之用
This commit is contained in:
parent
fa0bb7e664
commit
6bd329ab8b
|
@ -177,9 +177,9 @@ public class LiteFlowChainELBuilder {
|
|||
* @param elStr EL表达式
|
||||
* @return true 校验成功 false 校验失败
|
||||
*/
|
||||
public Boolean validate(String elStr) {
|
||||
public static boolean validate(String elStr) {
|
||||
try {
|
||||
this.setEL(elStr);
|
||||
LiteFlowChainELBuilder.createChain().setEL(elStr);
|
||||
return Boolean.TRUE;
|
||||
} catch (ELParseException e) {
|
||||
LOG.error(e.getMessage());
|
||||
|
|
|
@ -161,26 +161,4 @@ public class BuilderTest extends BaseTest {
|
|||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a1[组件A1]==>c2[组件C2]==>a2[组件A2]==>c1[组件C1]", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChainELExpressValidate() {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp.ACmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp.BCmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp.CCmp")
|
||||
.build();
|
||||
Boolean res = LiteFlowChainELBuilder.createChain().validate("THEN(a, b, h)");
|
||||
Assert.assertFalse(res);
|
||||
Assert.assertTrue(LiteFlowChainELBuilder.createChain().validate("THEN(a, b, c)"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.yomahub.liteflow.test.validateRule;
|
||||
|
||||
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.core.FlowExecutorHolder;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.base.BaseELSpringbootTest;
|
||||
import com.yomahub.liteflow.test.validateRule.cmp.ACmp;
|
||||
import com.yomahub.liteflow.test.validateRule.cmp.BCmp;
|
||||
import com.yomahub.liteflow.test.validateRule.cmp.CCmp;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
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.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ValidateRuleELSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
public class ValidateRuleELSpringbootTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testChainELExpressValidate() {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, h)"));
|
||||
Assert.assertTrue(LiteFlowChainELBuilder.validate("THEN(a, b, c)"));
|
||||
}
|
||||
}
|
|
@ -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.validateRule.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!");
|
||||
}
|
||||
}
|
|
@ -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.validateRule.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!");
|
||||
}
|
||||
|
||||
}
|
|
@ -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.validateRule.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!");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue