From 2c7926e2d09f9394b8d648fb22b11e63d4399a34 Mon Sep 17 00:00:00 2001 From: sunlishuo Date: Sat, 3 Oct 2026 10:06:16 +0800 Subject: [PATCH] [Console] Fix H2 quickstart project initialization --- .../src/main/resources/db/data-h2.sql | 2 +- .../base/config/H2InitializationTest.java | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/config/H2InitializationTest.java diff --git a/streampark-console/streampark-console-service/src/main/resources/db/data-h2.sql b/streampark-console/streampark-console-service/src/main/resources/db/data-h2.sql index 7dac02fb6b..682fbf6133 100644 --- a/streampark-console/streampark-console-service/src/main/resources/db/data-h2.sql +++ b/streampark-console/streampark-console-service/src/main/resources/db/data-h2.sql @@ -44,7 +44,7 @@ insert into `t_flink_effective` values (100000, 100000, 2, 100000, now()); -- ---------------------------- -- Records of t_flink_project -- ---------------------------- -insert into `t_flink_project` values (100000, 100000, 'streampark-quickstart', 'https://github.com/apache/streampark-quickstart', 'dev', null, null, null, null, null, null, 1, 1, null, 'streampark-quickstart', -1, now(), now()); +insert into `t_flink_project` values (100000, 100000, 'streampark-quickstart', 'https://github.com/apache/streampark-quickstart', 'dev', null, null, null, null, null, 1, 1, null, 'streampark-quickstart', -1, now(), now()); -- ---------------------------- -- Records of t_flink_sql diff --git a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/config/H2InitializationTest.java b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/config/H2InitializationTest.java new file mode 100644 index 0000000000..e1c61e30ad --- /dev/null +++ b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/base/config/H2InitializationTest.java @@ -0,0 +1,60 @@ +/* + * 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.base.config; + +import org.junit.jupiter.api.Test; +import org.springframework.core.io.ClassPathResource; +import org.springframework.jdbc.datasource.init.ScriptUtils; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; + +import static org.assertj.core.api.Assertions.assertThat; + +class H2InitializationTest { + + @Test + void initializesQuickstartProject() throws Exception { + try ( + Connection connection = DriverManager.getConnection( + "jdbc:h2:mem:project-seed;MODE=MySQL;DATABASE_TO_LOWER=TRUE", "sa", "")) { + ScriptUtils.executeSqlScript(connection, new ClassPathResource("db/schema-h2.sql")); + ScriptUtils.executeSqlScript(connection, new ClassPathResource("db/data-h2.sql")); + + try ( + Statement statement = connection.createStatement(); + ResultSet project = statement.executeQuery("select * from t_flink_project")) { + assertThat(project.next()).isTrue(); + assertThat(project.getLong("id")).isEqualTo(100000L); + assertThat(project.getLong("team_id")).isEqualTo(100000L); + assertThat(project.getString("name")).isEqualTo("streampark-quickstart"); + assertThat(project.getString("url")) + .isEqualTo("https://github.com/apache/streampark-quickstart"); + assertThat(project.getString("refs")).isEqualTo("dev"); + assertThat(project.getInt("type")).isEqualTo(1); + assertThat(project.getInt("repository")).isEqualTo(1); + assertThat(project.getInt("build_state")).isEqualTo(-1); + assertThat(project.getTimestamp("create_time")).isNotNull(); + assertThat(project.getTimestamp("modify_time")).isNotNull(); + assertThat(project.next()).isFalse(); + } + } + } +}