diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java new file mode 100644 index 00000000..a08e8cf9 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.parser.ClassJsonFlowParser; + +/** + * 模拟用户自定义源解析 + * @author dongguo.tao + * @date 2021/4/7 + */ +public class CustomJsonFlowParser extends ClassJsonFlowParser { + @Override + public String parseCustom() { + //模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"condition\":[{\"type\":\"then\",\"value\":\"c,g,f\"}]},{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,c\"},{\"type\":\"when\",\"value\":\"b,d,e(f|g)\"},{\"type\":\"then\",\"value\":\"chain2\"}]}]}}"; + return content; + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java new file mode 100644 index 00000000..7e809ded --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.entity.data.Slot; +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环境的自定义json parser单元测试 + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application.properties") +@SpringBootTest(classes = CustomParserJsonSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +public class CustomParserJsonSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testSpringboot() throws Exception{ + LiteflowResponse response = flowExecutor.execute("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java new file mode 100644 index 00000000..3862783e --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.FlowSystemException; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + String str = this.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new FlowSystemException("chain execute execption"); + } + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java new file mode 100644 index 00000000..8eb4f0aa --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.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!"); + } + +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java new file mode 100644 index 00000000..4590c5de --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.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!"); + } + +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java new file mode 100644 index 00000000..8ba82da1 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java new file mode 100644 index 00000000..15990c8b --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.core.NodeCondComponent; +import org.springframework.stereotype.Component; + +@Component("e") +public class ECmp extends NodeCondComponent { + + @Override + public String processCond() throws Exception { + return "g"; + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java new file mode 100644 index 00000000..517cd324 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java new file mode 100644 index 00000000..ab04bf20 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("g") +public class GCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-spring-boot-starter/src/test/resources/parsecustom/application.properties b/liteflow-spring-boot-starter/src/test/resources/parsecustom/application.properties new file mode 100644 index 00000000..d63b33f4 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/parsecustom/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.CustomJsonFlowParser \ No newline at end of file