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
This commit is contained in:
Michael Hoennig 2024-11-27 16:05:13 +01:00
parent 021c286c63
commit c1cc9c1589
2 changed files with 24 additions and 6 deletions

View File

@ -217,7 +217,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse
final HsOfficeMembershipEntity membership = ofNullable(emw.find( final HsOfficeMembershipEntity membership = ofNullable(emw.find(
HsOfficeMembershipEntity.class, HsOfficeMembershipEntity.class,
resource.getMembershipUuid())) resource.getMembershipUuid()))
.orElseThrow(() -> new EntityNotFoundException("ERROR: [400] membership.uuid %s not found".formatted( .orElseThrow(() -> new EntityNotFoundException("membership.uuid %s not found".formatted(
resource.getMembershipUuid()))); resource.getMembershipUuid())));
entity.setMembership(membership); entity.setMembership(membership);
} }
@ -227,7 +227,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse
throw new ValidationException("REVERSAL asset transaction requires revertedAssetTx.uuid"); throw new ValidationException("REVERSAL asset transaction requires revertedAssetTx.uuid");
} }
final var revertedAssetTx = coopAssetsTransactionRepo.findByUuid(resource.getRevertedAssetTxUuid()) 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()))); resource.getRevertedAssetTxUuid())));
revertedAssetTx.setReversalAssetTx(entity); revertedAssetTx.setReversalAssetTx(entity);
entity.setRevertedAssetTx(revertedAssetTx); entity.setRevertedAssetTx(revertedAssetTx);
@ -267,11 +267,11 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse
final var adoptingMembershipUuid = resource.getAdoptingMembershipUuid(); final var adoptingMembershipUuid = resource.getAdoptingMembershipUuid();
final var adoptingMembershipMemberNumber = resource.getAdoptingMembershipMemberNumber(); final var adoptingMembershipMemberNumber = resource.getAdoptingMembershipMemberNumber();
if (adoptingMembershipUuid != null && adoptingMembershipMemberNumber != null) { if (adoptingMembershipUuid != null && adoptingMembershipMemberNumber != null) {
throw new IllegalArgumentException( throw new ValidationException(
// @formatter:off // @formatter:off
resource.getTransactionType() == HsOfficeCoopAssetsTransactionTypeResource.TRANSFER resource.getTransactionType() == HsOfficeCoopAssetsTransactionTypeResource.TRANSFER
? "[400] either adoptingMembership.uuid or adoptingMembership.memberNumber can be given, not both" ? "either adoptingMembership.uuid or adoptingMembership.memberNumber can be given, not both"
: "[400] adoptingMembership.uuid and adoptingMembership.memberNumber must not be given for transactionType=" : "adoptingMembership.uuid and adoptingMembership.memberNumber must not be given for transactionType="
+ resource.getTransactionType()); + resource.getTransactionType());
// @formatter:on // @formatter:on
} }

View File

@ -500,6 +500,24 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
requestBody -> requestBody.without("membership.uuid"), requestBody -> requestBody.without("membership.uuid"),
"[membershipUuid must not be null but is \"null\"]"), // TODO.impl: should be membership.uuid, Spring validation-problem? "[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( TRANSACTION_TYPE_MISSING(
requestBody -> requestBody.without("transactionType"), requestBody -> requestBody.without("transactionType"),
"[transactionType must not be null but is \"null\"]"), "[transactionType must not be null but is \"null\"]"),
@ -576,7 +594,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
// - set SINGLE_TEST_CASE_EXECUTION to true - see above // - set SINGLE_TEST_CASE_EXECUTION to true - see above
// - select the test case enum value you want to run // - select the test case enum value you want to run
assumeThat(!SINGLE_TEST_CASE_EXECUTION || 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 // when
mockMvc.perform(MockMvcRequestBuilders mockMvc.perform(MockMvcRequestBuilders