1
0

rename partnerRole -> partnerRel, relationship -> relation and remove rel-Prefix (relAnchor etc.) (#23)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/23
Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
Michael Hoennig
2024-03-13 15:01:24 +01:00
parent 907e27ec19
commit 3faf2ea99e
39 changed files with 873 additions and 914 deletions

View File

@@ -41,7 +41,7 @@ public class ArchitectureTest {
"..hs.office.migration",
"..hs.office.partner",
"..hs.office.person",
"..hs.office.relationship",
"..hs.office.relation",
"..hs.office.sepamandate",
"..errors",
"..mapper",
@@ -148,7 +148,7 @@ public class ArchitectureTest {
public static final ArchRule hsOfficeContactPackageRule = classes()
.that().resideInAPackage("..hs.office.contact..")
.should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.office.contact..", "..hs.office.relationship..",
.resideInAnyPackage("..hs.office.contact..", "..hs.office.relation..",
"..hs.office.partner..",
"..hs.office.debitor..",
"..hs.office.membership..",
@@ -159,7 +159,7 @@ public class ArchitectureTest {
public static final ArchRule hsOfficePersonPackageRule = classes()
.that().resideInAPackage("..hs.office.person..")
.should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.office.person..", "..hs.office.relationship..",
.resideInAnyPackage("..hs.office.person..", "..hs.office.relation..",
"..hs.office.partner..",
"..hs.office.debitor..",
"..hs.office.membership..",
@@ -167,10 +167,10 @@ public class ArchitectureTest {
@ArchTest
@SuppressWarnings("unused")
public static final ArchRule hsOfficeRelationshipPackageRule = classes()
.that().resideInAPackage("..hs.office.relationship..")
public static final ArchRule hsOfficeRelationPackageRule = classes()
.that().resideInAPackage("..hs.office.relation..")
.should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.office.relationship..",
.resideInAnyPackage("..hs.office.relation..",
"..hs.office.partner..",
"..hs.office.migration..");

View File

@@ -18,8 +18,8 @@ import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerDetailsEntity;
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.relationship.HsOfficeRelationshipEntity;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.hs.office.sepamandate.HsOfficeSepaMandateEntity;
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
import net.hostsharing.test.JpaAttempt;
@@ -127,7 +127,7 @@ public class ImportOfficeData extends ContextBasedTest {
new String[]{"partner", "vip-contact", "ex-partner", "billing", "contractual", "operation"},
SUBSCRIBER_ROLES);
static int relationshipId = 2000000;
static int relationId = 2000000;
@Value("${spring.datasource.url}")
private String jdbcUrl;
@@ -144,7 +144,7 @@ public class ImportOfficeData extends ContextBasedTest {
private static Map<Integer, HsOfficeDebitorEntity> debitors = new WriteOnceMap<>();
private static Map<Integer, HsOfficeMembershipEntity> memberships = new WriteOnceMap<>();
private static Map<Integer, HsOfficeRelationshipEntity> relationships = new WriteOnceMap<>();
private static Map<Integer, HsOfficeRelationEntity> relations = new WriteOnceMap<>();
private static Map<Integer, HsOfficeSepaMandateEntity> sepaMandates = new WriteOnceMap<>();
private static Map<Integer, HsOfficeBankAccountEntity> bankAccounts = new WriteOnceMap<>();
private static Map<Integer, HsOfficeCoopSharesTransactionEntity> coopShares = new WriteOnceMap<>();
@@ -220,17 +220,17 @@ public class ImportOfficeData extends ContextBasedTest {
@Test
@Order(1021)
void buildDebitorRelationships() {
void buildDebitorRelations() {
debitors.forEach( (id, debitor) -> {
final var debitorRel = HsOfficeRelationshipEntity.builder()
.relType(HsOfficeRelationshipType.DEBITOR)
.relAnchor(debitor.getPartner().getPartnerRole().getRelHolder())
.relHolder(debitor.getPartner().getPartnerRole().getRelHolder()) // just 1 debitor/partner in legacy hsadmin
final var debitorRel = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.DEBITOR)
.anchor(debitor.getPartner().getPartnerRel().getHolder())
.holder(debitor.getPartner().getPartnerRel().getHolder()) // just 1 debitor/partner in legacy hsadmin
.contact(debitor.getBillingContact())
.build();
if (debitorRel.getRelAnchor() != null && debitorRel.getRelHolder() != null &&
if (debitorRel.getAnchor() != null && debitorRel.getHolder() != null &&
debitorRel.getContact() != null ) {
relationships.put(relationshipId++, debitorRel);
relations.put(relationId++, debitorRel);
}
});
}
@@ -288,28 +288,28 @@ public class ImportOfficeData extends ContextBasedTest {
22=Membership(M-1102200, ?? Test PS, D-1102200, [2021-04-01,), NONE)
}
""");
assertThat(toFormattedString(relationships)).isEqualToIgnoringWhitespace("""
assertThat(toFormattedString(relations)).isEqualToIgnoringWhitespace("""
{
2000000=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000001=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000002=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'),
2000003=rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='null null, null'),
2000004=rel(relAnchor='NP Mellies, Michael', relType='OPERATIONS', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000005=rel(relAnchor='NP Mellies, Michael', relType='REPRESENTATIVE', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000006=rel(relAnchor='LP JM GmbH', relType='EX_PARTNER', relHolder='LP JM e.K.', contact='JM e.K.'),
2000007=rel(relAnchor='LP JM GmbH', relType='OPERATIONS', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
2000008=rel(relAnchor='LP JM GmbH', relType='VIP_CONTACT', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
2000009=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='operations-announce', relHolder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
2000010=rel(relAnchor='LP JM GmbH', relType='REPRESENTATIVE', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000011=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='members-announce', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000012=rel(relAnchor='LP JM GmbH', relType='SUBSCRIBER', relMark='customers-announce', relHolder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000013=rel(relAnchor='LP JM GmbH', relType='VIP_CONTACT', relHolder='LP JM GmbH', contact='Frau Tammy Meyer-VIP , JM GmbH'),
2000014=rel(relAnchor='?? Test PS', relType='OPERATIONS', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'),
2000015=rel(relAnchor='?? Test PS', relType='REPRESENTATIVE', relHolder='?? Test PS', contact='Petra Schmidt , Test PS'),
2000016=rel(relAnchor='NP Mellies, Michael', relType='SUBSCRIBER', relMark='operations-announce', relHolder='NP Fanninga, Frauke', contact='Frau Frauke Fanninga '),
2000017=rel(relAnchor='NP Mellies, Michael', relType='DEBITOR', relHolder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000018=rel(relAnchor='LP JM GmbH', relType='DEBITOR', relHolder='LP JM GmbH', contact='Frau Dr. Jenny Meyer-Billing , JM GmbH'),
2000019=rel(relAnchor='?? Test PS', relType='DEBITOR', relHolder='?? Test PS', contact='Petra Schmidt , Test PS')
2000000=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000001=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000002=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
2000003=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='null null, null'),
2000004=rel(anchor='NP Mellies, Michael', type='OPERATIONS', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000005=rel(anchor='NP Mellies, Michael', type='REPRESENTATIVE', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000006=rel(anchor='LP JM GmbH', type='EX_PARTNER', holder='LP JM e.K.', contact='JM e.K.'),
2000007=rel(anchor='LP JM GmbH', type='OPERATIONS', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
2000008=rel(anchor='LP JM GmbH', type='VIP_CONTACT', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
2000009=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='operations-announce', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
2000010=rel(anchor='LP JM GmbH', type='REPRESENTATIVE', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000011=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='members-announce', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000012=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='customers-announce', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
2000013=rel(anchor='LP JM GmbH', type='VIP_CONTACT', holder='LP JM GmbH', contact='Frau Tammy Meyer-VIP , JM GmbH'),
2000014=rel(anchor='?? Test PS', type='OPERATIONS', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
2000015=rel(anchor='?? Test PS', type='REPRESENTATIVE', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
2000016=rel(anchor='NP Mellies, Michael', type='SUBSCRIBER', mark='operations-announce', holder='NP Fanninga, Frauke', contact='Frau Frauke Fanninga '),
2000017=rel(anchor='NP Mellies, Michael', type='DEBITOR', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
2000018=rel(anchor='LP JM GmbH', type='DEBITOR', holder='LP JM GmbH', contact='Frau Dr. Jenny Meyer-Billing , JM GmbH'),
2000019=rel(anchor='?? Test PS', type='DEBITOR', holder='?? Test PS', contact='Petra Schmidt , Test PS')
}
""");
}
@@ -419,20 +419,20 @@ public class ImportOfficeData extends ContextBasedTest {
@Test
@Order(2009)
void removeEmptyRelationships() {
void removeEmptyRelations() {
assumeThatWeAreImportingControlledTestData();
// avoid a error when persisting the deliberetely invalid partner entry #99
final var idsToRemove = new HashSet<Integer>();
relationships.forEach( (id, r) -> {
relations.forEach( (id, r) -> {
// such a record
if (r.getContact() == null || r.getContact().getLabel() == null ||
r.getRelHolder() == null | r.getRelHolder().getPersonType() == null ) {
r.getHolder() == null | r.getHolder().getPersonType() == null ) {
idsToRemove.add(id);
}
});
assertThat(idsToRemove.size()).isEqualTo(1); // only from partner #99 (partner+contractual roles)
idsToRemove.forEach(id -> relationships.remove(id));
idsToRemove.forEach(id -> relations.remove(id));
}
@Test
@@ -495,7 +495,7 @@ public class ImportOfficeData extends ContextBasedTest {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
relationships.forEach(this::persist);
relations.forEach(this::persist);
}).assertSuccessful();
jpaAttempt.transacted(() -> {
@@ -572,7 +572,7 @@ public class ImportOfficeData extends ContextBasedTest {
em.createNativeQuery("delete from hs_office_bankaccount where true").executeUpdate();
em.createNativeQuery("delete from hs_office_partner where true").executeUpdate();
em.createNativeQuery("delete from hs_office_partner_details where true").executeUpdate();
em.createNativeQuery("delete from hs_office_relationship where true").executeUpdate();
em.createNativeQuery("delete from hs_office_relation where true").executeUpdate();
em.createNativeQuery("delete from hs_office_contact where true").executeUpdate();
em.createNativeQuery("delete from hs_office_person where true").executeUpdate();
}).assertSuccessful();
@@ -676,18 +676,18 @@ public class ImportOfficeData extends ContextBasedTest {
.forEach(rec -> {
final var person = HsOfficePersonEntity.builder().build();
final var partnerRelationship = HsOfficeRelationshipEntity.builder()
.relHolder(person)
.relType(HsOfficeRelationshipType.PARTNER)
.relAnchor(mandant)
final var partnerRelation = HsOfficeRelationEntity.builder()
.holder(person)
.type(HsOfficeRelationType.PARTNER)
.anchor(mandant)
.contact(null) // is set during contacts import depending on assigned roles
.build();
relationships.put(relationshipId++, partnerRelationship);
relations.put(relationId++, partnerRelation);
final var partner = HsOfficePartnerEntity.builder()
.partnerNumber(rec.getInteger("member_id"))
.details(HsOfficePartnerDetailsEntity.builder().build())
.partnerRole(partnerRelationship)
.partnerRel(partnerRelation)
.contact(null) // is set during contacts import depending on assigned roles
.person(person)
.build();
@@ -845,7 +845,7 @@ public class ImportOfficeData extends ContextBasedTest {
final var debitor = debitors.get(bpId);
final var partnerPerson = partner.getPerson();
if (containsPartnerRole(rec)) {
if (containsPartnerRel(rec)) {
initPerson(partner.getPerson(), rec);
}
@@ -859,46 +859,46 @@ public class ImportOfficeData extends ContextBasedTest {
final var contact = HsOfficeContactEntity.builder().build();
initContact(contact, rec);
if (containsPartnerRole(rec)) {
if (containsPartnerRel(rec)) {
assertThat(partner.getContact()).isNull();
partner.setContact(contact);
partner.getPartnerRole().setContact(contact);
partner.getPartnerRel().setContact(contact);
}
if (containsRole(rec, "billing")) {
assertThat(debitor.getBillingContact()).isNull();
debitor.setBillingContact(contact);
}
if (containsRole(rec, "operation")) {
addRelationship(partnerPerson, contactPerson, contact, HsOfficeRelationshipType.OPERATIONS);
addRelation(partnerPerson, contactPerson, contact, HsOfficeRelationType.OPERATIONS);
}
if (containsRole(rec, "contractual")) {
addRelationship(partnerPerson, contactPerson, contact, HsOfficeRelationshipType.REPRESENTATIVE);
addRelation(partnerPerson, contactPerson, contact, HsOfficeRelationType.REPRESENTATIVE);
}
if (containsRole(rec, "ex-partner")) {
addRelationship(partnerPerson, contactPerson, contact, HsOfficeRelationshipType.EX_PARTNER);
addRelation(partnerPerson, contactPerson, contact, HsOfficeRelationType.EX_PARTNER);
}
if (containsRole(rec, "vip-contact")) {
addRelationship(partnerPerson, contactPerson, contact, HsOfficeRelationshipType.VIP_CONTACT);
addRelation(partnerPerson, contactPerson, contact, HsOfficeRelationType.VIP_CONTACT);
}
for (String subscriberRole: SUBSCRIBER_ROLES) {
if (containsRole(rec, subscriberRole)) {
addRelationship(partnerPerson, contactPerson, contact, HsOfficeRelationshipType.SUBSCRIBER)
.setRelMark(subscriberRole.split(":")[1])
addRelation(partnerPerson, contactPerson, contact, HsOfficeRelationType.SUBSCRIBER)
.setMark(subscriberRole.split(":")[1])
;
}
}
verifyContainsOnlyKnownRoles(rec.getString("roles"));
});
optionallyAddMissingContractualRelationships();
optionallyAddMissingContractualRelations();
}
private static void optionallyAddMissingContractualRelationships() {
private static void optionallyAddMissingContractualRelations() {
final var contractualMissing = new HashSet<Integer>();
partners.forEach( (id, partner) -> {
final var partnerPerson = partner.getPerson();
if (relationships.values().stream()
.filter(rel -> rel.getRelAnchor() == partnerPerson && rel.getRelType() == HsOfficeRelationshipType.REPRESENTATIVE)
if (relations.values().stream()
.filter(rel -> rel.getAnchor() == partnerPerson && rel.getType() == HsOfficeRelationType.REPRESENTATIVE)
.findFirst().isEmpty()) {
contractualMissing.add(partner.getPartnerNumber());
}
@@ -909,22 +909,22 @@ public class ImportOfficeData extends ContextBasedTest {
return ("," + roles + ",").contains("," + role + ",");
}
private static boolean containsPartnerRole(final Record rec) {
private static boolean containsPartnerRel(final Record rec) {
return containsRole(rec, "partner");
}
private static HsOfficeRelationshipEntity addRelationship(
private static HsOfficeRelationEntity addRelation(
final HsOfficePersonEntity partnerPerson,
final HsOfficePersonEntity contactPerson,
final HsOfficeContactEntity contact,
final HsOfficeRelationshipType representative) {
final var rel = HsOfficeRelationshipEntity.builder()
.relAnchor(partnerPerson)
.relHolder(contactPerson)
final HsOfficeRelationType representative) {
final var rel = HsOfficeRelationEntity.builder()
.anchor(partnerPerson)
.holder(contactPerson)
.contact(contact)
.relType(representative)
.type(representative)
.build();
relationships.put(relationshipId++, rel);
relations.put(relationId++, rel);
return rel;
}

View File

@@ -7,9 +7,9 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt;
@@ -41,7 +41,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
HsOfficePartnerRepository partnerRepo;
@Autowired
HsOfficeRelationshipRepository relationshipRepository;
HsOfficeRelationRepository relationRepository;
@Autowired
HsOfficePersonRepository personRepo;
@@ -102,9 +102,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.body("""
{
"partnerNumber": "20002",
"partnerRole": {
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"partnerRel": {
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
},
"personUuid": "%s",
@@ -155,9 +155,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.body("""
{
"partnerNumber": "20003",
"partnerRole": {
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"partnerRel": {
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
},
"personUuid": "%s",
@@ -193,9 +193,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.body("""
{
"partnerNumber": "20004",
"partnerRole": {
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"partnerRel": {
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
},
"personUuid": "%s",
@@ -413,7 +413,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
// then the given partner is gone
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty();
assertThat(relationshipRepository.findByUuid(givenPartner.getPartnerRole().getUuid())).isEmpty();
assertThat(relationRepository.findByUuid(givenPartner.getPartnerRel().getUuid())).isEmpty();
}
@Test
@@ -465,15 +465,15 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
final var givenPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0);
final var partnerRole = new HsOfficeRelationshipEntity();
partnerRole.setRelType(HsOfficeRelationshipType.PARTNER);
partnerRole.setRelAnchor(givenMandantPerson);
partnerRole.setRelHolder(givenPerson);
partnerRole.setContact(givenContact);
em.persist(partnerRole);
final var partnerRel = new HsOfficeRelationEntity();
partnerRel.setType(HsOfficeRelationType.PARTNER);
partnerRel.setAnchor(givenMandantPerson);
partnerRel.setHolder(givenPerson);
partnerRel.setContact(givenContact);
em.persist(partnerRel);
final var newPartner = HsOfficePartnerEntity.builder()
.partnerRole(partnerRole)
.partnerRel(partnerRel)
.partnerNumber(partnerNumber)
.person(givenPerson)
.contact(givenContact)
@@ -492,6 +492,6 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
cleanupAllNew(HsOfficePartnerEntity.class);
// TODO: should not be necessary anymore, once it's deleted via after delete trigger
cleanupAllNew(HsOfficeRelationshipEntity.class);
cleanupAllNew(HsOfficeRelationEntity.class);
}
}

View File

@@ -3,8 +3,8 @@ 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.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.mapper.Mapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
@@ -54,7 +54,7 @@ class HsOfficePartnerControllerRestTest {
HsOfficePartnerRepository partnerRepo;
@MockBean
HsOfficeRelationshipRepository relationshipRepo;
HsOfficeRelationRepository relationRepo;
@MockBean
EntityManager em;
@@ -100,9 +100,9 @@ class HsOfficePartnerControllerRestTest {
.content("""
{
"partnerNumber": "20002",
"partnerRole": {
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"partnerRel": {
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
},
"personUuid": "%s",
@@ -137,9 +137,9 @@ class HsOfficePartnerControllerRestTest {
.content("""
{
"partnerNumber": "20002",
"partnerRole": {
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"partnerRel": {
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
},
"personUuid": "%s",
@@ -175,11 +175,11 @@ class HsOfficePartnerControllerRestTest {
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)
final UUID givenRelationUuid = UUID.randomUUID();
when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationEntity.builder()
.uuid(givenRelationUuid)
.build());
when(relationshipRepo.deleteByUuid(givenRelationshipUuid)).thenReturn(0);
when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0);
// when
mockMvc.perform(MockMvcRequestBuilders
@@ -193,18 +193,18 @@ class HsOfficePartnerControllerRestTest {
}
@Test
void respondBadRequest_ifRelationshipCannotBeDeleted() throws Exception {
void respondBadRequest_ifRelationCannotBeDeleted() 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);
when(relationRepo.deleteByUuid(any())).thenReturn(0);
final UUID givenRelationshipUuid = UUID.randomUUID();
when(partnerMock.getPartnerRole()).thenReturn(HsOfficeRelationshipEntity.builder()
.uuid(givenRelationshipUuid)
final UUID givenRelationUuid = UUID.randomUUID();
when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationEntity.builder()
.uuid(givenRelationUuid)
.build());
when(relationshipRepo.deleteByUuid(givenRelationshipUuid)).thenReturn(0);
when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0);
// when
mockMvc.perform(MockMvcRequestBuilders

View File

@@ -3,9 +3,9 @@ package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
@@ -43,7 +43,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
HsOfficePartnerRepository partnerRepo;
@Autowired
HsOfficeRelationshipRepository relationshipRepo;
HsOfficeRelationRepository relationRepo;
@Autowired
HsOfficePersonRepository personRepo;
@@ -80,19 +80,19 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike("First GmbH").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("first contact").get(0);
final var partnerRole = HsOfficeRelationshipEntity.builder()
.relHolder(givenPartnerPerson)
.relType(HsOfficeRelationshipType.PARTNER)
.relAnchor(givenMandantorPerson)
final var partnerRel = HsOfficeRelationEntity.builder()
.holder(givenPartnerPerson)
.type(HsOfficeRelationType.PARTNER)
.anchor(givenMandantorPerson)
.contact(givenContact)
.build();
relationshipRepo.save(partnerRole);
relationRepo.save(partnerRel);
// when
final var result = attempt(em, () -> {
final var newPartner = HsOfficePartnerEntity.builder()
.partnerNumber(20031)
.partnerRole(partnerRole)
.partnerRel(partnerRel)
.person(givenPartnerPerson)
.contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder()
@@ -125,17 +125,17 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0);
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
final var newRelationship = HsOfficeRelationshipEntity.builder()
.relHolder(givenPartnerPerson)
.relType(HsOfficeRelationshipType.PARTNER)
.relAnchor(givenMandantPerson)
final var newRelation = HsOfficeRelationEntity.builder()
.holder(givenPartnerPerson)
.type(HsOfficeRelationType.PARTNER)
.anchor(givenMandantPerson)
.contact(givenContact)
.build();
relationshipRepo.save(newRelationship);
relationRepo.save(newRelation);
final var newPartner = HsOfficePartnerEntity.builder()
.partnerNumber(20032)
.partnerRole(newRelationship)
.partnerRel(newRelation)
.person(givenPartnerPerson)
.contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder().build())
@@ -146,9 +146,9 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
// then
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from(
initialRoleNames,
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.admin",
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.owner",
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant",
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.admin",
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.owner",
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.admin",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.agent",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.owner",
@@ -160,25 +160,25 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
.map(s -> s.replace("hs_office_", ""))
.containsExactlyInAnyOrder(distinct(fromFormatted(
initialGrantNames,
// relationship - TODO: check and cleanup
// relation - TODO: check and cleanup
"{ grant role person#HostsharingeG.tenant to role person#EBess.admin by system and assume }",
"{ grant role person#EBess.tenant to role person#HostsharingeG.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role partner#20032:EBess-4th.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role partner#20032:EBess-4th.tenant by system and assume }",
"{ grant role partner#20032:EBess-4th.agent to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.owner to role global#global.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role contact#4th.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role person#EBess.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.owner to role person#HostsharingeG.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role person#HostsharingeG.admin by system and assume }",
"{ grant perm UPDATE on relationship#HostsharingeG-with-PARTNER-EBess to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant perm DELETE on relationship#HostsharingeG-with-PARTNER-EBess to role relationship#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.admin to role relationship#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
"{ grant perm SELECT on relationship#HostsharingeG-with-PARTNER-EBess to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
"{ grant role contact#4th.tenant to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
"{ grant role person#EBess.tenant to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
"{ grant role person#HostsharingeG.tenant to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role partner#20032:EBess-4th.admin by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role partner#20032:EBess-4th.tenant by system and assume }",
"{ grant role partner#20032:EBess-4th.agent to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.owner to role global#global.admin by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role contact#4th.admin by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role person#EBess.admin by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.owner to role person#HostsharingeG.admin by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role person#HostsharingeG.admin by system and assume }",
"{ grant perm UPDATE on relation#HostsharingeG-with-PARTNER-EBess to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant perm DELETE on relation#HostsharingeG-with-PARTNER-EBess to role relation#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.admin to role relation#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
"{ grant perm SELECT on relation#HostsharingeG-with-PARTNER-EBess to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
"{ grant role contact#4th.tenant to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
"{ grant role person#EBess.tenant to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
"{ grant role person#HostsharingeG.tenant to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
// owner
"{ grant perm DELETE on partner#20032:EBess-4th to role partner#20032:EBess-4th.owner by system and assume }",
@@ -426,15 +426,15 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
// TODO: should deleting a partner automatically delete the PARTNER relationship? (same for debitor)
// TODO: should deleting a partner automatically delete the PARTNER relation? (same for debitor)
// TODO: why did the test cleanup check does not notice this, if missing?
return partnerRepo.deleteByUuid(givenPartner.getUuid()) +
relationshipRepo.deleteByUuid(givenPartner.getPartnerRole().getUuid());
relationRepo.deleteByUuid(givenPartner.getPartnerRel().getUuid());
});
// then
result.assertSuccessful();
assertThat(result.returnedValue()).isEqualTo(2); // partner+relationship
assertThat(result.returnedValue()).isEqualTo(2); // partner+relation
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(initialRoleNames);
assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder(initialGrantNames);
}
@@ -466,17 +466,17 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike(contact).get(0);
final var partnerRole = HsOfficeRelationshipEntity.builder()
.relHolder(givenPartnerPerson)
.relType(HsOfficeRelationshipType.PARTNER)
.relAnchor(givenMandantorPerson)
final var partnerRel = HsOfficeRelationEntity.builder()
.holder(givenPartnerPerson)
.type(HsOfficeRelationType.PARTNER)
.anchor(givenMandantorPerson)
.contact(givenContact)
.build();
relationshipRepo.save(partnerRole);
relationRepo.save(partnerRel);
final var newPartner = HsOfficePartnerEntity.builder()
.partnerNumber(partnerNumber)
.partnerRole(partnerRole)
.partnerRel(partnerRel)
.person(givenPartnerPerson)
.contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder().build())
@@ -502,7 +502,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
void cleanup() {
cleanupAllNew(HsOfficePartnerDetailsEntity.class); // TODO: should not be necessary
cleanupAllNew(HsOfficePartnerEntity.class);
cleanupAllNew(HsOfficeRelationshipEntity.class);
cleanupAllNew(HsOfficeRelationEntity.class);
}
private String[] distinct(final String[] strings) {

View File

@@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.office.relationship;
package net.hostsharing.hsadminng.hs.office.relation;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
@@ -7,7 +7,7 @@ import net.hostsharing.test.Accepts;
import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationshipTypeResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.test.JpaAttempt;
import org.json.JSONException;
@@ -31,7 +31,7 @@ import static org.hamcrest.Matchers.startsWith;
classes = { HsadminNgApplication.class, JpaAttempt.class }
)
@Transactional
class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithCleanup {
class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithCleanup {
public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
@LocalServerPort
@@ -44,7 +44,7 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
Context contextMock;
@Autowired
HsOfficeRelationshipRepository relationshipRepo;
HsOfficeRelationRepository relationRepo;
@Autowired
HsOfficePersonRepository personRepo;
@@ -56,11 +56,11 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
JpaAttempt jpaAttempt;
@Nested
@Accepts({ "Relationship:F(Find)" })
class ListRelationships {
@Accepts({ "Relation:F(Find)" })
class ListRelations {
@Test
void globalAdmin_withoutAssumedRoles_canViewAllRelationshipsOfGivenPersonAndType_ifNoCriteriaGiven() throws JSONException {
void globalAdmin_withoutAssumedRoles_canViewAllRelationsOfGivenPersonAndType_ifNoCriteriaGiven() throws JSONException {
// given
context.define("superuser-alex@hostsharing.net");
@@ -71,45 +71,45 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
.header("current-user", "superuser-alex@hostsharing.net")
.port(port)
.when()
.get("http://localhost/api/hs/office/relationships?personUuid=%s&relationshipType=%s"
.formatted(givenPerson.getUuid(), HsOfficeRelationshipTypeResource.PARTNER))
.get("http://localhost/api/hs/office/relations?personUuid=%s&relationType=%s"
.formatted(givenPerson.getUuid(), HsOfficeRelationTypeResource.PARTNER))
.then().log().all().assertThat()
.statusCode(200)
.contentType("application/json")
.body("", lenientlyEquals("""
[
{
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"relHolder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH" },
"relType": "PARTNER",
"relMark": null,
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"holder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH" },
"type": "PARTNER",
"mark": null,
"contact": { "label": "first contact" }
},
{
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"relHolder": { "personType": "INCORPORATED_FIRM", "tradeName": "Fourth eG" },
"relType": "PARTNER",
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"holder": { "personType": "INCORPORATED_FIRM", "tradeName": "Fourth eG" },
"type": "PARTNER",
"contact": { "label": "fourth contact" }
},
{
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"relHolder": { "personType": "LEGAL_PERSON", "tradeName": "Second e.K.", "givenName": "Peter", "familyName": "Smith" },
"relType": "PARTNER",
"relMark": null,
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"holder": { "personType": "LEGAL_PERSON", "tradeName": "Second e.K.", "givenName": "Peter", "familyName": "Smith" },
"type": "PARTNER",
"mark": null,
"contact": { "label": "second contact" }
},
{
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"relHolder": { "personType": "NATURAL_PERSON", "givenName": "Peter", "familyName": "Smith" },
"relType": "PARTNER",
"relMark": null,
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"holder": { "personType": "NATURAL_PERSON", "givenName": "Peter", "familyName": "Smith" },
"type": "PARTNER",
"mark": null,
"contact": { "label": "sixth contact" }
},
{
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"relHolder": { "personType": "INCORPORATED_FIRM", "tradeName": "Third OHG" },
"relType": "PARTNER",
"relMark": null,
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"holder": { "personType": "INCORPORATED_FIRM", "tradeName": "Third OHG" },
"type": "PARTNER",
"mark": null,
"contact": { "label": "third contact" }
}
]
@@ -119,11 +119,11 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
}
@Nested
@Accepts({ "Relationship:C(Create)" })
class AddRelationship {
@Accepts({ "Relation:C(Create)" })
class AddRelation {
@Test
void globalAdmin_withoutAssumedRole_canAddRelationship() {
void globalAdmin_withoutAssumedRole_canAddRelation() {
context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
@@ -136,38 +136,38 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
.contentType(ContentType.JSON)
.body("""
{
"relType": "%s",
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"type": "%s",
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
}
""".formatted(
HsOfficeRelationshipTypeResource.ACCOUNTING,
HsOfficeRelationTypeResource.DEBITOR,
givenAnchorPerson.getUuid(),
givenHolderPerson.getUuid(),
givenContact.getUuid()))
.port(port)
.when()
.post("http://localhost/api/hs/office/relationships")
.post("http://localhost/api/hs/office/relations")
.then().log().all().assertThat()
.statusCode(201)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("relType", is("ACCOUNTING"))
.body("relAnchor.tradeName", is("Third OHG"))
.body("relHolder.givenName", is("Paul"))
.body("type", is("DEBITOR"))
.body("anchor.tradeName", is("Third OHG"))
.body("holder.givenName", is("Paul"))
.body("contact.label", is("second contact"))
.header("Location", startsWith("http://localhost"))
.extract().header("Location"); // @formatter:on
// finally, the new relationship can be accessed under the generated UUID
final var newUserUuid = toCleanup(HsOfficeRelationshipEntity.class, UUID.fromString(
// finally, the new relation can be accessed under the generated UUID
final var newUserUuid = toCleanup(HsOfficeRelationEntity.class, UUID.fromString(
location.substring(location.lastIndexOf('/') + 1)));
assertThat(newUserUuid).isNotNull();
}
@Test
void globalAdmin_canNotAddRelationship_ifAnchorPersonDoesNotExist() {
void globalAdmin_canNotAddRelation_ifAnchorPersonDoesNotExist() {
context.define("superuser-alex@hostsharing.net");
final var givenAnchorPersonUuid = GIVEN_NON_EXISTING_HOLDER_PERSON_UUID;
@@ -180,27 +180,27 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
.contentType(ContentType.JSON)
.body("""
{
"relType": "%s",
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"type": "%s",
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
}
""".formatted(
HsOfficeRelationshipTypeResource.ACCOUNTING,
HsOfficeRelationTypeResource.DEBITOR,
givenAnchorPersonUuid,
givenHolderPerson.getUuid(),
givenContact.getUuid()))
.port(port)
.when()
.post("http://localhost/api/hs/office/relationships")
.post("http://localhost/api/hs/office/relations")
.then().log().all().assertThat()
.statusCode(404)
.body("message", is("cannot find relAnchorUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
.body("message", is("cannot find anchorUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
// @formatter:on
}
@Test
void globalAdmin_canNotAddRelationship_ifHolderPersonDoesNotExist() {
void globalAdmin_canNotAddRelation_ifHolderPersonDoesNotExist() {
context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
@@ -212,27 +212,27 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
.contentType(ContentType.JSON)
.body("""
{
"relType": "%s",
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"type": "%s",
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
}
""".formatted(
HsOfficeRelationshipTypeResource.ACCOUNTING,
HsOfficeRelationTypeResource.DEBITOR,
givenAnchorPerson.getUuid(),
GIVEN_NON_EXISTING_HOLDER_PERSON_UUID,
givenContact.getUuid()))
.port(port)
.when()
.post("http://localhost/api/hs/office/relationships")
.post("http://localhost/api/hs/office/relations")
.then().log().all().assertThat()
.statusCode(404)
.body("message", is("cannot find relHolderUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
.body("message", is("cannot find holderUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
// @formatter:on
}
@Test
void globalAdmin_canNotAddRelationship_ifContactDoesNotExist() {
void globalAdmin_canNotAddRelation_ifContactDoesNotExist() {
context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
@@ -245,19 +245,19 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
.contentType(ContentType.JSON)
.body("""
{
"relType": "%s",
"relAnchorUuid": "%s",
"relHolderUuid": "%s",
"type": "%s",
"anchorUuid": "%s",
"holderUuid": "%s",
"contactUuid": "%s"
}
""".formatted(
HsOfficeRelationshipTypeResource.ACCOUNTING,
HsOfficeRelationTypeResource.DEBITOR,
givenAnchorPerson.getUuid(),
givenHolderPerson.getUuid(),
givenContactUuid))
.port(port)
.when()
.post("http://localhost/api/hs/office/relationships")
.post("http://localhost/api/hs/office/relations")
.then().log().all().assertThat()
.statusCode(404)
.body("message", is("cannot find contactUuid 00000000-0000-0000-0000-000000000000"));
@@ -266,97 +266,97 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
}
@Nested
@Accepts({ "Relationship:R(Read)" })
class GetRelationship {
@Accepts({ "Relation:R(Read)" })
class GetRelation {
@Test
void globalAdmin_withoutAssumedRole_canGetArbitraryRelationship() {
void globalAdmin_withoutAssumedRole_canGetArbitraryRelation() {
context.define("superuser-alex@hostsharing.net");
final UUID givenRelationshipUuid = findRelationship("First", "Firby").getUuid();
final UUID givenRelationUuid = findRelation("First", "Firby").getUuid();
RestAssured // @formatter:off
.given()
.header("current-user", "superuser-alex@hostsharing.net")
.port(port)
.when()
.get("http://localhost/api/hs/office/relationships/" + givenRelationshipUuid)
.get("http://localhost/api/hs/office/relations/" + givenRelationUuid)
.then().log().body().assertThat()
.statusCode(200)
.contentType("application/json")
.body("", lenientlyEquals("""
{
"relAnchor": { "tradeName": "First GmbH" },
"relHolder": { "familyName": "Firby" },
"anchor": { "tradeName": "First GmbH" },
"holder": { "familyName": "Firby" },
"contact": { "label": "first contact" }
}
""")); // @formatter:on
}
@Test
@Accepts({ "Relationship:X(Access Control)" })
void normalUser_canNotGetUnrelatedRelationship() {
@Accepts({ "Relation:X(Access Control)" })
void normalUser_canNotGetUnrelatedRelation() {
context.define("superuser-alex@hostsharing.net");
final UUID givenRelationshipUuid = findRelationship("First", "Firby").getUuid();
final UUID givenRelationUuid = findRelation("First", "Firby").getUuid();
RestAssured // @formatter:off
.given()
.header("current-user", "selfregistered-user-drew@hostsharing.org")
.port(port)
.when()
.get("http://localhost/api/hs/office/relationships/" + givenRelationshipUuid)
.get("http://localhost/api/hs/office/relations/" + givenRelationUuid)
.then().log().body().assertThat()
.statusCode(404); // @formatter:on
}
@Test
@Accepts({ "Relationship:X(Access Control)" })
void contactAdminUser_canGetRelatedRelationship() {
@Accepts({ "Relation:X(Access Control)" })
void contactAdminUser_canGetRelatedRelation() {
context.define("superuser-alex@hostsharing.net");
final var givenRelationship = findRelationship("First", "Firby");
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("first contact");
final var givenRelation = findRelation("First", "Firby");
assertThat(givenRelation.getContact().getLabel()).isEqualTo("first contact");
RestAssured // @formatter:off
.given()
.header("current-user", "contact-admin@firstcontact.example.com")
.port(port)
.when()
.get("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
.get("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
.then().log().body().assertThat()
.statusCode(200)
.contentType("application/json")
.body("", lenientlyEquals("""
{
"relAnchor": { "tradeName": "First GmbH" },
"relHolder": { "familyName": "Firby" },
"anchor": { "tradeName": "First GmbH" },
"holder": { "familyName": "Firby" },
"contact": { "label": "first contact" }
}
""")); // @formatter:on
}
}
private HsOfficeRelationshipEntity findRelationship(
private HsOfficeRelationEntity findRelation(
final String anchorPersonName,
final String holderPersoneName) {
final var anchorPersonUuid = personRepo.findPersonByOptionalNameLike(anchorPersonName).get(0).getUuid();
final var holderPersonUuid = personRepo.findPersonByOptionalNameLike(holderPersoneName).get(0).getUuid();
final var givenRelationship = relationshipRepo
.findRelationshipRelatedToPersonUuid(anchorPersonUuid)
final var givenRelation = relationRepo
.findRelationRelatedToPersonUuid(anchorPersonUuid)
.stream()
.filter(r -> r.getRelHolder().getUuid().equals(holderPersonUuid))
.filter(r -> r.getHolder().getUuid().equals(holderPersonUuid))
.findFirst().orElseThrow();
return givenRelationship;
return givenRelation;
}
@Nested
@Accepts({ "Relationship:U(Update)" })
class PatchRelationship {
@Accepts({ "Relation:U(Update)" })
class PatchRelation {
@Test
void globalAdmin_withoutAssumedRole_canPatchContactOfArbitraryRelationship() {
void globalAdmin_withoutAssumedRole_canPatchContactOfArbitraryRelation() {
context.define("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact");
final var givenRelation = givenSomeTemporaryRelationBessler();
assertThat(givenRelation.getContact().getLabel()).isEqualTo("seventh contact");
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var location = RestAssured // @formatter:off
@@ -370,109 +370,109 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
""".formatted(givenContact.getUuid()))
.port(port)
.when()
.patch("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
.patch("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
.then().log().all().assertThat()
.statusCode(200)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("relType", is("REPRESENTATIVE"))
.body("relAnchor.tradeName", is("Erben Bessler"))
.body("relHolder.familyName", is("Winkler"))
.body("type", is("REPRESENTATIVE"))
.body("anchor.tradeName", is("Erben Bessler"))
.body("holder.familyName", is("Winkler"))
.body("contact.label", is("fourth contact"));
// @formatter:on
// finally, the relationship is actually updated
// finally, the relation is actually updated
context.define("superuser-alex@hostsharing.net");
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isPresent().get()
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent().get()
.matches(rel -> {
assertThat(rel.getRelAnchor().getTradeName()).contains("Bessler");
assertThat(rel.getRelHolder().getFamilyName()).contains("Winkler");
assertThat(rel.getAnchor().getTradeName()).contains("Bessler");
assertThat(rel.getHolder().getFamilyName()).contains("Winkler");
assertThat(rel.getContact().getLabel()).isEqualTo("fourth contact");
assertThat(rel.getRelType()).isEqualTo(HsOfficeRelationshipType.REPRESENTATIVE);
assertThat(rel.getType()).isEqualTo(HsOfficeRelationType.REPRESENTATIVE);
return true;
});
}
}
@Nested
@Accepts({ "Relationship:D(Delete)" })
class DeleteRelationship {
@Accepts({ "Relation:D(Delete)" })
class DeleteRelation {
@Test
void globalAdmin_withoutAssumedRole_canDeleteArbitraryRelationship() {
void globalAdmin_withoutAssumedRole_canDeleteArbitraryRelation() {
context.define("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
final var givenRelation = givenSomeTemporaryRelationBessler();
RestAssured // @formatter:off
.given()
.header("current-user", "superuser-alex@hostsharing.net")
.port(port)
.when()
.delete("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
.then().log().body().assertThat()
.statusCode(204); // @formatter:on
// then the given relationship is gone
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isEmpty();
// then the given relation is gone
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isEmpty();
}
@Test
@Accepts({ "Relationship:X(Access Control)" })
void contactAdminUser_canNotDeleteRelatedRelationship() {
@Accepts({ "Relation:X(Access Control)" })
void contactAdminUser_canNotDeleteRelatedRelation() {
context.define("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact");
final var givenRelation = givenSomeTemporaryRelationBessler();
assertThat(givenRelation.getContact().getLabel()).isEqualTo("seventh contact");
RestAssured // @formatter:off
.given()
.header("current-user", "contact-admin@seventhcontact.example.com")
.port(port)
.when()
.delete("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
.then().log().body().assertThat()
.statusCode(403); // @formatter:on
// then the given relationship is still there
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isNotEmpty();
// then the given relation is still there
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty();
}
@Test
@Accepts({ "Relationship:X(Access Control)" })
void normalUser_canNotDeleteUnrelatedRelationship() {
@Accepts({ "Relation:X(Access Control)" })
void normalUser_canNotDeleteUnrelatedRelation() {
context.define("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact");
final var givenRelation = givenSomeTemporaryRelationBessler();
assertThat(givenRelation.getContact().getLabel()).isEqualTo("seventh contact");
RestAssured // @formatter:off
.given()
.header("current-user", "selfregistered-user-drew@hostsharing.org")
.port(port)
.when()
.delete("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
.then().log().body().assertThat()
.statusCode(404); // @formatter:on
// then the given relationship is still there
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isNotEmpty();
// then the given relation is still there
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty();
}
}
private HsOfficeRelationshipEntity givenSomeTemporaryRelationshipBessler() {
private HsOfficeRelationEntity givenSomeTemporaryRelationBessler() {
return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("seventh contact").get(0);
final var newRelationship = HsOfficeRelationshipEntity.builder()
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
.relAnchor(givenAnchorPerson)
.relHolder(givenHolderPerson)
final var newRelation = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.REPRESENTATIVE)
.anchor(givenAnchorPerson)
.holder(givenHolderPerson)
.contact(givenContact)
.build();
assertThat(toCleanup(relationshipRepo.save(newRelationship))).isEqualTo(newRelationship);
assertThat(toCleanup(relationRepo.save(newRelation))).isEqualTo(newRelation);
return newRelationship;
return newRelation;
}).assertSuccessful().returnedValue();
}

View File

@@ -1,7 +1,7 @@
package net.hostsharing.hsadminng.hs.office.relationship;
package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationshipPatchResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationPatchResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.test.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach;
@@ -21,12 +21,12 @@ import static org.mockito.Mockito.lenient;
@TestInstance(PER_CLASS)
@ExtendWith(MockitoExtension.class)
class HsOfficeRelationshipEntityPatcherUnitTest extends PatchUnitTestBase<
HsOfficeRelationshipPatchResource,
HsOfficeRelationshipEntity
class HsOfficeRelationEntityPatcherUnitTest extends PatchUnitTestBase<
HsOfficeRelationPatchResource,
HsOfficeRelationEntity
> {
static final UUID INITIAL_RELATIONSHIP_UUID = UUID.randomUUID();
static final UUID INITIAL_RELATION_UUID = UUID.randomUUID();
static final UUID PATCHED_CONTACT_UUID = UUID.randomUUID();
@Mock
@@ -49,24 +49,24 @@ class HsOfficeRelationshipEntityPatcherUnitTest extends PatchUnitTestBase<
.build();
@Override
protected HsOfficeRelationshipEntity newInitialEntity() {
final var entity = new HsOfficeRelationshipEntity();
entity.setUuid(INITIAL_RELATIONSHIP_UUID);
entity.setRelType(HsOfficeRelationshipType.REPRESENTATIVE);
entity.setRelAnchor(givenInitialAnchorPerson);
entity.setRelHolder(givenInitialHolderPerson);
protected HsOfficeRelationEntity newInitialEntity() {
final var entity = new HsOfficeRelationEntity();
entity.setUuid(INITIAL_RELATION_UUID);
entity.setType(HsOfficeRelationType.REPRESENTATIVE);
entity.setAnchor(givenInitialAnchorPerson);
entity.setHolder(givenInitialHolderPerson);
entity.setContact(givenInitialContact);
return entity;
}
@Override
protected HsOfficeRelationshipPatchResource newPatchResource() {
return new HsOfficeRelationshipPatchResource();
protected HsOfficeRelationPatchResource newPatchResource() {
return new HsOfficeRelationPatchResource();
}
@Override
protected HsOfficeRelationshipEntityPatcher createPatcher(final HsOfficeRelationshipEntity relationship) {
return new HsOfficeRelationshipEntityPatcher(em, relationship);
protected HsOfficeRelationEntityPatcher createPatcher(final HsOfficeRelationEntity relation) {
return new HsOfficeRelationEntityPatcher(em, relation);
}
@Override
@@ -74,9 +74,9 @@ class HsOfficeRelationshipEntityPatcherUnitTest extends PatchUnitTestBase<
return Stream.of(
new JsonNullableProperty<>(
"contact",
HsOfficeRelationshipPatchResource::setContactUuid,
HsOfficeRelationPatchResource::setContactUuid,
PATCHED_CONTACT_UUID,
HsOfficeRelationshipEntity::setContact,
HsOfficeRelationEntity::setContact,
newContact(PATCHED_CONTACT_UUID))
.notNullable()
);

View File

@@ -0,0 +1,43 @@
package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class HsOfficeRelationEntityUnitTest {
private HsOfficePersonEntity anchor = HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("some trade name")
.build();
private HsOfficePersonEntity holder = HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.NATURAL_PERSON)
.familyName("Meier")
.givenName("Mellie")
.build();
@Test
void toStringReturnsAllProperties() {
final var given = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.SUBSCRIBER)
.mark("members-announce")
.anchor(anchor)
.holder(holder)
.build();
assertThat(given.toString()).isEqualTo("rel(anchor='LP some trade name', type='SUBSCRIBER', mark='members-announce', holder='NP Meier, Mellie')");
}
@Test
void toShortString() {
final var given = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.REPRESENTATIVE)
.anchor(anchor)
.holder(holder)
.build();
assertThat(given.toShortString()).isEqualTo("rel(anchor='LP some trade name', type='REPRESENTATIVE', holder='NP Meier, Mellie')");
}
}

View File

@@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.office.relationship;
package net.hostsharing.hsadminng.hs.office.relation;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
@@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest
@Import( { Context.class, JpaAttempt.class })
class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
@Autowired
HsOfficeRelationshipRepository relationshipRepo;
HsOfficeRelationRepository relationRepo;
@Autowired
HsOfficePersonRepository personRepo;
@@ -56,33 +56,33 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
HttpServletRequest request;
@Nested
class CreateRelationship {
class CreateRelation {
@Test
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewRelationship() {
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewRelation() {
// given
context("superuser-alex@hostsharing.net");
final var count = relationshipRepo.count();
final var count = relationRepo.count();
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Anita").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0);
// when
final var result = attempt(em, () -> {
final var newRelationship = HsOfficeRelationshipEntity.builder()
.relAnchor(givenAnchorPerson)
.relHolder(givenHolderPerson)
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
final var newRelation = HsOfficeRelationEntity.builder()
.anchor(givenAnchorPerson)
.holder(givenHolderPerson)
.type(HsOfficeRelationType.REPRESENTATIVE)
.contact(givenContact)
.build();
return toCleanup(relationshipRepo.save(newRelationship));
return toCleanup(relationRepo.save(newRelation));
});
// then
result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelationshipEntity::getUuid).isNotNull();
assertThatRelationshipIsPersisted(result.returnedValue());
assertThat(relationshipRepo.count()).isEqualTo(count + 1);
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelationEntity::getUuid).isNotNull();
assertThatRelationIsPersisted(result.returnedValue());
assertThat(relationRepo.count()).isEqualTo(count + 1);
}
@Test
@@ -97,190 +97,190 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Anita").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0);
final var newRelationship = HsOfficeRelationshipEntity.builder()
.relAnchor(givenAnchorPerson)
.relHolder(givenHolderPerson)
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
final var newRelation = HsOfficeRelationEntity.builder()
.anchor(givenAnchorPerson)
.holder(givenHolderPerson)
.type(HsOfficeRelationType.REPRESENTATIVE)
.contact(givenContact)
.build();
return toCleanup(relationshipRepo.save(newRelationship));
return toCleanup(relationRepo.save(newRelation));
});
// then
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from(
initialRoleNames,
"hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin",
"hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner",
"hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant"));
"hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin",
"hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner",
"hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant"));
assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder(Array.fromFormatted(
initialGrantNames,
"{ grant perm DELETE on hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita to role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner by system and assume }",
"{ grant role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner to role global#global.admin by system and assume }",
"{ grant role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner to role hs_office_person#BesslerAnita.admin by system and assume }",
"{ grant perm DELETE on hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita to role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner by system and assume }",
"{ grant role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner to role global#global.admin by system and assume }",
"{ grant role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner to role hs_office_person#BesslerAnita.admin by system and assume }",
"{ grant perm UPDATE on hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita to role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin by system and assume }",
"{ grant role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin to role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner by system and assume }",
"{ grant perm UPDATE on hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita to role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin by system and assume }",
"{ grant role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin to role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.owner by system and assume }",
"{ grant perm SELECT on hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita to role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant by system and assume }",
"{ grant role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant to role hs_office_contact#fourthcontact.admin by system and assume }",
"{ grant role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant to role hs_office_person#BesslerAnita.admin by system and assume }",
"{ grant perm SELECT on hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita to role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant by system and assume }",
"{ grant role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant to role hs_office_contact#fourthcontact.admin by system and assume }",
"{ grant role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant to role hs_office_person#BesslerAnita.admin by system and assume }",
"{ grant role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant to role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin by system and assume }",
"{ grant role hs_office_contact#fourthcontact.tenant to role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant by system and assume }",
"{ grant role hs_office_person#BesslerAnita.tenant to role hs_office_relationship#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant by system and assume }",
"{ grant role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant to role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.admin by system and assume }",
"{ grant role hs_office_contact#fourthcontact.tenant to role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant by system and assume }",
"{ grant role hs_office_person#BesslerAnita.tenant to role hs_office_relation#BesslerAnita-with-REPRESENTATIVE-BesslerAnita.tenant by system and assume }",
null)
);
}
private void assertThatRelationshipIsPersisted(final HsOfficeRelationshipEntity saved) {
final var found = relationshipRepo.findByUuid(saved.getUuid());
private void assertThatRelationIsPersisted(final HsOfficeRelationEntity saved) {
final var found = relationRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
}
}
@Nested
class FindAllRelationships {
class FindAllRelations {
@Test
public void globalAdmin_withoutAssumedRole_canViewAllRelationshipsOfArbitraryPerson() {
public void globalAdmin_withoutAssumedRole_canViewAllRelationsOfArbitraryPerson() {
// given
context("superuser-alex@hostsharing.net");
final var person = personRepo.findPersonByOptionalNameLike("Second e.K.").stream().findFirst().orElseThrow();
// when
final var result = relationshipRepo.findRelationshipRelatedToPersonUuid(person.getUuid());
final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid());
// then
allTheseRelationshipsAreReturned(
allTheseRelationsAreReturned(
result,
"rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='LP Second e.K.', contact='second contact')",
"rel(relAnchor='LP Second e.K.', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='second contact')");
"rel(anchor='LP Hostsharing eG', type='PARTNER', holder='LP Second e.K.', contact='second contact')",
"rel(anchor='LP Second e.K.', type='REPRESENTATIVE', holder='NP Smith, Peter', contact='second contact')");
}
@Test
public void normalUser_canViewRelationshipsOfOwnedPersons() {
public void normalUser_canViewRelationsOfOwnedPersons() {
// given:
context("person-FirstGmbH@example.com");
final var person = personRepo.findPersonByOptionalNameLike("First").stream().findFirst().orElseThrow();
// when:
final var result = relationshipRepo.findRelationshipRelatedToPersonUuid(person.getUuid());
final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid());
// then:
exactlyTheseRelationshipsAreReturned(
exactlyTheseRelationsAreReturned(
result,
"rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='LP First GmbH', contact='first contact')",
"rel(relAnchor='LP First GmbH', relType='REPRESENTATIVE', relHolder='NP Firby, Susan', contact='first contact')");
"rel(anchor='LP Hostsharing eG', type='PARTNER', holder='LP First GmbH', contact='first contact')",
"rel(anchor='LP First GmbH', type='REPRESENTATIVE', holder='NP Firby, Susan', contact='first contact')");
}
}
@Nested
class UpdateRelationship {
class UpdateRelation {
@Test
public void hostsharingAdmin_withoutAssumedRole_canUpdateContactOfArbitraryRelationship() {
public void hostsharingAdmin_withoutAssumedRole_canUpdateContactOfArbitraryRelation() {
// given
context("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
final var givenRelation = givenSomeTemporaryRelationBessler(
"Anita", "fifth contact");
assertThatRelationshipIsVisibleForUserWithRole(
givenRelationship,
assertThatRelationIsVisibleForUserWithRole(
givenRelation,
"hs_office_person#ErbenBesslerMelBessler.admin");
assertThatRelationshipActuallyInDatabase(givenRelationship);
assertThatRelationActuallyInDatabase(givenRelation);
context("superuser-alex@hostsharing.net");
final var givenContact = contactRepo.findContactByOptionalLabelLike("sixth contact").get(0);
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
givenRelationship.setContact(givenContact);
return toCleanup(relationshipRepo.save(givenRelationship));
givenRelation.setContact(givenContact);
return toCleanup(relationRepo.save(givenRelation));
});
// then
result.assertSuccessful();
assertThat(result.returnedValue().getContact().getLabel()).isEqualTo("sixth contact");
assertThatRelationshipIsVisibleForUserWithRole(
assertThatRelationIsVisibleForUserWithRole(
result.returnedValue(),
"global#global.admin");
assertThatRelationshipIsVisibleForUserWithRole(
assertThatRelationIsVisibleForUserWithRole(
result.returnedValue(),
"hs_office_contact#sixthcontact.admin");
assertThatRelationshipIsNotVisibleForUserWithRole(
assertThatRelationIsNotVisibleForUserWithRole(
result.returnedValue(),
"hs_office_contact#fifthcontact.admin");
relationshipRepo.deleteByUuid(givenRelationship.getUuid());
relationRepo.deleteByUuid(givenRelation.getUuid());
}
@Test
public void relHolderAdmin_canNotUpdateRelatedRelationship() {
public void holderAdmin_canNotUpdateRelatedRelation() {
// given
context("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
final var givenRelation = givenSomeTemporaryRelationBessler(
"Anita", "eighth");
assertThatRelationshipIsVisibleForUserWithRole(
givenRelationship,
assertThatRelationIsVisibleForUserWithRole(
givenRelation,
"hs_office_person#BesslerAnita.admin");
assertThatRelationshipActuallyInDatabase(givenRelationship);
assertThatRelationActuallyInDatabase(givenRelation);
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_person#BesslerAnita.admin");
givenRelationship.setContact(null);
return relationshipRepo.save(givenRelationship);
givenRelation.setContact(null);
return relationRepo.save(givenRelation);
});
// then
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
"[403] Subject ", " is not allowed to update hs_office_relationship uuid");
"[403] Subject ", " is not allowed to update hs_office_relation uuid");
}
@Test
public void contactAdmin_canNotUpdateRelatedRelationship() {
public void contactAdmin_canNotUpdateRelatedRelation() {
// given
context("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
final var givenRelation = givenSomeTemporaryRelationBessler(
"Anita", "ninth");
assertThatRelationshipIsVisibleForUserWithRole(
givenRelationship,
assertThatRelationIsVisibleForUserWithRole(
givenRelation,
"hs_office_contact#ninthcontact.admin");
assertThatRelationshipActuallyInDatabase(givenRelationship);
assertThatRelationActuallyInDatabase(givenRelation);
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact.admin");
givenRelationship.setContact(null); // TODO
return relationshipRepo.save(givenRelationship);
givenRelation.setContact(null); // TODO
return relationRepo.save(givenRelation);
});
// then
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
"[403] Subject ", " is not allowed to update hs_office_relationship uuid");
"[403] Subject ", " is not allowed to update hs_office_relation uuid");
}
private void assertThatRelationshipActuallyInDatabase(final HsOfficeRelationshipEntity saved) {
final var found = relationshipRepo.findByUuid(saved.getUuid());
private void assertThatRelationActuallyInDatabase(final HsOfficeRelationEntity saved) {
final var found = relationRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().isNotSameAs(saved).usingRecursiveComparison().isEqualTo(saved);
}
private void assertThatRelationshipIsVisibleForUserWithRole(
final HsOfficeRelationshipEntity entity,
private void assertThatRelationIsVisibleForUserWithRole(
final HsOfficeRelationEntity entity,
final String assumedRoles) {
jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", assumedRoles);
assertThatRelationshipActuallyInDatabase(entity);
assertThatRelationActuallyInDatabase(entity);
}).assertSuccessful();
}
private void assertThatRelationshipIsNotVisibleForUserWithRole(
final HsOfficeRelationshipEntity entity,
private void assertThatRelationIsNotVisibleForUserWithRole(
final HsOfficeRelationEntity entity,
final String assumedRoles) {
jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", assumedRoles);
final var found = relationshipRepo.findByUuid(entity.getUuid());
final var found = relationRepo.findByUuid(entity.getUuid());
assertThat(found).isEmpty();
}).assertSuccessful();
}
@@ -290,63 +290,63 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
class DeleteByUuid {
@Test
public void globalAdmin_withoutAssumedRole_canDeleteAnyRelationship() {
public void globalAdmin_withoutAssumedRole_canDeleteAnyRelation() {
// given
context("superuser-alex@hostsharing.net", null);
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
final var givenRelation = givenSomeTemporaryRelationBessler(
"Anita", "tenth");
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
relationshipRepo.deleteByUuid(givenRelationship.getUuid());
relationRepo.deleteByUuid(givenRelation.getUuid());
});
// then
result.assertSuccessful();
assertThat(jpaAttempt.transacted(() -> {
context("superuser-fran@hostsharing.net", null);
return relationshipRepo.findByUuid(givenRelationship.getUuid());
return relationRepo.findByUuid(givenRelation.getUuid());
}).assertSuccessful().returnedValue()).isEmpty();
}
@Test
public void contactUser_canViewButNotDeleteTheirRelatedRelationship() {
public void contactUser_canViewButNotDeleteTheirRelatedRelation() {
// given
context("superuser-alex@hostsharing.net", null);
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
final var givenRelation = givenSomeTemporaryRelationBessler(
"Anita", "eleventh");
// when
final var result = jpaAttempt.transacted(() -> {
context("contact-admin@eleventhcontact.example.com");
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isPresent();
relationshipRepo.deleteByUuid(givenRelationship.getUuid());
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent();
relationRepo.deleteByUuid(givenRelation.getUuid());
});
// then
result.assertExceptionWithRootCauseMessage(
JpaSystemException.class,
"[403] Subject ", " not allowed to delete hs_office_relationship");
"[403] Subject ", " not allowed to delete hs_office_relation");
assertThat(jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
return relationshipRepo.findByUuid(givenRelationship.getUuid());
return relationRepo.findByUuid(givenRelation.getUuid());
}).assertSuccessful().returnedValue()).isPresent(); // still there
}
@Test
public void deletingARelationshipAlsoDeletesRelatedRolesAndGrants() {
public void deletingARelationAlsoDeletesRelatedRolesAndGrants() {
// given
context("superuser-alex@hostsharing.net");
final var initialRoleNames = Array.from(distinctRoleNamesOf(rawRoleRepo.findAll()));
final var initialGrantNames = Array.from(distinctGrantDisplaysOf(rawGrantRepo.findAll()));
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
final var givenRelation = givenSomeTemporaryRelationBessler(
"Anita", "twelfth");
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
return relationshipRepo.deleteByUuid(givenRelationship.getUuid());
return relationRepo.deleteByUuid(givenRelation.getUuid());
});
// then
@@ -363,7 +363,7 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
final var query = em.createNativeQuery("""
select currentTask, targetTable, targetOp
from tx_journal_v
where targettable = 'hs_office_relationship';
where targettable = 'hs_office_relation';
""");
// when
@@ -371,40 +371,40 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
// then
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating relationship test-data HostsharingeG-FirstGmbH, hs_office_relationship, INSERT]",
"[creating relationship test-data FirstGmbH-Firby, hs_office_relationship, INSERT]");
"[creating relation test-data HostsharingeG-FirstGmbH, hs_office_relation, INSERT]",
"[creating relation test-data FirstGmbH-Firby, hs_office_relation, INSERT]");
}
private HsOfficeRelationshipEntity givenSomeTemporaryRelationshipBessler(final String holderPerson, final String contact) {
private HsOfficeRelationEntity givenSomeTemporaryRelationBessler(final String holderPerson, final String contact) {
return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike(holderPerson).get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike(contact).get(0);
final var newRelationship = HsOfficeRelationshipEntity.builder()
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
.relAnchor(givenAnchorPerson)
.relHolder(givenHolderPerson)
final var newRelation = HsOfficeRelationEntity.builder()
.type(HsOfficeRelationType.REPRESENTATIVE)
.anchor(givenAnchorPerson)
.holder(givenHolderPerson)
.contact(givenContact)
.build();
return toCleanup(relationshipRepo.save(newRelationship));
return toCleanup(relationRepo.save(newRelation));
}).assertSuccessful().returnedValue();
}
void exactlyTheseRelationshipsAreReturned(
final List<HsOfficeRelationshipEntity> actualResult,
final String... relationshipNames) {
void exactlyTheseRelationsAreReturned(
final List<HsOfficeRelationEntity> actualResult,
final String... relationNames) {
assertThat(actualResult)
.extracting(HsOfficeRelationshipEntity::toString)
.containsExactlyInAnyOrder(relationshipNames);
.extracting(HsOfficeRelationEntity::toString)
.containsExactlyInAnyOrder(relationNames);
}
void allTheseRelationshipsAreReturned(
final List<HsOfficeRelationshipEntity> actualResult,
final String... relationshipNames) {
void allTheseRelationsAreReturned(
final List<HsOfficeRelationEntity> actualResult,
final String... relationNames) {
assertThat(actualResult)
.extracting(HsOfficeRelationshipEntity::toString)
.contains(relationshipNames);
.extracting(HsOfficeRelationEntity::toString)
.contains(relationNames);
}
}

View File

@@ -1,44 +0,0 @@
package net.hostsharing.hsadminng.hs.office.relationship;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
class HsOfficeRelationshipEntityUnitTest {
private HsOfficePersonEntity anchor = HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.LEGAL_PERSON)
.tradeName("some trade name")
.build();
private HsOfficePersonEntity holder = HsOfficePersonEntity.builder()
.personType(HsOfficePersonType.NATURAL_PERSON)
.familyName("Meier")
.givenName("Mellie")
.build();
@Test
void toStringReturnsAllProperties() {
final var given = HsOfficeRelationshipEntity.builder()
.relType(HsOfficeRelationshipType.SUBSCRIBER)
.relMark("members-announce")
.relAnchor(anchor)
.relHolder(holder)
.build();
assertThat(given.toString()).isEqualTo("rel(relAnchor='LP some trade name', relType='SUBSCRIBER', relMark='members-announce', relHolder='NP Meier, Mellie')");
}
@Test
void toShortString() {
final var given = HsOfficeRelationshipEntity.builder()
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
.relAnchor(anchor)
.relHolder(holder)
.build();
assertThat(given.toShortString()).isEqualTo("rel(relAnchor='LP some trade name', relType='REPRESENTATIVE', relHolder='NP Meier, Mellie')");
}
}