diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java index ebc1065a..7bcaeb2a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerController.java @@ -11,6 +11,7 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartne import net.hostsharing.hsadminng.hs.office.migration.HasUuid; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity; +import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType; import net.hostsharing.hsadminng.mapper.Mapper; import org.springframework.beans.factory.annotation.Autowired; @@ -37,6 +38,9 @@ public class HsOfficePartnerController implements HsOfficePartnersApi { @Autowired private HsOfficePartnerRepository partnerRepo; + @Autowired + private HsOfficeRelationshipRepository relationshipRepo; + @PersistenceContext private EntityManager em; @@ -100,11 +104,16 @@ public class HsOfficePartnerController implements HsOfficePartnersApi { final UUID partnerUuid) { context.define(currentUser, assumedRoles); - final var result = partnerRepo.deleteByUuid(partnerUuid); - if (result == 0) { + final var partnerToDelete = partnerRepo.findByUuid(partnerUuid); + if (partnerToDelete.isEmpty()) { return ResponseEntity.notFound().build(); } + if (partnerRepo.deleteByUuid(partnerUuid) != 1 || + relationshipRepo.deleteByUuid(partnerToDelete.get().getPartnerRole().getUuid()) != 1 ) { + ResponseEntity.internalServerError().build(); + } + return ResponseEntity.noContent().build(); } diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java index a09e00b9..f3513e77 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java @@ -164,6 +164,7 @@ public class ArchitectureTest { .that().resideInAPackage("..hs.office.relationship..") .should().onlyBeAccessed().byClassesThat() .resideInAnyPackage("..hs.office.relationship..", + "..hs.office.partner..", "..hs.office.migration.."); @ArchTest diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java index aa9c507b..3eb93f4c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java @@ -36,13 +36,13 @@ class HsOfficeCoopSharesTransactionEntityUnitTest { void toStringEmptyTransactionDoesNotThrowException() { final var result = givenEmptyCoopSharesTransaction.toString(); - assertThat(result).isEqualTo("CoopShareTransaction(M-0)"); + assertThat(result).isEqualTo("CoopShareTransaction(0)"); } @Test void toShortStringEmptyTransactionDoesNotThrowException() { final var result = givenEmptyCoopSharesTransaction.toShortString(); - assertThat(result).isEqualTo("M-null+0"); + assertThat(result).isEqualTo("null+0"); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java index 6b43c94e..9569f8e2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java @@ -140,17 +140,17 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase // then allTheseCoopSharesTransactionsAreReturned( result, - "CoopShareTransaction(1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)", - "CoopShareTransaction(1000101, 2021-09-01, CANCELLATION, -2, ref 1000101-2, cancelling some)", - "CoopShareTransaction(1000101, 2022-10-20, ADJUSTMENT, 2, ref 1000101-3, some adjustment)", + "CoopShareTransaction(M-1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)", + "CoopShareTransaction(M-1000101, 2021-09-01, CANCELLATION, -2, ref 1000101-2, cancelling some)", + "CoopShareTransaction(M-1000101, 2022-10-20, ADJUSTMENT, 2, ref 1000101-3, some adjustment)", - "CoopShareTransaction(1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)", - "CoopShareTransaction(1000202, 2021-09-01, CANCELLATION, -2, ref 1000202-2, cancelling some)", - "CoopShareTransaction(1000202, 2022-10-20, ADJUSTMENT, 2, ref 1000202-3, some adjustment)", + "CoopShareTransaction(M-1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)", + "CoopShareTransaction(M-1000202, 2021-09-01, CANCELLATION, -2, ref 1000202-2, cancelling some)", + "CoopShareTransaction(M-1000202, 2022-10-20, ADJUSTMENT, 2, ref 1000202-3, some adjustment)", - "CoopShareTransaction(1000303, 2010-03-15, SUBSCRIPTION, 4, ref 1000303-1, initial subscription)", - "CoopShareTransaction(1000303, 2021-09-01, CANCELLATION, -2, ref 1000303-2, cancelling some)", - "CoopShareTransaction(1000303, 2022-10-20, ADJUSTMENT, 2, ref 1000303-3, some adjustment)"); + "CoopShareTransaction(M-1000303, 2010-03-15, SUBSCRIPTION, 4, ref 1000303-1, initial subscription)", + "CoopShareTransaction(M-1000303, 2021-09-01, CANCELLATION, -2, ref 1000303-2, cancelling some)", + "CoopShareTransaction(M-1000303, 2022-10-20, ADJUSTMENT, 2, ref 1000303-3, some adjustment)"); } @Test @@ -168,9 +168,9 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase // then allTheseCoopSharesTransactionsAreReturned( result, - "CoopShareTransaction(1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)", - "CoopShareTransaction(1000202, 2021-09-01, CANCELLATION, -2, ref 1000202-2, cancelling some)", - "CoopShareTransaction(1000202, 2022-10-20, ADJUSTMENT, 2, ref 1000202-3, some adjustment)"); + "CoopShareTransaction(M-1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)", + "CoopShareTransaction(M-1000202, 2021-09-01, CANCELLATION, -2, ref 1000202-2, cancelling some)", + "CoopShareTransaction(M-1000202, 2022-10-20, ADJUSTMENT, 2, ref 1000202-3, some adjustment)"); } @Test @@ -188,7 +188,7 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase // then allTheseCoopSharesTransactionsAreReturned( result, - "CoopShareTransaction(1000202, 2021-09-01, CANCELLATION, -2, ref 1000202-2, cancelling some)"); + "CoopShareTransaction(M-1000202, 2021-09-01, CANCELLATION, -2, ref 1000202-2, cancelling some)"); } @Test @@ -205,9 +205,9 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase // then: exactlyTheseCoopSharesTransactionsAreReturned( result, - "CoopShareTransaction(1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)", - "CoopShareTransaction(1000101, 2021-09-01, CANCELLATION, -2, ref 1000101-2, cancelling some)", - "CoopShareTransaction(1000101, 2022-10-20, ADJUSTMENT, 2, ref 1000101-3, some adjustment)"); + "CoopShareTransaction(M-1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)", + "CoopShareTransaction(M-1000101, 2021-09-01, CANCELLATION, -2, ref 1000101-2, cancelling some)", + "CoopShareTransaction(M-1000101, 2022-10-20, ADJUSTMENT, 2, ref 1000101-3, some adjustment)"); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java index 39146f56..eacda619 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java @@ -152,7 +152,7 @@ class HsOfficeDebitorControllerAcceptanceTest { context.define("superuser-alex@hostsharing.net"); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); - final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); + final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0); final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0); final var location = RestAssured // @formatter:off @@ -199,7 +199,7 @@ class HsOfficeDebitorControllerAcceptanceTest { context.define("superuser-alex@hostsharing.net"); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); - final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); + final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -243,7 +243,7 @@ class HsOfficeDebitorControllerAcceptanceTest { context.define("superuser-alex@hostsharing.net"); final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); - final var givenContactUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); + final var givenContactUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); final var location = RestAssured // @formatter:off .given() @@ -268,7 +268,7 @@ class HsOfficeDebitorControllerAcceptanceTest { .post("http://localhost/api/hs/office/debitors") .then().log().all().assertThat() .statusCode(400) - .body("message", is("Unable to find Contact with uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); + .body("message", is("Unable to find Contact with uuid 00000000-0000-0000-0000-000000000000")); // @formatter:on } @@ -276,8 +276,8 @@ class HsOfficeDebitorControllerAcceptanceTest { void globalAdmin_canNotAddDebitor_ifPartnerDoesNotExist() { context.define("superuser-alex@hostsharing.net"); - final var givenPartnerUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); - final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); + final var givenPartnerUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); + final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() @@ -301,7 +301,7 @@ class HsOfficeDebitorControllerAcceptanceTest { .post("http://localhost/api/hs/office/debitors") .then().log().all().assertThat() .statusCode(400) - .body("message", is("Unable to find Partner with uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); + .body("message", is("Unable to find Partner with uuid 00000000-0000-0000-0000-000000000000")); // @formatter:on } } @@ -382,7 +382,7 @@ class HsOfficeDebitorControllerAcceptanceTest { context.define("superuser-alex@hostsharing.net"); final var givenDebitor = givenSomeTemporaryDebitor(); - final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); + final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0); final var location = RestAssured // @formatter:off .given() diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java index e27e4b75..ffaa5129 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java @@ -128,8 +128,8 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll()).stream() // some search+replace to make the output fit into the screen width .map(s -> s.replace("superuser-alex@hostsharing.net", "superuser-alex")) - .map(s -> s.replace("22Fourthe.G.-fourthcontact", "FeG")) - .map(s -> s.replace("Fourthe.G.-fourthcontact", "FeG")) + .map(s -> s.replace("22FourtheG-fourthcontact", "FeG")) + .map(s -> s.replace("FourtheG-fourthcontact", "FeG")) .map(s -> s.replace("fourthcontact", "4th")) .map(s -> s.replace("hs_office_", "")) .toList(); @@ -151,15 +151,15 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { // then assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from( initialRoleNames, - "hs_office_debitor#1000422:Fourthe.G.-fourthcontact.owner", - "hs_office_debitor#1000422:Fourthe.G.-fourthcontact.admin", - "hs_office_debitor#1000422:Fourthe.G.-fourthcontact.agent", - "hs_office_debitor#1000422:Fourthe.G.-fourthcontact.tenant", - "hs_office_debitor#1000422:Fourthe.G.-fourthcontact.guest")); + "hs_office_debitor#1000422:FourtheG-fourthcontact.owner", + "hs_office_debitor#1000422:FourtheG-fourthcontact.admin", + "hs_office_debitor#1000422:FourtheG-fourthcontact.agent", + "hs_office_debitor#1000422:FourtheG-fourthcontact.tenant", + "hs_office_debitor#1000422:FourtheG-fourthcontact.guest")); assertThat(grantDisplaysOf(rawGrantRepo.findAll())) .map(s -> s.replace("superuser-alex@hostsharing.net", "superuser-alex")) - .map(s -> s.replace("22Fourthe.G.-fourthcontact", "FeG")) - .map(s -> s.replace("Fourthe.G.-fourthcontact", "FeG")) + .map(s -> s.replace("22FourtheG-fourthcontact", "FeG")) + .map(s -> s.replace("FourtheG-fourthcontact", "FeG")) .map(s -> s.replace("fourthcontact", "4th")) .map(s -> s.replace("hs_office_", "")) .containsExactlyInAnyOrder(Array.fromFormatted( @@ -290,7 +290,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", "Fourth", "fif"); assertThatDebitorIsVisibleForUserWithRole( givenDebitor, - "hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); + "hs_office_partner#10004:FourtheG-fourthcontact.admin"); assertThatDebitorActuallyInDatabase(givenDebitor); final var givenNewPartner = partnerRepo.findPartnerByOptionalNameLike("First").get(0); final var givenNewContact = contactRepo.findContactByOptionalLabelLike("sixth contact").get(0); @@ -320,7 +320,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { // ... partner role was reassigned: assertThatDebitorIsNotVisibleForUserWithRole( result.returnedValue(), - "hs_office_partner#10004:Fourthe.G.-fourthcontact.agent"); + "hs_office_partner#10004:FourtheG-fourthcontact.agent"); assertThatDebitorIsVisibleForUserWithRole( result.returnedValue(), "hs_office_partner#10001:FirstGmbH-firstcontact.agent"); @@ -336,7 +336,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { // ... bank-account role was reassigned: assertThatDebitorIsNotVisibleForUserWithRole( result.returnedValue(), - "hs_office_bankaccount#Fourthe.G..admin"); + "hs_office_bankaccount#FourtheG.admin"); assertThatDebitorIsVisibleForUserWithRole( result.returnedValue(), "hs_office_bankaccount#FirstGmbH.admin"); @@ -349,7 +349,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", null, "fig"); assertThatDebitorIsVisibleForUserWithRole( givenDebitor, - "hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); + "hs_office_partner#10004:FourtheG-fourthcontact.admin"); assertThatDebitorActuallyInDatabase(givenDebitor); final var givenNewBankAccount = bankAccountRepo.findByOptionalHolderLike("first").get(0); @@ -379,7 +379,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", "Fourth", "fih"); assertThatDebitorIsVisibleForUserWithRole( givenDebitor, - "hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); + "hs_office_partner#10004:FourtheG-fourthcontact.admin"); assertThatDebitorActuallyInDatabase(givenDebitor); // when @@ -398,7 +398,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { // ... bank-account role was removed from previous bank-account admin: assertThatDebitorIsNotVisibleForUserWithRole( result.returnedValue(), - "hs_office_bankaccount#Fourthe.G..admin"); + "hs_office_bankaccount#FourtheG.admin"); } @Test @@ -408,12 +408,12 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "eighth", "Fourth", "eig"); assertThatDebitorIsVisibleForUserWithRole( givenDebitor, - "hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); + "hs_office_partner#10004:FourtheG-fourthcontact.admin"); assertThatDebitorActuallyInDatabase(givenDebitor); // when final var result = jpaAttempt.transacted(() -> { - context("superuser-alex@hostsharing.net", "hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); + context("superuser-alex@hostsharing.net", "hs_office_partner#10004:FourtheG-fourthcontact.admin"); givenDebitor.setVatId("NEW-VAT-ID"); return debitorRepo.save(givenDebitor); }); @@ -502,7 +502,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { // when final var result = jpaAttempt.transacted(() -> { - context("person-Fourthe.G.@example.com"); + context("person-FourtheG@example.com"); assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent(); debitorRepo.deleteByUuid(givenDebitor.getUuid()); @@ -550,7 +550,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest { final var query = em.createNativeQuery(""" select currentTask, targetTable, targetOp from tx_journal_v - where targettable = 'hs_office_coopsharestransaction'; + where targettable = 'hs_office_debitor'; """); // when diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java index c16d6f39..dabbd825 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java @@ -9,12 +9,11 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity; +import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType; import net.hostsharing.test.Accepts; import net.hostsharing.test.JpaAttempt; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; @@ -22,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; +import java.util.List; import java.util.UUID; import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid; @@ -35,7 +35,6 @@ import static org.hamcrest.Matchers.*; ) class HsOfficePartnerControllerAcceptanceTest { -// private static final UUID GIVEN_NON_EXISTING_UUID = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); private static final UUID GIVEN_NON_EXISTING_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); @LocalServerPort @@ -50,6 +49,9 @@ class HsOfficePartnerControllerAcceptanceTest { @Autowired HsOfficePartnerRepository partnerRepo; + @Autowired + HsOfficeRelationshipRepository relationshipRepository; + @Autowired HsOfficePersonRepository personRepo; @@ -61,6 +63,7 @@ class HsOfficePartnerControllerAcceptanceTest { @PersistenceContext EntityManager em; + private long relationshipCountBefore; @Nested @Accepts({ "Partner:F(Find)" }) @@ -413,6 +416,7 @@ class HsOfficePartnerControllerAcceptanceTest { // then the given partner is gone assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty(); + assertThat(relationshipRepository.findByUuid(givenPartner.getPartnerRole().getUuid())).isEmpty(); } @Test @@ -485,17 +489,29 @@ class HsOfficePartnerControllerAcceptanceTest { }).assertSuccessful().returnedValue(); } + @BeforeEach + void countRelationships() { + context.define("superuser-alex@hostsharing.net", null); + relationshipCountBefore = relationshipRepository.count(); + } + @AfterEach + @SuppressWarnings("unchecked") void cleanup() { final var deleted = jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net", null); - em.createNativeQuery(""" - delete from hs_office_partner p + final var tempPartnerUuids = (List)em.createNativeQuery(""" + select uuid from hs_office_partner p where p.detailsuuid in ( select d.uuid from hs_office_partner_details d where d.registrationoffice like 'Temp %') """) - .executeUpdate(); + .getResultList(); + tempPartnerUuids.forEach(partnerUuid -> { + final var tempPartner = partnerRepo.findByUuid(partnerUuid).orElseThrow(); + em.remove(tempPartner); + em.remove(tempPartner.getPartnerRole()); + }); }).assertSuccessful().returnedValue(); final var remaining = jpaAttempt.transacted(() -> { @@ -508,6 +524,8 @@ class HsOfficePartnerControllerAcceptanceTest { .getSingleResult(); }).assertSuccessful().returnedValue(); System.err.println("@AfterEach" + ": " + deleted + " records deleted, " + remaining + " remaining"); - } + context.define("superuser-alex@hostsharing.net", null); + assertThat(relationshipRepository.count()).as("not all relationships got cleaned up").isEqualTo(relationshipCountBefore); + } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java index 1a5a6258..a69b0495 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java @@ -462,6 +462,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest { context("superuser-alex@hostsharing.net", null); tempPartners.forEach(tempPartner -> { System.out.println("DELETING temporary partner: " + tempPartner.toString()); + relationshipRepo.deleteByUuid(tempPartner.getPartnerRole().getUuid()); partnerRepo.deleteByUuid(tempPartner.getUuid()); }); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipControllerAcceptanceTest.java index f7b8047d..b53512e4 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relationship/HsOfficeRelationshipControllerAcceptanceTest.java @@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.startsWith; @Transactional class HsOfficeRelationshipControllerAcceptanceTest { - public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); + public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); @LocalServerPort private Integer port; @@ -241,7 +241,7 @@ class HsOfficeRelationshipControllerAcceptanceTest { context.define("superuser-alex@hostsharing.net"); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").get(0); - final var givenContactUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); + final var givenContactUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); final var location = RestAssured // @formatter:off .given() @@ -264,7 +264,7 @@ class HsOfficeRelationshipControllerAcceptanceTest { .post("http://localhost/api/hs/office/relationships") .then().log().all().assertThat() .statusCode(404) - .body("message", is("cannot find contactUuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); + .body("message", is("cannot find contactUuid 00000000-0000-0000-0000-000000000000")); // @formatter:on } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java index 0cf0c887..b716222d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java @@ -190,7 +190,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { context.define("superuser-alex@hostsharing.net"); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); - final var givenBankAccountUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); + final var givenBankAccountUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); final var location = RestAssured // @formatter:off .given() @@ -211,7 +211,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { .post("http://localhost/api/hs/office/sepamandates") .then().log().all().assertThat() .statusCode(400) - .body("message", is("Unable to find BankAccount with uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); + .body("message", is("Unable to find BankAccount with uuid 00000000-0000-0000-0000-000000000000")); // @formatter:on } @@ -219,7 +219,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { void globalAdmin_canNotAddSepaMandate_ifPersonDoesNotExist() { context.define("superuser-alex@hostsharing.net"); - final var givenDebitorUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); + final var givenDebitorUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); final var givenBankAccount = bankAccountRepo.findByIbanOrderByIban("DE02200505501015871393").get(0); final var location = RestAssured // @formatter:off @@ -241,7 +241,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { .post("http://localhost/api/hs/office/sepamandates") .then().log().all().assertThat() .statusCode(400) - .body("message", is("Unable to find Debitor with uuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); + .body("message", is("Unable to find Debitor with uuid 00000000-0000-0000-0000-000000000000")); // @formatter:on } }