WIP: add advanced scenario-tests for coop-assets #123

Draft
hsh-michaelhoennig wants to merge 16 commits from feature/add-advanced-scenario-tests-for-coop-assets into master
5 changed files with 44 additions and 20 deletions
Showing only changes of commit 87dfec9efe - Show all commits

View File

@ -147,16 +147,16 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse
} }
final BiConsumer<HsOfficeCoopAssetsTransactionEntity, HsOfficeCoopAssetsTransactionResource> ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { final BiConsumer<HsOfficeCoopAssetsTransactionEntity, HsOfficeCoopAssetsTransactionResource> ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> {
if (resource.getReversalAssetTx() != null) { if (entity.getReversalAssetTx() != null) {
resource.getReversalAssetTx().setRevertedAssetTxUuid(entity.getUuid()); resource.getReversalAssetTx().setRevertedAssetTxUuid(entity.getUuid());
} }
if (resource.getRevertedAssetTx() != null) { if (entity.getRevertedAssetTx() != null) {
resource.getRevertedAssetTx().setReversalAssetTxUuid(entity.getUuid()); resource.getRevertedAssetTx().setReversalAssetTxUuid(entity.getUuid());
} }
if (resource.getAdoptionAssetTx() != null) { if (entity.getAdoptionAssetTx() != null) {
resource.getAdoptionAssetTx().setTransferAssetTxUuid(entity.getUuid()); resource.getAdoptionAssetTx().setTransferAssetTxUuid(entity.getUuid());
} }
if (resource.getTransferAssetTx() != null) { if (entity.getTransferAssetTx() != null) {
resource.getTransferAssetTx().setAdoptionAssetTxUuid(entity.getUuid()); resource.getTransferAssetTx().setAdoptionAssetTxUuid(entity.getUuid());
} }
}; };
@ -174,7 +174,7 @@ public class HsOfficeCoopAssetsTransactionController implements HsOfficeCoopAsse
final var adoptingMembership = determineAdoptingMembership(resource); final var adoptingMembership = determineAdoptingMembership(resource);
if (adoptingMembership != null) { if (adoptingMembership != null) {
final var adoptingAssetTx = coopAssetsTransactionRepo.save(createAdoptingAssetTx(entity, adoptingMembership)); 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() return HsOfficeCoopAssetsTransactionEntity.builder()
.membership(adoptingMembership) .membership(adoptingMembership)
.transactionType(HsOfficeCoopAssetsTransactionType.ADOPTION) .transactionType(HsOfficeCoopAssetsTransactionType.ADOPTION)
.assetTransferTx(transferAssetTxEntity) .transferAssetTx(transferAssetTxEntity)
.assetValue(transferAssetTxEntity.getAssetValue().negate()) .assetValue(transferAssetTxEntity.getAssetValue().negate())
.comment(transferAssetTxEntity.getComment()) .comment(transferAssetTxEntity.getComment())
.reference(transferAssetTxEntity.getReference()) .reference(transferAssetTxEntity.getReference())

View File

@ -52,8 +52,8 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE
.withProp(HsOfficeCoopAssetsTransactionEntity::getComment) .withProp(HsOfficeCoopAssetsTransactionEntity::getComment)
.withProp(HsOfficeCoopAssetsTransactionEntity::getRevertedAssetTx) .withProp(HsOfficeCoopAssetsTransactionEntity::getRevertedAssetTx)
.withProp(HsOfficeCoopAssetsTransactionEntity::getReversalAssetTx) .withProp(HsOfficeCoopAssetsTransactionEntity::getReversalAssetTx)
.withProp(HsOfficeCoopAssetsTransactionEntity::getAssetAdoptionAssetTx) .withProp(HsOfficeCoopAssetsTransactionEntity::getAdoptionAssetTx)
.withProp(HsOfficeCoopAssetsTransactionEntity::getAssetTransferTx) .withProp(HsOfficeCoopAssetsTransactionEntity::getTransferAssetTx)
.quotedValues(false); .quotedValues(false);
@Id @Id
@ -109,11 +109,11 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE
// Optionally, the UUID of the corresponding transaction for a transfer transaction. // 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 @OneToOne(cascade = CascadeType.PERSIST) // TODO.impl: can probably be removed after office data migration
@JoinColumn(name = "assetadoptiontxuuid") @JoinColumn(name = "assetadoptiontxuuid")
private HsOfficeCoopAssetsTransactionEntity assetAdoptionAssetTx; private HsOfficeCoopAssetsTransactionEntity adoptionAssetTx;
// and the other way around // and the other way around
@OneToOne(mappedBy = "assetAdoptionAssetTx") @OneToOne(mappedBy = "adoptionAssetTx")
private HsOfficeCoopAssetsTransactionEntity assetTransferTx; private HsOfficeCoopAssetsTransactionEntity transferAssetTx;
@Override @Override
public HsOfficeCoopAssetsTransactionEntity load() { public HsOfficeCoopAssetsTransactionEntity load() {

View File

@ -900,7 +900,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
.findAny() .findAny()
.orElseThrow(() -> new IllegalStateException( .orElseThrow(() -> new IllegalStateException(
"cannot determine asset adoption entry for reversal " + assetTransaction)); "cannot determine asset adoption entry for reversal " + assetTransaction));
assetTransaction.setAssetAdoptionAssetTx(adoptionAssetTx); assetTransaction.setAdoptionAssetTx(adoptionAssetTx);
//adoptionAssetTx.setAssetTransferTx(assetTransaction); //adoptionAssetTx.setAssetTransferTx(assetTransaction);
} }

View File

@ -26,6 +26,7 @@ import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
import static net.hostsharing.hsadminng.rbac.test.JsonBuilder.jsonObject; 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.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -183,23 +184,47 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
.with("transactionType", "TRANSFER") .with("transactionType", "TRANSFER")
.with("assetValue", -64.00) .with("assetValue", -64.00)
.with("adoptingMembership.memberNumber", AVAILABLE_MEMBER_NUMBER), .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( ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE(
requestBody -> requestBody requestBody -> requestBody
.with("transactionType", "TRANSFER") .with("transactionType", "TRANSFER")
.with("assetValue", -64.00) .with("assetValue", -64.00)
.with("adoptingMembership.uuid", AVAILABLE_MEMBERSHIP_UUID.toString()), .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<JsonBuilder, JsonBuilder> givenBodyTransformation; private final Function<JsonBuilder, JsonBuilder> givenBodyTransformation;
private final String expectedErrorMessage; private final String expectedResponseBody;
SuccessfullyCreatedTestCases( SuccessfullyCreatedTestCases(
final Function<JsonBuilder, JsonBuilder> givenBodyTransformation, final Function<JsonBuilder, JsonBuilder> givenBodyTransformation,
final String expectedErrorMessage) { final String expectedResponseBody) {
this.givenBodyTransformation = givenBodyTransformation; this.givenBodyTransformation = givenBodyTransformation;
this.expectedErrorMessage = expectedErrorMessage; this.expectedResponseBody = expectedResponseBody;
} }
String givenRequestBody() { String givenRequestBody() {
@ -220,8 +245,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
.accept(MediaType.APPLICATION_JSON)) .accept(MediaType.APPLICATION_JSON))
// then // then
//FIXME.andExpect(jsonPath("message", is("ERROR: [400] " + testCase.expectedErrorMessage))) .andExpect(jsonPath("$", lenientlyEquals(testCase.expectedResponseBody)))
//FIXME.andExpect(jsonPath("statusPhrase", is("Bad Request")))
.andExpect(status().is2xxSuccessful()); .andExpect(status().is2xxSuccessful());
} }

View File

@ -60,7 +60,7 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
@Test @Test
void toStringWithAdoptedAssetTxContainsRevertedAssetTx() { void toStringWithAdoptedAssetTxContainsRevertedAssetTx() {
givenCoopAssetTransaction.setAssetAdoptionAssetTx(givenAdoptedCoopAssetTransaction); givenCoopAssetTransaction.setAdoptionAssetTx(givenAdoptedCoopAssetTransaction);
final var result = givenCoopAssetTransaction.toString(); final var result = givenCoopAssetTransaction.toString();