Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use testcontainers maven plugin for the generation of jooq code #1190

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -22,24 +26,31 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Java ${{ matrix.Java }}
- name: Set up Java 17 for build
uses: actions/setup-java@v3
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: |
Expand Down
279 changes: 131 additions & 148 deletions pom.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/main/java/de/rwth/idsg/steve/SteveConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/config/dev/main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ context.path = steve
#
db.ip = localhost
db.port = 3306
db.schema = stevedb
db.user = steve
db.password = changeme
db.schema = ${db.schema}
db.user = ${db.user}
db.password = ${db.password}

# Credentials for Web interface access
#
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/config/test/main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/de/rwth/idsg/steve/utils/FlywayMigrationRunner.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/
package de.rwth.idsg.steve.utils;

import de.rwth.idsg.steve.SteveConfiguration;
import org.flywaydb.core.api.configuration.FluentConfiguration;

/**
* @author Sevket Goekay <[email protected]>
* @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 = "classpath: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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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);
Expand Down
Loading