From c1cc9c15896360f575cf3471ed9328b620cac7d5 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 27 Nov 2024 16:05:13 +0100 Subject: [PATCH] add REST-tests: - MEMBERSHIP_UUID_NOT_FOUND_OR_NOT_ACCESSIBLE - MEMBERSHIP_UUID_AND_MEMBER_NUMBER_MUST_NOT_BE_GIVEN_BOTH - REVERSAL_ASSET_TRANSACTION_REQUIRES_REVERTED_ASSET_TX_UUID --- ...OfficeCoopAssetsTransactionController.java | 10 +++++----- ...opAssetsTransactionControllerRestTest.java | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionController.java index 4ec037b3..d3b99280 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionController.java @@ -217,7 +217,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse final HsOfficeMembershipEntity membership = ofNullable(emw.find( HsOfficeMembershipEntity.class, resource.getMembershipUuid())) - .orElseThrow(() -> new EntityNotFoundException("ERROR: [400] membership.uuid %s not found".formatted( + .orElseThrow(() -> new EntityNotFoundException("membership.uuid %s not found".formatted( resource.getMembershipUuid()))); entity.setMembership(membership); } @@ -227,7 +227,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse throw new ValidationException("REVERSAL asset transaction requires revertedAssetTx.uuid"); } final var revertedAssetTx = coopAssetsTransactionRepo.findByUuid(resource.getRevertedAssetTxUuid()) - .orElseThrow(() -> new EntityNotFoundException("ERROR: [400] revertedAssetTx.uuid %s not found".formatted( + .orElseThrow(() -> new EntityNotFoundException("revertedAssetTx.uuid %s not found".formatted( resource.getRevertedAssetTxUuid()))); revertedAssetTx.setReversalAssetTx(entity); entity.setRevertedAssetTx(revertedAssetTx); @@ -267,11 +267,11 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse final var adoptingMembershipUuid = resource.getAdoptingMembershipUuid(); final var adoptingMembershipMemberNumber = resource.getAdoptingMembershipMemberNumber(); if (adoptingMembershipUuid != null && adoptingMembershipMemberNumber != null) { - throw new IllegalArgumentException( + throw new ValidationException( // @formatter:off resource.getTransactionType() == HsOfficeCoopAssetsTransactionTypeResource.TRANSFER - ? "[400] either adoptingMembership.uuid or adoptingMembership.memberNumber can be given, not both" - : "[400] adoptingMembership.uuid and adoptingMembership.memberNumber must not be given for transactionType=" + ? "either adoptingMembership.uuid or adoptingMembership.memberNumber can be given, not both" + : "adoptingMembership.uuid and adoptingMembership.memberNumber must not be given for transactionType=" + resource.getTransactionType()); // @formatter:on } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerRestTest.java index 00490048..bd1a0698 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerRestTest.java @@ -500,6 +500,24 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { requestBody -> requestBody.without("membership.uuid"), "[membershipUuid must not be null but is \"null\"]"), // TODO.impl: should be membership.uuid, Spring validation-problem? + MEMBERSHIP_UUID_NOT_FOUND_OR_NOT_ACCESSIBLE( + requestBody -> requestBody.with("membership.uuid", UNAVAILABLE_MEMBERSHIP_UUID.toString()), + "membership.uuid " + UNAVAILABLE_MEMBERSHIP_UUID + " not found"), + + MEMBERSHIP_UUID_AND_MEMBER_NUMBER_MUST_NOT_BE_GIVEN_BOTH( + requestBody -> requestBody + .with("transactionType", TRANSFER.name()) + .with("assetValue", "-128.00") + .with("adoptingMembership.uuid", UNAVAILABLE_MEMBERSHIP_UUID.toString()) + .with("adoptingMembership.memberNumber", UNAVAILABLE_MEMBER_NUMBER), + "either adoptingMembership.uuid or adoptingMembership.memberNumber can be given, not both"), + + REVERSAL_ASSET_TRANSACTION_REQUIRES_REVERTED_ASSET_TX_UUID( + requestBody -> requestBody + .with("transactionType", REVERSAL.name()) + .with("assetValue", "-128.00"), + "REVERSAL asset transaction requires revertedAssetTx.uuid"), + TRANSACTION_TYPE_MISSING( requestBody -> requestBody.without("transactionType"), "[transactionType must not be null but is \"null\"]"), @@ -576,7 +594,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { // - set SINGLE_TEST_CASE_EXECUTION to true - see above // - select the test case enum value you want to run assumeThat(!SINGLE_TEST_CASE_EXECUTION || - testCase == BadRequestTestCases.ADOPTING_MEMBERSHIP_NUMBER_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE).isTrue(); + testCase == BadRequestTestCases.REVERSAL_ASSET_TRANSACTION_REQUIRES_REVERTED_ASSET_TX_UUID).isTrue(); // when mockMvc.perform(MockMvcRequestBuilders