diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java index c3111c01..02973b7f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportOfficeData.java @@ -4,11 +4,14 @@ import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import java.io.File; + /* * This 'test' includes the complete legacy 'office' data import. * @@ -58,4 +61,12 @@ import org.springframework.test.context.ActiveProfiles; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @ExtendWith(OrderedDependedTestsExtension.class) public class ImportOfficeData extends BaseOfficeDataImport { + + @Value("${spring.datasource.url}") + private String jdbcUrl; + + @AfterEach + void dumpOfficeData() { + PostgresTestcontainer.dump(jdbcUrl, new File("build/db/released-only-office-schema-with-import-test-data.sql")); + } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java index 12335e90..781e1de0 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java @@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.migration; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; @@ -23,9 +24,9 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE *

The test works as follows:

* *
    - *
  1. the database is initialized by `db/prod-only-office-schema-with-test-data.sql` from the test-resources
  2. + *
  3. the database is initialized by `db/released-only-office-schema-with-test-data.sql` from the test-resources
  4. *
  5. the current Liquibase-migrations (only-office but with-test-data) are performed
  6. - *
  7. a new dump is written to `db/prod-only-office-schema-with-test-data.sql` in the build-directory
  8. + *
  9. a new dump is written to `db/released-only-office-schema-with-test-data.sql` in the build-directory
  10. *
  11. an extra Liquibase-changeset (liquibase-migration-test) is applied
  12. *
  13. it's asserted that the extra changeset got applied
  14. *
@@ -41,12 +42,15 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE @DirtiesContext @ActiveProfiles("liquibase-migration-test") @Import(LiquibaseConfig.class) -@Sql(value = "/db/prod-only-office-schema-with-test-data.sql", executionPhase = BEFORE_TEST_CLASS) // reads prod-schema-dump +@Sql(value = "/db/released-only-office-schema-with-test-data.sql", executionPhase = BEFORE_TEST_CLASS) // reads prod-schema-dump public class LiquibaseCompatibilityIntegrationTest { private static final String EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION = "hs-global-liquibase-migration-test"; public static final int EXPECTED_LIQUIBASE_CHANGELOGS_IN_PROD_SCHEMA_DUMP = 287; + @Value("${spring.datasource.url}") + private String jdbcUrl; + @Autowired private LiquibaseMigration liquibase; @@ -58,7 +62,7 @@ public class LiquibaseCompatibilityIntegrationTest { // run the current migrations and dump the result to the build-directory liquibase.runWithContexts("only-office", "with-test-data"); - PostgresTestcontainer.dumpTo(new File("build/db/prod-only-office-schema-with-test-data.sql")); + PostgresTestcontainer.dump(jdbcUrl, new File("build/db/released-only-office-schema-with-test-data.sql")); // then add another migration and assert if it was applied liquibase.runWithContexts("liquibase-migration-test"); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/PostgresTestcontainer.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/PostgresTestcontainer.java index 7990232b..8de3e5ba 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/PostgresTestcontainer.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/PostgresTestcontainer.java @@ -18,10 +18,10 @@ import static org.assertj.core.api.Assertions.assertThat; public class PostgresTestcontainer { @SneakyThrows - public static void dumpTo(final File targetFileName) { + public static void dump(final String jdbcUrl, final File targetFileName) { makeDir(targetFileName.getParentFile()); - final var jdbcDatabaseContainer = getJdbcDatabaseContainer(); + final var jdbcDatabaseContainer = getJdbcDatabaseContainer(jdbcUrl); final var sqlDumpFile = new File(targetFileName.getParent(), "." + targetFileName.getName()); final var pb = new ProcessBuilder( @@ -69,14 +69,13 @@ public class PostgresTestcontainer { } @SneakyThrows - private static JdbcDatabaseContainer getJdbcDatabaseContainer() { + private static JdbcDatabaseContainer getJdbcDatabaseContainer(final String jdbcUrl) { // TODO.test: check if, in the future, there is a better way to access auto-created Testcontainers final var getContainerMethod = ContainerDatabaseDriver.class.getDeclaredMethod("getContainer", String.class); getContainerMethod.setAccessible(true); @SuppressWarnings("rawtypes") - final var container = (JdbcDatabaseContainer) getContainerMethod.invoke(null, - "jdbc:tc:postgresql:15.5-bookworm:///liquibaseMigrationTestTC"); + final var container = (JdbcDatabaseContainer) getContainerMethod.invoke(null, jdbcUrl); return container; } } diff --git a/src/test/resources/db/prod-only-office-schema-with-test-data.sql b/src/test/resources/db/released-only-office-schema-with-test-data.sql similarity index 100% rename from src/test/resources/db/prod-only-office-schema-with-test-data.sql rename to src/test/resources/db/released-only-office-schema-with-test-data.sql