From 87dfec9efea2e86c28989e578cad53c49166bef4 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 20 Nov 2024 16:55:26 +0100 Subject: [PATCH] verify response body --- ...OfficeCoopAssetsTransactionController.java | 12 +++--- .../HsOfficeCoopAssetsTransactionEntity.java | 10 ++--- .../hs/migration/BaseOfficeDataImport.java | 2 +- ...opAssetsTransactionControllerRestTest.java | 38 +++++++++++++++---- ...ceCoopAssetsTransactionEntityUnitTest.java | 2 +- 5 files changed, 44 insertions(+), 20 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 e69d56c4..1e7eeade 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 @@ -147,16 +147,16 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse } final BiConsumer ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { - if (resource.getReversalAssetTx() != null) { + if (entity.getReversalAssetTx() != null) { resource.getReversalAssetTx().setRevertedAssetTxUuid(entity.getUuid()); } - if (resource.getRevertedAssetTx() != null) { + if (entity.getRevertedAssetTx() != null) { resource.getRevertedAssetTx().setReversalAssetTxUuid(entity.getUuid()); } - if (resource.getAdoptionAssetTx() != null) { + if (entity.getAdoptionAssetTx() != null) { resource.getAdoptionAssetTx().setTransferAssetTxUuid(entity.getUuid()); } - if (resource.getTransferAssetTx() != null) { + if (entity.getTransferAssetTx() != null) { resource.getTransferAssetTx().setAdoptionAssetTxUuid(entity.getUuid()); } }; @@ -174,7 +174,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse final var adoptingMembership = determineAdoptingMembership(resource); if (adoptingMembership != null) { final var adoptingAssetTx = coopAssetsTransactionRepo.save(createAdoptingAssetTx(entity, adoptingMembership)); - entity.setAssetAdoptionAssetTx(adoptingAssetTx); + entity.setAdoptionAssetTx(adoptingAssetTx); } }; @@ -223,7 +223,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse return HsOfficeCoopAssetsTransactionEntity.builder() .membership(adoptingMembership) .transactionType(HsOfficeCoopAssetsTransactionType.ADOPTION) - .assetTransferTx(transferAssetTxEntity) + .transferAssetTx(transferAssetTxEntity) .assetValue(transferAssetTxEntity.getAssetValue().negate()) .comment(transferAssetTxEntity.getComment()) .reference(transferAssetTxEntity.getReference()) 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 408bdf4b..395c2895 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 @@ -52,8 +52,8 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE .withProp(HsOfficeCoopAssetsTransactionEntity::getComment) .withProp(HsOfficeCoopAssetsTransactionEntity::getRevertedAssetTx) .withProp(HsOfficeCoopAssetsTransactionEntity::getReversalAssetTx) - .withProp(HsOfficeCoopAssetsTransactionEntity::getAssetAdoptionAssetTx) - .withProp(HsOfficeCoopAssetsTransactionEntity::getAssetTransferTx) + .withProp(HsOfficeCoopAssetsTransactionEntity::getAdoptionAssetTx) + .withProp(HsOfficeCoopAssetsTransactionEntity::getTransferAssetTx) .quotedValues(false); @Id @@ -109,11 +109,11 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE // Optionally, the UUID of the corresponding transaction for a transfer transaction. @OneToOne(cascade = CascadeType.PERSIST) // TODO.impl: can probably be removed after office data migration @JoinColumn(name = "assetadoptiontxuuid") - private HsOfficeCoopAssetsTransactionEntity assetAdoptionAssetTx; + private HsOfficeCoopAssetsTransactionEntity adoptionAssetTx; // and the other way around - @OneToOne(mappedBy = "assetAdoptionAssetTx") - private HsOfficeCoopAssetsTransactionEntity assetTransferTx; + @OneToOne(mappedBy = "adoptionAssetTx") + private HsOfficeCoopAssetsTransactionEntity transferAssetTx; @Override public HsOfficeCoopAssetsTransactionEntity load() { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java index c160dc18..8d3682c9 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java @@ -900,7 +900,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport { .findAny() .orElseThrow(() -> new IllegalStateException( "cannot determine asset adoption entry for reversal " + assetTransaction)); - assetTransaction.setAssetAdoptionAssetTx(adoptionAssetTx); + assetTransaction.setAdoptionAssetTx(adoptionAssetTx); //adoptionAssetTx.setAssetTransferTx(assetTransaction); } 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 5d366788..dff6f356 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,6 +26,7 @@ import java.util.UUID; import java.util.function.Function; import static net.hostsharing.hsadminng.rbac.test.JsonBuilder.jsonObject; +import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals; import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -183,23 +184,47 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { .with("transactionType", "TRANSFER") .with("assetValue", -64.00) .with("adoptingMembership.memberNumber", AVAILABLE_MEMBER_NUMBER), - "adoptingMembership.memberNumber='M-1234699' not found or not accessible"), + """ + { + "transactionType": "TRANSFER", + "assetValue": -64.00, + "adoptionAssetTx": { + "transactionType": "ADOPTION", + "assetValue": 64.00 + }, + "reversalAssetTx": null, + "transferAssetTx": null, + "revertedAssetTx": null + } + """), ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE( requestBody -> requestBody .with("transactionType", "TRANSFER") .with("assetValue", -64.00) .with("adoptingMembership.uuid", AVAILABLE_MEMBERSHIP_UUID.toString()), - "adoptingMembership.uuid='" + UNAVAILABLE_MEMBERSHIP_UUID + "' not found or not accessible"); + """ + { + "transactionType": "TRANSFER", + "assetValue": -64.00, + "adoptionAssetTx": { + "transactionType": "ADOPTION", + "assetValue": 64.00 + }, + "transferAssetTx": null, + "revertedAssetTx": null, + "reversalAssetTx": null + } + """); private final Function givenBodyTransformation; - private final String expectedErrorMessage; + private final String expectedResponseBody; SuccessfullyCreatedTestCases( final Function givenBodyTransformation, - final String expectedErrorMessage) { + final String expectedResponseBody) { this.givenBodyTransformation = givenBodyTransformation; - this.expectedErrorMessage = expectedErrorMessage; + this.expectedResponseBody = expectedResponseBody; } String givenRequestBody() { @@ -220,8 +245,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest { .accept(MediaType.APPLICATION_JSON)) // then - //FIXME.andExpect(jsonPath("message", is("ERROR: [400] " + testCase.expectedErrorMessage))) - //FIXME.andExpect(jsonPath("statusPhrase", is("Bad Request"))) + .andExpect(jsonPath("$", lenientlyEquals(testCase.expectedResponseBody))) .andExpect(status().is2xxSuccessful()); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java index 261e1af2..cc6d2122 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntityUnitTest.java @@ -60,7 +60,7 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest { @Test void toStringWithAdoptedAssetTxContainsRevertedAssetTx() { - givenCoopAssetTransaction.setAssetAdoptionAssetTx(givenAdoptedCoopAssetTransaction); + givenCoopAssetTransaction.setAdoptionAssetTx(givenAdoptedCoopAssetTransaction); final var result = givenCoopAssetTransaction.toString();