From d6d24803cd11a0687f0aaebe10a747620f3acb07 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 22 Nov 2024 15:23:20 +0100 Subject: [PATCH] refactoring --- ...OfficeCoopAssetsTransactionController.java | 7 +- ...opAssetsTransactionControllerRestTest.java | 99 +++++++------------ 2 files changed, 39 insertions(+), 67 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 8dc0dacc..4fb4ea51 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 @@ -150,22 +150,27 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse final BiConsumer ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { resource.setMembershipUuid(entity.getMembership().getUuid()); resource.setMembershipMemberNumber(entity.getMembership().getTaggedMemberNumber()); - // FIXME: extract to one method to be used in all 4 cases + + // FIXME: actually needed? if (entity.getReversalAssetTx() != null) { resource.getReversalAssetTx().setRevertedAssetTxUuid(entity.getUuid()); resource.getReversalAssetTx().setMembershipUuid(entity.getRevertedAssetTx().getMembership().getUuid()); resource.getReversalAssetTx().setMembershipMemberNumber(entity.getRevertedAssetTx().getTaggedMemberNumber()); } + if (entity.getRevertedAssetTx() != null) { resource.getRevertedAssetTx().setReversalAssetTxUuid(entity.getUuid()); resource.getRevertedAssetTx().setMembershipUuid(entity.getReversalAssetTx().getMembership().getUuid()); resource.getRevertedAssetTx().setMembershipMemberNumber(entity.getReversalAssetTx().getTaggedMemberNumber()); } + if (entity.getAdoptionAssetTx() != null) { resource.getAdoptionAssetTx().setTransferAssetTxUuid(entity.getUuid()); resource.getAdoptionAssetTx().setMembershipUuid(entity.getAdoptionAssetTx().getMembership().getUuid()); resource.getAdoptionAssetTx().setMembershipMemberNumber(entity.getAdoptionAssetTx().getTaggedMemberNumber()); } + + // FIXME: actually needed? if (entity.getTransferAssetTx() != null) { resource.getTransferAssetTx().setAdoptionAssetTxUuid(entity.getUuid()); resource.getTransferAssetTx().setMembershipUuid(entity.getTransferAssetTx().getMembership().getUuid()); 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 dd50594c..0589356b 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 @@ -26,7 +26,6 @@ import java.util.Optional; import java.util.UUID; import java.util.function.Function; -import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionControllerRestTest.SuccessfullyCreatedTestCases.ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE; import static net.hostsharing.hsadminng.rbac.test.JsonBuilder.jsonObject; import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals; import static org.hamcrest.Matchers.is; @@ -64,7 +63,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { .memberNumberSuffix(suffixOf(AVAILABLE_TARGET_MEMBER_NUMBER)) .build(); - private static final UUID NEW_EXPLICITLY_CREATED_ASSET_TX_UUID = TestUuidGenerator.get(3); + private static final UUID NEW_EXPLICITLY_CREATED_ASSET_TX_UUID = TestUuidGenerator.get(5); // might change if impl changes @Autowired MockMvc mockMvc; @@ -201,19 +200,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { .with("transactionType", "TRANSFER") .with("assetValue", -64.00) .with("adoptingMembership.memberNumber", AVAILABLE_TARGET_MEMBER_NUMBER), - """ - { - "transactionType": "TRANSFER", - "assetValue": -64.00, - "adoptionAssetTx": { - "transactionType": "ADOPTION", - "assetValue": 64.00 - }, - "reversalAssetTx": null, - "transferAssetTx": null, - "revertedAssetTx": null - } - """), + Expected.TRANSFER_RESPONSE), ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE( requestBody -> requestBody @@ -221,55 +208,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { .with("assetValue", -64.00) .with("membership.uuid", ORIGIN_MEMBERSHIP_UUID.toString()) .with("adoptingMembership.uuid", AVAILABLE_TARGET_MEMBERSHIP_UUID.toString()), -// """ -// { -// "uuid": "%{NEW_EXPLICITLY_CREATED_ASSET_TX_UUID}", -// "membership.uuid": "%{ORIGIN_MEMBERSHIP_UUID}", -// "transactionType": "TRANSFER", -// "assetValue": -64.00, -// "adoptionAssetTx": { -// "membership.uuid": "%{AVAILABLE_MEMBERSHIP_UUID}", -// "transactionType": "ADOPTION", -// "assetValue": 64.00, -// "transferAssetTx.uuid": "%{NEW_EXPLICITLY_CREATED_ASSET_TX_UUID}" -// }, -// "transferAssetTx": null, -// "revertedAssetTx": null, -// "reversalAssetTx": null -// } -// """ -// .replace("%{NEW_EXPLICITLY_CREATED_ASSET_TX_UUID}", NEW_EXPLICITLY_CREATED_ASSET_TX_UUID.toString()) -// .replace("%{ORIGIN_MEMBERSHIP_UUID}", ORIGIN_MEMBERSHIP_UUID.toString()) -// .replace("%{AVAILABLE_MEMBERSHIP_UUID}", AVAILABLE_TARGET_MEMBERSHIP_UUID.toString())); - """ - { - "uuid": "55555555-5555-5555-5555-555555555555", - "membership.uuid": "11111111-1111-1111-1111-111111111111", - "membership.memberNumber": "M-1111100", - "transactionType": "TRANSFER", - "assetValue": -64, - "valueDate": "2022-10-13", - "reference": "valid reference", - "comment": "valid comment", - "adoptionAssetTx": { - "uuid": "44444444-4444-4444-4444-444444444444", - "membership.uuid": "22222222-2222-2222-2222-222222222222", - "membership.memberNumber": "M-1234500", - "transactionType": "ADOPTION", - "assetValue": 64, - "valueDate": "2022-10-13", - "reference": "valid reference", - "comment": "valid comment", - "adoptionAssetTx.uuid": null, - "transferAssetTx.uuid": "55555555-5555-5555-5555-555555555555", - "revertedAssetTx.uuid": null, - "reversalAssetTx.uuid": null - }, - "transferAssetTx": null, - "revertedAssetTx": null, - "reversalAssetTx": null - } - """); + Expected.TRANSFER_RESPONSE); private final Function givenBodyTransformation; private final String expectedResponseBody; @@ -284,14 +223,42 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { String givenRequestBody() { return givenBodyTransformation.apply(jsonObject(INSERT_REQUEST_BODY_TEMPLATE)).toString(); } + + private static class Expected { + + public static final String TRANSFER_RESPONSE = """ + { + "uuid": "%{NEW_EXPLICITLY_CREATED_ASSET_TX_UUID}", + "membership.uuid": "%{ORIGIN_MEMBERSHIP_UUID}", + "membership.memberNumber": "%{ORIGIN_MEMBER_NUMBER}", + "transactionType": "TRANSFER", + "assetValue": -64.00, + "adoptionAssetTx": { + "membership.uuid": "%{AVAILABLE_MEMBERSHIP_UUID}", + "membership.memberNumber": "%{AVAILABLE_TARGET_MEMBER_NUMBER}", + "transactionType": "ADOPTION", + "assetValue": 64.00, + "transferAssetTx.uuid": "%{NEW_EXPLICITLY_CREATED_ASSET_TX_UUID}" + }, + "transferAssetTx": null, + "revertedAssetTx": null, + "reversalAssetTx": null + } + """ + .replace("%{NEW_EXPLICITLY_CREATED_ASSET_TX_UUID}", NEW_EXPLICITLY_CREATED_ASSET_TX_UUID.toString()) + .replace("%{ORIGIN_MEMBERSHIP_UUID}", ORIGIN_MEMBERSHIP_UUID.toString()) + .replace("%{ORIGIN_MEMBER_NUMBER}", ORIGIN_MEMBER_NUMBER) + .replace("%{AVAILABLE_MEMBERSHIP_UUID}", AVAILABLE_TARGET_MEMBERSHIP_UUID.toString()) + .replace("%{AVAILABLE_TARGET_MEMBER_NUMBER}", AVAILABLE_TARGET_MEMBER_NUMBER); + } } @ParameterizedTest @EnumSource(SuccessfullyCreatedTestCases.class) void respondWithSuccessfullyCreated(final SuccessfullyCreatedTestCases testCase) throws Exception { // uncomment, if you need to run just a single test-case in this data-driven test-method - org.assertj.core.api.Assumptions.assumeThat( - testCase == ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE).isTrue(); + // org.assertj.core.api.Assumptions.assumeThat( + // testCase == ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE).isTrue(); // when mockMvc.perform(MockMvcRequestBuilders