refactoring
This commit is contained in:
parent
dbb162e0d1
commit
5b85a9463e
@ -62,7 +62,6 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE
|
|||||||
public class LiquibaseCompatibilityIntegrationTest {
|
public class LiquibaseCompatibilityIntegrationTest {
|
||||||
|
|
||||||
private static final String EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION = "hs-global-liquibase-migration-test";
|
private static final String EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION = "hs-global-liquibase-migration-test";
|
||||||
private static int initialChangeSetCount = 0;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
@ -76,14 +75,29 @@ public class LiquibaseCompatibilityIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
void migrationWorksBasedOnAPreviouslyPopulatedSchema() {
|
void migrationWorksBasedOnAPreviouslyPopulatedSchema() {
|
||||||
// check the initial status from the @Sql-annotation
|
// 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
|
// run the current migrations and dump the result to the build-directory
|
||||||
runLiquibaseMigrationsWithContexts("only-office", "with-test-data");
|
runLiquibaseMigrationsWithContexts("only-office", "with-test-data");
|
||||||
dumpTo(new File("build/db/prod-only-office-schema-with-test-data.sql"));
|
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");
|
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");
|
final var liquibaseScripts = singleColumnSqlQuery("SELECT id FROM public.databasechangelog");
|
||||||
assertThat(liquibaseScripts).hasSizeGreaterThan(initialChangeSetCount);
|
assertThat(liquibaseScripts).hasSizeGreaterThan(initialChangeSetCount);
|
||||||
assertThat(liquibaseScripts).contains(EXPECTED_CHANGESET_ONLY_AFTER_NEW_MIGRATION);
|
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();
|
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
|
@SneakyThrows
|
||||||
private void runLiquibaseMigrationsWithContexts(final String... contexts) {
|
private void runLiquibaseMigrationsWithContexts(final String... contexts) {
|
||||||
liquibase.update(
|
liquibase.update(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user