diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 90c754cf3..19a237f99 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -3,6 +3,10 @@ on: [ push, pull_request ]
jobs:
build:
+ env:
+ DB_USER: steve
+ DB_PASSWORD: changeme
+ DB_SCHEMA: stevedb_test_2aa6a783d47d
strategy:
fail-fast: false
matrix:
@@ -22,24 +26,31 @@ jobs:
steps:
- uses: actions/checkout@v2
- - name: Set up Java ${{ matrix.Java }}
+ - name: Set up Java 17 for build
uses: actions/setup-java@v2
with:
- java-version: ${{ matrix.java }}
+ java-version: 17
distribution: 'temurin'
cache: maven
- - name: Set up MySQL
+ - name: Set up MySQL for tests
run: |
mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "SELECT @@VERSION;"
- mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "CREATE DATABASE stevedb_test_2aa6a783d47d;" -v
- mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "CREATE USER 'steve'@'%' IDENTIFIED BY 'changeme';" -v
- mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "GRANT ALL PRIVILEGES ON stevedb_test_2aa6a783d47d.* TO 'steve'@'%';" -v
- mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "GRANT SELECT ON mysql.proc TO 'steve'@'%';" -v || true
- mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "GRANT SUPER ON *.* TO 'steve'@'%';" -v || true
+ mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "CREATE DATABASE $DB_SCHEMA;" -v
+ mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "CREATE USER '$DB_USER'@'%' IDENTIFIED BY '$DB_PASSWORD';" -v
+ mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "GRANT ALL PRIVILEGES ON $DB_SCHEMA.* TO '$DB_USER'@'%';" -v
+ mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "GRANT SELECT ON mysql.proc TO '$DB_USER'@'%';" -v || true
+ mysql -h 127.0.0.1 -P 3306 -uroot -proot -e "GRANT SUPER ON *.* TO '$DB_USER'@'%';" -v || true
- name: Build with Maven
- run: ./mvnw -B -V -Dmaven.javadoc.skip=true -Ptest clean package --file pom.xml
+ run: ./mvnw -B -V -Dmaven.javadoc.skip=true -Ddb.user=$DB_USER -Ddb.password=$DB_PASSWORD -Ddb.schema=$DB_SCHEMA -Ptest clean package --file pom.xml
+
+ - name: Set up Java ${{ matrix.Java }} for run
+ uses: actions/setup-java@v2
+ with:
+ java-version: ${{ matrix.java }}
+ distribution: 'temurin'
+ cache: maven
- name: Start the app and visit signin web page
run: |
diff --git a/pom.xml b/pom.xml
index 9f536d055..00a82bf9f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,8 @@
10.0.14
1.18.28
2.15.2
+ 7.15.0
+ 5.9.3
1.18.3
4.2
@@ -190,6 +192,11 @@
org.apache.maven.plugins
maven-surefire-plugin
3.1.2
+
+
+ ${db.schema}
+
+
@@ -246,26 +253,6 @@
-
-
- org.codehaus.mojo
- properties-maven-plugin
- 1.1.0
-
-
- initialize
-
- read-project-properties
-
-
-
- src/main/resources/config/${envName}/main.properties
-
-
-
-
-
-
org.apache.maven.plugins
maven-dependency-plugin
@@ -701,13 +688,19 @@
org.junit.jupiter
junit-jupiter-engine
- 5.9.3
+ ${junit.version}
test
org.junit.jupiter
junit-jupiter-params
- 5.9.3
+ ${junit.version}
+ test
+
+
+ org.flywaydb
+ flyway-core
+ ${flyway.version}
test
diff --git a/src/main/java/de/rwth/idsg/steve/SteveConfiguration.java b/src/main/java/de/rwth/idsg/steve/SteveConfiguration.java
index 7aeb2e911..ba0722c18 100644
--- a/src/main/java/de/rwth/idsg/steve/SteveConfiguration.java
+++ b/src/main/java/de/rwth/idsg/steve/SteveConfiguration.java
@@ -180,6 +180,10 @@ public static class DB {
private final String userName;
private final String password;
private final boolean sqlLogging;
+
+ public String getJdbcUrl() {
+ return "jdbc:mysql://" + ip + ":" + port + "/" + schema;
+ }
}
// Credentials for Web interface access
diff --git a/src/main/java/de/rwth/idsg/steve/config/BeanConfiguration.java b/src/main/java/de/rwth/idsg/steve/config/BeanConfiguration.java
index 234c2caad..dca3fbc47 100644
--- a/src/main/java/de/rwth/idsg/steve/config/BeanConfiguration.java
+++ b/src/main/java/de/rwth/idsg/steve/config/BeanConfiguration.java
@@ -94,7 +94,7 @@ private void initDataSource() {
HikariConfig hc = new HikariConfig();
// set standard params
- hc.setJdbcUrl("jdbc:mysql://" + dbConfig.getIp() + ":" + dbConfig.getPort() + "/" + dbConfig.getSchema());
+ hc.setJdbcUrl(dbConfig.getJdbcUrl());
hc.setUsername(dbConfig.getUserName());
hc.setPassword(dbConfig.getPassword());
diff --git a/src/main/resources/config/test/main.properties b/src/main/resources/config/test/main.properties
index 66c566de9..0d4a9f1a8 100644
--- a/src/main/resources/config/test/main.properties
+++ b/src/main/resources/config/test/main.properties
@@ -8,9 +8,9 @@ context.path = steve
#
db.ip = localhost
db.port = 3306
-db.schema = stevedb_test_2aa6a783d47d
-db.user = steve
-db.password = changeme
+db.schema = ${db.schema}
+db.user = ${db.user}
+db.password = ${db.password}
# Credentials for Web interface access
#
diff --git a/src/test/java/de/rwth/idsg/steve/utils/FlywayMigrationRunner.java b/src/test/java/de/rwth/idsg/steve/utils/FlywayMigrationRunner.java
new file mode 100644
index 000000000..9f8b6f3ee
--- /dev/null
+++ b/src/test/java/de/rwth/idsg/steve/utils/FlywayMigrationRunner.java
@@ -0,0 +1,58 @@
+/*
+ * SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
+ * Copyright (C) 2013-2023 SteVe Community Team
+ * All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package de.rwth.idsg.steve.utils;
+
+import de.rwth.idsg.steve.SteveConfiguration;
+import org.flywaydb.core.api.configuration.FluentConfiguration;
+
+/**
+ * @author Sevket Goekay
+ * @since 08.08.2021
+ */
+public class FlywayMigrationRunner {
+
+ private static final String INIT_SQL = "SET default_storage_engine=InnoDB;";
+ private static final String BOOKKEEPING_TABLE = "schema_version";
+ private static final String LOCATION_OF_MIGRATIONS = "filesystem:src/main/resources/db/migration";
+
+ public static void run(SteveConfiguration sc) {
+ try {
+ getConfig(sc.getDb()).load().migrate();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * This configuration should be kept in-sync with the one of the flyway-maven-plugin in pom.xml
+ */
+ private static FluentConfiguration getConfig(SteveConfiguration.DB dbConfig) {
+ return new FluentConfiguration()
+ .initSql(INIT_SQL)
+ .outOfOrder(true)
+ .table(BOOKKEEPING_TABLE)
+ .cleanDisabled(true)
+ .schemas(dbConfig.getSchema())
+ .defaultSchema(dbConfig.getSchema())
+ .locations(LOCATION_OF_MIGRATIONS)
+ .dataSource(dbConfig.getJdbcUrl(), dbConfig.getUserName(), dbConfig.getPassword());
+ }
+}
diff --git a/src/test/java/de/rwth/idsg/steve/utils/__DatabasePreparer__.java b/src/test/java/de/rwth/idsg/steve/utils/__DatabasePreparer__.java
index 0d5650812..dc9495319 100644
--- a/src/test/java/de/rwth/idsg/steve/utils/__DatabasePreparer__.java
+++ b/src/test/java/de/rwth/idsg/steve/utils/__DatabasePreparer__.java
@@ -19,6 +19,7 @@
package de.rwth.idsg.steve.utils;
import com.google.common.collect.Sets;
+import de.rwth.idsg.steve.SteveConfiguration;
import de.rwth.idsg.steve.config.BeanConfiguration;
import de.rwth.idsg.steve.repository.dto.ChargePoint;
import de.rwth.idsg.steve.repository.dto.ConnectorStatus;
@@ -66,7 +67,7 @@
*/
public class __DatabasePreparer__ {
- private static final String SCHEMA_TO_TRUNCATE = "stevedb_test_2aa6a783d47d";
+ private static final String SCHEMA_TO_TRUNCATE = System.getProperty("schemaToTruncate", "stevedb_test_2aa6a783d47d");
private static final String REGISTERED_CHARGE_BOX_ID = "charge_box_2aa6a783d47d";
private static final String REGISTERED_CHARGE_BOX_ID_2 = "charge_box_2aa6a783d47d_2";
private static final String REGISTERED_OCPP_TAG = "id_tag_2aa6a783d47d";
@@ -75,6 +76,8 @@ public class __DatabasePreparer__ {
private static final DSLContext dslContext = beanConfiguration.dslContext();
public static void prepare() {
+ SteveConfiguration sc = SteveConfiguration.CONFIG;
+ FlywayMigrationRunner.run(sc);
runOperation(ctx -> {
truncateTables(ctx);
insertChargeBox(ctx);