diff --git a/build.gradle b/build.gradle index 04edf341..876ff878 100644 --- a/build.gradle +++ b/build.gradle @@ -118,8 +118,8 @@ openapiProcessor { springRoot { processorName 'spring' processor 'io.openapiprocessor:openapi-processor-spring:2022.5' - apiPath "$projectDir/src/main/resources/api-definition.yaml" - mapping "$projectDir/src/main/resources/api-mappings.yaml" + apiPath "$projectDir/src/main/resources/api-definition/api-definition.yaml" + mapping "$projectDir/src/main/resources/api-definition/api-mappings.yaml" targetDir "$buildDir/generated/sources/openapi-javax" showWarnings true openApiNullable true diff --git a/doc/hs-office-data-structure.md b/doc/hs-office-data-structure.md index b84264d0..cce17510 100644 --- a/doc/hs-office-data-structure.md +++ b/doc/hs-office-data-structure.md @@ -64,7 +64,7 @@ classDiagram } class partner-MeierGmbH { - +Numeric partnerNumber: 12345 + +Numeric partnerNumber: P-12345 +Relation partnerRel } partner-MeierGmbH *-- rel-MeierGmbH diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java index 69932d5b..a09a33bc 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java @@ -5,8 +5,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import net.hostsharing.hsadminng.errors.DisplayAs; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -14,7 +14,7 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import java.util.UUID; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; // a partial HsOfficeDebitorEntity to reduce the number of SQL queries to load the entity @Entity diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java index 07d85007..2d63df74 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItem.java @@ -15,8 +15,8 @@ import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.CascadeType; @@ -45,7 +45,7 @@ import static java.util.Optional.ofNullable; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.lowerInclusiveFromPostgresDateRange; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.upperInclusiveFromPostgresDateRange; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java index 742cf88f..90235732 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java @@ -4,14 +4,14 @@ import lombok.*; import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import java.util.UUID; import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java index e89e962f..d327f354 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java @@ -15,8 +15,8 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.CascadeType; @@ -42,7 +42,7 @@ import java.util.Optional; import java.util.UUID; import static java.util.Collections.emptyMap; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java index 5be09962..edc26010 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/bankaccount/HsOfficeBankAccountEntity.java @@ -5,8 +5,8 @@ import lombok.experimental.FieldNameConstants; import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import java.io.IOException; @@ -16,7 +16,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Permission.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectReference.UserRole.CREATOR; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "bankaccount_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java index a4267f53..dc5bca3e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/contact/HsOfficeContact.java @@ -12,8 +12,8 @@ import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.persistence.BaseEntity; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Type; @@ -27,7 +27,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @MappedSuperclass @Getter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java index 18e12a11..cc2e504b 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java @@ -10,8 +10,8 @@ import net.hostsharing.hsadminng.errors.DisplayAs; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.GenericGenerator; import jakarta.persistence.*; @@ -31,7 +31,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.ADMIN; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.AGENT; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "coopassettx_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java index 54787ad7..b5329cea 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java @@ -10,8 +10,8 @@ import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import jakarta.persistence.*; import java.io.IOException; @@ -29,7 +29,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.ADMIN; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.AGENT; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "coopsharetx_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java index 32721f0d..011db6a2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java @@ -22,8 +22,10 @@ import jakarta.persistence.PersistenceContext; import jakarta.validation.ValidationException; import java.util.List; import java.util.UUID; +import java.util.function.BiConsumer; import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR; +import static net.hostsharing.hsadminng.repr.TaggedNumber.cropTag; @RestController @@ -49,24 +51,24 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { @Override @Transactional(readOnly = true) - public ResponseEntity> listDebitors( + public ResponseEntity> getListOfDebitors( final String currentSubject, final String assumedRoles, final String name, - final Integer debitorNumber) { + final String debitorNumber) { context.define(currentSubject, assumedRoles); final var entities = debitorNumber != null - ? debitorRepo.findDebitorByDebitorNumber(debitorNumber) + ? debitorRepo.findDebitorByDebitorNumber(cropTag("D-", debitorNumber)) : debitorRepo.findDebitorByOptionalNameLike(name); - final var resources = mapper.mapList(entities, HsOfficeDebitorResource.class); + final var resources = mapper.mapList(entities, HsOfficeDebitorResource.class, ENTITY_TO_RESOURCE_POSTMAPPER); return ResponseEntity.ok(resources); } @Override @Transactional - public ResponseEntity addDebitor( + public ResponseEntity postNewDebitor( String currentSubject, String assumedRoles, HsOfficeDebitorInsertResource body) { @@ -107,13 +109,13 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { .path("/api/hs/office/debitors/{id}") .buildAndExpand(savedEntity.getUuid()) .toUri(); - final var mapped = mapper.map(savedEntity, HsOfficeDebitorResource.class); + final var mapped = mapper.map(savedEntity, HsOfficeDebitorResource.class, ENTITY_TO_RESOURCE_POSTMAPPER); return ResponseEntity.created(uri).body(mapped); } @Override @Transactional(readOnly = true) - public ResponseEntity getDebitorByUuid( + public ResponseEntity getSingleDebitorByUuid( final String currentSubject, final String assumedRoles, final UUID debitorUuid) { @@ -124,7 +126,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { if (result.isEmpty()) { return ResponseEntity.notFound().build(); } - return ResponseEntity.ok(mapper.map(result.get(), HsOfficeDebitorResource.class)); + return ResponseEntity.ok(mapper.map(result.get(), HsOfficeDebitorResource.class, ENTITY_TO_RESOURCE_POSTMAPPER)); } @Override @@ -159,7 +161,11 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { final var saved = debitorRepo.save(current); Hibernate.initialize(saved); - final var mapped = mapper.map(saved, HsOfficeDebitorResource.class); + final var mapped = mapper.map(saved, HsOfficeDebitorResource.class, ENTITY_TO_RESOURCE_POSTMAPPER); return ResponseEntity.ok(mapped); } + + final BiConsumer ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { + resource.setDebitorNumber(entity.getTaggedDebitorNumber()); + }; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java index 2c339605..623fa2cf 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntity.java @@ -14,8 +14,8 @@ import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.JoinFormula; import org.hibernate.annotations.NotFound; @@ -51,7 +51,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.fetchedBySql; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "debitor_rv") @@ -142,19 +142,14 @@ public class HsOfficeDebitorEntity implements BaseEntity, return this; } - private String getDebitorNumberString() { + public String getTaggedDebitorNumber() { return ofNullable(partner) .filter(partner -> debitorNumberSuffix != null) .map(HsOfficePartnerEntity::getPartnerNumber) - .map(Object::toString) - .map(partnerNumber -> partnerNumber + debitorNumberSuffix) + .map(partnerNumber -> DEBITOR_NUMBER_TAG + partnerNumber + debitorNumberSuffix) .orElse(null); } - public Integer getDebitorNumber() { - return ofNullable(getDebitorNumberString()).map(Integer::parseInt).orElse(null); - } - @Override public String toString() { return stringify.apply(this); @@ -162,7 +157,7 @@ public class HsOfficeDebitorEntity implements BaseEntity, @Override public String toShortString() { - return DEBITOR_NUMBER_TAG + getDebitorNumberString(); + return getTaggedDebitorNumber(); } public static RbacView rbac() { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java index bb6cd0f2..30dabb59 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java @@ -16,13 +16,16 @@ public interface HsOfficeDebitorRepository extends Repository findDebitorByDebitorNumber(int partnerNumber, byte debitorNumberSuffix); + WHERE partner.partnerNumber = :partnerNumber + AND debitor.debitorNumberSuffix = :debitorNumberSuffix + """) + List findDebitorByDebitorNumber(int partnerNumber, String debitorNumberSuffix); default List findDebitorByDebitorNumber(int debitorNumber) { - return findDebitorByDebitorNumber( debitorNumber/100, (byte) (debitorNumber%100)); + final var partnerNumber = debitorNumber / 100; + final String suffix = String.format("%02d", debitorNumber % 100); + final var result = findDebitorByDebitorNumber(partnerNumber, suffix); + return result; } @Query(""" diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java index 62dcd1c2..f41bd5c2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java @@ -17,9 +17,9 @@ import java.util.UUID; import java.util.function.BiConsumer; import static java.util.Optional.ofNullable; +import static net.hostsharing.hsadminng.repr.TaggedNumber.cropTag; @RestController - public class HsOfficeMembershipController implements HsOfficeMembershipsApi { @Autowired @@ -33,16 +33,18 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi { @Override @Transactional(readOnly = true) - public ResponseEntity> listMemberships( + public ResponseEntity> getListOfMemberships( final String currentSubject, final String assumedRoles, final UUID partnerUuid, - final Integer memberNumber) { + final String memberNumber) { context.define(currentSubject, assumedRoles); - final var entities = ( memberNumber != null) - ? ofNullable(membershipRepo.findMembershipByMemberNumber(memberNumber)).stream().toList() - : membershipRepo.findMembershipsByOptionalPartnerUuid(partnerUuid); + final var entities = (memberNumber != null) + ? ofNullable(membershipRepo.findMembershipByMemberNumber( + cropTag(HsOfficeMembershipEntity.MEMBER_NUMBER_TAG, memberNumber))).stream() + .toList() + : membershipRepo.findMembershipsByOptionalPartnerUuid(partnerUuid); final var resources = mapper.mapList(entities, HsOfficeMembershipResource.class, SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER); @@ -51,7 +53,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi { @Override @Transactional - public ResponseEntity addMembership( + public ResponseEntity postNewMembership( final String currentSubject, final String assumedRoles, final HsOfficeMembershipInsertResource body) { @@ -74,7 +76,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi { @Override @Transactional(readOnly = true) - public ResponseEntity getMembershipByUuid( + public ResponseEntity getSingleMembershipByUuid( final String currentSubject, final String assumedRoles, final UUID membershipUuid) { @@ -125,7 +127,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi { } final BiConsumer SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { - // TODO.refa: this should be possible via ModelMapper config + resource.setMemberNumber(entity.getTaggedMemberNumber()); resource.setValidFrom(entity.getValidity().lower()); if (entity.getValidity().hasUpperBound()) { resource.setValidTo(entity.getValidity().upper().minusDays(1)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java index 893623d7..1b05a90c 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipEntity.java @@ -13,8 +13,8 @@ import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; import net.hostsharing.hsadminng.rbac.generator.RbacView.SQL; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.Column; @@ -53,7 +53,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.OWNER; import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.TENANT; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.fetchedBySql; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "membership_rv") @@ -130,6 +130,7 @@ public class HsOfficeMembershipEntity implements BaseEntity SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java index f781212e..94ac21e2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateEntity.java @@ -9,8 +9,8 @@ import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.persistence.BaseEntity; import net.hostsharing.hsadminng.rbac.generator.RbacView; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.*; @@ -30,7 +30,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectRefer import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.*; import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; @Entity @Table(schema = "hs_office", name = "sepamandate_rv") diff --git a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java b/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java similarity index 99% rename from src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java rename to src/main/java/net/hostsharing/hsadminng/repr/Stringify.java index 269b0c69..aaa3ea73 100644 --- a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java +++ b/src/main/java/net/hostsharing/hsadminng/repr/Stringify.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.stringify; +package net.hostsharing.hsadminng.repr; import net.hostsharing.hsadminng.errors.DisplayAs; diff --git a/src/main/java/net/hostsharing/hsadminng/stringify/Stringifyable.java b/src/main/java/net/hostsharing/hsadminng/repr/Stringifyable.java similarity index 59% rename from src/main/java/net/hostsharing/hsadminng/stringify/Stringifyable.java rename to src/main/java/net/hostsharing/hsadminng/repr/Stringifyable.java index 70877dc9..397a6c2b 100644 --- a/src/main/java/net/hostsharing/hsadminng/stringify/Stringifyable.java +++ b/src/main/java/net/hostsharing/hsadminng/repr/Stringifyable.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.stringify; +package net.hostsharing.hsadminng.repr; public interface Stringifyable { diff --git a/src/main/java/net/hostsharing/hsadminng/repr/TaggedNumber.java b/src/main/java/net/hostsharing/hsadminng/repr/TaggedNumber.java new file mode 100644 index 00000000..ab445ec0 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/repr/TaggedNumber.java @@ -0,0 +1,15 @@ +package net.hostsharing.hsadminng.repr; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class TaggedNumber { + + public static Integer cropTag(final String tag, final String taggedNumber) { + return taggedNumber.startsWith(tag) ? Integer.valueOf(taggedNumber.substring(tag.length())) : invalidTag(tag, taggedNumber); + } + + private static Integer invalidTag(final String tag, final String taggedNumber) { + throw new IllegalArgumentException("Expected " + tag + "... but got: " + taggedNumber); + } +} diff --git a/src/main/resources/api-definition.yaml b/src/main/resources/api-definition/api-definition.yaml similarity index 100% rename from src/main/resources/api-definition.yaml rename to src/main/resources/api-definition/api-definition.yaml diff --git a/src/main/resources/api-mappings.yaml b/src/main/resources/api-definition/api-mappings.yaml similarity index 100% rename from src/main/resources/api-mappings.yaml rename to src/main/resources/api-definition/api-mappings.yaml diff --git a/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml index bc3d402e..bca2f0a2 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml @@ -12,10 +12,10 @@ components: debitorRel: $ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation' debitorNumber: - type: integer - format: int32 - minimum: 1000000 - maximum: 9999999 + type: string + minLength: 9 + maxLength: 9 + pattern: 'D-[0-9]{7}' debitorNumberSuffix: type: string pattern: '^[0-9][0-9]$' diff --git a/src/main/resources/api-definition/hs-office/hs-office-debitors-with-uuid.yaml b/src/main/resources/api-definition/hs-office/hs-office-debitors-with-uuid.yaml index feb8e473..22548852 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-debitors-with-uuid.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-debitors-with-uuid.yaml @@ -2,7 +2,7 @@ get: tags: - hs-office-debitors description: 'Fetch a single debitor by its uuid, if visible for the current subject.' - operationId: getDebitorByUuid + operationId: getSingleDebitorByUuid parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml b/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml index 16554531..c825817f 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml @@ -3,7 +3,7 @@ get: description: Returns the list of (optionally filtered) debitors which are visible to the current subject or any of it's assumed roles. tags: - hs-office-debitors - operationId: listDebitors + operationId: getListOfDebitors parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' @@ -17,7 +17,10 @@ get: in: query required: false schema: - type: integer + type: string + minLength: 9 + maxLength: 9 + pattern: 'D-[0-9]{7}' description: Debitor number of the requested debitor. responses: "200": @@ -37,7 +40,7 @@ post: summary: Adds a new debitor. tags: - hs-office-debitors - operationId: addDebitor + operationId: postNewDebitor parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-membership-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-membership-schemas.yaml index 20459f4e..cc723a41 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-membership-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-membership-schemas.yaml @@ -26,9 +26,10 @@ components: mainDebitor: $ref: 'hs-office-debitor-schemas.yaml#/components/schemas/HsOfficeDebitor' memberNumber: - type: integer - minimum: 1000000 - maximum: 9999999 + type: string + minLength: 9 + maxLength: 9 + pattern: 'M-[0-9]{7}' memberNumberSuffix: type: string minLength: 2 diff --git a/src/main/resources/api-definition/hs-office/hs-office-memberships-with-uuid.yaml b/src/main/resources/api-definition/hs-office/hs-office-memberships-with-uuid.yaml index 1511e09f..820fc0bc 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-memberships-with-uuid.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-memberships-with-uuid.yaml @@ -2,7 +2,7 @@ get: tags: - hs-office-memberships description: 'Fetch a single membership by its uuid, if visible for the current subject.' - operationId: getMembershipByUuid + operationId: getSingleMembershipByUuid parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-memberships.yaml b/src/main/resources/api-definition/hs-office/hs-office-memberships.yaml index 8436134b..9b2c27b4 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-memberships.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-memberships.yaml @@ -4,7 +4,7 @@ get: The list can optionally be filtered by either the `partnerUuid` or the `memberNumber` - not both at the same time. tags: - hs-office-memberships - operationId: listMemberships + operationId: getListOfMemberships parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' @@ -19,7 +19,10 @@ get: in: query required: false schema: - type: integer + type: string + minLength: 9 + maxLength: 9 + pattern: 'M-[0-9]{7}' description: Member number, exclusive to `partnerUuid`. responses: "200": @@ -39,7 +42,7 @@ post: summary: Adds a new membership. tags: - hs-office-memberships - operationId: addMembership + operationId: postNewMembership parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml index bd327e10..2fd3d39b 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-partner-schemas.yaml @@ -10,10 +10,10 @@ components: type: string format: uuid partnerNumber: - type: integer - format: int8 - minimum: 10000 - maximum: 99999 + type: string + minLength: 7 + maxLength: 7 + pattern: 'P-[0-9]{5}' partnerRel: $ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation' details: @@ -86,10 +86,10 @@ components: type: object properties: partnerNumber: - type: integer - format: int8 - minimum: 10000 - maximum: 99999 + type: string + minLength: 7 + maxLength: 7 + pattern: 'P-[0-9]{5}' partnerRel: $ref: '#/components/schemas/HsOfficePartnerRelInsert' details: diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java index 3c3cae0c..e53a7c75 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java @@ -77,7 +77,7 @@ public class ArchitectureTest { "..rbac.grant", "..rbac.role", "..rbac.object", - "..stringify" + "..repr" // ATTENTION: Don't simply add packages here, also add arch rules for the new package! ); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java index f6623fe0..53f32e80 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java @@ -72,7 +72,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu EntityManager em; @Nested - class ListDebitors { + class GetListOfDebitors { @Test void globalAdmin_withoutAssumedRoles_canViewAllDebitors_ifNoCriteriaGiven() { @@ -110,10 +110,10 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu "phoneNumbers": { "phone_office": "+49 123 1234567" } } }, - "debitorNumber": 1000111, + "debitorNumber": "D-1000111", "debitorNumberSuffix": "11", "partner": { - "partnerNumber": 10001, + "partnerNumber": "P-10001", "partnerRel": { "anchor": { "personType": "LEGAL_PERSON", @@ -165,10 +165,10 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu "emailAddresses": { "main": "contact-admin@secondcontact.example.com" } } }, - "debitorNumber": 1000212, + "debitorNumber": "D-1000212", "debitorNumberSuffix": "12", "partner": { - "partnerNumber": 10002, + "partnerNumber": "P-10002", "partnerRel": { "anchor": {"tradeName": "Hostsharing eG"}, "holder": {"tradeName": "Second e.K."}, @@ -199,10 +199,10 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu "emailAddresses": { "main": "contact-admin@thirdcontact.example.com" } } }, - "debitorNumber": 1000313, + "debitorNumber": "D-1000313", "debitorNumberSuffix": "13", "partner": { - "partnerNumber": 10003, + "partnerNumber": "P-10003", "partnerRel": { "anchor": {"tradeName": "Hostsharing eG"}, "holder": {"tradeName": "Third OHG"}, @@ -237,15 +237,15 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu .header("current-subject", "superuser-alex@hostsharing.net") .port(port) .when() - .get("http://localhost/api/hs/office/debitors?debitorNumber=1000212") + .get("http://localhost/api/hs/office/debitors?debitorNumber=D-1000212") .then().log().all().assertThat() .statusCode(200) .contentType("application/json") .body("", lenientlyEquals(""" [ { - "debitorNumber": 1000212, - "partner": { "partnerNumber": 10002 }, + "debitorNumber": "D-1000212", + "partner": { "partnerNumber": "P-10002" }, "debitorRel": { "contact": { "caption": "second contact" } }, @@ -260,7 +260,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu } @Nested - class AddDebitor { + class PostNewDebitor { @Test void globalAdmin_withoutAssumedRole_canAddDebitorWithBankAccount() { @@ -436,7 +436,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu } @Nested - class GetDebitor { + class GetSingleDebitorByUuid { @Test void globalAdmin_withoutAssumedRole_canGetArbitraryDebitor() { @@ -534,8 +534,8 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType("application/json") .body("", lenientlyEquals(""" { - "debitorNumber": 1000111, - "partner": { "partnerNumber": 10001 }, + "debitorNumber": "D-1000111", + "partner": { "partnerNumber": "P-10001" }, "debitorRel": { "contact": { "caption": "first contact" } }, "refundBankAccount": null } @@ -581,10 +581,10 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu "mark": null, "contact": { "caption": "fourth contact" } }, - "debitorNumber": 10004${debitorNumberSuffix}, + "debitorNumber": "D-10004${debitorNumberSuffix}", "debitorNumberSuffix": "${debitorNumberSuffix}", "partner": { - "partnerNumber": 10004, + "partnerNumber": "P-10004", "partnerRel": { "anchor": { "tradeName": "Hostsharing eG" }, "holder": { "tradeName": "Fourth eG" }, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java index 951ff536..a1c5ea0e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorEntityUnitTest.java @@ -65,9 +65,9 @@ class HsOfficeDebitorEntityUnitTest { .build()) .build(); - final var result = given.getDebitorNumber(); + final var result = given.getTaggedDebitorNumber(); - assertThat(result).isEqualTo(1234567); + assertThat(result).isEqualTo("D-1234567"); } @Test @@ -78,7 +78,7 @@ class HsOfficeDebitorEntityUnitTest { .partner(null) .build(); - final var result = given.getDebitorNumber(); + final var result = given.getTaggedDebitorNumber(); assertThat(result).isNull(); } @@ -91,7 +91,7 @@ class HsOfficeDebitorEntityUnitTest { .partner(HsOfficePartnerEntity.builder().build()) .build(); - final var result = given.getDebitorNumber(); + final var result = given.getTaggedDebitorNumber(); assertThat(result).isNull(); } @@ -106,7 +106,7 @@ class HsOfficeDebitorEntityUnitTest { .build()) .build(); - final var result = given.getDebitorNumber(); + final var result = given.getTaggedDebitorNumber(); assertThat(result).isNull(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java index f3793da1..2a8beba2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerAcceptanceTest.java @@ -77,24 +77,24 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .body("", lenientlyEquals(""" [ { - "partner": { "partnerNumber": 10001 }, - "memberNumber": 1000101, + "partner": { "partnerNumber": "P-10001" }, + "memberNumber": "M-1000101", "memberNumberSuffix": "01", "validFrom": "2022-10-01", "validTo": null, "status": "ACTIVE" }, { - "partner": { "partnerNumber": 10002 }, - "memberNumber": 1000202, + "partner": { "partnerNumber": "P-10002" }, + "memberNumber": "M-1000202", "memberNumberSuffix": "02", "validFrom": "2022-10-01", "validTo": null, "status": "ACTIVE" }, { - "partner": { "partnerNumber": 10003 }, - "memberNumber": 1000303, + "partner": { "partnerNumber": "P-10003" }, + "memberNumber": "M-1000303", "memberNumberSuffix": "03", "validFrom": "2022-10-01", "validTo": null, @@ -124,8 +124,8 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .body("", lenientlyEquals(""" [ { - "partner": { "partnerNumber": 10001 }, - "memberNumber": 1000101, + "partner": { "partnerNumber": "P-10001" }, + "memberNumber": "M-1000101", "memberNumberSuffix": "01", "validFrom": "2022-10-01", "validTo": null, @@ -144,7 +144,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .header("current-subject", "superuser-alex@hostsharing.net") .port(port) .when() - .queryParam("memberNumber", 1000202 ) + .queryParam("memberNumber", "M-1000202" ) .get("http://localhost/api/hs/office/memberships") .then().log().all().assertThat() .statusCode(200) @@ -152,8 +152,8 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .body("", lenientlyEquals(""" [ { - "partner": { "partnerNumber": 10002 }, - "memberNumber": 1000202, + "partner": { "partnerNumber": "P-10002" }, + "memberNumber": "M-1000202", "memberNumberSuffix": "02", "validFrom": "2022-10-01", "validTo": null, @@ -195,8 +195,8 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .statusCode(201) .contentType(ContentType.JSON) .body("uuid", isUuidValid()) - .body("partner.partnerNumber", is(10003)) - .body("memberNumber", is(expectedMemberNumber)) + .body("partner.partnerNumber", is("P-10003")) + .body("memberNumber", is("M-" + expectedMemberNumber)) .body("memberNumberSuffix", is(givenMemberSuffix)) .body("validFrom", is("2022-10-13")) .body("validTo", equalTo(null)) @@ -230,8 +230,8 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .contentType("application/json") .body("", lenientlyEquals(""" { - "partner": { "partnerNumber": 10001 }, - "memberNumber": 1000101, + "partner": { "partnerNumber": "P-10001" }, + "memberNumber": "M-1000101", "memberNumberSuffix": "01", "validFrom": "2022-10-01", "validTo": null, @@ -256,7 +256,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle } @Test - void parnerRelAgent_canGetRelatedMembership() { + void partnerRelAgent_canGetRelatedMembership() { context.define("superuser-alex@hostsharing.net"); final var givenMembershipUuid = membershipRepo.findMembershipByMemberNumber(1000303).getUuid(); @@ -272,8 +272,8 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .contentType("application/json") .body("", lenientlyEquals(""" { - "partner": { "partnerNumber": 10003 }, - "memberNumber": 1000303, + "partner": { "partnerNumber": "P-10003" }, + "memberNumber": "M-1000303", "memberNumberSuffix": "03", "validFrom": "2022-10-01", "validTo": null, @@ -309,7 +309,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle .statusCode(200) .contentType(ContentType.JSON) .body("uuid", isUuidValid()) - .body("partner.partnerNumber", is(givenMembership.getPartner().getPartnerNumber())) + .body("partner.partnerNumber", is("P-" + givenMembership.getPartner().getPartnerNumber())) .body("memberNumberSuffix", is(givenMembership.getMemberNumberSuffix())) .body("validFrom", is("2022-11-01")) .body("validTo", is("2023-12-31")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java index 2306fcca..cc4b7d0d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java @@ -46,14 +46,14 @@ public class HsOfficeMembershipControllerRestTest { EntityManagerWrapper em; @Nested - class GetMemberships { + class GetListOfMemberships { @Test void findMembershipByNonExistingMemberNumberReturnsEmptyList() throws Exception { // when mockMvc.perform(MockMvcRequestBuilders - .get("/api/hs/office/memberships?memberNumber=12345") + .get("/api/hs/office/memberships?memberNumber=M-1234501") .header("current-subject", "superuser-alex@hostsharing.net") .contentType(MediaType.APPLICATION_JSON) .content(""" @@ -73,7 +73,7 @@ public class HsOfficeMembershipControllerRestTest { } @Nested - class AddMembership { + class PostNewMembership { @Test void respondBadRequest_ifPartnerUuidIsMissing() throws Exception { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java index c2ec1271..9f2f3318 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerAcceptanceTest.java @@ -71,11 +71,11 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType("application/json") .body("", lenientlyEquals(""" [ - { partnerNumber: 10001 }, - { partnerNumber: 10002 }, - { partnerNumber: 10003 }, - { partnerNumber: 10004 }, - { partnerNumber: 10010 } + { partnerNumber: "P-10001" }, + { partnerNumber: "P-10002" }, + { partnerNumber: "P-10003" }, + { partnerNumber: "P-10004" }, + { partnerNumber: "P-10010" } ] """)); // @formatter:on @@ -100,7 +100,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20002", + "partnerNumber": "P-20002", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -123,7 +123,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body("", lenientlyEquals(""" { - "partnerNumber": 20002, + "partnerNumber": "P-20002", "partnerRel": { "anchor": { "tradeName": "Hostsharing eG" }, "holder": { "tradeName": "Third OHG" }, @@ -159,7 +159,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20003", + "partnerNumber": "P-20003", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -197,7 +197,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20004", + "partnerNumber": "P-20004", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -247,7 +247,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType("application/json") .body("", lenientlyEquals(""" { - "partnerNumber": 10001, + "partnerNumber": "P-10001", "partnerRel": { "anchor": { "tradeName": "Hostsharing eG" }, "holder": { "tradeName": "First GmbH" }, @@ -320,7 +320,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body(""" { - "partnerNumber": "20011", + "partnerNumber": "P-20011", "partnerRel.uuid": "%s", "details": { "registrationOffice": "Temp Registergericht Aurich", @@ -339,7 +339,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu .contentType(ContentType.JSON) .body("", lenientlyEquals(""" { - "partnerNumber": 20011, + "partnerNumber": "P-20011", "partnerRel": { "anchor": { "tradeName": "Hostsharing eG" }, "holder": { "tradeName": "Third OHG" }, diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java index 889e776f..74270f69 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java @@ -99,7 +99,7 @@ class HsOfficePartnerControllerRestTest { .contentType(MediaType.APPLICATION_JSON) .content(""" { - "partnerNumber": "20002", + "partnerNumber": "P-20002", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", @@ -136,7 +136,7 @@ class HsOfficePartnerControllerRestTest { .contentType(MediaType.APPLICATION_JSON) .content(""" { - "partnerNumber": "20002", + "partnerNumber": "P-20002", "partnerRel": { "anchor.uuid": "%s", "holder.uuid": "%s", diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java index 13af695b..0f7362df 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java @@ -8,8 +8,9 @@ import net.hostsharing.hsadminng.hs.office.scenarios.contact.ReplaceContactData; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateExternalDebitorForPartner; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSelfDebitorForPartner; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSepaMandateForDebitor; -import net.hostsharing.hsadminng.hs.office.scenarios.debitor.FinallyDeleteSepaMandateForDebitor; +import net.hostsharing.hsadminng.hs.office.scenarios.debitor.DeleteDebitor; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.DontDeleteDefaultDebitor; +import net.hostsharing.hsadminng.hs.office.scenarios.debitor.FinallyDeleteSepaMandateForDebitor; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.InvalidateSepaMandateForDebitor; import net.hostsharing.hsadminng.hs.office.scenarios.membership.CancelMembership; import net.hostsharing.hsadminng.hs.office.scenarios.membership.CreateMembership; @@ -20,10 +21,9 @@ import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopshares.Creat import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopshares.CreateCoopSharesRevertTransaction; import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopshares.CreateCoopSharesSubscriptionTransaction; import net.hostsharing.hsadminng.hs.office.scenarios.partner.AddOperationsContactToPartner; -import net.hostsharing.hsadminng.hs.office.scenarios.partner.CreatePartner; -import net.hostsharing.hsadminng.hs.office.scenarios.debitor.DeleteDebitor; -import net.hostsharing.hsadminng.hs.office.scenarios.partner.DeletePartner; import net.hostsharing.hsadminng.hs.office.scenarios.partner.AddRepresentativeToPartner; +import net.hostsharing.hsadminng.hs.office.scenarios.partner.CreatePartner; +import net.hostsharing.hsadminng.hs.office.scenarios.partner.DeletePartner; import net.hostsharing.hsadminng.hs.office.scenarios.person.ShouldUpdatePersonData; import net.hostsharing.hsadminng.hs.office.scenarios.subscription.RemoveOperationsContactFromPartner; import net.hostsharing.hsadminng.hs.office.scenarios.subscription.SubscribeToMailinglist; @@ -55,10 +55,10 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(1010) - @Produces(explicitly = "Partner: P-31010 - Test AG", implicitly = {"Person: Test AG", "Contact: Test AG - Hamburg"}) + @Produces(explicitly = "Partner: P-31010 - Test AG", implicitly = { "Person: Test AG", "Contact: Test AG - Hamburg" }) void shouldCreateLegalPersonAsPartner() { new CreatePartner(this) - .given("partnerNumber", 31010) + .given("partnerNumber", "P-31010") .given("personType", "LEGAL_PERSON") .given("tradeName", "Test AG") .given("contactCaption", "Test AG - Hamburg") @@ -77,10 +77,11 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(1011) - @Produces(explicitly = "Partner: P-31011 - Michelle Matthieu", implicitly = {"Person: Michelle Matthieu", "Contact: Michelle Matthieu"}) + @Produces(explicitly = "Partner: P-31011 - Michelle Matthieu", implicitly = { "Person: Michelle Matthieu", + "Contact: Michelle Matthieu" }) void shouldCreateNaturalPersonAsPartner() { new CreatePartner(this) - .given("partnerNumber", 31011) + .given("partnerNumber", "P-31011") .given("personType", "NATURAL_PERSON") .given("givenName", "Michelle") .given("familyName", "Matthieu") @@ -148,7 +149,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Order(1090) void shouldDeletePartner() { new DeletePartner(this) - .given("partnerNumber", 31020) + .given("partnerNumber", "P-31020") .doRun(); } @@ -191,16 +192,16 @@ class HsOfficeScenarioTests extends ScenarioTest { .given("partnerName", "Test AG") .given("newContactCaption", "Test AG - China") .given("newPostalAddress", """ - "firm": "Test AG", - "name": "Fi Zhong-Kha", - "building": "Thi Chi Koh Building", - "street": "No.2 Commercial Second Street", - "district": "Niushan Wei Wu", - "city": "Dongguan City", - "province": "Guangdong Province", - "country": "China" - """) - .given("newOfficePhoneNumber", "++15 999 654321" ) + "firm": "Test AG", + "name": "Fi Zhong-Kha", + "building": "Thi Chi Koh Building", + "street": "No.2 Commercial Second Street", + "district": "Niushan Wei Wu", + "city": "Dongguan City", + "province": "Guangdong Province", + "country": "China" + """) + .given("newOfficePhoneNumber", "++15 999 654321") .given("newEmailAddress", "norden@test-ag.example.org") .doRun(); } @@ -218,9 +219,9 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(2010) @Requires("Partner: P-31010 - Test AG") - @Produces("Debitor: Test AG - main debitor") + @Produces("Debitor: D-3101000 - Test AG - main debitor") void shouldCreateSelfDebitorForPartner() { - new CreateSelfDebitorForPartner(this, "Debitor: Test AG - main debitor") + new CreateSelfDebitorForPartner(this) .given("partnerPersonTradeName", "Test AG") .given("billingContactCaption", "Test AG - billing department") .given("billingContactEmailAddress", "billing@test-ag.example.org") @@ -238,7 +239,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(2011) @Requires("Person: Test AG") - @Produces("Debitor: Billing GmbH") + @Produces("Debitor: D-3101001 - Test AG - main debitor") void shouldCreateExternalDebitorForPartner() { new CreateExternalDebitorForPartner(this) .given("partnerPersonTradeName", "Test AG") @@ -258,9 +259,10 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(2020) @Requires("Person: Test AG") + @Produces(explicitly = "Debitor: D-3101000 - Test AG - delete debitor", permanent = false) void shouldDeleteDebitor() { new DeleteDebitor(this) - .given("partnerNumber", 31020) + .given("partnerNumber", "P-31020") .given("debitorSuffix", "02") .doRun(); } @@ -271,7 +273,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Disabled("see TODO.spec in DontDeleteDefaultDebitor") void shouldNotDeleteDefaultDebitor() { new DontDeleteDefaultDebitor(this) - .given("partnerNumber", 31010) + .given("partnerNumber", "P-31010") .given("debitorSuffix", "00") .doRun(); } @@ -283,7 +285,7 @@ class HsOfficeScenarioTests extends ScenarioTest { void shouldCreateSepaMandateForDebitor() { new CreateSepaMandateForDebitor(this) // existing debitor - .given("debitorNumber", "3101000") + .given("debitorNumber", "D-3101000") // new sepa-mandate .given("mandateReference", "Test AG - main debitor") @@ -337,7 +339,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Produces("Coop-Shares SUBSCRIPTION Transaction") void shouldSubscribeCoopShares() { new CreateCoopSharesSubscriptionTransaction(this) - .given("memberNumber", "3101000") + .given("memberNumber", "M-3101000") .given("reference", "sign 2024-01-15") .given("shareCount", 100) .given("comment", "Signing the Membership") @@ -350,7 +352,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Requires("Membership: M-3101000 - Test AG") void shouldRevertCoopSharesSubscription() { new CreateCoopSharesRevertTransaction(this) - .given("memberNumber", "3101000") + .given("memberNumber", "M-3101000") .given("comment", "reverting some incorrect transaction") .given("dateOfIncorrectTransaction", "2024-02-15") .doRun(); @@ -362,7 +364,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Produces("Coop-Shares CANCELLATION Transaction") void shouldCancelCoopSharesSubscription() { new CreateCoopSharesCancellationTransaction(this) - .given("memberNumber", "3101000") + .given("memberNumber", "M-3101000") .given("reference", "cancel 2024-01-15") .given("sharesToCancel", 8) .given("comment", "Cancelling 8 Shares") @@ -376,9 +378,9 @@ class HsOfficeScenarioTests extends ScenarioTest { @Produces("Coop-Assets DEPOSIT Transaction") void shouldSubscribeCoopAssets() { new CreateCoopAssetsDepositTransaction(this) - .given("memberNumber", "3101000") + .given("memberNumber", "M-3101000") .given("reference", "sign 2024-01-15") - .given("assetValue", 100*64) + .given("assetValue", 100 * 64) .given("comment", "disposal for initial shares") .given("transactionDate", "2024-01-15") .doRun(); @@ -386,10 +388,10 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(4302) - @Requires("Membership: M-3101000 - Test AG") + @Requires("Coop-Assets DEPOSIT Transaction") void shouldRevertCoopAssetsSubscription() { new CreateCoopAssetsRevertTransaction(this) - .given("memberNumber", "3101000") + .given("memberNumber", "M-3101000") .given("comment", "reverting some incorrect transaction") .given("dateOfIncorrectTransaction", "2024-02-15") .doRun(); @@ -401,9 +403,9 @@ class HsOfficeScenarioTests extends ScenarioTest { @Produces("Coop-Assets DISBURSAL Transaction") void shouldDisburseCoopAssets() { new CreateCoopAssetsDisbursalTransaction(this) - .given("memberNumber", "3101000") + .given("memberNumber", "M-3101000") .given("reference", "cancel 2024-01-15") - .given("valueToDisburse", 8*64) + .given("valueToDisburse", 8 * 64) .given("comment", "disbursal according to shares cancellation") .given("transactionDate", "2024-02-15") .doRun(); @@ -414,7 +416,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Requires("Membership: M-3101000 - Test AG") void shouldCancelMembershipOfPartner() { new CancelMembership(this) - .given("memberNumber", "3101000") + .given("memberNumber", "M-3101000") .given("validTo", "2025-12-30") .given("newStatus", "CANCELLED") .doRun(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/Produces.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/Produces.java index 07bc4e47..5d24fd2c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/Produces.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/Produces.java @@ -12,4 +12,5 @@ public @interface Produces { String value() default ""; // same as explicitly, makes it possible to omit the property name String explicitly() default ""; // same as value String[] implicitly() default {}; + boolean permanent() default true; // false means that the object gets deleted again in the process } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/ScenarioTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/ScenarioTest.java index 530eba74..3e0dab34 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/ScenarioTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/ScenarioTest.java @@ -113,6 +113,8 @@ public abstract class ScenarioTest extends ContextBasedTest { // and it does not produce anything we already have (would cause errors) SetUtils.intersection(testMethodProduces, knowVariables().keySet()).isEmpty() ) { + assertThat(producesAnnot.permanent()).as("cannot depend on non-permanent producer: " + potentialProducerMethod); + // then we recursively produce the pre-requisites of the producer method callRequiredProducers(potentialProducerMethod); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/CreateSelfDebitorForPartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/CreateSelfDebitorForPartner.java index 1cc7a049..41b40ee6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/CreateSelfDebitorForPartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/CreateSelfDebitorForPartner.java @@ -9,8 +9,8 @@ import static org.springframework.http.HttpStatus.OK; public class CreateSelfDebitorForPartner extends UseCase { - public CreateSelfDebitorForPartner(final ScenarioTest testSuite, final String resultAlias) { - super(testSuite, resultAlias); + public CreateSelfDebitorForPartner(final ScenarioTest testSuite) { + super(testSuite); } @Override diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/DeleteDebitor.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/DeleteDebitor.java index 19a0f159..84e9cd30 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/DeleteDebitor.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/debitor/DeleteDebitor.java @@ -9,7 +9,7 @@ public class DeleteDebitor extends UseCase { public DeleteDebitor(final ScenarioTest testSuite) { super(testSuite); - requires("Debitor: Test AG - delete debitor", alias -> new CreateSelfDebitorForPartner(testSuite, alias) + requires("Debitor: Test AG - delete debitor", alias -> new CreateSelfDebitorForPartner(testSuite) .given("partnerPersonTradeName", "Test AG") .given("billingContactCaption", "Test AG - billing department") .given("billingContactEmailAddress", "billing@test-ag.example.org") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopassets/CreateCoopAssetsRevertTransaction.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopassets/CreateCoopAssetsRevertTransaction.java index 0750847c..a83c21a2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopassets/CreateCoopAssetsRevertTransaction.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopassets/CreateCoopAssetsRevertTransaction.java @@ -9,7 +9,7 @@ public class CreateCoopAssetsRevertTransaction extends CreateCoopAssetsTransacti requires("CoopAssets-Transaction with incorrect assetValue", alias -> new CreateCoopAssetsDepositTransaction(testSuite) - .given("memberNumber", "3101000") + .given("memberNumber", "%{memberNumber}") .given("reference", "sign %{dateOfIncorrectTransaction}") // same as revertedAssetTx .given("assetValue", 10) .given("comment", "coop-assets deposit transaction with wrong asset value") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopshares/CreateCoopSharesRevertTransaction.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopshares/CreateCoopSharesRevertTransaction.java index 03963834..8464393a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopshares/CreateCoopSharesRevertTransaction.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/coopshares/CreateCoopSharesRevertTransaction.java @@ -9,7 +9,7 @@ public class CreateCoopSharesRevertTransaction extends CreateCoopSharesTransacti requires("CoopShares-Transaction with incorrect shareCount", alias -> new CreateCoopSharesSubscriptionTransaction(testSuite) - .given("memberNumber", "3101000") + .given("memberNumber", "%{memberNumber}") .given("reference", "sign %{dateOfIncorrectTransaction}") // same as revertedShareTx .given("shareCount", 100) .given("comment", "coop-shares subscription transaction with wrong share count") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java index 82a011dc..7812a9fb 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java @@ -72,21 +72,21 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl .body("", lenientlyEquals(""" [ { - "debitor": { "debitorNumber": 1000111 }, + "debitor": { "debitorNumber": "D-1000111" }, "bankAccount": { "holder": "First GmbH" }, "reference": "ref-10001-11", "validFrom": "2022-10-01", "validTo": "2026-12-31" }, { - "debitor": { "debitorNumber": 1000212 }, + "debitor": { "debitorNumber": "D-1000212" }, "bankAccount": { "holder": "Second e.K." }, "reference": "ref-10002-12", "validFrom": "2022-10-01", "validTo": "2026-12-31" }, { - "debitor": { "debitorNumber": 1000313 }, + "debitor": { "debitorNumber": "D-1000313" }, "bankAccount": { "holder": "Third OHG" }, "reference": "ref-10003-13", "validFrom": "2022-10-01", @@ -113,7 +113,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl .body("", lenientlyEquals(""" [ { - "debitor": { "debitorNumber": 1000111 }, + "debitor": { "debitorNumber": "D-1000111" }, "bankAccount": { "iban": "DE02120300000000202051", "holder": "First GmbH" @@ -158,7 +158,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl .statusCode(201) .contentType(ContentType.JSON) .body("uuid", isUuidValid()) - .body("debitor.partner.partnerNumber", is(10003)) + .body("debitor.partner.partnerNumber", is("P-10003")) .body("bankAccount.iban", is("DE02200505501015871393")) .body("reference", is("temp ref CAT A")) .body("validFrom", is("2022-10-13")) @@ -280,7 +280,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl .contentType("application/json") .body("", lenientlyEquals(""" { - "debitor": { "debitorNumber": 1000111 }, + "debitor": { "debitorNumber": "D-1000111" }, "bankAccount": { "holder": "First GmbH", "iban": "DE02120300000000202051" @@ -327,7 +327,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl .contentType("application/json") .body("", lenientlyEquals(""" { - "debitor": { "debitorNumber": 1000111 }, + "debitor": { "debitorNumber": "D-1000111" }, "bankAccount": { "holder": "First GmbH", "iban": "DE02120300000000202051" @@ -367,7 +367,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl .statusCode(200) .contentType(ContentType.JSON) .body("uuid", isUuidValid()) - .body("debitor.debitorNumber", is(1000111)) + .body("debitor.debitorNumber", is("D-1000111")) .body("bankAccount.iban", is("DE02120300000000202051")) .body("reference", is("temp ref CAT Z - patched")) .body("agreement", is("2020-06-01")) @@ -410,7 +410,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl .statusCode(200) .contentType(ContentType.JSON) .body("uuid", isUuidValid()) - .body("debitor.debitorNumber", is(1000111)) + .body("debitor.debitorNumber", is("D-1000111")) .body("bankAccount.iban", is("DE02120300000000202051")) .body("reference", is("temp ref CAT Z")) .body("validFrom", is("2022-11-01")) diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java b/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java index 0267871f..1d22056d 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/test/StringifyUnitTest.java @@ -2,13 +2,13 @@ package net.hostsharing.hsadminng.rbac.test; import lombok.*; import lombok.experimental.FieldNameConstants; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; +import net.hostsharing.hsadminng.repr.Stringify; +import net.hostsharing.hsadminng.repr.Stringifyable; import org.junit.jupiter.api.Test; import java.util.UUID; -import static net.hostsharing.hsadminng.stringify.Stringify.stringify; +import static net.hostsharing.hsadminng.repr.Stringify.stringify; import static org.assertj.core.api.Assertions.assertThat; class StringifyUnitTest { diff --git a/src/test/java/net/hostsharing/hsadminng/repr/TaggedNumberUnitTest.java b/src/test/java/net/hostsharing/hsadminng/repr/TaggedNumberUnitTest.java new file mode 100644 index 00000000..ca373f38 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/repr/TaggedNumberUnitTest.java @@ -0,0 +1,22 @@ +package net.hostsharing.hsadminng.repr; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +class TaggedNumberUnitTest { + + @Test + void cropsProperTag() { + assertThat(TaggedNumber.cropTag("P-", "P-12345")).isEqualTo(12345); + } + + @Test + void throwsExceptionForImproperTag() { + final var exception = catchThrowable(() -> TaggedNumber.cropTag("P-", "X-12345")); + assertThat(exception).isInstanceOf(IllegalArgumentException.class); + assertThat(exception.getMessage()).isEqualTo("Expected P-... but got: X-12345"); + } + +}