Compare commits

..

No commits in common. "4ed6737302e8a372e34011c7424558c7db18a3be" and "c1490e5901c3258bd1ca6f99e3076df3e4130edf" have entirely different histories.

25 changed files with 102 additions and 294 deletions

View File

@ -308,8 +308,6 @@ tasks.register('importOfficeData', Test) {
group 'verification' group 'verification'
description 'run the import jobs as tests' description 'run the import jobs as tests'
mustRunAfter spotlessJava
} }

View File

@ -1,6 +1,6 @@
package net.hostsharing.hsadminng.errors; package net.hostsharing.hsadminng.errors;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import java.util.UUID; import java.util.UUID;

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.bankaccount;
import lombok.*; import lombok.*;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.contact;
import lombok.*; import lombok.*;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;

View File

@ -4,7 +4,7 @@ package net.hostsharing.hsadminng.hs.office.coopassets;
import lombok.*; import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.coopshares;
import lombok.*; import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;

View File

@ -4,7 +4,7 @@ import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;

View File

@ -5,7 +5,7 @@ import com.vladmihalcea.hibernate.type.range.Range;
import lombok.*; import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.persistence; package net.hostsharing.hsadminng.hs.office.migration;
import java.util.UUID; import java.util.UUID;

View File

@ -8,14 +8,13 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartne
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRoleInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRoleInsertResource;
import net.hostsharing.hsadminng.persistence.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.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;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -113,7 +112,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
if (partnerRepo.deleteByUuid(partnerUuid) != 1 || if (partnerRepo.deleteByUuid(partnerUuid) != 1 ||
// TODO: move to after delete trigger in partner // TODO: move to after delete trigger in partner
relationshipRepo.deleteByUuid(partnerToDelete.get().getPartnerRole().getUuid()) != 1 ) { relationshipRepo.deleteByUuid(partnerToDelete.get().getPartnerRole().getUuid()) != 1 ) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); ResponseEntity.internalServerError().build();
} }
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
@ -160,7 +159,9 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
private <E extends HasUuid> E ref(final Class<E> entityClass, final UUID uuid) { private <E extends HasUuid> E ref(final Class<E> entityClass, final UUID uuid) {
try { try {
return em.getReference(entityClass, uuid); final var e = em.getReference(entityClass, uuid);
em.contains(e); // TODO: check if this is really needed to force an exception if not existing
return e;
} catch (final Throwable exc) { } catch (final Throwable exc) {
throw new ReferenceNotFoundException(entityClass, uuid, exc); throw new ReferenceNotFoundException(entityClass, uuid, exc);
} }

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
import lombok.*; import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
import lombok.*; import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.persistence.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.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.person;
import lombok.*; import lombok.*;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.relationship;
import lombok.*; import lombok.*;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.persistence.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.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;

View File

@ -6,7 +6,7 @@ import lombok.*;
import net.hostsharing.hsadminng.errors.DisplayName; import net.hostsharing.hsadminng.errors.DisplayName;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable; import net.hostsharing.hsadminng.stringify.Stringifyable;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;

View File

@ -33,10 +33,10 @@ create table hs_office_partner
( (
uuid uuid unique references RbacObject (uuid) initially deferred, uuid uuid unique references RbacObject (uuid) initially deferred,
partnerNumber numeric(5) unique not null, partnerNumber numeric(5) unique not null,
partnerRoleUuid uuid not null references hs_office_relationship(uuid), -- TODO: delete in after delete trigger partnerRoleUuid uuid not null references hs_office_relationship(uuid) on delete cascade,
personUuid uuid not null references hs_office_person(uuid), -- TODO: remove, replaced by partnerRoleUuid personUuid uuid not null references hs_office_person(uuid), -- TODO: remove, replaced by partnerRoleUuid
contactUuid uuid not null references hs_office_contact(uuid), -- TODO: remove, replaced by partnerRoleUuid contactUuid uuid not null references hs_office_contact(uuid), -- TODO: remove, replaced by partnerRoleUuid
detailsUuid uuid not null references hs_office_partner_details(uuid) -- deleted in after delete trigger detailsUuid uuid not null references hs_office_partner_details(uuid) on delete cascade
); );
--// --//

View File

@ -30,7 +30,6 @@ public class ArchitectureTest {
"..test.pac", "..test.pac",
"..context", "..context",
"..generated..", "..generated..",
"..persistence..",
"..hs.office.bankaccount", "..hs.office.bankaccount",
"..hs.office.contact", "..hs.office.contact",
"..hs.office.coopassets", "..hs.office.coopassets",

View File

@ -1,15 +1,14 @@
package net.hostsharing.hsadminng.hs.office.debitor; package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
@ -34,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeDebitorRepository debitorRepo; HsOfficeDebitorRepository debitorRepo;
@ -83,7 +82,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
.defaultPrefix("abc") .defaultPrefix("abc")
.billable(false) .billable(false)
.build(); .build();
return toCleanup(debitorRepo.save(newDebitor)); return debitorRepo.save(newDebitor);
}); });
// then // then
@ -114,12 +113,11 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
.vatBusiness(false) .vatBusiness(false)
.defaultPrefix(givenPrefix) .defaultPrefix(givenPrefix)
.build(); .build();
return toCleanup(debitorRepo.save(newDebitor)); return debitorRepo.save(newDebitor);
}); });
// then // then
System.out.println("ok"); result.assertExceptionWithRootCauseMessage(org.hibernate.exception.ConstraintViolationException.class);
// result.assertExceptionWithRootCauseMessage(org.hibernate.exception.ConstraintViolationException.class);
} }
@Test @Test
@ -147,7 +145,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
.defaultPrefix("abc") .defaultPrefix("abc")
.billable(false) .billable(false)
.build(); .build();
return toCleanup(debitorRepo.save(newDebitor)); return debitorRepo.save(newDebitor);
}).assertSuccessful(); }).assertSuccessful();
// then // then
@ -219,7 +217,6 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
} }
@ParameterizedTest @ParameterizedTest
@Disabled // TODO: reactivate once partner.person + partner.contact are removed
@ValueSource(strings = { @ValueSource(strings = {
"hs_office_partner#10001:FirstGmbH-firstcontact.admin", "hs_office_partner#10001:FirstGmbH-firstcontact.admin",
"hs_office_person#FirstGmbH.admin", "hs_office_person#FirstGmbH.admin",
@ -230,7 +227,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net", assumedRole); context("superuser-alex@hostsharing.net", assumedRole);
// when: // when:
final var result = debitorRepo.findDebitorByOptionalNameLike(""); final var result = debitorRepo.findDebitorByOptionalNameLike(null);
// then: // then:
exactlyTheseDebitorsAreReturned(result, exactlyTheseDebitorsAreReturned(result,
@ -311,7 +308,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
givenDebitor.setVatId(givenNewVatId); givenDebitor.setVatId(givenNewVatId);
givenDebitor.setVatCountryCode(givenNewVatCountryCode); givenDebitor.setVatCountryCode(givenNewVatCountryCode);
givenDebitor.setVatBusiness(givenNewVatBusiness); givenDebitor.setVatBusiness(givenNewVatBusiness);
return toCleanup(debitorRepo.save(givenDebitor)); return debitorRepo.save(givenDebitor);
}); });
// then // then
@ -360,7 +357,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
givenDebitor.setRefundBankAccount(givenNewBankAccount); givenDebitor.setRefundBankAccount(givenNewBankAccount);
return toCleanup(debitorRepo.save(givenDebitor)); return debitorRepo.save(givenDebitor);
}); });
// then // then
@ -389,7 +386,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
givenDebitor.setRefundBankAccount(null); givenDebitor.setRefundBankAccount(null);
return toCleanup(debitorRepo.save(givenDebitor)); return debitorRepo.save(givenDebitor);
}); });
// then // then
@ -418,7 +415,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_partner#10004:FourtheG-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 toCleanup(debitorRepo.save(givenDebitor)); return debitorRepo.save(givenDebitor);
}); });
// then // then
@ -440,7 +437,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact.admin"); context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact.admin");
givenDebitor.setVatId("NEW-VAT-ID"); givenDebitor.setVatId("NEW-VAT-ID");
return toCleanup(debitorRepo.save(givenDebitor)); return debitorRepo.save(givenDebitor);
}); });
// then // then
@ -581,7 +578,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
.billable(true) .billable(true)
.build(); .build();
return toCleanup(debitorRepo.save(newDebitor)); return debitorRepo.save(newDebitor);
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }

