Skip to content

Commit

Permalink
Upgrade JDK, Gradle, Jooq
Browse files Browse the repository at this point in the history
Switch to Testcontainers
  • Loading branch information
rbuehlma committed Sep 21, 2024
1 parent 9c4a4bb commit c97e31a
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 141 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@ on: [ push, pull_request]
jobs:
container-job:
runs-on: ubuntu-latest
container: adoptopenjdk:8-jdk

services:
postgres:
image: postgres:10
env:
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
container: eclipse-temurin:21-jdk

steps:
- name: Install dependencies
Expand All @@ -27,9 +16,9 @@ jobs:
- name: Build
run: ./gradlew -S -i assemble
- name: Test
run: ./gradlew -S -i test -Ppostgresql_database_url="jdbc:postgresql://postgres:5432/postgres?user=postgres&password=password"
run: ./gradlew -S -i test
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: ./**/build/test-results/**/*.xml
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish_gradle_plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
java-version: '21'
distribution: 'temurin'

- name: Prepare GPG key
run: mkdir build && echo '${{secrets.SIGNING_KEY_FILE_BASE64}}' | base64 -d > build/adam_signing_key.gpg
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish_to_central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
java-version: '21'
distribution: 'temurin'

- name: Prepare GPG key
run: mkdir build && echo '${{secrets.SIGNING_KEY_FILE_BASE64}}' | base64 -d > build/adam_signing_key.gpg
Expand Down
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import static java.nio.charset.StandardCharsets.UTF_8

buildscript {
repositories {
mavenCentral()
Expand Down Expand Up @@ -38,3 +40,14 @@ nexusPublishing {
}
}
}

ext.getLocalProperty = { key, file = "local.properties" ->
def properties = new Properties()
def localProperties = new File(rootProject.rootDir, file)
if (localProperties.isFile()) {
new InputStreamReader(new FileInputStream(localProperties), UTF_8).with {properties.load}
return properties.getProperty(key, "")
} else {
return null
}
}
15 changes: 7 additions & 8 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
plugins {
id 'java'
id 'java-library'
id "ch.ergon.gradle.goodies.versioning"
id 'maven'
}

group 'ch.ergon.adam'
description 'The core functionality of ADAM'

sourceCompatibility = 1.8
sourceCompatibility = 21

dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
compile group: 'com.google.guava', name: 'guava', version: '30.1-jre'
compile group: 'org.reflections', name: 'reflections', version: '0.9.12'
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.10.0.202012080955-r'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
api 'com.google.guava:guava:33.3.0-jre'
implementation group: 'org.reflections', name: 'reflections', version: '0.9.12'
api group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.10.0.202012080955-r'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
}

