amend partner related tests to new test data

This commit is contained in:
Michael Hoennig 2024-01-28 14:40:04 +01:00
parent 170aa5e462
commit ebb94969e7
10 changed files with 91 additions and 62 deletions

View File

@ -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.migration.HasUuid;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity; 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.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.hsadminng.mapper.Mapper; import net.hostsharing.hsadminng.mapper.Mapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -37,6 +38,9 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
@Autowired @Autowired
private HsOfficePartnerRepository partnerRepo; private HsOfficePartnerRepository partnerRepo;
@Autowired
private HsOfficeRelationshipRepository relationshipRepo;
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@ -100,11 +104,16 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
final UUID partnerUuid) { final UUID partnerUuid) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var result = partnerRepo.deleteByUuid(partnerUuid); final var partnerToDelete = partnerRepo.findByUuid(partnerUuid);
if (result == 0) { if (partnerToDelete.isEmpty()) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
if (partnerRepo.deleteByUuid(partnerUuid) != 1 ||
relationshipRepo.deleteByUuid(partnerToDelete.get().getPartnerRole().getUuid()) != 1 ) {
ResponseEntity.internalServerError().build();
}
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
} }

View File

@ -164,6 +164,7 @@ public class ArchitectureTest {
.that().resideInAPackage("..hs.office.relationship..") .that().resideInAPackage("..hs.office.relationship..")
.should().onlyBeAccessed().byClassesThat() .should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.office.relationship..", .resideInAnyPackage("..hs.office.relationship..",
"..hs.office.partner..",
"..hs.office.migration.."); "..hs.office.migration..");
@ArchTest @ArchTest

View File

@ -36,13 +36,13 @@ class HsOfficeCoopSharesTransactionEntityUnitTest {
void toStringEmptyTransactionDoesNotThrowException() { void toStringEmptyTransactionDoesNotThrowException() {
final var result = givenEmptyCoopSharesTransaction.toString(); final var result = givenEmptyCoopSharesTransaction.toString();
assertThat(result).isEqualTo("CoopShareTransaction(M-0)"); assertThat(result).isEqualTo("CoopShareTransaction(0)");
} }
@Test @Test
void toShortStringEmptyTransactionDoesNotThrowException() { void toShortStringEmptyTransactionDoesNotThrowException() {
final var result = givenEmptyCoopSharesTransaction.toShortString(); final var result = givenEmptyCoopSharesTransaction.toShortString();
assertThat(result).isEqualTo("M-null+0"); assertThat(result).isEqualTo("null+0");
} }
} }

View File

@ -140,17 +140,17 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase
// then // then
allTheseCoopSharesTransactionsAreReturned( allTheseCoopSharesTransactionsAreReturned(
result, result,
"CoopShareTransaction(1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)", "CoopShareTransaction(M-1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)",
"CoopShareTransaction(1000101, 2021-09-01, CANCELLATION, -2, ref 1000101-2, cancelling some)", "CoopShareTransaction(M-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, 2022-10-20, ADJUSTMENT, 2, ref 1000101-3, some adjustment)",
"CoopShareTransaction(1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)", "CoopShareTransaction(M-1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)",
"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)",
"CoopShareTransaction(1000202, 2022-10-20, ADJUSTMENT, 2, ref 1000202-3, some adjustment)", "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(M-1000303, 2010-03-15, SUBSCRIPTION, 4, ref 1000303-1, initial subscription)",
"CoopShareTransaction(1000303, 2021-09-01, CANCELLATION, -2, ref 1000303-2, cancelling some)", "CoopShareTransaction(M-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, 2022-10-20, ADJUSTMENT, 2, ref 1000303-3, some adjustment)");
} }
@Test @Test
@ -168,9 +168,9 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase
// then // then
allTheseCoopSharesTransactionsAreReturned( allTheseCoopSharesTransactionsAreReturned(
result, result,
"CoopShareTransaction(1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)", "CoopShareTransaction(M-1000202, 2010-03-15, SUBSCRIPTION, 4, ref 1000202-1, initial subscription)",
"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)",
"CoopShareTransaction(1000202, 2022-10-20, ADJUSTMENT, 2, ref 1000202-3, some adjustment)"); "CoopShareTransaction(M-1000202, 2022-10-20, ADJUSTMENT, 2, ref 1000202-3, some adjustment)");
} }
@Test @Test
@ -188,7 +188,7 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase
// then // then
allTheseCoopSharesTransactionsAreReturned( allTheseCoopSharesTransactionsAreReturned(
result, 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 @Test
@ -205,9 +205,9 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase
// then: // then:
exactlyTheseCoopSharesTransactionsAreReturned( exactlyTheseCoopSharesTransactionsAreReturned(
result, result,
"CoopShareTransaction(1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)", "CoopShareTransaction(M-1000101, 2010-03-15, SUBSCRIPTION, 4, ref 1000101-1, initial subscription)",
"CoopShareTransaction(1000101, 2021-09-01, CANCELLATION, -2, ref 1000101-2, cancelling some)", "CoopShareTransaction(M-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, 2022-10-20, ADJUSTMENT, 2, ref 1000101-3, some adjustment)");
} }
} }

