feature/remove-office-data-import #155
@ -4,11 +4,14 @@ import net.hostsharing.hsadminng.context.Context;
|
|||||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
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.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This 'test' includes the complete legacy 'office' data import.
|
* This 'test' includes the complete legacy 'office' data import.
|
||||||
*
|
*
|
||||||
@ -58,4 +61,12 @@ import org.springframework.test.context.ActiveProfiles;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
@ExtendWith(OrderedDependedTestsExtension.class)
|
@ExtendWith(OrderedDependedTestsExtension.class)
|
||||||
public class ImportOfficeData extends BaseOfficeDataImport {
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.migration;
|
|||||||
import org.junit.jupiter.api.Tag;
|
import org.junit.jupiter.api.Tag;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
@ -23,9 +24,9 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE
|
|||||||
* <p>The test works as follows:</p>
|
* <p>The test works as follows:</p>
|
||||||
*
|
*
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>the database is initialized by `db/prod-only-office-schema-with-test-data.sql` from the test-resources</li>
|
* <li>the database is initialized by `db/released-only-office-schema-with-test-data.sql` from the test-resources</li>
|
||||||
* <li>the current Liquibase-migrations (only-office but with-test-data) are performed</li>
|
* <li>the current Liquibase-migrations (only-office but with-test-data) are performed</li>
|
||||||
* <li>a new dump is written to `db/prod-only-office-schema-with-test-data.sql` in the build-directory</li>
|
* <li>a new dump is written to `db/released-only-office-schema-with-test-data.sql` in the build-directory</li>
|
||||||
* <li>an extra Liquibase-changeset (liquibase-migration-test) is applied</li>
|
* <li>an extra Liquibase-changeset (liquibase-migration-test) is applied</li>
|
||||||
* <li>it's asserted that the extra changeset got applied</li>
|
* <li>it's asserted that the extra changeset got applied</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
@ -41,12 +42,15 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TE
|
|||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@ActiveProfiles("liquibase-migration-test")
|
@ActiveProfiles("liquibase-migration-test")
|
||||||
@Import(LiquibaseConfig.class)
|
@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 {
|
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";
|
||||||
public static final int EXPECTED_LIQUIBASE_CHANGELOGS_IN_PROD_SCHEMA_DUMP = 287;
|
public static final int EXPECTED_LIQUIBASE_CHANGELOGS_IN_PROD_SCHEMA_DUMP = 287;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.url}")
|
||||||
|
private String jdbcUrl;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LiquibaseMigration liquibase;
|
private LiquibaseMigration liquibase;
|
||||||
|
|
||||||
@ -58,7 +62,7 @@ public class LiquibaseCompatibilityIntegrationTest {
|
|||||||
|
|
||||||
// run the current migrations and dump the result to the build-directory
|
// run the current migrations and dump the result to the build-directory
|
||||||
liquibase.runWithContexts("only-office", "with-test-data");
|
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
|
// then add another migration and assert if it was applied
|
||||||
liquibase.runWithContexts("liquibase-migration-test");
|
liquibase.runWithContexts("liquibase-migration-test");
|
||||||
|
@ -18,10 +18,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
public class PostgresTestcontainer {
|
public class PostgresTestcontainer {
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void dumpTo(final File targetFileName) {
|
public static void dump(final String jdbcUrl, final File targetFileName) {
|
||||||
makeDir(targetFileName.getParentFile());
|
makeDir(targetFileName.getParentFile());
|
||||||
|
|
||||||
final var jdbcDatabaseContainer = getJdbcDatabaseContainer();
|
final var jdbcDatabaseContainer = getJdbcDatabaseContainer(jdbcUrl);
|
||||||
|
|
||||||
final var sqlDumpFile = new File(targetFileName.getParent(), "." + targetFileName.getName());
|
final var sqlDumpFile = new File(targetFileName.getParent(), "." + targetFileName.getName());
|
||||||
final var pb = new ProcessBuilder(
|
final var pb = new ProcessBuilder(
|
||||||
@ -69,14 +69,13 @@ public class PostgresTestcontainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@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
|
// 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);
|
final var getContainerMethod = ContainerDatabaseDriver.class.getDeclaredMethod("getContainer", String.class);
|
||||||
getContainerMethod.setAccessible(true);
|
getContainerMethod.setAccessible(true);
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
final var container = (JdbcDatabaseContainer) getContainerMethod.invoke(null,
|
final var container = (JdbcDatabaseContainer) getContainerMethod.invoke(null, jdbcUrl);
|
||||||
"jdbc:tc:postgresql:15.5-bookworm:///liquibaseMigrationTestTC");
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user