apply from: "${rootProject.projectDir}/publish.gradle"
Expand Down
6 changes: 3 additions & 3 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ plugins {
group 'ch.ergon.adam'
description = 'The ADAM Gradle Plugin'

sourceCompatibility = 1.8
sourceCompatibility = 21

dependencies {
compile gradleApi()
compile project(':core')
implementation gradleApi()
implementation project(':core')
}

apply from: "${rootProject.projectDir}/common.gradle"
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion integration-test-db/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plugins {

group 'ch.ergon.adam'

sourceCompatibility = 1.8
sourceCompatibility = 21
25 changes: 15 additions & 10 deletions integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ plugins {

group 'ch.ergon.adam'

sourceCompatibility = 1.8
sourceCompatibility = 21

dependencies {
testCompile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.14.1'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testCompile project(':core')
testCompile project(':yml')
testCompile project(':postgresql')
testCompile project(':sqlite')
testCompile project(':integration-test-db')
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.14.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
testImplementation project(':core')
testImplementation project(':yml')
testImplementation project(':postgresql')
testImplementation project(':sqlite')
testImplementation project(':integration-test-db')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testImplementation("org.testcontainers:testcontainers:1.20.1")
testImplementation("org.testcontainers:junit-jupiter:1.20.1")
testImplementation("org.testcontainers:postgresql:1.20.1")
testImplementation("org.postgresql:postgresql:42.7.1")
testImplementation("org.testcontainers:oracle-free:1.20.1")
testImplementation('com.oracle.database.jdbc:ojdbc11:23.5.0.24.07')
}

test {
systemProperty "postgresql_database_url", project.findProperty("postgresql_database_url") ?: 'jdbc:postgresql://localhost:5432/test?user=test&password=test'
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,12 @@ protected String targetToYml() {
return baos.toString();
}

protected String sourceToYml() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
YmlSink ymlSink = new YmlSink(baos);
new SchemaMigrator(new EmptySource(), getSourceDbSource(), ymlSink).migrate();
return baos.toString();
}


}
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package ch.ergon.adam.integrationtest;

import org.testcontainers.containers.PostgreSQLContainer;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import static java.lang.String.format;

public class PostgreSqlToSqliteTestDbUrlProvider extends TestDbUrlProvider {

private static final String DATABASE_URL_PROPERTY = "postgresql_database_url";
private static final String DATABASE_URL_DEFAULT = "jdbc:postgresql://localhost:5432/test?user=test&password=test";
private final static PostgreSQLContainer<?> container = new PostgreSQLContainer<>("postgres:15-alpine");

private static final String SOURCE_SCHEMA = "test-source";
protected static final String TARGET_SCHEMA = "test-target";
private static Map<String, Connection> connectionsByUrl = new HashMap<>();
private final Path tempFolder;

public PostgreSqlToSqliteTestDbUrlProvider() throws IOException {
Expand Down Expand Up @@ -55,7 +54,10 @@ protected String getPostgreSqlDbUrl(String schema) {
}

private String getPostgreSqlDbUrl() {
return System.getProperty(DATABASE_URL_PROPERTY, DATABASE_URL_DEFAULT);
if (!container.isRunning()) {
container.start();
}
return container.getJdbcUrl() + "&user=" + container.getUsername() + "&password=" + container.getPassword();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class PostgreSqlArrayFieldTest extends AbstractDbTestBase {

Expand Down Expand Up @@ -39,7 +40,7 @@ public void testCreateTableToYml() throws Exception {
schema.getTable("test_table").getField("array_col").setDefaultValue("'{}'");
migrateTargetWithSchema(schema);
String yml = targetToYml();
assertThat(yml, is(YML));
assertEquals(YML, yml);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import static ch.ergon.adam.core.db.schema.DataType.NUMERIC;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

public class PostgreSqlCreateTableTest extends AbstractDbTestBase {

Expand Down Expand Up @@ -185,7 +182,7 @@ public void testCreateTableToYml() throws Exception {
getSourceDbConnection().createStatement().execute(CREATE_TABLE_SQL);
sourceToTarget();
String yml = targetToYml();
assertThat(yml, is(YML));
assertEquals(YML, yml);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ch.ergon.adam.integrationtest.TestDbUrlProvider;
import ch.ergon.adam.postgresql.PostgreSqlFactory;
import ch.ergon.adam.postgresql.PostgreSqlTransactionWrapper;
import org.testcontainers.containers.PostgreSQLContainer;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -13,8 +14,8 @@

public class PostgreSqlTestDbUrlProvider extends TestDbUrlProvider {

private static final String DATABASE_URL_PROPERTY = "postgresql_database_url";
private static final String DATABASE_URL_DEFAULT = "jdbc:postgresql://localhost:5432/test?user=test&password=test";
private static final PostgreSQLContainer<?> container = new PostgreSQLContainer<>("postgres:15-alpine");

private static final String SOURCE_SCHEMA = "test-source";
protected static final String TARGET_SCHEMA = "test-target";

Expand Down Expand Up @@ -43,7 +44,10 @@ protected String getDbUrl(String schema) {
}

protected String getDbUrl() {
return System.getProperty(DATABASE_URL_PROPERTY, DATABASE_URL_DEFAULT);
if (!container.isRunning()) {
container.start();
}
return container.getJdbcUrl() + "&user=" + container.getUsername() + "&password=" + container.getPassword();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ private void verifySchema(Schema schema) {
assertNull(field.getDbEnum());
assertThat(field.getDataType(), is(DataType.VARCHAR));

Index index = table.getIndex("pk");
Index index = table.getIndexes().stream().filter(Index::isPrimary).findFirst().orElse(null);
assertNotNull(index);
assertTrue(index.isPrimary());
assertTrue(index.isUnique());
assertThat(index.getFields().size(), is(1));
assertThat(index.getFields().get(0).getName(), is("id"));

index = table.getIndex("test_table_col1_idx");
index = table.getIndexes().stream().filter(i -> !i.isPrimary()).findFirst().orElse(null);
assertNotNull(index);
assertFalse(index.isPrimary());
assertTrue(index.isUnique());
Expand Down
11 changes: 5 additions & 6 deletions jooq/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
plugins {
id 'java'
id 'maven'
id 'java-library'
id "ch.ergon.gradle.goodies.versioning"
}

group 'ch.ergon.adam'
description 'The jOOQ plugin for ADAM'

sourceCompatibility = 1.8
sourceCompatibility = 21

dependencies {
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
compile project(':core')
compile group: 'org.jooq', name: 'jooq', version: '3.14.8'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
api project(':core')
api group: 'org.jooq', name: 'jooq', version: '3.19.11'
}

apply from: "${rootProject.projectDir}/publish.gradle"
Expand Down
Loading

0 comments on commit c97e31a

Please sign in to comment.