This is an automated email from the ASF dual-hosted git repository.

fanjia pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/seatunnel-web.git


The following commit(s) were added to refs/heads/main by this push:
     new 5302b8c5 [Improvement][Seatunnel-web] Support H2 database in 
integration tests (#219)
5302b8c5 is described below

commit 5302b8c5b3842b3dc72c44ed76456fb3535c6241
Author: Mohammad Arshad <[email protected]>
AuthorDate: Fri Sep 27 08:14:40 2024 +0530

    [Improvement][Seatunnel-web] Support H2 database in integration tests (#219)
---
 .../apache/seatunnel/app/dal/mapper/UserMapper.xml   |  4 ++--
 .../main/resources/script/seatunnel_server_h2.sql    |  6 ++++++
 seatunnel-web-it/README.md                           | 11 +++++++----
 .../seatunnel/app/common/SeaTunnelWebCluster.java    | 20 ++++++++++++++++++--
 seatunnel-web-it/src/test/resources/application.yml  | 11 ++++++++++-
 5 files changed, 43 insertions(+), 9 deletions(-)

diff --git 
a/seatunnel-server/seatunnel-app/src/main/resources/org/apache/seatunnel/app/dal/mapper/UserMapper.xml
 
b/seatunnel-server/seatunnel-app/src/main/resources/org/apache/seatunnel/app/dal/mapper/UserMapper.xml
index f4115071..0539f9cc 100644
--- 
a/seatunnel-server/seatunnel-app/src/main/resources/org/apache/seatunnel/app/dal/mapper/UserMapper.xml
+++ 
b/seatunnel-server/seatunnel-app/src/main/resources/org/apache/seatunnel/app/dal/mapper/UserMapper.xml
@@ -36,7 +36,7 @@
     <insert id="insert" keyColumn="id" keyProperty="id" 
parameterType="org.apache.seatunnel.app.dal.entity.User"
             useGeneratedKeys="true">
         insert into `user` (username, password, status, type)
-                value (#{username,jdbcType=VARCHAR}, 
#{password,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
+                values (#{username,jdbcType=VARCHAR}, 
#{password,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
                        #{type,jdbcType=TINYINT})
     </insert>
     <update id="updateByPrimaryKey">
@@ -99,7 +99,7 @@
     <select id="queryEnabledUsers" 
resultType="org.apache.seatunnel.app.dal.entity.User">
         select
         <include refid="Base_Column_List"/>
-        from user
+        from `user`
         where status = 0
     </select>
 </mapper>
diff --git 
a/seatunnel-server/seatunnel-app/src/main/resources/script/seatunnel_server_h2.sql
 
b/seatunnel-server/seatunnel-app/src/main/resources/script/seatunnel_server_h2.sql
index c85527f2..f9bfb51a 100644
--- 
a/seatunnel-server/seatunnel-app/src/main/resources/script/seatunnel_server_h2.sql
+++ 
b/seatunnel-server/seatunnel-app/src/main/resources/script/seatunnel_server_h2.sql
@@ -39,6 +39,12 @@ CREATE TABLE role (
                       update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP 
ON UPDATE CURRENT_TIMESTAMP
 );
 
+-- ----------------------------
+-- Records of role
+-- ----------------------------
+INSERT INTO role (type, role_name, description) VALUES (0, 'ADMIN_ROLE', 
'Admin User');
+INSERT INTO role (type, role_name, description) VALUES (1, 'NORMAL_ROLE', 
'Normal User');
+
 -- ----------------------------
 -- Table structure for role_user_relation
 -- ----------------------------
diff --git a/seatunnel-web-it/README.md b/seatunnel-web-it/README.md
index 97e05701..373ec96b 100644
--- a/seatunnel-web-it/README.md
+++ b/seatunnel-web-it/README.md
@@ -1,13 +1,16 @@
 Build seatunnel-web
 ./mvnw clean install -DskipTests
 
-Update mysql database details in src/test/resources/application.yml and Run 
the seatunnel-web-it integration tests
-./mvnw -T 1C -B verify -DskipUT=true -DskipIT=false 
-DSEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7 
-DST_WEB_BASEDIR_PATH=seatunnel-web-dist/target/apache-seatunnel-web-1.0.0-SNAPSHOT/apache-seatunnel-web-1.0.0-SNAPSHOT
+Run seatunnel-web-it integration tests
+./mvnw -T 1C -B verify -DskipUT=true -DskipIT=false 
-DSEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7 
-DST_WEB_BASEDIR_PATH=seatunnel-web-dist/target/apache-seatunnel-web-1.0.2-SNAPSHOT/apache-seatunnel-web-1.0.2-SNAPSHOT
 NOTE: Please remember to update the versions according to the latest supported 
versions.
 
 If you're using a version of Java higher than Java 8 for running the tests, 
add the following VM options: 
--DitJvmArgs="--add-opens java.base/java.lang.invoke=ALL-UNNAMED".
+-DitJvmArgs="-Xmx1024m --add-opens java.base/java.lang.invoke=ALL-UNNAMED 
--add-opens java.base/java.net=ALL-UNNAMED"
 
 While running integrations tests from IDE, ensure following VM options are set
 SEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7
-ST_WEB_BASEDIR_PATH=/some/path/seatunnel-web-dist/target/apache-seatunnel-web-1.0.0-SNAPSHOT/apache-seatunnel-web-1.0.0-SNAPSHOT
+ST_WEB_BASEDIR_PATH=/some/path/seatunnel-web-dist/target/apache-seatunnel-web-1.0.2-SNAPSHOT/apache-seatunnel-web-1.0.2-SNAPSHOT
+
+By default, integration tests use the H2 database. If you want to use the 
MySQL database, update the MySQL database details in 
src/test/resources/application.yml and run the seatunnel-web-it integration 
tests with the -DdbType=mysql option as shown below:
+./mvnw -T 1C -B verify -DskipUT=true -DskipIT=false -DdbType=mysql 
-DSEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7 
-DST_WEB_BASEDIR_PATH=seatunnel-web-dist/target/apache-seatunnel-web-1.0.2-SNAPSHOT/apache-seatunnel-web-1.0.2-SNAPSHOT
diff --git 
a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/common/SeaTunnelWebCluster.java
 
b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/common/SeaTunnelWebCluster.java
index a5b630a9..df4127da 100644
--- 
a/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/common/SeaTunnelWebCluster.java
+++ 
b/seatunnel-web-it/src/test/java/org/apache/seatunnel/app/common/SeaTunnelWebCluster.java
@@ -32,11 +32,19 @@ import com.hazelcast.logging.ILogger;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @Slf4j
 public class SeaTunnelWebCluster {
+    private static final String DB_TYPE_H2 = "h2";
+    private static final String DB_TYPE_MYSQL = "mysql";
+    private static final Set<String> SUPPORTED_DB_TYPES =
+            Collections.unmodifiableSet(new 
HashSet<>(Arrays.asList(DB_TYPE_H2, DB_TYPE_MYSQL)));
     private SeaTunnelServer server;
     private HazelcastInstanceImpl instance;
     private ConfigurableApplicationContext applicationContext;
@@ -59,8 +67,16 @@ public class SeaTunnelWebCluster {
         server = 
instance.node.nodeEngine.getService(SeaTunnelServer.SERVICE_NAME);
         ILogger LOGGER = 
instance.node.nodeEngine.getLogger(SeaTunnelWebCluster.class);
 
-        // String[] args = {"--spring.profiles.active=h2"};
-        String[] args = {};
+        // For integration tests, default database is H2, so the default 
spring profile is h2
+        String dbType = System.getProperty("dbType", DB_TYPE_H2);
+        if (!SUPPORTED_DB_TYPES.contains(dbType)) {
+            throw new IllegalArgumentException(
+                    "Invalid dbType: " + dbType + ". Supported values are: " + 
SUPPORTED_DB_TYPES);
+        }
+
+        String springProfile = dbType.equals(DB_TYPE_MYSQL) ? "default" : "h2";
+        String[] args = {"--spring.profiles.active=" + springProfile};
+
         applicationContext = SpringApplication.run(SeatunnelApplication.class, 
args);
         LOGGER.info("SeaTunnel-web server started.");
         assertTrue(isRunning());
diff --git a/seatunnel-web-it/src/test/resources/application.yml 
b/seatunnel-web-it/src/test/resources/application.yml
index 3b49d2a3..276983f3 100644
--- a/seatunnel-web-it/src/test/resources/application.yml
+++ b/seatunnel-web-it/src/test/resources/application.yml
@@ -40,6 +40,10 @@ jwt:
 
 ---
 spring:
+  application:
+    name: seatunnel
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss
   config:
     activate:
       on-profile: h2
@@ -57,4 +61,9 @@ spring:
       path: /h2
       settings:
         trace: false
-        web-allow-others: false
\ No newline at end of file
+        web-allow-others: false
+jwt:
+  expireTime: 86400
+  # please add key when deploy
+  secretKey: https://github.com/apache/seatunnel
+  algorithm: HS256
\ No newline at end of file

Reply via email to