View File

@ -21,7 +21,6 @@ import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity; import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity;
import net.hostsharing.hsadminng.persistence.HasUuid;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -648,6 +647,7 @@ public class ImportOfficeData extends ContextBasedTest {
.personType(HsOfficePersonType.LEGAL_PERSON) .personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("Hostsharing eG") .tradeName("Hostsharing eG")
.build(); .build();
assertThat(persons.containsKey(1)).describedAs("overwriting " + persons.get(1) + " index " + 1 + " with " + mandant).isFalse();
persons.put(1, mandant); persons.put(1, mandant);
records.stream() records.stream()
@ -662,7 +662,10 @@ public class ImportOfficeData extends ContextBasedTest {
.relAnchor(mandant) .relAnchor(mandant)
.contact(null) // is set during contacts import depending on assigned roles .contact(null) // is set during contacts import depending on assigned roles
.build(); .build();
relationships.put(relationshipId++, partnerRelationship); final Integer i3 = relationshipId++;
assertThat(relationships.containsKey(i3)).describedAs("overwriting " + relationships.get(i3) + " index " + i3
+ " with " + partnerRelationship).isFalse();
relationships.put(i3, partnerRelationship);
final var partner = HsOfficePartnerEntity.builder() final var partner = HsOfficePartnerEntity.builder()
.partnerNumber(rec.getInteger("member_id")) .partnerNumber(rec.getInteger("member_id"))
@ -671,7 +674,9 @@ public class ImportOfficeData extends ContextBasedTest {
.contact(null) // is set during contacts import depending on assigned roles .contact(null) // is set during contacts import depending on assigned roles
.person(person) .person(person)
.build(); .build();
partners.put(rec.getInteger("bp_id"), partner); final Integer i2 = rec.getInteger("bp_id");
assertThat(partners.containsKey(i2)).describedAs("overwriting " + partners.get(i2) + " index " + i2 + " with " + partner).isFalse();
partners.put(i2, partner);
final var debitor = HsOfficeDebitorEntity.builder() final var debitor = HsOfficeDebitorEntity.builder()
.partner(partner) .partner(partner)
@ -683,7 +688,9 @@ public class ImportOfficeData extends ContextBasedTest {
.vatBusiness("GROSS".equals(rec.getString("indicator_vat"))) // TODO: remove .vatBusiness("GROSS".equals(rec.getString("indicator_vat"))) // TODO: remove
.vatId(rec.getString("uid_vat")) .vatId(rec.getString("uid_vat"))
.build(); .build();
debitors.put(rec.getInteger("bp_id"), debitor); final Integer i1 = rec.getInteger("bp_id");
assertThat(debitors.containsKey(i1)).describedAs("overwriting " + debitors.get(i1) + " index " + i1 + " with " + debitor).isFalse();
debitors.put(i1, debitor);
if (isNotBlank(rec.getString("member_since"))) { if (isNotBlank(rec.getString("member_since"))) {
assertThat(rec.getInteger("member_id")).isEqualTo(partner.getPartnerNumber()); assertThat(rec.getInteger("member_id")).isEqualTo(partner.getPartnerNumber());
@ -700,7 +707,9 @@ public class ImportOfficeData extends ContextBasedTest {
: HsOfficeReasonForTermination.UNKNOWN) : HsOfficeReasonForTermination.UNKNOWN)
.mainDebitor(debitor) .mainDebitor(debitor)
.build(); .build();
memberships.put(rec.getInteger("bp_id"), membership); final Integer i = rec.getInteger("bp_id");
assertThat(memberships.containsKey(i)).describedAs("overwriting " + memberships.get(i) + " index " + i + " with " + membership).isFalse();
memberships.put(i, membership);
} }
}); });
} }
@ -729,7 +738,9 @@ public class ImportOfficeData extends ContextBasedTest {
.comment( rec.getString("comment")) .comment( rec.getString("comment"))
.build(); .build();
coopShares.put(rec.getInteger("member_share_id"), shareTransaction); final Integer i = rec.getInteger("member_share_id");
assertThat(coopShares.containsKey(i)).describedAs("overwriting " + coopShares.get(i) + " index " + i + " with " + shareTransaction).isFalse();
coopShares.put(i, shareTransaction);
}); });
} }
@ -772,7 +783,9 @@ public class ImportOfficeData extends ContextBasedTest {
.comment(rec.getString("comment")) .comment(rec.getString("comment"))
.build(); .build();
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction); final Integer i = rec.getInteger("member_asset_id");
assertThat(coopAssets.containsKey(i)).describedAs("overwriting " + coopAssets.get(i) + " index " + i + " with " + assetTransaction).isFalse();
coopAssets.put(i, assetTransaction);
}); });
} }
@ -906,7 +919,9 @@ public class ImportOfficeData extends ContextBasedTest {
.contact(contact) .contact(contact)
.relType(representative) .relType(representative)
.build(); .build();
relationships.put(relationshipId++, rel); final Integer i = relationshipId++;
assertThat(relationships.containsKey(i)).describedAs("overwriting " + relationships.get(i) + " index " + i + " with " + rel).isFalse();
relationships.put(i, rel);
return rel; return rel;
} }
@ -917,7 +932,9 @@ public class ImportOfficeData extends ContextBasedTest {
person.setTradeName(contactRecord.getString("firma")); person.setTradeName(contactRecord.getString("firma"));
determinePersonType(person, contactRecord.getString("roles")); determinePersonType(person, contactRecord.getString("roles"));
persons.put(contactRecord.getInteger("contact_id"), person); final Integer i = contactRecord.getInteger("contact_id");
assertThat(persons.containsKey(i)).describedAs("overwriting " + persons.get(i) + " index " + i + " with " + person).isFalse();
persons.put(i, person);
return person; return person;
} }
@ -972,7 +989,9 @@ public class ImportOfficeData extends ContextBasedTest {
contact.setPostalAddress(toAddress(contactRecord)); contact.setPostalAddress(toAddress(contactRecord));
contact.setPhoneNumbers(toPhoneNumbers(contactRecord)); contact.setPhoneNumbers(toPhoneNumbers(contactRecord));
contacts.put(contactRecord.getInteger("contact_id"), contact); final Integer i = contactRecord.getInteger("contact_id");
assertThat(contacts.containsKey(i)).describedAs("overwriting " + contacts.get(i) + " index " + i + " with " + contact).isFalse();
contacts.put(i, contact);
return contact; return contact;
} }

