38235bd7d1d1ac1ce73c49cf271223dbe36c22fe..1edbe864b6575e37477228b331aa3822d4889ec0
2022-10-30 Michael Hoennig
amend architecture test
1edbe8 diff | tree
2022-10-30 Michael Hoennig
use test database
1307b4 diff | tree
2022-10-30 Michael Hoennig
add some asserts to sepa mandate import
e9984c diff | tree
2022-10-30 Michael Hoennig
add some asserts
3b1a98 diff | tree
3 files modified
151 ■■■■ changed files
src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java 58 ●●●● patch | view | raw | blame | history
src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java 89 ●●●● patch | view | raw | blame | history
src/test/resources/application.yml 4 ●●●● patch | view | raw | blame | history
src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java
@@ -30,16 +30,17 @@
                    "..test.pac",
                    "..context",
                    "..generated..",
                    "..hs.office.person",
                    "..hs.office.partner",
                    "..hs.office.bankaccount",
                    "..hs.office.debitor",
                    "..hs.office.relationship",
                    "..hs.office.contact",
                    "..hs.office.sepamandate",
                    "..hs.office.coopassets",
                    "..hs.office.coopshares",
                    "..hs.office.debitor",
                    "..hs.office.membership",
                    "..hs.office.migration",
                    "..hs.office.partner",
                    "..hs.office.person",
                    "..hs.office.relationship",
                    "..hs.office.sepamandate",
                    "..errors",
                    "..mapper",
                    "..ping",
