From df56e6def08808aee649c6e70a8bb8a8c9ec2d89 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 16 Jul 2024 10:04:00 +0200 Subject: [PATCH] amend text formatting to changed config formatting in prod code and extract .tc-environment --- .aliases | 15 +++----- .tc-environment | 5 +++ .../hs/office/migration/ImportOfficeData.java | 36 +++++++------------ 3 files changed, 21 insertions(+), 35 deletions(-) create mode 100644 .tc-environment diff --git a/.aliases b/.aliases index cb78c781..991f34de 100644 --- a/.aliases +++ b/.aliases @@ -1,9 +1,6 @@ -# For using the alias import-office-tables, # copy these exports to .environment (ignored by git) -# and amend them according to your external DB: -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= -export HSADMINNG_POSTGRES_RESTRICTED_USERNAME=restricted +# For using the alias import-office-tables, +# copy the file .tc-environment to .environment (ignored by git) +# and amend them according to your external DB. gradleWrapper () { if [ ! -f gradlew ]; then @@ -46,11 +43,7 @@ postgresAutodoc () { alias postgres-autodoc=postgresAutodoc function importOfficeData() { - 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 - export HSADMINNG_SUPERUSER=superuser-alex@hostsharing.net + source .tc-environment if [ -f .environment ]; then source .environment diff --git a/.tc-environment b/.tc-environment new file mode 100644 index 00000000..5c7b8d42 --- /dev/null +++ b/.tc-environment @@ -0,0 +1,5 @@ +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= +export HSADMINNG_POSTGRES_RESTRICTED_USERNAME=restricted +export HSADMINNG_MIGRATION_DATA_PATH=migration 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 9ecedc07..52188e79 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 @@ -92,13 +92,7 @@ import static org.assertj.core.api.Fail.fail; -- maybe something like that is needed for the 2nd user -- GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public to hsh99_restricted; - * Then copy this to a file named .environment (excluded from git) and fill in your specific values: - - export HSADMINNG_POSTGRES_JDBC_URL=jdbc:postgresql://localhost:6432/hsh99_hsadminng - export HSADMINNG_POSTGRES_ADMIN_USERNAME=hsh99_admin - export HSADMINNG_POSTGRES_ADMIN_PASSWORD=password - export HSADMINNG_POSTGRES_RESTRICTED_USERNAME=hsh99_restricted - export HSADMINNG_SUPERUSER=some-precreated-superuser@example.org + * Then copy the file .tc-environment to a file named .environment (excluded from git) and fill in your specific values. * To finally import the office data, run: * @@ -253,16 +247,16 @@ public class ImportOfficeData extends ContextBasedTest { """); assertThat(toFormattedString(contacts)).isEqualToIgnoringWhitespace(""" { - 1101=contact(caption='Herr Michael Mellies ', emailAddresses='{ main: mih@example.org }'), - 1200=contact(caption='JM e.K.', emailAddresses='{ main: jm-ex-partner@example.org }'), - 1201=contact(caption='Frau Dr. Jenny Meyer-Billing , JM GmbH', emailAddresses='{ main: jm-billing@example.org }'), - 1202=contact(caption='Herr Andrew Meyer-Operation , JM GmbH', emailAddresses='{ main: am-operation@example.org }'), - 1203=contact(caption='Herr Philip Meyer-Contract , JM GmbH', emailAddresses='{ main: pm-partner@example.org }'), - 1204=contact(caption='Frau Tammy Meyer-VIP , JM GmbH', emailAddresses='{ main: tm-vip@example.org }'), - 1301=contact(caption='Petra Schmidt , Test PS', emailAddresses='{ main: ps@example.com }'), - 1401=contact(caption='Frau Frauke Fanninga ', emailAddresses='{ main: ff@example.org }'), - 1501=contact(caption='Frau Cecilia Camus ', emailAddresses='{ main: cc@example.org }') - } + 1101=contact(caption='Herr Michael Mellies ', emailAddresses='{ "main": "mih@example.org"}'), + 1200=contact(caption='JM e.K.', emailAddresses='{ "main": "jm-ex-partner@example.org"}'), + 1201=contact(caption='Frau Dr. Jenny Meyer-Billing , JM GmbH', emailAddresses='{ "main": "jm-billing@example.org"}'), + 1202=contact(caption='Herr Andrew Meyer-Operation , JM GmbH', emailAddresses='{ "main": "am-operation@example.org"}'), + 1203=contact(caption='Herr Philip Meyer-Contract , JM GmbH', emailAddresses='{ "main": "pm-partner@example.org"}'), + 1204=contact(caption='Frau Tammy Meyer-VIP , JM GmbH', emailAddresses='{ "main": "tm-vip@example.org"}'), + 1301=contact(caption='Petra Schmidt , Test PS', emailAddresses='{ "main": "ps@example.com"}'), + 1401=contact(caption='Frau Frauke Fanninga ', emailAddresses='{ "main": "ff@example.org"}'), + 1501=contact(caption='Frau Cecilia Camus ', emailAddresses='{ "main": "cc@example.org"}') + } """); assertThat(toFormattedString(persons)).isEqualToIgnoringWhitespace(""" { @@ -1141,6 +1135,7 @@ public class ImportOfficeData extends ContextBasedTest { return "{\n" + map.keySet().stream() .map(id -> " " + id + "=" + map.get(id).toString()) + .map(e -> e.replaceAll("\n ", " ").replace("\n", "")) .collect(Collectors.joining(",\n")) + "\n}\n"; } @@ -1228,13 +1223,6 @@ public class ImportOfficeData extends ContextBasedTest { return new InputStreamReader(requireNonNull(getClass().getClassLoader().getResourceAsStream(resourcePath))); } - private Reader fileReader(@NotNull final Path filePath) throws IOException { - // Path path = Paths.get( - // ClassLoader.getSystemResource("csv/twoColumn.csv").toURI()) - // ); - return Files.newBufferedReader(filePath); - } - private static String[] justHeader(final List lines) { return stream(lines.getFirst()).map(String::trim).toArray(String[]::new); }