diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore new file mode 100644 index 000000000..5ff6309b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml new file mode 100644 index 000000000..b7bd4c935 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/pom.xml @@ -0,0 +1,86 @@ + + + + liteflow-testcase-el + com.yomahub + ${revision} + ../pom.xml + + 4.0.0 + + liteflow-testcase-el-sql-springboot-dynamic + + + 2.1.214 + 2.6.8 + 4.1.2 + 2.7.13 + + + + + org.springframework.boot + spring-boot-starter + ${spring-boot.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + com.yomahub + liteflow-spring-boot-starter + ${revision} + + + + com.yomahub + liteflow-rule-sql + ${revision} + test + + + + org.springframework.boot + spring-boot-starter-test + + + + org.springframework.boot + spring-boot-starter-data-jpa + ${jpa.version} + test + + + + com.h2database + h2 + ${h2.version} + test + + + + com.yomahub + liteflow-script-groovy + ${revision} + test + + + + com.yomahub + liteflow-script-graaljs + ${revision} + test + + + + + com.baomidou + dynamic-datasource-spring-boot-starter + ${dynamic-datasource.version} + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/BaseTest.java new file mode 100644 index 000000000..eb7287357 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test; + +import com.yomahub.liteflow.core.FlowInitHook; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.thread.ExecutorHelper; +import org.junit.jupiter.api.AfterAll; + +/** + * @author tangkc + * @since 2.8.6 + */ +public class BaseTest { + + @AfterAll + public static void cleanScanCache() { + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + FlowInitHook.cleanHook(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELMultiLanguageSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELMultiLanguageSpringbootTest.java new file mode 100644 index 000000000..427351b64 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELMultiLanguageSpringbootTest.java @@ -0,0 +1,34 @@ +package com.yomahub.liteflow.test.sql; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-dynamic-data-source-xml.properties") +@SpringBootTest(classes = SQLWithXmlELMultiLanguageSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELMultiLanguageSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMultiLanguage1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x2[python脚本]==>x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java new file mode 100644 index 000000000..d694f7bf8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/SQLWithXmlELSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.sql; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + +/** + * @author tangkc + * @since 2.9.0 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/application-dynamic-data-source-xml.properties") +@SpringBootTest(classes = SQLWithXmlELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.sql.cmp"}) +public class SQLWithXmlELSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + @Test + public void testSQLWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertEquals("a==>b==>c", response.getExecuteStepStr()); + } + + @Test + public void testSQLWithScriptXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("x0[if 脚本]==>a==>b", response.getExecuteStepStrWithoutTime()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java new file mode 100644 index 000000000..f263fa7d7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.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!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java new file mode 100644 index 000000000..c2ffd816c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/BCmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.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-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java new file mode 100644 index 000000000..0d45928bb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/java/com/yomahub/liteflow/test/sql/cmp/CCmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

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

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.sql.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-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/application-dynamic-data-source-xml.properties b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/application-dynamic-data-source-xml.properties new file mode 100644 index 000000000..8645c0b2e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/application-dynamic-data-source-xml.properties @@ -0,0 +1,31 @@ +liteflow.rule-source-ext-data={\ + "applicationName":"demo",\ + "chainTableName":"EL_TABLE",\ + "chainApplicationNameField":"application_name",\ + "chainNameField":"chain_name",\ + "elDataField":"EL_DATA",\ + "scriptTableName":"script_node_table",\ + "scriptApplicationNameField":"application_name",\ + "scriptIdField":"script_node_id",\ + "scriptNameField":"script_node_name",\ + "scriptDataField":"script_node_data",\ + "scriptLanguageField":"script_language",\ + "scriptTypeField":"script_node_type"\ + } +spring.profiles.active=test +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.dynamic.primary=h2-first +spring.datasource.dynamic.strict=false +spring.datasource.dynamic.datasource.h2-first.url=jdbc:h2:mem:test_db1 +spring.datasource.dynamic.datasource.h2-first.username=root1 +spring.datasource.dynamic.datasource.h2-first.password=123456 +spring.datasource.dynamic.datasource.h2-first.init.schema=classpath:/sql/schema.sql +spring.datasource.dynamic.datasource.h2-first.init.data=classpath:/sql/data.sql +spring.datasource.dynamic.datasource.h2-second.url=jdbc:h2:mem:test_db2 +spring.datasource.dynamic.datasource.h2-second.username=root2 +spring.datasource.dynamic.datasource.h2-second.password=123456 +spring.datasource.dynamic.datasource.h2-second.init.schema=classpath:/sql/second/schema.sql +spring.datasource.dynamic.datasource.h2-second.init.data=classpath:/sql/second/data.sql + + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql new file mode 100644 index 000000000..dda527ee6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/data.sql @@ -0,0 +1,14 @@ +DELETE FROM EL_TABLE; + +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain1','THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain2','THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain3','IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','','IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME,CHAIN_NAME,EL_DATA) values ('demo','chain4','IF(x2, IF(x0, THEN(a, b)));'); + +DELETE FROM SCRIPT_NODE_TABLE; + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x0','if 脚本','if_script','return true','groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x1','if 脚本','if_script','return false','groovy'); + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME,SCRIPT_NODE_ID,SCRIPT_NODE_NAME,SCRIPT_NODE_TYPE,SCRIPT_NODE_DATA,SCRIPT_LANGUAGE) values ('demo','x2','python脚本','if_script','return true','js'); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/schema.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/schema.sql new file mode 100644 index 000000000..fa60f098a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/schema.sql @@ -0,0 +1,20 @@ +create table IF NOT EXISTS `EL_TABLE` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `chain_name` varchar(32) NOT NULL, + `el_data` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); + +create table IF NOT EXISTS `script_node_table` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `script_node_id` varchar(32) NOT NULL, + `script_node_name` varchar(32) NOT NULL, + `script_node_type` varchar(32) NOT NULL, + `script_node_data` varchar(1024) NOT NULL, + `script_language` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql new file mode 100644 index 000000000..35412b6a8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/data.sql @@ -0,0 +1,27 @@ +DELETE +FROM EL_TABLE; + +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain11', 'THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain21', 'THEN(a, b, c);'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain31', 'IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', '', 'IF(x0, THEN(a, b));'); +INSERT INTO EL_TABLE (APPLICATION_NAME, CHAIN_NAME, EL_DATA) +values ('demo', 'chain41', 'IF(x2, IF(x0, THEN(a, b)));'); + +DELETE +FROM SCRIPT_NODE_TABLE; + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, + SCRIPT_LANGUAGE) +values ('demo', 'x01', 'if 脚本', 'if_script', 'return true', 'groovy'); +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, + SCRIPT_LANGUAGE) +values ('demo', 'x11', 'if 脚本', 'if_script', 'return false', 'groovy'); + +INSERT INTO SCRIPT_NODE_TABLE (APPLICATION_NAME, SCRIPT_NODE_ID, SCRIPT_NODE_NAME, SCRIPT_NODE_TYPE, SCRIPT_NODE_DATA, + SCRIPT_LANGUAGE) +values ('demo', 'x21', 'python脚本', 'if_script', 'return true', 'js'); diff --git a/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/schema.sql b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/schema.sql new file mode 100644 index 000000000..fa60f098a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-sql-springboot-dynamic/src/test/resources/sql/second/schema.sql @@ -0,0 +1,20 @@ +create table IF NOT EXISTS `EL_TABLE` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `chain_name` varchar(32) NOT NULL, + `el_data` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); + +create table IF NOT EXISTS `script_node_table` +( + `id` bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + `application_name` varchar(32) NOT NULL, + `script_node_id` varchar(32) NOT NULL, + `script_node_name` varchar(32) NOT NULL, + `script_node_type` varchar(32) NOT NULL, + `script_node_data` varchar(1024) NOT NULL, + `script_language` varchar(1024) NOT NULL, + PRIMARY KEY (`id`) +); \ No newline at end of file diff --git a/liteflow-testcase-el/pom.xml b/liteflow-testcase-el/pom.xml index 2d53f3497..8f23e9e9f 100644 --- a/liteflow-testcase-el/pom.xml +++ b/liteflow-testcase-el/pom.xml @@ -34,6 +34,7 @@ liteflow-testcase-el-script-lua-springboot liteflow-testcase-el-script-multi-language-springboot liteflow-testcase-el-script-aviator-springboot + liteflow-testcase-el-sql-springboot-dynamic