From eac8717bb87ac7b09c421bc3798545c1bbd6fb32 Mon Sep 17 00:00:00 2001
From: Michael Hoennig The test needs a dump, ideally from the version of the lastest prod-release:
-
- pg-sql-reset
-
- ./gradlew bootRun --args='--spring.profiles.active=only-office'
-
-
-
- cat >src/test/resources/db/prod-only-office-schema-with-test-data.sql <
docker exec -i hsadmin-ng-postgres /usr/bin/pg_dump \
- --column-inserts --disable-dollar-quoting -U postgres postgres \
- >>src/test/resources/db/prod-only-office-schema-with-test-data.sql
-
-
-
- The generated dump has to be committed to git and will be used in future test-runs - until it gets replaced at the next release.
-*/ +/** + * Tests, if the Liquibase scripts can be applied to a database ionitialized with schemas + * and test-data from a previous version. + * + *The test needs a dump, ideally from the version of the lastest prod-release:
+ * + *pg-sql-reset
+ *
+ * ./gradlew bootRun --args='--spring.profiles.active=only-office'
+ *
+ * cat >src/test/resources/db/prod-only-office-schema-with-test-data.sql <
+ *
+ * docker exec -i hsadmin-ng-postgres /usr/bin/pg_dump \
+ * --column-inserts --disable-dollar-quoting -U postgres postgres \
+ * >>src/test/resources/db/prod-only-office-schema-with-test-data.sql
+ *
+ * The generated dump has to be committed to git and will be used in future test-runs + * until it gets replaced at the next release.
+ */ @Tag("importOfficeData") @DataJpaTest(properties = { - "spring.liquibase.enabled=false" // @Sql should go first, Liquibase will be initialized programmtically + "spring.liquibase.enabled=false" // @Sql should go first, Liquibase will be initialized programmatically }) @ActiveProfiles("only-office") @TestPropertySource(properties = "spring.liquibase.contexts=only-office") @DirtiesContext -@Import({ Context.class, JpaAttempt.class, LiquibaseConfig.class}) +@Import({ Context.class, JpaAttempt.class, LiquibaseConfig.class }) @Sql(value = "/db/prod-only-office-schema-with-test-data.sql", executionPhase = BEFORE_TEST_CLASS) public class LiquibaseCompatibilityIntegrationTest extends CsvDataImport { + private static final String EXPECTED_CHANGESET = "hs-hosting-SCHEMA"; + private static int initialChangeSetCount = 0; + @Autowired private DataSource dataSource; @@ -85,19 +92,34 @@ public class LiquibaseCompatibilityIntegrationTest extends CsvDataImport { @BeforeEach public void setup() throws Exception { - - final var schemas = em.createNativeQuery("SELECT * FROM pg_catalog.pg_tables WHERE schemaname='public'").getResultList(); - assertThat(schemas).hasSize(2); - - final var liquibaseScripts = em.createNativeQuery("SELECT * FROM public.databasechangelog").getResultList(); - assertThat(liquibaseScripts).hasSize(286); - - // Step 2: Run Liquibase migrations - liquibase.update(new liquibase.Contexts(), new liquibase.LabelExpression()); + assertThatDatabaseIsInitialized(); + runLiquibaseMigrations(); } @Test void test() { - // FIXME: check if changes got applied + final var liquibaseScripts = singleColumnSqlQuery("SELECT id FROM public.databasechangelog"); + assertThat(liquibaseScripts).hasSizeGreaterThan(initialChangeSetCount); + assertThat(liquibaseScripts).contains(EXPECTED_CHANGESET); + } + + private void assertThatDatabaseIsInitialized() { + 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); + initialChangeSetCount = liquibaseScripts.size(); + } + + private void runLiquibaseMigrations() throws LiquibaseException { + liquibase.update(new liquibase.Contexts(), new liquibase.LabelExpression()); + } + + private List