!199 enhancement #I7KZCZ在使用数据库配置的时候,使用配置文件中已经配置的数据源

Merge pull request !199 from 与或非/issues/I7KZCZ
This commit is contained in:
铂赛东 2023-07-22 08:20:00 +00:00 committed by Gitee
commit 24e84b5f93
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 406 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>liteflow-testcase-el</artifactId>
<groupId>com.yomahub</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>liteflow-testcase-el-sql-springboot-dynamic</artifactId>
<properties>
<h2.version>2.1.214</h2.version>
<jpa.version>2.6.8</jpa.version>
<dynamic-datasource.version>4.1.2</dynamic-datasource.version>
<spring-boot.version>2.7.13</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-rule-sql</artifactId>
<version>${revision}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${jpa.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-script-groovy</artifactId>
<version>${revision}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-script-graaljs</artifactId>
<version>${revision}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>${dynamic-datasource.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -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();
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -0,0 +1,22 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @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!");
}
}

View File

@ -0,0 +1,22 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @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!");
}
}

View File

@ -0,0 +1,22 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @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!");
}
}

View File

@ -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

View File

@ -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','<chain3>','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');

View File

@ -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`)
);

View File

@ -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', '<chain31>', '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');

View File

@ -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`)
);

View File

@ -34,6 +34,7 @@
<module>liteflow-testcase-el-script-lua-springboot</module>
<module>liteflow-testcase-el-script-multi-language-springboot</module>
<module>liteflow-testcase-el-script-aviator-springboot</module>
<module>liteflow-testcase-el-sql-springboot-dynamic</module>
</modules>
<build>