View File

@ -152,7 +152,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); 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 givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
@ -199,7 +199,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); 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 final var location = RestAssured // @formatter:off
.given() .given()
@ -243,7 +243,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Third").get(0); 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 final var location = RestAssured // @formatter:off
.given() .given()
@ -268,7 +268,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
.post("http://localhost/api/hs/office/debitors") .post("http://localhost/api/hs/office/debitors")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(400) .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 // @formatter:on
} }
@ -276,8 +276,8 @@ class HsOfficeDebitorControllerAcceptanceTest {
void globalAdmin_canNotAddDebitor_ifPartnerDoesNotExist() { void globalAdmin_canNotAddDebitor_ifPartnerDoesNotExist() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartnerUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); final var givenPartnerUuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -301,7 +301,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
.post("http://localhost/api/hs/office/debitors") .post("http://localhost/api/hs/office/debitors")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(400) .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 // @formatter:on
} }
} }
@ -382,7 +382,7 @@ class HsOfficeDebitorControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor(); 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 final var location = RestAssured // @formatter:off
.given() .given()

View File

@ -128,8 +128,8 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll()).stream() final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll()).stream()
// some search+replace to make the output fit into the screen width // 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("superuser-alex@hostsharing.net", "superuser-alex"))
.map(s -> s.replace("22Fourthe.G.-fourthcontact", "FeG")) .map(s -> s.replace("22FourtheG-fourthcontact", "FeG"))
.map(s -> s.replace("Fourthe.G.-fourthcontact", "FeG")) .map(s -> s.replace("FourtheG-fourthcontact", "FeG"))
.map(s -> s.replace("fourthcontact", "4th")) .map(s -> s.replace("fourthcontact", "4th"))
.map(s -> s.replace("hs_office_", "")) .map(s -> s.replace("hs_office_", ""))
.toList(); .toList();
@ -151,15 +151,15 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
// then // then
assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from( assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from(
initialRoleNames, initialRoleNames,
"hs_office_debitor#1000422:Fourthe.G.-fourthcontact.owner", "hs_office_debitor#1000422:FourtheG-fourthcontact.owner",
"hs_office_debitor#1000422:Fourthe.G.-fourthcontact.admin", "hs_office_debitor#1000422:FourtheG-fourthcontact.admin",
"hs_office_debitor#1000422:Fourthe.G.-fourthcontact.agent", "hs_office_debitor#1000422:FourtheG-fourthcontact.agent",
"hs_office_debitor#1000422:Fourthe.G.-fourthcontact.tenant", "hs_office_debitor#1000422:FourtheG-fourthcontact.tenant",
"hs_office_debitor#1000422:Fourthe.G.-fourthcontact.guest")); "hs_office_debitor#1000422:FourtheG-fourthcontact.guest"));
assertThat(grantDisplaysOf(rawGrantRepo.findAll())) assertThat(grantDisplaysOf(rawGrantRepo.findAll()))
.map(s -> s.replace("superuser-alex@hostsharing.net", "superuser-alex")) .map(s -> s.replace("superuser-alex@hostsharing.net", "superuser-alex"))
.map(s -> s.replace("22Fourthe.G.-fourthcontact", "FeG")) .map(s -> s.replace("22FourtheG-fourthcontact", "FeG"))
.map(s -> s.replace("Fourthe.G.-fourthcontact", "FeG")) .map(s -> s.replace("FourtheG-fourthcontact", "FeG"))
.map(s -> s.replace("fourthcontact", "4th")) .map(s -> s.replace("fourthcontact", "4th"))
.map(s -> s.replace("hs_office_", "")) .map(s -> s.replace("hs_office_", ""))
.containsExactlyInAnyOrder(Array.fromFormatted( .containsExactlyInAnyOrder(Array.fromFormatted(
@ -290,7 +290,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", "Fourth", "fif"); final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", "Fourth", "fif");
assertThatDebitorIsVisibleForUserWithRole( assertThatDebitorIsVisibleForUserWithRole(
givenDebitor, givenDebitor,
"hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); "hs_office_partner#10004:FourtheG-fourthcontact.admin");
assertThatDebitorActuallyInDatabase(givenDebitor); assertThatDebitorActuallyInDatabase(givenDebitor);
final var givenNewPartner = partnerRepo.findPartnerByOptionalNameLike("First").get(0); final var givenNewPartner = partnerRepo.findPartnerByOptionalNameLike("First").get(0);
final var givenNewContact = contactRepo.findContactByOptionalLabelLike("sixth contact").get(0); final var givenNewContact = contactRepo.findContactByOptionalLabelLike("sixth contact").get(0);
@ -320,7 +320,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
// ... partner role was reassigned: // ... partner role was reassigned:
assertThatDebitorIsNotVisibleForUserWithRole( assertThatDebitorIsNotVisibleForUserWithRole(
result.returnedValue(), result.returnedValue(),
"hs_office_partner#10004:Fourthe.G.-fourthcontact.agent"); "hs_office_partner#10004:FourtheG-fourthcontact.agent");
assertThatDebitorIsVisibleForUserWithRole( assertThatDebitorIsVisibleForUserWithRole(
result.returnedValue(), result.returnedValue(),
"hs_office_partner#10001:FirstGmbH-firstcontact.agent"); "hs_office_partner#10001:FirstGmbH-firstcontact.agent");
@ -336,7 +336,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
// ... bank-account role was reassigned: // ... bank-account role was reassigned:
assertThatDebitorIsNotVisibleForUserWithRole( assertThatDebitorIsNotVisibleForUserWithRole(
result.returnedValue(), result.returnedValue(),
"hs_office_bankaccount#Fourthe.G..admin"); "hs_office_bankaccount#FourtheG.admin");
assertThatDebitorIsVisibleForUserWithRole( assertThatDebitorIsVisibleForUserWithRole(
result.returnedValue(), result.returnedValue(),
"hs_office_bankaccount#FirstGmbH.admin"); "hs_office_bankaccount#FirstGmbH.admin");
@ -349,7 +349,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", null, "fig"); final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", null, "fig");
assertThatDebitorIsVisibleForUserWithRole( assertThatDebitorIsVisibleForUserWithRole(
givenDebitor, givenDebitor,
"hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); "hs_office_partner#10004:FourtheG-fourthcontact.admin");
assertThatDebitorActuallyInDatabase(givenDebitor); assertThatDebitorActuallyInDatabase(givenDebitor);
final var givenNewBankAccount = bankAccountRepo.findByOptionalHolderLike("first").get(0); 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"); final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", "Fourth", "fih");
assertThatDebitorIsVisibleForUserWithRole( assertThatDebitorIsVisibleForUserWithRole(
givenDebitor, givenDebitor,
"hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); "hs_office_partner#10004:FourtheG-fourthcontact.admin");
assertThatDebitorActuallyInDatabase(givenDebitor); assertThatDebitorActuallyInDatabase(givenDebitor);
// when // when
@ -398,7 +398,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
// ... bank-account role was removed from previous bank-account admin: // ... bank-account role was removed from previous bank-account admin:
assertThatDebitorIsNotVisibleForUserWithRole( assertThatDebitorIsNotVisibleForUserWithRole(
result.returnedValue(), result.returnedValue(),
"hs_office_bankaccount#Fourthe.G..admin"); "hs_office_bankaccount#FourtheG.admin");
} }
@Test @Test
@ -408,12 +408,12 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "eighth", "Fourth", "eig"); final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "eighth", "Fourth", "eig");
assertThatDebitorIsVisibleForUserWithRole( assertThatDebitorIsVisibleForUserWithRole(
givenDebitor, givenDebitor,
"hs_office_partner#10004:Fourthe.G.-fourthcontact.admin"); "hs_office_partner#10004:FourtheG-fourthcontact.admin");
assertThatDebitorActuallyInDatabase(givenDebitor); assertThatDebitorActuallyInDatabase(givenDebitor);
// when // when
final var result = jpaAttempt.transacted(() -> { 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"); givenDebitor.setVatId("NEW-VAT-ID");
return debitorRepo.save(givenDebitor); return debitorRepo.save(givenDebitor);
}); });
@ -502,7 +502,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("person-Fourthe.G.@example.com"); context("person-FourtheG@example.com");
assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent(); assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent();
debitorRepo.deleteByUuid(givenDebitor.getUuid()); debitorRepo.deleteByUuid(givenDebitor.getUuid());
@ -550,7 +550,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
final var query = em.createNativeQuery(""" final var query = em.createNativeQuery("""
select currentTask, targetTable, targetOp select currentTask, targetTable, targetOp
from tx_journal_v from tx_journal_v
where targettable = 'hs_office_coopsharestransaction'; where targettable = 'hs_office_debitor';
"""); """);
// when // when

View File

@ -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.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity; 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.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort; 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.EntityManager;
import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid; import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
@ -35,7 +35,6 @@ import static org.hamcrest.Matchers.*;
) )
class HsOfficePartnerControllerAcceptanceTest { 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"); private static final UUID GIVEN_NON_EXISTING_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
@LocalServerPort @LocalServerPort
@ -50,6 +49,9 @@ class HsOfficePartnerControllerAcceptanceTest {
@Autowired @Autowired
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@Autowired
HsOfficeRelationshipRepository relationshipRepository;
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -61,6 +63,7 @@ class HsOfficePartnerControllerAcceptanceTest {
@PersistenceContext @PersistenceContext
EntityManager em; EntityManager em;
private long relationshipCountBefore;
@Nested @Nested
@Accepts({ "Partner:F(Find)" }) @Accepts({ "Partner:F(Find)" })
@ -413,6 +416,7 @@ class HsOfficePartnerControllerAcceptanceTest {
// then the given partner is gone // then the given partner is gone
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty(); assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty();
assertThat(relationshipRepository.findByUuid(givenPartner.getPartnerRole().getUuid())).isEmpty();
} }
@Test @Test
@ -485,17 +489,29 @@ class HsOfficePartnerControllerAcceptanceTest {
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
@BeforeEach
void countRelationships() {
context.define("superuser-alex@hostsharing.net", null);
relationshipCountBefore = relationshipRepository.count();
}
@AfterEach @AfterEach
@SuppressWarnings("unchecked")
void cleanup() { void cleanup() {
final var deleted = jpaAttempt.transacted(() -> { final var deleted = jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null); context.define("superuser-alex@hostsharing.net", null);
em.createNativeQuery(""" final var tempPartnerUuids = (List<UUID>)em.createNativeQuery("""
delete from hs_office_partner p select uuid from hs_office_partner p
where p.detailsuuid in ( where p.detailsuuid in (
select d.uuid from hs_office_partner_details d select d.uuid from hs_office_partner_details d
where d.registrationoffice like 'Temp %') 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(); }).assertSuccessful().returnedValue();
final var remaining = jpaAttempt.transacted(() -> { final var remaining = jpaAttempt.transacted(() -> {
@ -508,6 +524,8 @@ class HsOfficePartnerControllerAcceptanceTest {
.getSingleResult(); .getSingleResult();
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
System.err.println("@AfterEach" + ": " + deleted + " records deleted, " + remaining + " remaining"); 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);
}
} }

View File

@ -462,6 +462,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
context("superuser-alex@hostsharing.net", null); context("superuser-alex@hostsharing.net", null);
tempPartners.forEach(tempPartner -> { tempPartners.forEach(tempPartner -> {
System.out.println("DELETING temporary partner: " + tempPartner.toString()); System.out.println("DELETING temporary partner: " + tempPartner.toString());
relationshipRepo.deleteByUuid(tempPartner.getPartnerRole().getUuid());
partnerRepo.deleteByUuid(tempPartner.getUuid()); partnerRepo.deleteByUuid(tempPartner.getUuid());
}); });
} }

View File

@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.startsWith;
@Transactional @Transactional
class HsOfficeRelationshipControllerAcceptanceTest { 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 @LocalServerPort
private Integer port; private Integer port;
@ -241,7 +241,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").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 final var location = RestAssured // @formatter:off
.given() .given()
@ -264,7 +264,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
.post("http://localhost/api/hs/office/relationships") .post("http://localhost/api/hs/office/relationships")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(404) .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 // @formatter:on
} }
} }

View File

@ -190,7 +190,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); 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 final var location = RestAssured // @formatter:off
.given() .given()
@ -211,7 +211,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest {
.post("http://localhost/api/hs/office/sepamandates") .post("http://localhost/api/hs/office/sepamandates")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(400) .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 // @formatter:on
} }
@ -219,7 +219,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest {
void globalAdmin_canNotAddSepaMandate_ifPersonDoesNotExist() { void globalAdmin_canNotAddSepaMandate_ifPersonDoesNotExist() {
context.define("superuser-alex@hostsharing.net"); 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 givenBankAccount = bankAccountRepo.findByIbanOrderByIban("DE02200505501015871393").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
@ -241,7 +241,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest {
.post("http://localhost/api/hs/office/sepamandates") .post("http://localhost/api/hs/office/sepamandates")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(400) .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 // @formatter:on
} }
} }