diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index 04ab79e44..945e4672b 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -9,7 +9,7 @@ com.yomahub liteflow - 2.5.6 + 2.5.7 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 3ced81919..a9cdf4f45 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -15,6 +15,7 @@ import com.yomahub.liteflow.enums.FlowParserTypeEnum; import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.parser.*; import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.util.SpringAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -122,14 +123,14 @@ public class FlowExecutor { } } else if(isClassConfig(path)){ LOG.info("flow info loaded from class config,class={},format type={}", path, pattern.getType()); - Class c = Class.forName(path); + Class c = Class.forName(path); switch (pattern) { case TYPE_XML: - return (XmlFlowParser) c.newInstance(); + return (XmlFlowParser) SpringAware.registerBean(c); case TYPE_JSON: - return (JsonFlowParser) c.newInstance(); + return (JsonFlowParser) SpringAware.registerBean(c); case TYPE_YML: - return (YmlFlowParser) c.newInstance(); + return (YmlFlowParser) SpringAware.registerBean(c); default: } } else if(isZKConfig(path)) { diff --git a/liteflow-spring-boot-starter/pom.xml b/liteflow-spring-boot-starter/pom.xml index 96f36a864..3bf30b88d 100644 --- a/liteflow-spring-boot-starter/pom.xml +++ b/liteflow-spring-boot-starter/pom.xml @@ -10,7 +10,7 @@ liteflow com.yomahub - 2.5.6 + 2.5.7 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 index 50181ee43..8b21ea1e8 100644 --- 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 @@ -21,7 +21,7 @@ import javax.annotation.Resource; * @since 2.5.0 */ @RunWith(SpringRunner.class) -@TestPropertySource(value = "classpath:/parsecustom/application.properties") +@TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties") @SpringBootTest(classes = CustomParserJsonSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java new file mode 100644 index 000000000..6fde641d4 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.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环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties") +@SpringBootTest(classes = CustomParserXmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +public class CustomParserXmlSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testSpringboot() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java new file mode 100644 index 000000000..3d4eece3b --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.parsecustom.bean; + +import org.springframework.stereotype.Component; + +@Component +public class TestBean { + + public String returnXmlContent(){ + return ""; + } +} 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/parser/CustomJsonFlowParser.java similarity index 94% rename from liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomJsonFlowParser.java rename to liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java index a08e8cf98..dd3a41929 100644 --- 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/parser/CustomJsonFlowParser.java @@ -1,11 +1,11 @@ -package com.yomahub.liteflow.test.parsecustom; +package com.yomahub.liteflow.test.parsecustom.parser; import com.yomahub.liteflow.parser.ClassJsonFlowParser; /** * 模拟用户自定义源解析 * @author dongguo.tao - * @date 2021/4/7 + * @since 2.5.0 */ public class CustomJsonFlowParser extends ClassJsonFlowParser { @Override diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java new file mode 100644 index 000000000..064323b89 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.ClassXmlFlowParser; +import com.yomahub.liteflow.test.parsecustom.bean.TestBean; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +public class CustomXmlFlowParser extends ClassXmlFlowParser { + + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } +} diff --git a/liteflow-spring-boot-starter/src/test/resources/parsecustom/application-custom-json.properties b/liteflow-spring-boot-starter/src/test/resources/parsecustom/application-custom-json.properties new file mode 100644 index 000000000..989a199c9 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/parsecustom/application-custom-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/parsecustom/application-custom-xml.properties b/liteflow-spring-boot-starter/src/test/resources/parsecustom/application-custom-xml.properties new file mode 100644 index 000000000..c1763fe16 --- /dev/null +++ b/liteflow-spring-boot-starter/src/test/resources/parsecustom/application-custom-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/test/resources/parsecustom/application.properties b/liteflow-spring-boot-starter/src/test/resources/parsecustom/application.properties deleted file mode 100644 index d63b33f49..000000000 --- a/liteflow-spring-boot-starter/src/test/resources/parsecustom/application.properties +++ /dev/null @@ -1 +0,0 @@ -liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.CustomJsonFlowParser \ No newline at end of file diff --git a/liteflow-test-spring/pom.xml b/liteflow-test-spring/pom.xml index 1b5d89200..c1eccb842 100644 --- a/liteflow-test-spring/pom.xml +++ b/liteflow-test-spring/pom.xml @@ -9,7 +9,7 @@ liteflow com.yomahub - 2.5.6 + 2.5.7 diff --git a/liteflow-test-springboot/pom.xml b/liteflow-test-springboot/pom.xml index 734c6e906..22bef1270 100644 --- a/liteflow-test-springboot/pom.xml +++ b/liteflow-test-springboot/pom.xml @@ -9,7 +9,7 @@ liteflow com.yomahub - 2.5.6 + 2.5.7 diff --git a/pom.xml b/pom.xml index 233d7ffb1..74f84fff0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yomahub liteflow pom - 2.5.6 + 2.5.7 liteflow a lightweight and practical micro-process framework https://github.com/bryan31/liteflow