From 2d81d3f6fda69850b61eadbf7d6a4252c23b4343 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 25 Jan 2024 10:07:24 +0100 Subject: [PATCH] persist relationships before partners to avoid transient reference --- .aliases | 2 +- .../hs/office/migration/ImportOfficeData.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.aliases b/.aliases index 9eef231d..cb78c781 100644 --- a/.aliases +++ b/.aliases @@ -46,7 +46,7 @@ postgresAutodoc () { alias postgres-autodoc=postgresAutodoc function importOfficeData() { - export HSADMINNG_POSTGRES_JDBC=jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers + export HSADMINNG_POSTGRES_JDBC_URL=jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers export HSADMINNG_POSTGRES_ADMIN_USERNAME=admin export HSADMINNG_POSTGRES_ADMIN_PASSWORD=password export HSADMINNG_POSTGRES_RESTRICTED_USERNAME=restricted diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java index 2b43b65b..0e0f45ca 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java @@ -163,7 +163,7 @@ public class ImportOfficeData extends ContextBasedTest { @Test @Order(1011) void verifyBusinessPartners() { - assumeThat(postgresAdminUser).isEqualTo("admin"); + assumeThatWeAreImportingControlledTestData(); // no contacts yet => mostly null values assertThat(toFormattedString(partners)).isEqualToIgnoringWhitespace(""" @@ -204,7 +204,7 @@ public class ImportOfficeData extends ContextBasedTest { @Test @Order(1021) void verifyContacts() { - assumeThat(postgresAdminUser).isEqualTo("admin"); + assumeThatWeAreImportingControlledTestData(); assertThat(toFormattedString(partners)).isEqualToIgnoringWhitespace(""" { @@ -280,7 +280,7 @@ public class ImportOfficeData extends ContextBasedTest { @Test @Order(1031) void verifySepaMandates() { - assumeThat(postgresAdminUser).isEqualTo("admin"); + assumeThatWeAreImportingControlledTestData(); assertThat(toFormattedString(bankAccounts)).isEqualToIgnoringWhitespace(""" { @@ -312,7 +312,7 @@ public class ImportOfficeData extends ContextBasedTest { @Test @Order(1041) void verifyCoopShares() { - assumeThat(postgresAdminUser).isEqualTo("admin"); + assumeThatWeAreImportingControlledTestData(); assertThat(toFormattedString(coopShares)).isEqualToIgnoringWhitespace(""" { @@ -339,7 +339,7 @@ public class ImportOfficeData extends ContextBasedTest { @Test @Order(1051) void verifyCoopAssets() { - assumeThat(postgresAdminUser).isEqualTo("admin"); + assumeThatWeAreImportingControlledTestData(); assertThat(toFormattedString(coopAssets)).isEqualToIgnoringWhitespace(""" { @@ -377,6 +377,11 @@ public class ImportOfficeData extends ContextBasedTest { persons.forEach(this::persist); }).assertSuccessful(); + jpaAttempt.transacted(() -> { + context(rbacSuperuser); + relationships.forEach(this::persist); + }).assertSuccessful(); + jpaAttempt.transacted(() -> { context(rbacSuperuser); partners.forEach(this::persist); @@ -391,26 +396,17 @@ public class ImportOfficeData extends ContextBasedTest { jpaAttempt.transacted(() -> { context(rbacSuperuser); memberships.forEach(this::persist); - - }).assertSuccessful(); - - jpaAttempt.transacted(() -> { - context(rbacSuperuser); - relationships.forEach(this::persist); - }).assertSuccessful(); jpaAttempt.transacted(() -> { context(rbacSuperuser); bankAccounts.forEach(this::persist); - }).assertSuccessful(); jpaAttempt.transacted(() -> { context(rbacSuperuser); sepaMandates.forEach(this::persist); updateLegacyIds(sepaMandates, "hs_office_sepamandate_legacy_id", "sepa_mandate_id"); - }).assertSuccessful(); jpaAttempt.transacted(() -> { @@ -441,6 +437,10 @@ public class ImportOfficeData extends ContextBasedTest { } + private static void assumeThatWeAreImportingControlledTestData() { + assumeThat(partners.size()).isLessThan(100); + } + private void deleteTestDataFromHsOfficeTables() { jpaAttempt.transacted(() -> { context(rbacSuperuser);