Upgrade to SpringBoot 3.4.1 and dependencies #147
@ -6,19 +6,19 @@ import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacObjectRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.orm.jpa.JpaSystemException;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
@ -27,17 +27,17 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.hostsharing.hsadminng.mapper.Array.from;
|
||||
import static net.hostsharing.hsadminng.rbac.grant.RawRbacGrantEntity.distinctGrantDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.role.RawRbacObjectEntity.objectDisplaysOf;
|
||||
import static net.hostsharing.hsadminng.rbac.role.RawRbacRoleEntity.distinctRoleNamesOf;
|
||||
import static net.hostsharing.hsadminng.mapper.Array.from;
|
||||
import static net.hostsharing.hsadminng.rbac.role.RbacRoleType.ADMIN;
|
||||
import static net.hostsharing.hsadminng.rbac.role.RbacRoleType.AGENT;
|
||||
import static net.hostsharing.hsadminng.rbac.test.JpaAttempt.attempt;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DataJpaTest
|
||||
@Import( { Context.class, JpaAttempt.class })
|
||||
@Import({ Context.class, JpaAttempt.class })
|
||||
class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@Autowired
|
||||
@ -81,14 +81,15 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
final var partnerRel = givenSomeTemporaryHostsharingPartnerRel("Winkler", "first contact");
|
||||
|
||||
// when
|
||||
final var result = attempt(em, () -> {
|
||||
final var newPartner = HsOfficePartnerRbacEntity.builder()
|
||||
.partnerNumber(20031)
|
||||
.partnerRel(partnerRel)
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
return partnerRepo.save(newPartner);
|
||||
});
|
||||
final var result = attempt(
|
||||
em, () -> {
|
||||
final var newPartner = HsOfficePartnerRbacEntity.builder()
|
||||
.partnerNumber(20031)
|
||||
.partnerRel(partnerRel)
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
return partnerRepo.save(newPartner);
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
@ -109,26 +110,27 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
.toList();
|
||||
|
||||
// when
|
||||
attempt(em, () -> {
|
||||
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
|
||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
|
||||
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||
attempt(
|
||||
em, () -> {
|
||||
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
|
||||
final var givenContact = contactrealRepo.findContactByOptionalCaptionLike("fourth contact").get(0);
|
||||
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||
|
||||
final var newRelation = HsOfficeRelationRealEntity.builder()
|
||||
.holder(givenPartnerPerson)
|
||||
.type(HsOfficeRelationType.PARTNER)
|
||||
.anchor(givenMandantPerson)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
relationRepo.save(newRelation);
|
||||
final var newRelation = HsOfficeRelationRealEntity.builder()
|
||||
.holder(givenPartnerPerson)
|
||||
.type(HsOfficeRelationType.PARTNER)
|
||||
.anchor(givenMandantPerson)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
relationRepo.save(newRelation);
|
||||
|
||||
final var newPartner = HsOfficePartnerRbacEntity.builder()
|
||||
.partnerNumber(20032)
|
||||
.partnerRel(newRelation)
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
return partnerRepo.save(newPartner);
|
||||
}).assertSuccessful();
|
||||
final var newPartner = HsOfficePartnerRbacEntity.builder()
|
||||
.partnerNumber(20032)
|
||||
.partnerRel(newRelation)
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
return partnerRepo.save(newPartner);
|
||||
}).assertSuccessful();
|
||||
|
||||
// then
|
||||
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(from(
|
||||
@ -208,29 +210,32 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
}
|
||||
|
||||
@Test
|
||||
public void partnerAgent_canViewOnlyRelatedPartnersWithoutDetails() {
|
||||
public void partnerAgent_canViewOnlyRelatedPartnersWithDetails() {
|
||||
// given:
|
||||
context("person-FirstGmbH@example.com",
|
||||
context(
|
||||
"person-FirstGmbH@example.com",
|
||||
"hs_office.relation#HostsharingeG-with-PARTNER-FirstGmbH:AGENT");
|
||||
|
||||
// when:
|
||||
final var result = partnerRepo.findPartnerByOptionalNameLike(null);
|
||||
|
||||
// then:
|
||||
exactlyThesePartnersAreReturned(result, "partner(P-10001: LP First GmbH, first contact)");
|
||||
exactlyThesePartnersAreReturned(result,
|
||||
"partner(P-10001: LP First GmbH, first contact)+(partnerDetails(Hamburg, RegNo123456789))");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void partnerTenant_canViewRelatedPartnersButWithoutDetails() {
|
||||
// given:
|
||||
context("person-FirstGmbH@example.com",
|
||||
context(
|
||||
"person-FirstGmbH@example.com",
|
||||
"hs_office.relation#HostsharingeG-with-PARTNER-FirstGmbH:TENANT");
|
||||
|
||||
// when:
|
||||
final var result = partnerRepo.findPartnerByOptionalNameLike(null);
|
||||
|
||||
// then:
|
||||
exactlyThesePartnersAreReturned(result, "partner(P-10001: LP First GmbH, first contact)");
|
||||
exactlyThesePartnersAreReturned(result, "partner(P-10001: LP First GmbH, first contact)+null");
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,7 +243,7 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
class FindByNameLike {
|
||||
|
||||
@Test
|
||||
public void globalAdmin_withoutAssumedRole_canViewAllPartners() {
|
||||
public void globalAdmin_withoutAssumedRole_canViewAllPartnersWithDetails() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
|
||||
@ -246,7 +251,8 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
final var result = partnerRepo.findPartnerByOptionalNameLike("third contact");
|
||||
|
||||
// then
|
||||
exactlyThesePartnersAreReturned(result, "partner(P-10003: IF Third OHG, third contact)");
|
||||
exactlyThesePartnersAreReturned(result,
|
||||
"partner(P-10003: IF Third OHG, third contact)+(partnerDetails(Hamburg, RegNo123456789))");
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,7 +321,8 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net",
|
||||
context(
|
||||
"superuser-alex@hostsharing.net",
|
||||
givenPartner.getPartnerRel().roleId(AGENT));
|
||||
givenPartner.getDetails().setBirthName("new birthname");
|
||||
return partnerRepo.save(givenPartner);
|
||||
@ -327,7 +334,11 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
|
||||
private void assertThatPartnerActuallyInDatabase(final HsOfficePartnerRbacEntity saved) {
|
||||
final var found = partnerRepo.findByUuid(saved.getUuid());
|
||||
assertThat(found).isNotEmpty().get().isNotSameAs(saved).extracting(HsOfficePartnerRbacEntity::toString).isEqualTo(saved.toString());
|
||||
assertThat(found).isNotEmpty()
|
||||
.get()
|
||||
.isNotSameAs(saved)
|
||||
.extracting(HsOfficePartnerRbacEntity::toString)
|
||||
.isEqualTo(saved.toString());
|
||||
}
|
||||
|
||||
private void assertThatPartnerIsVisibleForUserWithRole(
|
||||
@ -428,7 +439,7 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
select currentTask, targetTable, targetOp, targetdelta->>'partnernumber'
|
||||
from base.tx_journal_v
|
||||
where targettable = 'hs_office.partner';
|
||||
""");
|
||||
""");
|
||||
|
||||
// when
|
||||
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
|
||||
@ -454,7 +465,7 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
|
||||
final var savedPartner = partnerRepo.save(newPartner);
|
||||
final var savedPartner = partnerRepo.save(newPartner);
|
||||
em.flush();
|
||||
final var partner = em.find(savedPartner.getClass(), savedPartner.getUuid());
|
||||
return savedPartner;
|
||||
@ -478,7 +489,9 @@ class HsOfficePartnerRbacRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
|
||||
void exactlyThesePartnersAreReturned(final List<HsOfficePartnerRbacEntity> actualResult, final String... partnerNames) {
|
||||
assertThat(actualResult)
|
||||
.extracting(HsOfficePartnerRbacEntity::toString)
|
||||
.extracting(partner ->
|
||||
partner.toString() + "+" +
|
||||
(partner.getDetails() != null ? ("(" + partner.getDetails() + ")") : "null"))
|
||||
.containsExactlyInAnyOrder(partnerNames);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user