View File

@ -288,6 +288,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Nested @Nested
@Accepts({ "Partner:U(Update)" }) @Accepts({ "Partner:U(Update)" })
@Transactional @Transactional
@Disabled // TODO: enable one partner.person + partner.contract are removed
class PatchPartner { class PatchPartner {
@Test @Test
@ -395,6 +396,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Nested @Nested
@Accepts({ "Partner:D(Delete)" }) @Accepts({ "Partner:D(Delete)" })
@Transactional @Transactional
@Disabled // TODO: enable one partner.person + partner.contract are removed
class DeletePartner { class DeletePartner {
@Test @Test

View File

@ -1,221 +0,0 @@
package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
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.mapper.Mapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityNotFoundException;
import jakarta.persistence.SynchronizationType;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebMvcTest(HsOfficePartnerController.class)
@Import(Mapper.class)
class HsOfficePartnerControllerRestTest {
static final UUID GIVEN_MANDANTE_UUID = UUID.randomUUID();
static final UUID GIVEN_PERSON_UUID = UUID.randomUUID();
static final UUID GIVEN_CONTACT_UUID = UUID.randomUUID();
static final UUID GIVEN_INVALID_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
@Autowired
MockMvc mockMvc;
@MockBean
Context contextMock;
@MockBean
HsOfficePartnerRepository partnerRepo;
@MockBean
HsOfficeRelationshipRepository relationshipRepo;
@MockBean
EntityManager em;
@MockBean
EntityManagerFactory emf;
@Mock
HsOfficePersonEntity mandateMock;
@Mock
HsOfficePersonEntity personMock;
@Mock
HsOfficeContactEntity contactMock;
@Mock
HsOfficePartnerEntity partnerMock;
@BeforeEach
void init() {
when(emf.createEntityManager()).thenReturn(em);
when(emf.createEntityManager(any(Map.class))).thenReturn(em);
when(emf.createEntityManager(any(SynchronizationType.class))).thenReturn(em);
when(emf.createEntityManager(any(SynchronizationType.class), any(Map.class))).thenReturn(em);
lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_MANDANTE_UUID)).thenReturn(mandateMock);
lenient().when(em.getReference(HsOfficePersonEntity.class, GIVEN_PERSON_UUID)).thenReturn(personMock);
lenient().when(em.getReference(HsOfficeContactEntity.class, GIVEN_CONTACT_UUID)).thenReturn(contactMock);
lenient().when(em.getReference(any(), eq(GIVEN_INVALID_UUID))).thenThrow(EntityNotFoundException.class);
}
@Nested
class AddPartner {
@Test
void respondBadRequest_ifPersonUuidIsInvalid() throws Exception {
// when
mockMvc.perform(MockMvcRequestBuilders
.post("/api/hs/office/partners")
.header("current-user", "superuser-alex@hostsharing.net")
.contentType(MediaType.APPLICATION_JSON)
.content("""
{
"partnerNumber": "20002",
"partnerRole": {
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"contactUuid": "%s"
},
"personUuid": "%s",
"contactUuid": "%s",
"details": {
"registrationOffice": "Temp Registergericht Aurich",
"registrationNumber": "111111"
}
}
""".formatted(
GIVEN_MANDANTE_UUID,
GIVEN_INVALID_UUID,
GIVEN_CONTACT_UUID,
GIVEN_INVALID_UUID,
GIVEN_CONTACT_UUID))
.accept(MediaType.APPLICATION_JSON))
// then
.andExpect(status().is4xxClientError())
.andExpect(jsonPath("statusCode", is(400)))
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
.andExpect(jsonPath("message", startsWith("Cannot resolve HsOfficePersonEntity with uuid ")));
}
@Test
void respondBadRequest_ifContactUuidIsInvalid() throws Exception {
// when
mockMvc.perform(MockMvcRequestBuilders
.post("/api/hs/office/partners")
.header("current-user", "superuser-alex@hostsharing.net")
.contentType(MediaType.APPLICATION_JSON)
.content("""
{
"partnerNumber": "20002",
"partnerRole": {
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"contactUuid": "%s"
},
"personUuid": "%s",
"contactUuid": "%s",
"details": {
"registrationOffice": "Temp Registergericht Aurich",
"registrationNumber": "111111"
}
}
""".formatted(
GIVEN_MANDANTE_UUID,
GIVEN_PERSON_UUID,
GIVEN_INVALID_UUID,
GIVEN_PERSON_UUID,
GIVEN_INVALID_UUID))
.accept(MediaType.APPLICATION_JSON))
// then
.andExpect(status().is4xxClientError())
.andExpect(jsonPath("statusCode", is(400)))
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
.andExpect(jsonPath("message", startsWith("Cannot resolve HsOfficeContactEntity with uuid ")));
}
}
@Nested
class DeletePartner {
@Test
void respondBadRequest_ifPartnerCannotBeDeleted() throws Exception {
// given
final UUID givenPartnerUuid = UUID.randomUUID();
when(partnerRepo.findByUuid(givenPartnerUuid)).thenReturn(Optional.of(partnerMock));
when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0);
final UUID givenRelationshipUuid = UUID.randomUUID();
when(partnerMock.getPartnerRole()).thenReturn(HsOfficeRelationshipEntity.builder()
.uuid(givenRelationshipUuid)
.build());
when(relationshipRepo.deleteByUuid(givenRelationshipUuid)).thenReturn(0);
// when
mockMvc.perform(MockMvcRequestBuilders
.delete("/api/hs/office/partners/" + givenPartnerUuid)
.header("current-user", "superuser-alex@hostsharing.net")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
// then
.andExpect(status().isForbidden());
}
@Test
void respondBadRequest_ifRelationshipCannotBeDeleted() throws Exception {
// given
final UUID givenPartnerUuid = UUID.randomUUID();
when(partnerRepo.findByUuid(givenPartnerUuid)).thenReturn(Optional.of(partnerMock));
when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(1);
when(relationshipRepo.deleteByUuid(any())).thenReturn(0);
final UUID givenRelationshipUuid = UUID.randomUUID();
when(partnerMock.getPartnerRole()).thenReturn(HsOfficeRelationshipEntity.builder()
.uuid(givenRelationshipUuid)
.build());
when(relationshipRepo.deleteByUuid(givenRelationshipUuid)).thenReturn(0);
// when
mockMvc.perform(MockMvcRequestBuilders
.delete("/api/hs/office/partners/" + givenPartnerUuid)
.header("current-user", "superuser-alex@hostsharing.net")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
// then
.andExpect(status().isForbidden());
}
}
}

View File

@ -1,13 +1,14 @@
package net.hostsharing.hsadminng.hs.office.relationship; package net.hostsharing.hsadminng.hs.office.relationship;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -20,7 +21,9 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf; import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf;
import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.distinctRoleNamesOf; import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.distinctRoleNamesOf;
@ -29,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeRelationshipRepository relationshipRepo; HsOfficeRelationshipRepository relationshipRepo;
@ -55,6 +58,8 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
@MockBean @MockBean
HttpServletRequest request; HttpServletRequest request;
Set<HsOfficeRelationshipEntity> tempRelationships = new HashSet<>();
@Nested @Nested
class CreateRelationship { class CreateRelationship {
@ -69,13 +74,13 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newRelationship = HsOfficeRelationshipEntity.builder() final var newRelationship = toCleanup(HsOfficeRelationshipEntity.builder()
.relAnchor(givenAnchorPerson) .relAnchor(givenAnchorPerson)
.relHolder(givenHolderPerson) .relHolder(givenHolderPerson)
.relType(HsOfficeRelationshipType.REPRESENTATIVE) .relType(HsOfficeRelationshipType.REPRESENTATIVE)
.contact(givenContact) .contact(givenContact)
.build(); .build());
return toCleanup(relationshipRepo.save(newRelationship)); return relationshipRepo.save(newRelationship);
}); });
// then // then
@ -97,13 +102,13 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Anita").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Anita").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0);
final var newRelationship = HsOfficeRelationshipEntity.builder() final var newRelationship = toCleanup(HsOfficeRelationshipEntity.builder()
.relAnchor(givenAnchorPerson) .relAnchor(givenAnchorPerson)
.relHolder(givenHolderPerson) .relHolder(givenHolderPerson)
.relType(HsOfficeRelationshipType.REPRESENTATIVE) .relType(HsOfficeRelationshipType.REPRESENTATIVE)
.contact(givenContact) .contact(givenContact)
.build(); .build());
return toCleanup(relationshipRepo.save(newRelationship)); return relationshipRepo.save(newRelationship);
}); });
// then // then
@ -392,10 +397,26 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
.contact(givenContact) .contact(givenContact)
.build(); .build();
return toCleanup(relationshipRepo.save(newRelationship)); toCleanup(newRelationship);
return relationshipRepo.save(newRelationship);
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
private HsOfficeRelationshipEntity toCleanup(final HsOfficeRelationshipEntity tempRelationship) {
tempRelationships.add(tempRelationship);
return tempRelationship;
}
@AfterEach
void cleanup() {
context("superuser-alex@hostsharing.net", null);
tempRelationships.forEach(tempRelationship -> {
System.out.println("DELETING temporary relationship: " + tempRelationship);
relationshipRepo.deleteByUuid(tempRelationship.getUuid());
});
}
void exactlyTheseRelationshipsAreReturned( void exactlyTheseRelationshipsAreReturned(
final List<HsOfficeRelationshipEntity> actualResult, final List<HsOfficeRelationshipEntity> actualResult,
final String... relationshipNames) { final String... relationshipNames) {

View File

@ -1,7 +1,7 @@
package net.hostsharing.hsadminng.hs.office.test; package net.hostsharing.hsadminng.hs.office.test;
import net.hostsharing.hsadminng.context.ContextBasedTest; import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantEntity; import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantEntity;
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleEntity; import net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleEntity;
@ -63,9 +63,6 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
public <E extends HasUuid> E toCleanup(final E entity) { public <E extends HasUuid> E toCleanup(final E entity) {
out.println("toCleanup(" + entity.getClass() + ", " + entity.getUuid()); out.println("toCleanup(" + entity.getClass() + ", " + entity.getUuid());
if ( entity.getUuid() == null ) {
throw new IllegalArgumentException("only persisted entities with valid uuid allowed");
}
entitiesToCleanup.put(entity.getUuid(), entity.getClass()); entitiesToCleanup.put(entity.getUuid(), entity.getClass());
return entity; return entity;
} }
@ -156,9 +153,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
out.println(ContextBasedTestWithCleanup.class.getSimpleName() + ".cleanupAndCheckCleanup"); out.println(ContextBasedTestWithCleanup.class.getSimpleName() + ".cleanupAndCheckCleanup");
cleanupTemporaryTestData(); cleanupTemporaryTestData();
deleteLeakedRbacObjects(); deleteLeakedRbacObjects();
long rbacObjectCount = assertNoNewRbackObjectsRolesAndGrantsLeaked(); assertNoNewRbackObjectsRolesAndGrantsLeaked();
out.println("TOTAL OBJECT COUNT (after): " + rbacObjectCount);
} }
private void cleanupTemporaryTestData() { private void cleanupTemporaryTestData() {
@ -174,8 +169,8 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
}); });
} }
private long assertNoNewRbackObjectsRolesAndGrantsLeaked() { private void assertNoNewRbackObjectsRolesAndGrantsLeaked() {
return jpaAttempt.transacted(() -> { jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
assertEqual(initialRbacObjects, allRbacObjects()); assertEqual(initialRbacObjects, allRbacObjects());
if (DETAILED_BUT_SLOW_CHECK) { if (DETAILED_BUT_SLOW_CHECK) {
@ -185,19 +180,17 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
// The detailed check works with sets, thus it cannot determine duplicates. // The detailed check works with sets, thus it cannot determine duplicates.
// Therefore, we always compare the counts as well. // Therefore, we always compare the counts as well.
long rbacObjectCount = 0; assertThat(rbacObjectRepo.count()).as("not all business objects got cleaned up (by current test)")
assertThat(rbacObjectCount = rbacObjectRepo.count()).as("not all business objects got cleaned up (by current test)")
.isEqualTo(initialRbacObjectCount); .isEqualTo(initialRbacObjectCount);
assertThat(rbacRoleRepo.count()).as("not all rbac roles got cleaned up (by current test)") assertThat(rbacRoleRepo.count()).as("not all rbac roles got cleaned up (by current test)")
.isEqualTo(initialRbacRoleCount); .isEqualTo(initialRbacRoleCount);
assertThat(rbacGrantRepo.count()).as("not all rbac grants got cleaned up (by current test)") assertThat(rbacGrantRepo.count()).as("not all rbac grants got cleaned up (by current test)")
.isEqualTo(initialRbacGrantCount); .isEqualTo(initialRbacGrantCount);
return rbacObjectCount; }).assertSuccessful();
}).assertSuccessful().returnedValue();
} }
private void deleteLeakedRbacObjects() { private void deleteLeakedRbacObjects() {
jpaAttempt.transacted(() -> rbacObjectRepo.findAll()).returnedValue().stream() rbacObjectRepo.findAll().stream()
.filter(o -> o.serialId > latestIntialTestDataSerialId) .filter(o -> o.serialId > latestIntialTestDataSerialId)
.sorted(comparing(o -> o.serialId)) .sorted(comparing(o -> o.serialId))
.forEach(o -> { .forEach(o -> {

View File

@ -130,7 +130,6 @@ public class JpaAttempt {
final Class<? extends RuntimeException> expectedExceptionClass, final Class<? extends RuntimeException> expectedExceptionClass,
final String... expectedRootCauseMessages) { final String... expectedRootCauseMessages) {
assertThat(wasSuccessful()).as("wasSuccessful").isFalse(); assertThat(wasSuccessful()).as("wasSuccessful").isFalse();
// TODO: also check the expected exception class itself
final String firstRootCauseMessageLine = firstRootCauseMessageLineOf(caughtException(expectedExceptionClass)); final String firstRootCauseMessageLine = firstRootCauseMessageLineOf(caughtException(expectedExceptionClass));
for (String expectedRootCauseMessage : expectedRootCauseMessages) { for (String expectedRootCauseMessage : expectedRootCauseMessages) {
assertThat(firstRootCauseMessageLine).contains(expectedRootCauseMessage); assertThat(firstRootCauseMessageLine).contains(expectedRootCauseMessage);

View File

@ -1,6 +1,6 @@
package net.hostsharing.test; package net.hostsharing.test;
import net.hostsharing.hsadminng.persistence.HasUuid; import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.EntityPatcher;
import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Named;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;