create dump of imported office data
This commit is contained in:
parent
aef3c9c546
commit
aaf88fe4e4
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
* <p>The test works as follows:</p>
|
||||
*
|
||||
* <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>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>it's asserted that the extra changeset got applied</li>
|
||||
* </ol>
|
||||
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user