@@ -121,14 +122,19 @@
    public static final ArchRule hsOfficeBankAccountPackageRule = classes()
            .that().resideInAPackage("..hs.office.bankaccount..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.bankaccount..", "..hs.office.sepamandate..", "..hs.office.debitor..");
            .resideInAnyPackage("..hs.office.bankaccount..",
                    "..hs.office.sepamandate..",
                    "..hs.office.debitor..",
                    "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule hsOfficeSepaMandatePackageRule = classes()
            .that().resideInAPackage("..hs.office.sepamandate..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.sepamandate..", "..hs.office.debitor..");
            .resideInAnyPackage("..hs.office.sepamandate..",
                    "..hs.office.debitor..",
                    "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
@@ -136,7 +142,10 @@
            .that().resideInAPackage("..hs.office.contact..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.contact..", "..hs.office.relationship..",
                    "..hs.office.partner..", "..hs.office.debitor..", "..hs.office.membership..");
                    "..hs.office.partner..",
                    "..hs.office.debitor..",
                    "..hs.office.membership..",
                    "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
@@ -144,35 +153,47 @@
            .that().resideInAPackage("..hs.office.person..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.person..", "..hs.office.relationship..",
                    "..hs.office.partner..", "..hs.office.debitor..", "..hs.office.membership..");
                    "..hs.office.partner..",
                    "..hs.office.debitor..",
                    "..hs.office.membership..",
                    "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule hsOfficeRelationshipPackageRule = classes()
            .that().resideInAPackage("..hs.office.relationship..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.relationship..");
            .resideInAnyPackage("..hs.office.relationship..",
                    "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule hsOfficePartnerPackageRule = classes()
            .that().resideInAPackage("..hs.office.partner..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.partner..", "..hs.office.debitor..", "..hs.office.membership..");
            .resideInAnyPackage("..hs.office.partner..",
                    "..hs.office.debitor..",
                    "..hs.office.membership..",
                    "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule hsOfficeMembershipPackageRule = classes()
            .that().resideInAPackage("..hs.office.membership..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.membership..", "..hs.office.coopassets..", "..hs.office.coopshares..");
            .resideInAnyPackage("..hs.office.membership..",
                    "..hs.office.coopassets..",
                    "..hs.office.coopshares..",
                    "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule hsOfficeCoopAssetsPackageRule = classes()
        .that().resideInAPackage("..hs.office.coopassets..")
        .should().onlyBeAccessed().byClassesThat()
        .resideInAnyPackage("..hs.office.coopassets..");
        .resideInAnyPackage(
                "..hs.office.coopassets..",
                "..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
@@ -180,6 +201,13 @@
            .that().resideInAPackage("..hs.office.coopshares..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.coopshares..");
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule hsOfficeMigrationPackageRule = classes()
            .that().resideInAPackage("..hs.office.migration..")
            .should().onlyBeAccessed().byClassesThat()
            .resideInAnyPackage("..hs.office.migration..");
    @ArchTest
    @SuppressWarnings("unused")
@@ -197,7 +225,7 @@
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule doNotUsejakartaTransactionAnnotationAtClassLevel = noClasses()
    public static final ArchRule doNotUseJakartaTransactionAnnotationAtClassLevel = noClasses()
            .should().beAnnotatedWith(jakarta.transaction.Transactional.class.getName())
            .as("Use @%s instead of @%s.".formatted(
                    org.springframework.transaction.annotation.Transactional.class.getName(),
@@ -205,7 +233,7 @@
    @ArchTest
    @SuppressWarnings("unused")
    public static final ArchRule doNotUsejakartaTransactionAnnotationAtMethodLevel = noMethods()
    public static final ArchRule doNotUseJakartaTransactionAnnotationAtMethodLevel = noMethods()
            .should().beAnnotatedWith(jakarta.transaction.Transactional.class)
            .as("Use @%s instead of @%s.".formatted(
                    org.springframework.transaction.annotation.Transactional.class.getName(),
src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportBusinessPartners.java
@@ -24,6 +24,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@@ -42,6 +43,16 @@
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.assertj.core.api.Assertions.assertThat;
/*
 * This 'test' includes the complete legacy 'office' data import.
 *
 * There is no code in 'main' because the import is not needed a normal runtime.
 * There is some test data in Java resources to verfiy the data conversion.
 * For a real import a main method will be added later
 * which reads CSV files from the file system.
 */
@DataJpaTest
@Import({ Context.class, JpaAttempt.class })
@@ -75,6 +86,13 @@
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        // no sensible content without contacts, thus just checking counts
        assertThat(partners.size()).isEqualTo(3);
        assertThat(contacts.size()).isEqualTo(0);
        assertThat(persons.size()).isEqualTo(3);
        assertThat(debitors.size()).isEqualTo(3);
        assertThat(memberships.size()).isEqualTo(3);
    }
    @Test
@@ -87,6 +105,43 @@
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        assertThat(partners.toString()).isEqualToIgnoringWhitespace("""
                {
                     7=partner(Michael, Mellies: Herr Michael Mellies ),
                    10=partner(JM e.K.: Frau Dr. Jenny Meyer , JM e.K.),
                    12=partner(Test PS: Paule Schmidt , Test PS)
                }
                """);
        assertThat(contacts.toString()).isEqualToIgnoringWhitespace("""
                {
                    101=contact(label='Frau Dr. Jenny Meyer , JM e.K.', emailAddresses='jm@example.org'),
                    102=contact(label='Herr Andrew Meyer , JM e.K.', emailAddresses='am@example.org'),
                     71=contact(label='Herr Michael Mellies ', emailAddresses='mih@example.org'),
                     121=contact(label='Paule Schmidt , Test PS', emailAddresses='ps@example.com')
                 }
                """);
        assertThat(persons.toString()).isEqualToIgnoringWhitespace("""
                {
                     7=person(personType='UNKNOWN', tradeName='', familyName='Michael', givenName='Mellies'),
                    10=person(personType='UNKNOWN', tradeName='JM e.K.', familyName='Jenny', givenName='Meyer'),
                    12=person(personType='UNKNOWN', tradeName='Test PS', familyName='Paule', givenName='Schmidt')
                }
                """);
        assertThat(debitors.toString()).isEqualToIgnoringWhitespace("""
                {
                     7=debitor(10007: Michael, Mellies),
                    10=debitor(10010: JM e.K.),
                    12=debitor(11012: Test PS)
                }
                """);
        assertThat(memberships.toString()).isEqualToIgnoringWhitespace("""
                {
                     7=Membership(10007, Michael, Mellies, 10007, [2000-12-06,), NONE),
                    10=Membership(10010, JM e.K., 10010, [2000-12-06,2016-01-01), UNKNOWN),
                    12=Membership(11012, Test PS, 11012, [2021-04-01,), NONE)
                }
                """);
    }
    @Test
@@ -99,22 +154,36 @@
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        assertThat(bankAccounts.toString()).isEqualToIgnoringWhitespace("""
                {
                    234234=bankAccount(holder='Michael Mellies', iban='DE37500105177419788228', bic='INGDDEFFXXX'),
                    235662=bankAccount(holder='JM e.K.', iban='DE49500105174516484892', bic='INGDDEFFXXX')
                }
                """);
        assertThat(sepaMandates.toString()).isEqualToIgnoringWhitespace("""
                {
                    234234=SEPA-Mandate(DE37500105177419788228, MH12345, 2004-06-12, [2004-06-15,)),
                    235662=SEPA-Mandate(DE49500105174516484892, JM33344, 2005-06-28, [2005-07-01,))
                }
                """);
    }
    @Test
    @Order(10)
    @Transactional
    void persistEntities() {
        jpaAttempt.transacted(() -> {
            context("superuser-alex@hostsharing.net"); // TODO: use real user
        context("superuser-alex@hostsharing.net"); // TODO: use real user for actual import
            contacts.forEach((id, contact) -> em.persist(contact));
            persons.forEach((id, person) -> em.persist(person));
            partners.forEach((id, partner) -> em.persist(partner));
            debitors.forEach((id, debitor) -> em.persist(debitor));
            memberships.forEach((id, membership) -> em.persist(membership));
            bankAccounts.forEach((id, account) -> em.persist(account));
            sepaMandates.forEach((id, mandate) -> em.persist(mandate));
        }).assertSuccessful();
        contacts.forEach((id, contact) -> em.persist(contact));
        persons.forEach((id, person) -> em.persist(person));
        partners.forEach((id, partner) -> em.persist(partner));
        debitors.forEach((id, debitor) -> em.persist(debitor));
        memberships.forEach((id, membership) -> em.persist(membership));
        bankAccounts.forEach((id, account) -> em.persist(account));
        sepaMandates.forEach((id, mandate) -> em.persist(mandate));
        em.flush();
    }
    public List<String[]> readAllLines(Reader reader) throws Exception {
src/test/resources/application.yml
@@ -4,8 +4,8 @@
            platform: postgres
    datasource:
        url-tc: jdbc:tc:postgresql:13.7-bullseye:///spring_boot_testcontainers
        url: jdbc:postgresql://localhost:5432/postgres
        url: jdbc:tc:postgresql:13.7-bullseye:///spring_boot_testcontainers
        url-local: jdbc:postgresql://localhost:5432/postgres
        username: postgres
        password: password