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 811ddbc7..d3cbb817 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/LiquibaseCompatibilityIntegrationTest.java @@ -62,7 +62,6 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE public class LiquibaseCompatibilityIntegrationTest { private static final String EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION = "hs-global-liquibase-migration-test"; - private static int initialChangeSetCount = 0; @Autowired private DataSource dataSource; @@ -76,14 +75,29 @@ public class LiquibaseCompatibilityIntegrationTest { @Test void migrationWorksBasedOnAPreviouslyPopulatedSchema() { // check the initial status from the @Sql-annotation - assertThatDatabaseIsInitializedWithLatestProdSchemasAndTestDataBySqlAnnotation(); + final var initialChangeSetCount = assertProdReferenceStatusAfterRestore(); // run the current migrations and dump the result to the build-directory runLiquibaseMigrationsWithContexts("only-office", "with-test-data"); dumpTo(new File("build/db/prod-only-office-schema-with-test-data.sql")); - // then add another migration and test if it was applied + // then add another migration and assert if it was applied runLiquibaseMigrationsWithContexts("liquibase-migration-test"); + assertThatCurrentMigrationsGotApplied(initialChangeSetCount); + } + + private int assertProdReferenceStatusAfterRestore() { + final var schemas = singleColumnSqlQuery("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'"); + assertThat(schemas).containsExactly("databasechangelog", "databasechangeloglock"); + + final var liquibaseScripts1 = singleColumnSqlQuery("SELECT * FROM public.databasechangelog"); + assertThat(liquibaseScripts1).hasSizeGreaterThan(285); + assertThat(liquibaseScripts1).doesNotContain(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION); + final var initialChangeSetCount = liquibaseScripts1.size(); + return initialChangeSetCount; + } + + private void assertThatCurrentMigrationsGotApplied(final int initialChangeSetCount) { final var liquibaseScripts = singleColumnSqlQuery("SELECT id FROM public.databasechangelog"); assertThat(liquibaseScripts).hasSizeGreaterThan(initialChangeSetCount); assertThat(liquibaseScripts).contains(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION); @@ -143,16 +157,6 @@ public class LiquibaseCompatibilityIntegrationTest { assertThat(dir.isDirectory() || dir.mkdirs()).describedAs(dir + " cannot be created").isTrue(); } - private void assertThatDatabaseIsInitializedWithLatestProdSchemasAndTestDataBySqlAnnotation() { - final var schemas = singleColumnSqlQuery("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'"); - assertThat(schemas).containsExactly("databasechangelog", "databasechangeloglock"); - - final var liquibaseScripts = singleColumnSqlQuery("SELECT * FROM public.databasechangelog"); - assertThat(liquibaseScripts).hasSizeGreaterThan(285); - assertThat(liquibaseScripts).doesNotContain(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION); - initialChangeSetCount = liquibaseScripts.size(); - } - @SneakyThrows private void runLiquibaseMigrationsWithContexts(final String... contexts) { liquibase.update(