You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2023/03/05 09:03:33 UTC

[incubator-streampark] branch dev updated: [Issue-2014][test] Add SpringTestBase class. (#2395)

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

benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


The following commit(s) were added to refs/heads/dev by this push:
     new 124376f3e [Issue-2014][test] Add SpringTestBase class. (#2395)
124376f3e is described below

commit 124376f3e66f4703a6f635e415a965466130d720
Author: Pan Yuepeng <fl...@126.com>
AuthorDate: Sun Mar 5 17:03:28 2023 +0800

    [Issue-2014][test] Add SpringTestBase class. (#2395)
    
    * [Issue-2014][test] Add SpringTestBase class.
    
    * Fixed the un-runnable test cases that are missing spring context, disabled the test cases that are missing available external services or components
    
    * Disable the test cases in SenderEmailTest.java due to the external email service is not available.
    
    * Updated based on review comments
    
    * Open the test switch for console-service module in maven
    
    * Disable the RegexTest test case about external service environment
    
    * Remove '-am' parameter
---
 .github/workflows/maven.yml                        |   2 +-
 pom.xml                                            |   9 ++
 .../streampark-console-service/pom.xml             |  46 ++++--
 .../console/core/runner/EnvInitializer.java        | 179 +++++++++++----------
 .../apache/streampark/common/util/RegexTest.java   |   3 +
 .../apache/streampark/console/SpringTestBase.java  |  78 +++++++++
 .../console/base/util/EncryptUtilsTest.java        |   4 +-
 .../console/core/bean/SenderEmailTest.java         |   2 +
 .../streampark/console/core/entity/GitTest.java    |   3 +
 .../core/service/ApplicationServiceTest.java       |  36 +++--
 .../console/core/service/VariableServiceTest.java  |  11 +-
 .../core/service/alert/AlertServiceTest.java       |   2 +
 .../core/utils/YarnQueueLabelExpressionTest.java   |   4 +-
 .../console/system/authentication/JWTTest.java     |   3 +-
 .../src/test/resources/application-test.yml        |  34 ++++
 15 files changed, 290 insertions(+), 126 deletions(-)

diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 5b7d3300c..6f5741933 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -93,5 +93,5 @@ jobs:
       - name: Build with Maven
         run: ./mvnw -B clean package -P${{ matrix.scala }} -DskipTests
       - name: Test with Maven
-        run: ./mvnw -B test -P${{ matrix.scala }} -pl '!streampark-console/streampark-console-service' -am
+        run: ./mvnw -B test -P${{ matrix.scala }}
 
diff --git a/pom.xml b/pom.xml
index e10795e8d..1ddb914c9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -141,6 +141,8 @@
         <httpclient.version>4.5.13</httpclient.version>
         <lombok.version>1.18.24</lombok.version>
         <jupiter.version>5.9.1</jupiter.version>
+        <mockito.version>3.4.6</mockito.version>
+        <assertj.version>3.23.1</assertj.version>
 
         <PermGen>64m</PermGen>
         <MaxPermGen>512m</MaxPermGen>
@@ -598,6 +600,13 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>
+                <groupId>org.assertj</groupId>
+                <artifactId>assertj-core</artifactId>
+                <version>${assertj.version}</version>
+                <scope>test</scope>
+            </dependency>
+
         </dependencies>
 
     </dependencyManagement>
diff --git a/streampark-console/streampark-console-service/pom.xml b/streampark-console/streampark-console-service/pom.xml
index 0f4678091..fb4f9b5ec 100644
--- a/streampark-console/streampark-console-service/pom.xml
+++ b/streampark-console/streampark-console-service/pom.xml
@@ -157,18 +157,6 @@
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-            <scope>test</scope>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.junit.jupiter</groupId>
-                    <artifactId>junit-jupiter</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-websocket</artifactId>
@@ -389,6 +377,40 @@
             <artifactId>knife4j-spring-boot-autoconfigure</artifactId>
             <version>${swagger-bootstrap.version}</version>
         </dependency>
+
+        <!--Test dependencies start.-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.junit.jupiter</groupId>
+                    <artifactId>junit-jupiter</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <!--Test dependencies end.-->
+
     </dependencies>
 
     <build>
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
index 348b12b8f..04155ae23 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
@@ -45,8 +45,10 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
 import java.nio.file.Files;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -61,7 +63,7 @@ public class EnvInitializer implements ApplicationRunner {
 
   @Autowired private SettingService settingService;
 
-  private final Map<StorageType, Boolean> initialized = new ConcurrentHashMap<>(2);
+  private final Set<StorageType> initialized = new HashSet<>(2);
 
   private final FileFilter fileFilter = p -> !".gitkeep".equals(p.getName());
 
@@ -72,6 +74,12 @@ public class EnvInitializer implements ApplicationRunner {
 
   @Override
   public void run(ApplicationArguments args) throws Exception {
+    Optional<String> profile =
+        Arrays.stream(context.getEnvironment().getActiveProfiles()).findFirst();
+    if ("test".equals(profile.orElse(null))) {
+      return;
+    }
+
     String appHome = WebUtils.getAppHome();
     if (appHome == null) {
       throw new ExceptionInInitializerError(
@@ -132,109 +140,110 @@ public class EnvInitializer implements ApplicationRunner {
     SystemPropertyUtils.set(key, value);
   }
 
-  /** @param storageType */
   public synchronized void storageInitialize(StorageType storageType) {
 
+    if (initialized.contains(storageType)) {
+      return;
+    }
+
     final String mkdirLog = "storage initialize, now mkdir [{}] starting ...";
 
-    if (initialized.get(storageType) == null) {
-      FsOperator fsOperator = FsOperator.of(storageType);
-      Workspace workspace = Workspace.of(storageType);
-
-      // 1. prepare workspace dir
-      if (storageType.equals(LFS)) {
-        String localDist = Workspace.APP_LOCAL_DIST();
-        if (!fsOperator.exists(localDist)) {
-          log.info(mkdirLog, localDist);
-          fsOperator.mkdirs(localDist);
-        }
-      }
+    FsOperator fsOperator = FsOperator.of(storageType);
+    Workspace workspace = Workspace.of(storageType);
 
-      String appUploads = workspace.APP_UPLOADS();
-      if (!fsOperator.exists(appUploads)) {
-        log.info(mkdirLog, appUploads);
-        fsOperator.mkdirs(appUploads);
+    // 1. prepare workspace dir
+    if (storageType.equals(LFS)) {
+      String localDist = Workspace.APP_LOCAL_DIST();
+      if (!fsOperator.exists(localDist)) {
+        log.info(mkdirLog, localDist);
+        fsOperator.mkdirs(localDist);
       }
+    }
 
-      String appWorkspace = workspace.APP_WORKSPACE();
-      if (!fsOperator.exists(appWorkspace)) {
-        log.info(mkdirLog, appWorkspace);
-        fsOperator.mkdirs(appWorkspace);
-      }
+    String appUploads = workspace.APP_UPLOADS();
+    if (!fsOperator.exists(appUploads)) {
+      log.info(mkdirLog, appUploads);
+      fsOperator.mkdirs(appUploads);
+    }
 
-      String appBackups = workspace.APP_BACKUPS();
-      if (!fsOperator.exists(appBackups)) {
-        log.info(mkdirLog, appBackups);
-        fsOperator.mkdirs(appBackups);
-      }
+    String appWorkspace = workspace.APP_WORKSPACE();
+    if (!fsOperator.exists(appWorkspace)) {
+      log.info(mkdirLog, appWorkspace);
+      fsOperator.mkdirs(appWorkspace);
+    }
 
-      String appSavePoints = workspace.APP_SAVEPOINTS();
-      if (!fsOperator.exists(appSavePoints)) {
-        log.info(mkdirLog, appSavePoints);
-        fsOperator.mkdirs(appSavePoints);
-      }
+    String appBackups = workspace.APP_BACKUPS();
+    if (!fsOperator.exists(appBackups)) {
+      log.info(mkdirLog, appBackups);
+      fsOperator.mkdirs(appBackups);
+    }
 
-      String appJars = workspace.APP_JARS();
-      if (!fsOperator.exists(appJars)) {
-        log.info(mkdirLog, appJars);
-        fsOperator.mkdirs(appJars);
-      }
+    String appSavePoints = workspace.APP_SAVEPOINTS();
+    if (!fsOperator.exists(appSavePoints)) {
+      log.info(mkdirLog, appSavePoints);
+      fsOperator.mkdirs(appSavePoints);
+    }
 
-      // 2. upload jar.
-      // 2.1) upload client jar
-      File client = WebUtils.getAppClientDir();
-      Utils.required(
-          client.exists() && client.listFiles().length > 0,
-          client.getAbsolutePath().concat(" is not exists or empty directory "));
+    String appJars = workspace.APP_JARS();
+    if (!fsOperator.exists(appJars)) {
+      log.info(mkdirLog, appJars);
+      fsOperator.mkdirs(appJars);
+    }
 
-      String appClient = workspace.APP_CLIENT();
-      fsOperator.mkCleanDirs(appClient);
+    // 2. upload jar.
+    // 2.1) upload client jar
+    File client = WebUtils.getAppClientDir();
+    Utils.required(
+        client.exists() && client.listFiles().length > 0,
+        client.getAbsolutePath().concat(" is not exists or empty directory "));
 
-      for (File file : client.listFiles(fileFilter)) {
-        log.info("load client:{} to {}", file.getName(), appClient);
-        fsOperator.upload(file.getAbsolutePath(), appClient);
-      }
+    String appClient = workspace.APP_CLIENT();
+    fsOperator.mkCleanDirs(appClient);
 
-      // 2.2) upload plugin jar.
-      String appPlugins = workspace.APP_PLUGINS();
-      fsOperator.mkCleanDirs(appPlugins);
+    for (File file : client.listFiles(fileFilter)) {
+      log.info("load client:{} to {}", file.getName(), appClient);
+      fsOperator.upload(file.getAbsolutePath(), appClient);
+    }
 
-      File plugins = WebUtils.getAppPluginsDir();
-      for (File file : plugins.listFiles(fileFilter)) {
-        log.info("load plugin:{} to {}", file.getName(), appPlugins);
-        fsOperator.upload(file.getAbsolutePath(), appPlugins);
-      }
+    // 2.2) upload plugin jar.
+    String appPlugins = workspace.APP_PLUGINS();
+    fsOperator.mkCleanDirs(appPlugins);
 
-      // 2.3) upload shims jar
-      File[] shims =
-          WebUtils.getAppLibDir()
-              .listFiles(pathname -> pathname.getName().matches(PATTERN_FLINK_SHIMS_JAR.pattern()));
-
-      Utils.required(shims != null && shims.length > 0, "streampark-flink-shims jar not exist");
-
-      String appShims = workspace.APP_SHIMS();
-      fsOperator.delete(appShims);
-
-      for (File file : shims) {
-        Matcher matcher = PATTERN_FLINK_SHIMS_JAR.matcher(file.getName());
-        if (matcher.matches()) {
-          String version = matcher.group(1);
-          String shimsPath = appShims.concat("/flink-").concat(version);
-          fsOperator.mkdirs(shimsPath);
-          log.info("load shims:{} to {}", file.getName(), shimsPath);
-          fsOperator.upload(file.getAbsolutePath(), shimsPath);
-        }
-      }
+    File plugins = WebUtils.getAppPluginsDir();
+    for (File file : plugins.listFiles(fileFilter)) {
+      log.info("load plugin:{} to {}", file.getName(), appPlugins);
+      fsOperator.upload(file.getAbsolutePath(), appPlugins);
+    }
+
+    // 2.3) upload shims jar
+    File[] shims =
+        WebUtils.getAppLibDir()
+            .listFiles(pathname -> pathname.getName().matches(PATTERN_FLINK_SHIMS_JAR.pattern()));
+
+    Utils.required(shims != null && shims.length > 0, "streampark-flink-shims jar not exist");
 
-      // 2.4) create maven local repository dir
+    String appShims = workspace.APP_SHIMS();
+    fsOperator.delete(appShims);
 
-      String localMavenRepo = Workspace.MAVEN_LOCAL_PATH();
-      if (FsOperator.lfs().exists(localMavenRepo)) {
-        FsOperator.lfs().mkdirs(localMavenRepo);
+    for (File file : shims) {
+      Matcher matcher = PATTERN_FLINK_SHIMS_JAR.matcher(file.getName());
+      if (matcher.matches()) {
+        String version = matcher.group(1);
+        String shimsPath = appShims.concat("/flink-").concat(version);
+        fsOperator.mkdirs(shimsPath);
+        log.info("load shims:{} to {}", file.getName(), shimsPath);
+        fsOperator.upload(file.getAbsolutePath(), shimsPath);
       }
+    }
+
+    // 2.4) create maven local repository dir
 
-      initialized.put(storageType, Boolean.TRUE);
+    String localMavenRepo = Workspace.MAVEN_LOCAL_PATH();
+    if (FsOperator.lfs().exists(localMavenRepo)) {
+      FsOperator.lfs().mkdirs(localMavenRepo);
     }
+
+    initialized.add(storageType);
   }
 
   public void checkFlinkEnv(StorageType storageType, FlinkEnv flinkEnv) throws IOException {
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/common/util/RegexTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/common/util/RegexTest.java
index 4fe9eaaa4..718d0425f 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/common/util/RegexTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/common/util/RegexTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.streampark.common.util;
 
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.io.File;
@@ -44,6 +45,7 @@ class RegexTest {
     }
   }
 
+  @Disabled("This test case can't be runnable due to the depended jar is not available.")
   @Test
   void classLoader() throws MalformedURLException {
     List<URL> libCache = new ArrayList<>(0);
@@ -82,6 +84,7 @@ class RegexTest {
     System.out.println(urlClassLoader);
   }
 
+  @Disabled("This test case can't be runnable due to the environment is not available.")
   @Test
   void flinkVersion() {
     final Pattern flinkVersionPattern = Pattern.compile("^Version: (.*), Commit ID: (.*)$");
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/SpringTestBase.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/SpringTestBase.java
new file mode 100644
index 000000000..20384b813
--- /dev/null
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/SpringTestBase.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.console;
+
+import org.apache.streampark.common.conf.CommonConfig;
+import org.apache.streampark.common.conf.ConfigConst;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestEntityManager;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+/** base tester. */
+@Transactional
+@ActiveProfiles("test")
+@AutoConfigureTestEntityManager
+@AutoConfigureWebTestClient(timeout = "60000")
+@TestPropertySource(locations = {"classpath:application-test.yml"})
+@ExtendWith({MockitoExtension.class, SpringExtension.class})
+@SpringBootTest(
+    classes = StreamParkConsoleBootstrap.class,
+    webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+public abstract class SpringTestBase {
+
+  protected static final Logger LOG = LoggerFactory.getLogger(SpringTestBase.class);
+
+  @BeforeAll
+  public static void init(@TempDir File tempPath) throws IOException {
+    // Skip the EnvInitializer#run method by flag in System.properties.
+    // See https://github.com/apache/incubator-streampark/issues/2014
+    LOG.info("Start mock EnvInitializer init.");
+    String mockedHome = tempPath.getAbsolutePath();
+    Path localWorkspace =
+        Files.createDirectories(new File(mockedHome + "/localWorkspace").toPath());
+
+    System.setProperty(ConfigConst.KEY_APP_HOME(), mockedHome);
+    System.setProperty(
+        CommonConfig.STREAMPARK_WORKSPACE_LOCAL().key(),
+        localWorkspace.toAbsolutePath().toString());
+
+    Files.createDirectories(new File(mockedHome + "/temp").toPath());
+
+    LOG.info(
+        "Complete mock EnvInitializer init, app home: {}, {}: {}",
+        tempPath.getAbsolutePath(),
+        CommonConfig.STREAMPARK_WORKSPACE_LOCAL().key(),
+        localWorkspace.toAbsolutePath());
+  }
+}
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/util/EncryptUtilsTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/util/EncryptUtilsTest.java
index e9bd4b00e..398c14288 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/util/EncryptUtilsTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/util/EncryptUtilsTest.java
@@ -20,10 +20,10 @@ package org.apache.streampark.console.base.util;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-public class EncryptUtilsTest {
+class EncryptUtilsTest {
 
   @Test
-  public void testEncrypt() throws Exception {
+  void testEncrypt() throws Exception {
     String value = "apache streampark";
     String encrypt = EncryptUtils.encrypt(value, "streampark");
     String decrypt = EncryptUtils.decrypt(encrypt, "streampark");
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/bean/SenderEmailTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/bean/SenderEmailTest.java
index 0a82fd521..459eae30a 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/bean/SenderEmailTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/bean/SenderEmailTest.java
@@ -28,6 +28,7 @@ import org.apache.commons.mail.HtmlEmail;
 
 import freemarker.template.Template;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.io.StringWriter;
@@ -55,6 +56,7 @@ class SenderEmailTest {
   }
 
   @Test
+  @Disabled("This test case can't be runnable due to the email service is not available.")
   void alert() {
     Application application = new Application();
     application.setStartTime(new Date());
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/entity/GitTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/entity/GitTest.java
index 70e125707..584b3e6a1 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/entity/GitTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/entity/GitTest.java
@@ -21,6 +21,7 @@ import org.apache.streampark.console.core.enums.GitAuthorizedError;
 import org.apache.streampark.console.core.enums.GitCredential;
 
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.util.List;
@@ -35,12 +36,14 @@ class GitTest {
     project.setGitCredential(GitCredential.HTTPS.getValue());
   }
 
+  @Disabled("This test case can't be runnable due to external service is not available.")
   @Test
   void getBranchs() {
     List<String> branches = project.getAllBranches();
     branches.forEach(System.out::println);
   }
 
+  @Disabled("This test case can't be runnable due to external service is not available.")
   @Test
   void auth() {
     GitAuthorizedError error = project.gitCheck();
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/ApplicationServiceTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/ApplicationServiceTest.java
index 223008738..45c3f4ff4 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/ApplicationServiceTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/ApplicationServiceTest.java
@@ -17,30 +17,27 @@
 
 package org.apache.streampark.console.core.service;
 
-import org.apache.streampark.console.StreamParkConsoleBootstrap;
+import org.apache.streampark.console.SpringTestBase;
 import org.apache.streampark.console.core.entity.Application;
 
 import org.apache.http.entity.ContentType;
 
+import org.h2.store.fs.FileUtils;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.mock.web.MockMultipartFile;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.nio.file.Path;
 import java.util.Date;
 
-/** org.apache.streampark.console.core.service.ApplicationServiceTest */
-@ExtendWith(SpringExtension.class)
-@SpringBootTest(
-    classes = StreamParkConsoleBootstrap.class,
-    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-class ApplicationServiceTest {
+/** org.apache.streampark.console.core.service.ApplicationServiceTest. */
+class ApplicationServiceTest extends SpringTestBase {
 
   @Autowired private ApplicationService applicationService;
 
@@ -82,6 +79,7 @@ class ApplicationServiceTest {
   }
 
   @Test
+  @Disabled("We couldn't do integration test with external services or components.")
   void start() throws Exception {
     Application application = new Application();
     application.setId(1304056220683497473L);
@@ -93,14 +91,22 @@ class ApplicationServiceTest {
   }
 
   @Test
-  void uploadTest() throws Exception {
-    File file = new File(""); // specify the file path
+  void uploadTest(@TempDir Path tempDir) throws Exception {
+    // specify the file path
+    File fileToStoreUploadFile =
+        new File(tempDir.toFile().getAbsolutePath() + "/fileToStoreUploadFile");
+    FileUtils.createFile(fileToStoreUploadFile.getAbsolutePath());
+
+    File fileToUpload = new File(tempDir.toFile().getAbsolutePath() + "/fileToUpload.jar");
+    FileUtils.createFile(fileToUpload.getAbsolutePath());
+    System.out.println(fileToUpload.exists());
     MultipartFile mulFile =
         new MockMultipartFile(
-            "", // fileName (eg: streampark.jar)
-            "", // originalFilename (eg: path + fileName = /tmp/file/streampark.jar)
+            "test", // fileName (eg: streampark.jar)
+            fileToUpload.getAbsolutePath(), // originalFilename (eg: path + fileName =
+            // /tmp/file/streampark.jar)
             ContentType.APPLICATION_OCTET_STREAM.toString(),
-            new FileInputStream(file));
+            new FileInputStream(fileToStoreUploadFile));
     applicationService.upload(mulFile);
   }
 }
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/VariableServiceTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/VariableServiceTest.java
index 74f339e9c..d1c0436d4 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/VariableServiceTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/VariableServiceTest.java
@@ -17,22 +17,15 @@
 
 package org.apache.streampark.console.core.service;
 
-import org.apache.streampark.console.StreamParkConsoleBootstrap;
+import org.apache.streampark.console.SpringTestBase;
 import org.apache.streampark.console.core.entity.Variable;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 /** org.apache.streampark.console.core.service.VariableServiceTest */
-@ExtendWith(SpringExtension.class)
-@SpringBootTest(
-    classes = StreamParkConsoleBootstrap.class,
-    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-class VariableServiceTest {
+class VariableServiceTest extends SpringTestBase {
 
   @Autowired private VariableService variableService;
 
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java
index 0925f22a9..5e226e8f4 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java
@@ -29,12 +29,14 @@ import org.apache.streampark.console.core.service.alert.impl.WeComAlertNotifySer
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.springframework.web.client.RestTemplate;
 
 import java.util.Date;
 import java.util.TimeZone;
 
+@Disabled("These test cases can't be runnable due to external service is not available.")
 class AlertServiceTest {
   AlertTemplate alertTemplate;
   AlertConfigWithParams params = new AlertConfigWithParams();
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/utils/YarnQueueLabelExpressionTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/utils/YarnQueueLabelExpressionTest.java
index 8068c688b..f7676bcf3 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/utils/YarnQueueLabelExpressionTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/utils/YarnQueueLabelExpressionTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.streampark.console.core.utils;
 
+import org.apache.streampark.console.base.exception.ApiAlertException;
+
 import org.junit.jupiter.api.Test;
 
 import static org.apache.streampark.console.core.utils.YarnQueueLabelExpression.ERR_HINTS;
@@ -60,7 +62,7 @@ class YarnQueueLabelExpressionTest {
     assertThat(YarnQueueLabelExpression.of("a").getLabelExpression()).isEmpty();
     assertThat(YarnQueueLabelExpression.of("a").getQueue()).isEqualTo("a");
     assertThatThrownBy(() -> YarnQueueLabelExpression.of("a@"))
-        .isInstanceOf(IllegalArgumentException.class)
+        .isInstanceOf(ApiAlertException.class)
         .hasMessageContaining(ERR_HINTS);
   }
 }
diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/system/authentication/JWTTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/system/authentication/JWTTest.java
index 649d53482..582f1c490 100644
--- a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/system/authentication/JWTTest.java
+++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/system/authentication/JWTTest.java
@@ -18,6 +18,7 @@
 package org.apache.streampark.console.system.authentication;
 
 import org.apache.streampark.common.util.DateUtils;
+import org.apache.streampark.console.SpringTestBase;
 import org.apache.streampark.console.system.entity.AccessToken;
 
 import com.auth0.jwt.JWT;
@@ -28,7 +29,7 @@ import java.util.Date;
 import java.util.TimeZone;
 import java.util.UUID;
 
-class JWTTest {
+class JWTTest extends SpringTestBase {
 
   @Test
   void getExpireTime() {
diff --git a/streampark-console/streampark-console-service/src/test/resources/application-test.yml b/streampark-console/streampark-console-service/src/test/resources/application-test.yml
new file mode 100644
index 000000000..db8d8b3c6
--- /dev/null
+++ b/streampark-console/streampark-console-service/src/test/resources/application-test.yml
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+logging:
+  level:
+    root: debug
+
+spring:
+  datasource:
+    driver-class-name: org.h2.Driver
+    url: jdbc:h2:mem:streampark;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;INIT=runscript from 'classpath:db/schema-h2.sql'
+    username: sa
+    password: sa
+  sql:
+    init:
+      data-locations: classpath:db/data-h2.sql
+      continue-on-error: true
+      username: sa
+      password: sa
+      mode: always