amend tests to lazy-loading references by introducing RbacObject.load()

This commit is contained in:
Michael Hoennig 2024-07-24 09:57:51 +02:00
parent b79a8ca22d
commit aa9696cfe1
16 changed files with 29 additions and 24 deletions

View File

@ -13,7 +13,6 @@ import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import net.hostsharing.hsadminng.stringify.Stringify;
import net.hostsharing.hsadminng.stringify.Stringifyable;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import jakarta.persistence.Column;

View File

@ -75,6 +75,13 @@ public class HsOfficePartnerEntity implements Stringifyable, RbacObject<HsOffice
@NotFound(action = NotFoundAction.IGNORE)
private HsOfficePartnerDetailsEntity details;
@Override
public HsOfficePartnerEntity load() {
RbacObject.super.load();
partnerRel.load();
return this;
}
public String getTaggedPartnerNumber() {
return PARTNER_NUMBER_TAG + partnerNumber;
}

View File

@ -76,7 +76,7 @@ public class HsOfficeRelationEntity implements RbacObject, Stringifyable {
private String mark;
@Override
public RbacObject<?> load() {
public HsOfficeRelationEntity load() {
RbacObject.super.load();
anchor.load();
holder.load();

View File

@ -372,6 +372,7 @@ create table RbacPermission
op RbacOp not null,
opTableName varchar(60)
);
-- TODO.perf: check if these indexes are really useful
create index on RbacPermission (objectUuid, op);
create index on RbacPermission (opTableName, op);

View File

@ -123,7 +123,7 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
private void assertThatBankAccountIsPersisted(final HsOfficeBankAccountEntity saved) {
final var found = bankAccountRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
}
}

View File

@ -122,7 +122,7 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
private void assertThatContactIsPersisted(final HsOfficeContactEntity saved) {
final var found = contactRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
}
}

View File

@ -638,7 +638,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
.vatReverseCharge(false)
.build();
return debitorRepo.save(newDebitor);
return debitorRepo.save(newDebitor).load();
}).assertSuccessful().returnedValue();
}

View File

@ -1,7 +1,6 @@
package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;

View File

@ -4,7 +4,6 @@ import io.hypersistence.utils.hibernate.type.range.Range;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
@ -144,7 +143,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
private void assertThatMembershipIsPersisted(final HsOfficeMembershipEntity saved) {
final var found = membershipRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString()) ;
}
}
@ -203,12 +202,9 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
@Test
public void globalAdmin_canUpdateValidityOfArbitraryMembership() {
// given
final var givenMembership = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
final var tempMembership = givenSomeTemporaryMembership("First", "11");
assertThatMembershipExistsAndIsAccessibleToCurrentContext(tempMembership);
return tempMembership;
}).assertSuccessful().returnedValue();
final var givenMembership = givenSomeTemporaryMembership("First", "11");
assertThatMembershipExistsAndIsAccessibleToCurrentContext(givenMembership);
final var newValidityEnd = LocalDate.now();
// when
@ -366,8 +362,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
.membershipFeeBillable(true)
.build();
final HsOfficeMembershipEntity entity = membershipRepo.save(newMembership);
return toCleanup(entity.load());
return toCleanup(membershipRepo.save(newMembership).load());
}).assertSuccessful().returnedValue();
}

View File

@ -180,7 +180,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
private void assertThatPartnerIsPersisted(final HsOfficePartnerEntity saved) {
final var found = partnerRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
}
}

View File

@ -298,7 +298,10 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
.statusCode(204); // @formatter:on
// then the given person is still there
jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net");
assertThat(personRepo.findByUuid(givenPerson.getUuid())).isEmpty();
}).assertSuccessful();
}
@Test

View File

@ -124,7 +124,7 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
private void assertThatPersonIsPersisted(final HsOfficePersonEntity saved) {
final var found = personRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
}
}

View File

@ -158,7 +158,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
private void assertThatRelationIsPersisted(final HsOfficeRelationEntity saved) {
final var found = relationRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
}
}
@ -225,7 +225,7 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
givenRelation.setContact(givenContact);
return toCleanup(relationRepo.save(givenRelation));
return toCleanup(relationRepo.save(givenRelation).load());
});
// then

View File

@ -152,7 +152,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
private void assertThatSepaMandateIsPersisted(final HsOfficeSepaMandateEntity saved) {
final var found = sepaMandateRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
}
}
@ -250,7 +250,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isNotEmpty().get()
.usingRecursiveComparison().isEqualTo(givenSepaMandate);
.extracting(Object::toString).isEqualTo(givenSepaMandate.toString());
}).assertSuccessful();
}

View File

@ -90,7 +90,7 @@ class TestCustomerRepositoryIntegrationTest extends ContextBasedTest {
private void assertThatCustomerIsPersisted(final TestCustomerEntity saved) {
final var found = testCustomerRepository.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().extracting(Object::toString).isEqualTo(saved.toString());
}
}

View File

@ -28,6 +28,7 @@ spring:
change-log: classpath:/db/changelog/db.changelog-master.yaml
contexts: tc,test,dev
# FIXME: re-activate?
#logging:
# level:
# liquibase: INFO