add advanced scenario-tests for coop-assets (#123)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/123 Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
@@ -449,7 +449,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
||||
1094=CoopAssetsTransaction(M-1000300: 2023-10-06, DEPOSIT, 3072, 1000300, Kapitalerhoehung - Ueberweisung),
|
||||
31000=CoopAssetsTransaction(M-1002000: 2000-12-06, DEPOSIT, 128.00, 1002000, for subscription B),
|
||||
32000=CoopAssetsTransaction(M-1000300: 2005-01-10, DEPOSIT, 2560.00, 1000300, for subscription C),
|
||||
33001=CoopAssetsTransaction(M-1000300: 2005-01-10, TRANSFER, -512.00, 1000300, for transfer to 10),
|
||||
33001=CoopAssetsTransaction(M-1000300: 2005-01-10, TRANSFER, -512.00, 1000300, for transfer to 10, M-1002000:ADO:+512.00),
|
||||
33002=CoopAssetsTransaction(M-1002000: 2005-01-10, ADOPTION, 512.00, 1002000, for transfer from 7),
|
||||
34001=CoopAssetsTransaction(M-1002000: 2016-12-31, CLEARING, -8.00, 1002000, for cancellation D),
|
||||
34002=CoopAssetsTransaction(M-1002000: 2016-12-31, DISBURSAL, -100.00, 1002000, for cancellation D),
|
||||
@@ -877,21 +877,44 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
||||
.comment(rec.getString("comment"))
|
||||
.reference(member.getMemberNumber().toString())
|
||||
.build();
|
||||
|
||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.REVERSAL) {
|
||||
final var negativeValue = assetTransaction.getAssetValue().negate();
|
||||
final var revertedAssetTx = coopAssets.values().stream().filter(a ->
|
||||
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.REVERSAL &&
|
||||
a.getMembership() == assetTransaction.getMembership() &&
|
||||
a.getAssetValue().equals(negativeValue))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"cannot determine asset reverse entry for reversal " + assetTransaction));
|
||||
assetTransaction.setRevertedAssetTx(revertedAssetTx);
|
||||
}
|
||||
|
||||
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
||||
});
|
||||
|
||||
coopAssets.values().forEach(assetTransaction -> {
|
||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.REVERSAL) {
|
||||
connectToRelatedRevertedAssetTx(assetTransaction);
|
||||
}
|
||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.TRANSFER) {
|
||||
connectToRelatedAdoptionAssetTx(assetTransaction);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void connectToRelatedRevertedAssetTx(final HsOfficeCoopAssetsTransactionEntity assetTransaction) {
|
||||
final var negativeValue = assetTransaction.getAssetValue().negate();
|
||||
final var revertedAssetTx = coopAssets.values().stream().filter(a ->
|
||||
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.REVERSAL &&
|
||||
a.getMembership() == assetTransaction.getMembership() &&
|
||||
a.getAssetValue().equals(negativeValue))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"cannot determine asset reverse entry for reversal " + assetTransaction));
|
||||
assetTransaction.setRevertedAssetTx(revertedAssetTx);
|
||||
//revertedAssetTx.setAssetReversalTx(assetTransaction);
|
||||
}
|
||||
|
||||
private static void connectToRelatedAdoptionAssetTx(final HsOfficeCoopAssetsTransactionEntity assetTransaction) {
|
||||
final var negativeValue = assetTransaction.getAssetValue().negate();
|
||||
final var adoptionAssetTx = coopAssets.values().stream().filter(a ->
|
||||
a.getTransactionType() == HsOfficeCoopAssetsTransactionType.ADOPTION &&
|
||||
a.getMembership() != assetTransaction.getMembership() &&
|
||||
a.getValueDate().equals(assetTransaction.getValueDate()) &&
|
||||
a.getAssetValue().equals(negativeValue))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"cannot determine asset adoption entry for reversal " + assetTransaction));
|
||||
assetTransaction.setAdoptionAssetTx(adoptionAssetTx);
|
||||
//adoptionAssetTx.setAssetTransferTx(assetTransaction);
|
||||
}
|
||||
|
||||
private static HsOfficeMembershipEntity createOnDemandMembership(final Integer bpId) {
|
||||
|
@@ -173,8 +173,13 @@ public class CsvDataImport extends ContextBasedTest {
|
||||
//System.out.println("persisting #" + entity.hashCode() + ": " + entity);
|
||||
em.persist(entity);
|
||||
// uncomment for debugging purposes
|
||||
// em.flush(); // makes it slow, but produces better error messages
|
||||
// System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid());
|
||||
// try {
|
||||
// em.flush(); // makes it slow, but produces better error messages
|
||||
// System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid());
|
||||
// return entity;
|
||||
// } catch (final Exception exc) {
|
||||
// throw exc; // for breakpoints
|
||||
// }
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ class HsOfficeBankAccountControllerRestTest {
|
||||
Context contextMock;
|
||||
|
||||
@MockBean
|
||||
@SuppressWarnings("unused") // not used in test, but in controller class
|
||||
StandardMapper mapper;
|
||||
|
||||
@MockBean
|
||||
|
@@ -69,7 +69,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", hasSize(12)); // @formatter:on
|
||||
.body("", hasSize(3*6)); // @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,14 +94,22 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
"assetValue": 320.00,
|
||||
"valueDate": "2010-03-15",
|
||||
"reference": "ref 1000202-1",
|
||||
"comment": "initial deposit"
|
||||
"comment": "initial deposit",
|
||||
"adoptionAssetTx": null,
|
||||
"transferAssetTx": null,
|
||||
"revertedAssetTx": null,
|
||||
"reversalAssetTx": null
|
||||
},
|
||||
{
|
||||
"transactionType": "DISBURSAL",
|
||||
"assetValue": -128.00,
|
||||
"valueDate": "2021-09-01",
|
||||
"reference": "ref 1000202-2",
|
||||
"comment": "partial disbursal"
|
||||
"comment": "partial disbursal",
|
||||
"adoptionAssetTx": null,
|
||||
"transferAssetTx": null,
|
||||
"revertedAssetTx": null,
|
||||
"reversalAssetTx": null
|
||||
},
|
||||
{
|
||||
"transactionType": "DEPOSIT",
|
||||
@@ -109,12 +117,18 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
"valueDate": "2022-10-20",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some loss",
|
||||
"adoptionAssetTx": null,
|
||||
"transferAssetTx": null,
|
||||
"revertedAssetTx": null,
|
||||
"reversalAssetTx": {
|
||||
"transactionType": "REVERSAL",
|
||||
"assetValue": -128.00,
|
||||
"valueDate": "2022-10-21",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some reversal"
|
||||
"comment": "some reversal",
|
||||
"adoptionAssetTx.uuid": null,
|
||||
"transferAssetTx.uuid": null,
|
||||
"reversalAssetTx.uuid": null
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -123,13 +137,59 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
"valueDate": "2022-10-21",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some reversal",
|
||||
"adoptionAssetTx": null,
|
||||
"transferAssetTx": null,
|
||||
"revertedAssetTx": {
|
||||
"transactionType": "DEPOSIT",
|
||||
"assetValue": 128.00,
|
||||
"valueDate": "2022-10-20",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some loss"
|
||||
}
|
||||
"comment": "some loss",
|
||||
"adoptionAssetTx.uuid": null,
|
||||
"transferAssetTx.uuid": null,
|
||||
"revertedAssetTx.uuid": null
|
||||
},
|
||||
"reversalAssetTx": null
|
||||
},
|
||||
{
|
||||
"transactionType": "TRANSFER",
|
||||
"assetValue": -192.00,
|
||||
"valueDate": "2023-12-31",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some reversal",
|
||||
"adoptionAssetTx": {
|
||||
"transactionType": "ADOPTION",
|
||||
"assetValue": 192.00,
|
||||
"valueDate": "2023-12-31",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some reversal",
|
||||
"adoptionAssetTx.uuid": null,
|
||||
"revertedAssetTx.uuid": null,
|
||||
"reversalAssetTx.uuid": null
|
||||
},
|
||||
"transferAssetTx": null,
|
||||
"revertedAssetTx": null,
|
||||
"reversalAssetTx": null
|
||||
},
|
||||
{
|
||||
"transactionType": "ADOPTION",
|
||||
"assetValue": 192.00,
|
||||
"valueDate": "2023-12-31",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some reversal",
|
||||
"adoptionAssetTx": null,
|
||||
"transferAssetTx": {
|
||||
"transactionType": "TRANSFER",
|
||||
"assetValue": -192.00,
|
||||
"valueDate": "2023-12-31",
|
||||
"reference": "ref 1000202-3",
|
||||
"comment": "some reversal",
|
||||
"transferAssetTx.uuid": null,
|
||||
"revertedAssetTx.uuid": null,
|
||||
"reversalAssetTx.uuid": null
|
||||
},
|
||||
"revertedAssetTx": null,
|
||||
"reversalAssetTx": null
|
||||
}
|
||||
]
|
||||
""")); // @formatter:on
|
||||
|
@@ -1,50 +1,116 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
|
||||
import net.hostsharing.hsadminng.test.TestUuidGenerator;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Optional;
|
||||
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.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeCoopAssetsTransactionController.class)
|
||||
@Import({ StrictMapper.class, JsonObjectMapperConfiguration.class })
|
||||
@RunWith(SpringRunner.class)
|
||||
class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
|
||||
private static final UUID UNAVAILABLE_MEMBERSHIP_UUID = TestUuidGenerator.use(0);
|
||||
private static final String UNAVAILABLE_MEMBER_NUMBER = "M-1234699";
|
||||
|
||||
private static final UUID ORIGIN_MEMBERSHIP_UUID = TestUuidGenerator.use(1);
|
||||
private static final String ORIGIN_MEMBER_NUMBER = "M-1111100";
|
||||
public final HsOfficeMembershipEntity ORIGIN_TARGET_MEMBER_ENTITY = HsOfficeMembershipEntity.builder()
|
||||
.uuid(ORIGIN_MEMBERSHIP_UUID)
|
||||
.partner(HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(partnerNumberOf(ORIGIN_MEMBER_NUMBER))
|
||||
.build())
|
||||
.memberNumberSuffix(suffixOf(ORIGIN_MEMBER_NUMBER))
|
||||
.build();
|
||||
|
||||
private static final UUID AVAILABLE_TARGET_MEMBERSHIP_UUID = TestUuidGenerator.use(2);
|
||||
private static final String AVAILABLE_TARGET_MEMBER_NUMBER = "M-1234500";
|
||||
public final HsOfficeMembershipEntity AVAILABLE_MEMBER_ENTITY = HsOfficeMembershipEntity.builder()
|
||||
.uuid(AVAILABLE_TARGET_MEMBERSHIP_UUID)
|
||||
.partner(HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(partnerNumberOf(AVAILABLE_TARGET_MEMBER_NUMBER))
|
||||
.build())
|
||||
.memberNumberSuffix(suffixOf(AVAILABLE_TARGET_MEMBER_NUMBER))
|
||||
.build();
|
||||
|
||||
// the following refs might change if impl changes
|
||||
private static final UUID NEW_EXPLICITLY_CREATED_REVERSAL_ASSET_TX_UUID = TestUuidGenerator.ref(4);
|
||||
private static final UUID NEW_EXPLICITLY_CREATED_TRANSFER_ASSET_TX_UUID = TestUuidGenerator.ref(5);
|
||||
|
||||
private static final UUID SOME_EXISTING_LOSS_ASSET_TX_UUID = TestUuidGenerator.use(3);
|
||||
public final HsOfficeCoopAssetsTransactionEntity SOME_EXISTING_LOSS_ASSET_TX_ENTITY = HsOfficeCoopAssetsTransactionEntity.builder()
|
||||
.uuid(SOME_EXISTING_LOSS_ASSET_TX_UUID)
|
||||
.membership(ORIGIN_TARGET_MEMBER_ENTITY)
|
||||
.transactionType(HsOfficeCoopAssetsTransactionType.LOSS)
|
||||
.assetValue(BigDecimal.valueOf(-64))
|
||||
.reference("some loss asset tx ref")
|
||||
.comment("some loss asset tx comment")
|
||||
.valueDate(LocalDate.parse("2024-10-15"))
|
||||
.build();
|
||||
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
Context contextMock;
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unused") // not used in test, but in controller class
|
||||
StrictMapper mapper;
|
||||
|
||||
@MockBean
|
||||
StandardMapper mapper;
|
||||
EntityManagerWrapper emw; // even if not used in test anymore, it's needed by base-class of StrictMapper
|
||||
|
||||
@MockBean
|
||||
HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo;
|
||||
|
||||
static final String VALID_INSERT_REQUEST_BODY = """
|
||||
@MockBean
|
||||
HsOfficeMembershipRepository membershipRepo;
|
||||
|
||||
static final String INSERT_REQUEST_BODY_TEMPLATE = """
|
||||
{
|
||||
"membership.uuid": "%s",
|
||||
"transactionType": "DEPOSIT",
|
||||
"assetValue": 128.00,
|
||||
"valueDate": "2022-10-13",
|
||||
"reference": "valid reference",
|
||||
"comment": "valid comment"
|
||||
"comment": "valid comment",
|
||||
"adoptingMembership.uuid": null,
|
||||
"adoptingMembership.memberNumber": null
|
||||
}
|
||||
""".formatted(UUID.randomUUID());
|
||||
""".formatted(ORIGIN_MEMBERSHIP_UUID);
|
||||
|
||||
enum BadRequestTestCases {
|
||||
MEMBERSHIP_UUID_MISSING(
|
||||
@@ -65,8 +131,6 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
.with("assetValue", -64.00),
|
||||
"[for DEPOSIT, assetValue must be positive but is \"-64.00\"]"),
|
||||
|
||||
//TODO: other transaction types
|
||||
|
||||
ASSETS_VALUE_FOR_DISBURSAL_MUST_BE_NEGATIVE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "DISBURSAL")
|
||||
@@ -75,6 +139,20 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
|
||||
//TODO: other transaction types
|
||||
|
||||
ADOPTING_MEMBERSHIP_NUMBER_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "TRANSFER")
|
||||
.with("assetValue", -64.00)
|
||||
.with("adoptingMembership.memberNumber", UNAVAILABLE_MEMBER_NUMBER),
|
||||
"adoptingMembership.memberNumber='M-1234699' not found or not accessible"),
|
||||
|
||||
ADOPTING_MEMBERSHIP_UUID_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "TRANSFER")
|
||||
.with("assetValue", -64.00)
|
||||
.with("adoptingMembership.uuid", UNAVAILABLE_MEMBERSHIP_UUID.toString()),
|
||||
"adoptingMembership.uuid='" + UNAVAILABLE_MEMBERSHIP_UUID + "' not found or not accessible"),
|
||||
|
||||
ASSETS_VALUE_MUST_NOT_BE_NULL(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "REVERSAL")
|
||||
@@ -104,13 +182,16 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
}
|
||||
|
||||
String givenRequestBody() {
|
||||
return givenBodyTransformation.apply(jsonObject(VALID_INSERT_REQUEST_BODY)).toString();
|
||||
return givenBodyTransformation.apply(jsonObject(INSERT_REQUEST_BODY_TEMPLATE)).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(BadRequestTestCases.class)
|
||||
void respondWithBadRequest(final BadRequestTestCases testCase) throws Exception {
|
||||
// HOWTO: run just a single test-case in a data-driven test-method
|
||||
// org.assertj.core.api.Assumptions.assumeThat(
|
||||
// testCase == ADOPTING_MEMBERSHIP_NUMBER_FOR_TRANSFER_MUST_BE_GIVEN_AND_AVAILABLE).isTrue();
|
||||
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
@@ -127,4 +208,160 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
enum SuccessfullyCreatedTestCases {
|
||||
|
||||
REVERTING_SIMPLE_ASSET_TRANSACTION(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "REVERSAL")
|
||||
.with("assetValue", "64.00")
|
||||
.with("valueDate", "2024-10-15")
|
||||
.with("reference", "reversal ref")
|
||||
.with("comment", "reversal comment")
|
||||
.with("revertedAssetTx.uuid", SOME_EXISTING_LOSS_ASSET_TX_UUID.toString()),
|
||||
Expected.REVERT_RESPONSE),
|
||||
|
||||
TRANSFER_TO_GIVEN_AVAILABLE_MEMBERSHIP_NUMBER(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "TRANSFER")
|
||||
.with("assetValue", -64.00)
|
||||
.with("adoptingMembership.memberNumber", AVAILABLE_TARGET_MEMBER_NUMBER),
|
||||
Expected.TRANSFER_RESPONSE),
|
||||
|
||||
TRANSFER_TO_GIVEN_AVAILABLE_MEMBERSHIP_UUID(
|
||||
requestBody -> requestBody
|
||||
.with("transactionType", "TRANSFER")
|
||||
.with("assetValue", -64.00)
|
||||
.with("membership.uuid", ORIGIN_MEMBERSHIP_UUID.toString())
|
||||
.with("adoptingMembership.uuid", AVAILABLE_TARGET_MEMBERSHIP_UUID.toString()),
|
||||
Expected.TRANSFER_RESPONSE);
|
||||
|
||||
private final Function<JsonBuilder, JsonBuilder> givenBodyTransformation;
|
||||
private final String expectedResponseBody;
|
||||
|
||||
SuccessfullyCreatedTestCases(
|
||||
final Function<JsonBuilder, JsonBuilder> givenBodyTransformation,
|
||||
final String expectedResponseBody) {
|
||||
this.givenBodyTransformation = givenBodyTransformation;
|
||||
this.expectedResponseBody = expectedResponseBody;
|
||||
}
|
||||
|
||||
String givenRequestBody() {
|
||||
return givenBodyTransformation.apply(jsonObject(INSERT_REQUEST_BODY_TEMPLATE)).toString();
|
||||
}
|
||||
|
||||
private static class Expected {
|
||||
|
||||
public static final String REVERT_RESPONSE = """
|
||||
{
|
||||
"uuid": "%{NEW_EXPLICITLY_CREATED_REVERSAL_ASSET_TX_UUID}",
|
||||
"membership.uuid": "%{ORIGIN_MEMBERSHIP_UUID}",
|
||||
"membership.memberNumber": "%{ORIGIN_MEMBER_NUMBER}",
|
||||
"transactionType": "REVERSAL",
|
||||
"assetValue": 64.00,
|
||||
"valueDate": "2024-10-15",
|
||||
"reference": "reversal ref",
|
||||
"comment": "reversal comment",
|
||||
"adoptionAssetTx": null,
|
||||
"transferAssetTx": null,
|
||||
"revertedAssetTx": {
|
||||
"uuid": "%{SOME_EXISTING_LOSS_ASSET_TX_UUID}",
|
||||
"membership.uuid": "%{ORIGIN_MEMBERSHIP_UUID}",
|
||||
"membership.memberNumber": "%{ORIGIN_MEMBER_NUMBER}",
|
||||
"transactionType": "LOSS",
|
||||
"assetValue": -64.00,
|
||||
"valueDate": "2024-10-15",
|
||||
"reference": "some loss asset tx ref",
|
||||
"comment": "some loss asset tx comment",
|
||||
"adoptionAssetTx.uuid": null,
|
||||
"transferAssetTx.uuid": null,
|
||||
"revertedAssetTx.uuid": null,
|
||||
"reversalAssetTx.uuid": "%{NEW_EXPLICITLY_CREATED_REVERSAL_ASSET_TX_UUID}"
|
||||
}
|
||||
}
|
||||
"""
|
||||
.replace("%{NEW_EXPLICITLY_CREATED_REVERSAL_ASSET_TX_UUID}", NEW_EXPLICITLY_CREATED_REVERSAL_ASSET_TX_UUID.toString())
|
||||
.replace("%{ORIGIN_MEMBERSHIP_UUID}", ORIGIN_MEMBERSHIP_UUID.toString())
|
||||
.replace("%{ORIGIN_MEMBER_NUMBER}", ORIGIN_MEMBER_NUMBER)
|
||||
.replace("%{SOME_EXISTING_LOSS_ASSET_TX_UUID}", SOME_EXISTING_LOSS_ASSET_TX_UUID.toString());
|
||||
|
||||
public static final String TRANSFER_RESPONSE = """
|
||||
{
|
||||
"uuid": "%{NEW_EXPLICITLY_CREATED_TRANSFER_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_TRANSFER_ASSET_TX_UUID}"
|
||||
},
|
||||
"transferAssetTx": null,
|
||||
"revertedAssetTx": null,
|
||||
"reversalAssetTx": null
|
||||
}
|
||||
"""
|
||||
.replace("%{NEW_EXPLICITLY_CREATED_TRANSFER_ASSET_TX_UUID}", NEW_EXPLICITLY_CREATED_TRANSFER_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();
|
||||
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/coopassetstransactions")
|
||||
.header("current-subject", "superuser-alex@hostsharing.net")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(testCase.givenRequestBody())
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
.andExpect(status().is2xxSuccessful())
|
||||
.andExpect(jsonPath("$", lenientlyEquals(testCase.expectedResponseBody)));
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void initMocks() {
|
||||
TestUuidGenerator.start(4);
|
||||
|
||||
when(emw.find(eq(HsOfficeMembershipEntity.class), eq(ORIGIN_MEMBERSHIP_UUID))).thenReturn(ORIGIN_TARGET_MEMBER_ENTITY);
|
||||
when(emw.find(eq(HsOfficeMembershipEntity.class), eq(AVAILABLE_TARGET_MEMBERSHIP_UUID))).thenReturn(AVAILABLE_MEMBER_ENTITY);
|
||||
|
||||
final var availableMemberNumber = Integer.valueOf(AVAILABLE_TARGET_MEMBER_NUMBER.substring("M-".length()));
|
||||
when(membershipRepo.findMembershipByMemberNumber(eq(availableMemberNumber))).thenReturn(AVAILABLE_MEMBER_ENTITY);
|
||||
|
||||
when(membershipRepo.findByUuid(eq(ORIGIN_MEMBERSHIP_UUID))).thenReturn(Optional.of(ORIGIN_TARGET_MEMBER_ENTITY));
|
||||
when(membershipRepo.findByUuid(eq(AVAILABLE_TARGET_MEMBERSHIP_UUID))).thenReturn(Optional.of(AVAILABLE_MEMBER_ENTITY));
|
||||
|
||||
when(coopAssetsTransactionRepo.findByUuid(SOME_EXISTING_LOSS_ASSET_TX_UUID))
|
||||
.thenReturn(Optional.of(SOME_EXISTING_LOSS_ASSET_TX_ENTITY));
|
||||
when(coopAssetsTransactionRepo.save(any(HsOfficeCoopAssetsTransactionEntity.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
final var entity = (HsOfficeCoopAssetsTransactionEntity) invocation.getArgument(0);
|
||||
if (entity.getUuid() == null) {
|
||||
entity.setUuid(TestUuidGenerator.next());
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private int partnerNumberOf(final String memberNumber) {
|
||||
return Integer.parseInt(memberNumber.substring("M-".length(), memberNumber.length()-2));
|
||||
}
|
||||
|
||||
private String suffixOf(final String memberNumber) {
|
||||
return memberNumber.substring("M-".length()+5);
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
|
||||
.comment("some comment")
|
||||
.build();
|
||||
|
||||
|
||||
final HsOfficeCoopAssetsTransactionEntity givenCoopAssetReversalTransaction = HsOfficeCoopAssetsTransactionEntity.builder()
|
||||
.membership(TEST_MEMBERSHIP)
|
||||
.reference("some-ref")
|
||||
@@ -31,6 +30,16 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
|
||||
.revertedAssetTx(givenCoopAssetTransaction)
|
||||
.build();
|
||||
|
||||
final HsOfficeCoopAssetsTransactionEntity givenAdoptedCoopAssetTransaction = HsOfficeCoopAssetsTransactionEntity.builder()
|
||||
.membership(TEST_MEMBERSHIP)
|
||||
.reference("some-ref")
|
||||
.valueDate(LocalDate.parse("2020-01-15"))
|
||||
.transactionType(HsOfficeCoopAssetsTransactionType.ADOPTION)
|
||||
.assetValue(new BigDecimal("128.00"))
|
||||
.comment("some comment")
|
||||
.revertedAssetTx(givenCoopAssetTransaction)
|
||||
.build();
|
||||
|
||||
final HsOfficeCoopAssetsTransactionEntity givenEmptyCoopAssetsTransaction = HsOfficeCoopAssetsTransactionEntity.builder().build();
|
||||
|
||||
@Test
|
||||
@@ -49,6 +58,15 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
|
||||
assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref, some comment, M-1000101:REV:-128.00)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void toStringWithAdoptedAssetTxContainsRevertedAssetTx() {
|
||||
givenCoopAssetTransaction.setAdoptionAssetTx(givenAdoptedCoopAssetTransaction);
|
||||
|
||||
final var result = givenCoopAssetTransaction.toString();
|
||||
|
||||
assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref, some comment, M-1000101:ADO:+128.00)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void toShortStringContainsOnlyMemberNumberSuffixAndSharesCountOnly() {
|
||||
final var result = givenCoopAssetTransaction.toShortString();
|
||||
|
@@ -144,16 +144,22 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
|
||||
"CoopAssetsTransaction(M-1000101: 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)",
|
||||
"CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss, M-1000101:REV:-128.00)",
|
||||
"CoopAssetsTransaction(M-1000101: 2022-10-21, REVERSAL, -128.00, ref 1000101-3, some reversal, M-1000101:DEP:+128.00)",
|
||||
"CoopAssetsTransaction(M-1000101: 2023-12-31, ADOPTION, 192.00, ref 1000101-3, some reversal, M-1000101:TRA:-192.00)",
|
||||
"CoopAssetsTransaction(M-1000101: 2023-12-31, TRANSFER, -192.00, ref 1000101-3, some reversal, M-1000101:ADO:+192.00)",
|
||||
|
||||
"CoopAssetsTransaction(M-1000202: 2010-03-15, DEPOSIT, 320.00, ref 1000202-1, initial deposit)",
|
||||
"CoopAssetsTransaction(M-1000202: 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)",
|
||||
"CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss, M-1000202:REV:-128.00)",
|
||||
"CoopAssetsTransaction(M-1000202: 2022-10-21, REVERSAL, -128.00, ref 1000202-3, some reversal, M-1000202:DEP:+128.00)",
|
||||
"CoopAssetsTransaction(M-1000202: 2023-12-31, TRANSFER, -192.00, ref 1000202-3, some reversal, M-1000202:ADO:+192.00)",
|
||||
"CoopAssetsTransaction(M-1000202: 2023-12-31, ADOPTION, 192.00, ref 1000202-3, some reversal, M-1000202:TRA:-192.00)",
|
||||
|
||||
"CoopAssetsTransaction(M-1000303: 2010-03-15, DEPOSIT, 320.00, ref 1000303-1, initial deposit)",
|
||||
"CoopAssetsTransaction(M-1000303: 2021-09-01, DISBURSAL, -128.00, ref 1000303-2, partial disbursal)",
|
||||
"CoopAssetsTransaction(M-1000303: 2022-10-20, DEPOSIT, 128.00, ref 1000303-3, some loss, M-1000303:REV:-128.00)",
|
||||
"CoopAssetsTransaction(M-1000303: 2022-10-21, REVERSAL, -128.00, ref 1000303-3, some reversal, M-1000303:DEP:+128.00)");
|
||||
"CoopAssetsTransaction(M-1000303: 2022-10-21, REVERSAL, -128.00, ref 1000303-3, some reversal, M-1000303:DEP:+128.00)",
|
||||
"CoopAssetsTransaction(M-1000303: 2023-12-31, TRANSFER, -192.00, ref 1000303-3, some reversal, M-1000303:ADO:+192.00)",
|
||||
"CoopAssetsTransaction(M-1000303: 2023-12-31, ADOPTION, 192.00, ref 1000303-3, some reversal, M-1000303:TRA:-192.00)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,7 +180,9 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
|
||||
"CoopAssetsTransaction(M-1000202: 2010-03-15, DEPOSIT, 320.00, ref 1000202-1, initial deposit)",
|
||||
"CoopAssetsTransaction(M-1000202: 2021-09-01, DISBURSAL, -128.00, ref 1000202-2, partial disbursal)",
|
||||
"CoopAssetsTransaction(M-1000202: 2022-10-20, DEPOSIT, 128.00, ref 1000202-3, some loss, M-1000202:REV:-128.00)",
|
||||
"CoopAssetsTransaction(M-1000202: 2022-10-21, REVERSAL, -128.00, ref 1000202-3, some reversal, M-1000202:DEP:+128.00)");
|
||||
"CoopAssetsTransaction(M-1000202: 2022-10-21, REVERSAL, -128.00, ref 1000202-3, some reversal, M-1000202:DEP:+128.00)",
|
||||
"CoopAssetsTransaction(M-1000202: 2023-12-31, TRANSFER, -192.00, ref 1000202-3, some reversal, M-1000202:ADO:+192.00)",
|
||||
"CoopAssetsTransaction(M-1000202: 2023-12-31, ADOPTION, 192.00, ref 1000202-3, some reversal, M-1000202:TRA:-192.00)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -212,7 +220,9 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase
|
||||
"CoopAssetsTransaction(M-1000101: 2010-03-15, DEPOSIT, 320.00, ref 1000101-1, initial deposit)",
|
||||
"CoopAssetsTransaction(M-1000101: 2021-09-01, DISBURSAL, -128.00, ref 1000101-2, partial disbursal)",
|
||||
"CoopAssetsTransaction(M-1000101: 2022-10-20, DEPOSIT, 128.00, ref 1000101-3, some loss, M-1000101:REV:-128.00)",
|
||||
"CoopAssetsTransaction(M-1000101: 2022-10-21, REVERSAL, -128.00, ref 1000101-3, some reversal, M-1000101:DEP:+128.00)");
|
||||
"CoopAssetsTransaction(M-1000101: 2022-10-21, REVERSAL, -128.00, ref 1000101-3, some reversal, M-1000101:DEP:+128.00)",
|
||||
"CoopAssetsTransaction(M-1000101: 2023-12-31, TRANSFER, -192.00, ref 1000101-3, some reversal, M-1000101:ADO:+192.00)",
|
||||
"CoopAssetsTransaction(M-1000101: 2023-12-31, ADOPTION, 192.00, ref 1000101-3, some reversal, M-1000101:TRA:-192.00)");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -30,6 +30,7 @@ class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
Context contextMock;
|
||||
|
||||
@MockBean
|
||||
@SuppressWarnings("unused") // not used in test, but in controller class
|
||||
StandardMapper mapper;
|
||||
|
||||
@MockBean
|
||||
|
@@ -40,7 +40,7 @@ class HsOfficeCoopSharesTransactionEntityUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void toStringWithRevertedAssetTxContainsRevertedAssetTx() {
|
||||
void toStringWithRelatedAssetTxContainsRelatedAssetTx() {
|
||||
givenCoopSharesTransaction.setRevertedShareTx(givenCoopShareReversalTransaction);
|
||||
|
||||
final var result = givenCoopSharesTransaction.toString();
|
||||
|
@@ -17,6 +17,7 @@ import net.hostsharing.hsadminng.hs.office.scenarios.membership.CreateMembership
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopassets.CreateCoopAssetsDepositTransaction;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopassets.CreateCoopAssetsDisbursalTransaction;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopassets.CreateCoopAssetsRevertTransaction;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopassets.CreateCoopAssetsTransferTransaction;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopshares.CreateCoopSharesCancellationTransaction;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopshares.CreateCoopSharesRevertTransaction;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.coopshares.CreateCoopSharesSubscriptionTransaction;
|
||||
@@ -29,12 +30,15 @@ import net.hostsharing.hsadminng.hs.office.scenarios.subscription.RemoveOperatio
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.subscription.SubscribeToMailinglist;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.subscription.UnsubscribeFromMailinglist;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.test.IgnoreOnFailure;
|
||||
import net.hostsharing.hsadminng.test.IgnoreOnFailureExtension;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@@ -51,6 +55,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
)
|
||||
@DirtiesContext
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@ExtendWith(IgnoreOnFailureExtension.class)
|
||||
class HsOfficeScenarioTests extends ScenarioTest {
|
||||
|
||||
@Test
|
||||
@@ -77,8 +82,8 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
|
||||
@Test
|
||||
@Order(1011)
|
||||
@Produces(explicitly = "Partner: P-31011 - Michelle Matthieu", implicitly = { "Person: Michelle Matthieu",
|
||||
"Contact: Michelle Matthieu" })
|
||||
@Produces(explicitly = "Partner: P-31011 - Michelle Matthieu",
|
||||
implicitly = { "Person: Michelle Matthieu", "Contact: Michelle Matthieu" })
|
||||
void shouldCreateNaturalPersonAsPartner() {
|
||||
new CreatePartner(this)
|
||||
.given("partnerNumber", "P-31011")
|
||||
@@ -336,7 +341,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
@Test
|
||||
@Order(4201)
|
||||
@Requires("Membership: M-3101000 - Test AG")
|
||||
@Produces("Coop-Shares SUBSCRIPTION Transaction")
|
||||
@Produces("Coop-Shares M-3101000 - Test AG - SUBSCRIPTION Transaction")
|
||||
void shouldSubscribeCoopShares() {
|
||||
new CreateCoopSharesSubscriptionTransaction(this)
|
||||
.given("memberNumber", "M-3101000")
|
||||
@@ -360,8 +365,8 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
|
||||
@Test
|
||||
@Order(4202)
|
||||
@Requires("Coop-Shares SUBSCRIPTION Transaction")
|
||||
@Produces("Coop-Shares CANCELLATION Transaction")
|
||||
@Requires("Coop-Shares M-3101000 - Test AG - SUBSCRIPTION Transaction")
|
||||
@Produces("Coop-Shares M-3101000 - Test AG - CANCELLATION Transaction")
|
||||
void shouldCancelCoopSharesSubscription() {
|
||||
new CreateCoopSharesCancellationTransaction(this)
|
||||
.given("memberNumber", "M-3101000")
|
||||
@@ -375,7 +380,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
@Test
|
||||
@Order(4301)
|
||||
@Requires("Membership: M-3101000 - Test AG")
|
||||
@Produces("Coop-Assets DEPOSIT Transaction")
|
||||
@Produces("Coop-Assets M-3101000 - Test AG - DEPOSIT Transaction")
|
||||
void shouldSubscribeCoopAssets() {
|
||||
new CreateCoopAssetsDepositTransaction(this)
|
||||
.given("memberNumber", "M-3101000")
|
||||
@@ -388,7 +393,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
|
||||
@Test
|
||||
@Order(4302)
|
||||
@Requires("Coop-Assets DEPOSIT Transaction")
|
||||
@Requires("Membership: M-3101000 - Test AG")
|
||||
void shouldRevertCoopAssetsSubscription() {
|
||||
new CreateCoopAssetsRevertTransaction(this)
|
||||
.given("memberNumber", "M-3101000")
|
||||
@@ -398,9 +403,9 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4302)
|
||||
@Requires("Coop-Assets DEPOSIT Transaction")
|
||||
@Produces("Coop-Assets DISBURSAL Transaction")
|
||||
@Order(4303)
|
||||
@Requires("Coop-Assets M-3101000 - Test AG - DEPOSIT Transaction")
|
||||
@Produces("Coop-Assets M-3101000 - Test AG - DISBURSAL Transaction")
|
||||
void shouldDisburseCoopAssets() {
|
||||
new CreateCoopAssetsDisbursalTransaction(this)
|
||||
.given("memberNumber", "M-3101000")
|
||||
@@ -411,6 +416,33 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
.doRun();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4304)
|
||||
@Requires("Coop-Assets M-3101000 - Test AG - DEPOSIT Transaction")
|
||||
@Produces("Coop-Assets M-3101000 - Test AG - TRANSFER Transaction")
|
||||
void shouldTransferCoopAssets() {
|
||||
new CreateCoopAssetsTransferTransaction(this)
|
||||
.given("transferringMemberNumber", "M-3101000")
|
||||
.given("adoptingMemberNumber", "M-4303000")
|
||||
.given("reference", "transfer 2024-12-31")
|
||||
.given("valueToDisburse", 2 * 64)
|
||||
.given("comment", "transfer assets from M-3101000 to M-4303000")
|
||||
.given("transactionDate", "2024-12-31")
|
||||
.doRun();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4305)
|
||||
@Requires("Coop-Assets M-3101000 - Test AG - TRANSFER Transaction")
|
||||
@IgnoreOnFailure("TODO.impl: reverting transfers is not implemented yet")
|
||||
void shouldRevertCoopAssetsTransfer() {
|
||||
new CreateCoopAssetsRevertTransaction(this)
|
||||
.given("memberNumber", "M-3101000")
|
||||
.given("comment", "reverting some incorrect transfer transaction")
|
||||
.given("dateOfIncorrectTransaction", "2024-02-15")
|
||||
.doRun();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4900)
|
||||
@Requires("Membership: M-3101000 - Test AG")
|
||||
|
@@ -36,6 +36,7 @@ import java.util.function.Supplier;
|
||||
import static java.net.URLEncoder.encode;
|
||||
import static net.hostsharing.hsadminng.hs.office.scenarios.TemplateResolver.Resolver.DROP_COMMENTS;
|
||||
import static net.hostsharing.hsadminng.hs.office.scenarios.TemplateResolver.Resolver.KEEP_COMMENTS;
|
||||
import static net.hostsharing.hsadminng.test.DebuggerDetection.isDebuggerAttached;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.platform.commons.util.StringUtils.isBlank;
|
||||
@@ -151,7 +152,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
.GET()
|
||||
.uri(new URI("http://localhost:" + testSuite.port + uriPath))
|
||||
.header("current-subject", ScenarioTest.RUN_AS_USER)
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.timeout(seconds(10))
|
||||
.build();
|
||||
final var response = client.send(request, BodyHandlers.ofString());
|
||||
return new HttpResponse(HttpMethod.GET, uriPath, null, response);
|
||||
@@ -166,7 +167,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
.uri(new URI("http://localhost:" + testSuite.port + uriPath))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("current-subject", ScenarioTest.RUN_AS_USER)
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.timeout(seconds(10))
|
||||
.build();
|
||||
final var response = client.send(request, BodyHandlers.ofString());
|
||||
return new HttpResponse(HttpMethod.POST, uriPath, requestBody, response);
|
||||
@@ -181,7 +182,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
.uri(new URI("http://localhost:" + testSuite.port + uriPath))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("current-subject", ScenarioTest.RUN_AS_USER)
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.timeout(seconds(10))
|
||||
.build();
|
||||
final var response = client.send(request, BodyHandlers.ofString());
|
||||
return new HttpResponse(HttpMethod.PATCH, uriPath, requestBody, response);
|
||||
@@ -195,7 +196,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
.uri(new URI("http://localhost:" + testSuite.port + uriPath))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("current-subject", ScenarioTest.RUN_AS_USER)
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.timeout(seconds(10))
|
||||
.build();
|
||||
final var response = client.send(request, BodyHandlers.ofString());
|
||||
return new HttpResponse(HttpMethod.DELETE, uriPath, null, response);
|
||||
@@ -237,6 +238,10 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
}
|
||||
}
|
||||
|
||||
private static Duration seconds(final int secondsIfNoDebuggerAttached) {
|
||||
return isDebuggerAttached() ? Duration.ofHours(1) : Duration.ofSeconds(secondsIfNoDebuggerAttached);
|
||||
}
|
||||
|
||||
public final class HttpResponse {
|
||||
|
||||
@Getter
|
||||
|
@@ -10,7 +10,7 @@ public class CreateCoopAssetsRevertTransaction extends CreateCoopAssetsTransacti
|
||||
requires("CoopAssets-Transaction with incorrect assetValue", alias ->
|
||||
new CreateCoopAssetsDepositTransaction(testSuite)
|
||||
.given("memberNumber", "%{memberNumber}")
|
||||
.given("reference", "sign %{dateOfIncorrectTransaction}") // same as revertedAssetTx
|
||||
.given("reference", "sign %{dateOfIncorrectTransaction}") // same as relatedAssetTx
|
||||
.given("assetValue", 10)
|
||||
.given("comment", "coop-assets deposit transaction with wrong asset value")
|
||||
.given("transactionDate", "%{dateOfIncorrectTransaction}")
|
||||
@@ -20,7 +20,7 @@ public class CreateCoopAssetsRevertTransaction extends CreateCoopAssetsTransacti
|
||||
@Override
|
||||
protected HttpResponse run() {
|
||||
given("transactionType", "REVERSAL");
|
||||
given("assetValue", -100);
|
||||
given("assetValue", -10);
|
||||
given("revertedAssetTx", uuid("CoopAssets-Transaction with incorrect assetValue"));
|
||||
return super.run();
|
||||
}
|
||||
|
@@ -32,7 +32,8 @@ public abstract class CreateCoopAssetsTransaction extends UseCase<CreateCoopAsse
|
||||
"assetValue": ${assetValue},
|
||||
"comment": ${comment},
|
||||
"valueDate": ${transactionDate},
|
||||
"revertedAssetTx.uuid": ${revertedAssetTx???}
|
||||
"revertedAssetTx.uuid": ${revertedAssetTx???},
|
||||
"adoptingMembership.memberNumber": ${adoptingMemberNumber???}
|
||||
}
|
||||
"""))
|
||||
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
||||
|
@@ -0,0 +1,46 @@
|
||||
package net.hostsharing.hsadminng.hs.office.scenarios.membership.coopassets;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.membership.CreateMembership;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.partner.CreatePartner;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.scenarios.TemplateResolver.Resolver.DROP_COMMENTS;
|
||||
|
||||
public class CreateCoopAssetsTransferTransaction extends CreateCoopAssetsTransaction {
|
||||
|
||||
public CreateCoopAssetsTransferTransaction(final ScenarioTest testSuite) {
|
||||
super(testSuite);
|
||||
|
||||
requires("Partner: New AG", alias -> new CreatePartner(testSuite, alias)
|
||||
.given("partnerNumber", toPartnerNumber("%{adoptingMemberNumber}"))
|
||||
.given("personType", "LEGAL_PERSON")
|
||||
.given("tradeName", "New AG")
|
||||
.given("contactCaption", "New AG - Board of Directors")
|
||||
.given("emailAddress", "board-of-directors@new-ag.example.org")
|
||||
);
|
||||
|
||||
requires("Membership: New AG", alias -> new CreateMembership(testSuite)
|
||||
.given("partnerNumber", toPartnerNumber("%{adoptingMemberNumber}"))
|
||||
.given("partnerName", "New AG")
|
||||
.given("validFrom", "2024-11-15")
|
||||
.given("newStatus", "ACTIVE")
|
||||
.given("membershipFeeBillable", "true")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpResponse run() {
|
||||
introduction("Additionally to the TRANSFER, the ADOPTION is automatically booked for the receiving member.");
|
||||
|
||||
given("memberNumber", "%{transferringMemberNumber}");
|
||||
given("transactionType", "TRANSFER");
|
||||
given("assetValue", "-%{valueToDisburse}");
|
||||
given("assetValue", "-%{valueToDisburse}");
|
||||
return super.run();
|
||||
}
|
||||
|
||||
private String toPartnerNumber(final String resolvableString) {
|
||||
final var memberNumber = ScenarioTest.resolve(resolvableString, DROP_COMMENTS);
|
||||
return "P-" + memberNumber.substring("M-".length(), 7);
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package net.hostsharing.hsadminng.test;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
@UtilityClass
|
||||
public class DebuggerDetection {
|
||||
public static boolean isDebuggerAttached() {
|
||||
// check for typical debug arguments in the JVM input arguments
|
||||
return ManagementFactory.getRuntimeMXBean().getInputArguments().stream()
|
||||
.anyMatch(arg -> arg.contains("-agentlib:jdwp"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package net.hostsharing.hsadminng.test;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Use this annotation on JUnit Jupiter test-methods to convert failure to ignore.
|
||||
*
|
||||
* <p>
|
||||
* The test-class also has to add the extension {link IgnoreOnFailureExtension}.
|
||||
* </p>
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface IgnoreOnFailure {
|
||||
/// a comment, e.g. about the feature under construction
|
||||
String value() default "";
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
package net.hostsharing.hsadminng.test;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import org.junit.jupiter.api.extension.InvocationInterceptor;
|
||||
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
|
||||
/**
|
||||
* Use this JUnit Jupiter extension to ignore failing tests annotated with annotation {@link IgnoreOnFailure}.
|
||||
*
|
||||
* <p>
|
||||
* This is useful for outside-in-TDD, if you write a high-level (e.g. Acceptance- or Scenario-Test) before
|
||||
* you even have an implementation for that new feature.
|
||||
* As long as no other tests breaks, it's not a real problem merging your new test and incomplete implementation.
|
||||
* </p>
|
||||
* <p>
|
||||
* Once the test turns green, remove the annotation {@link IgnoreOnFailure}.
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
// BLOG: A JUnit Jupiter extension to ignore failed acceptance tests for outside-in TDD
|
||||
public class IgnoreOnFailureExtension implements InvocationInterceptor {
|
||||
|
||||
/// @hidden
|
||||
@Override
|
||||
public void interceptTestMethod(
|
||||
final Invocation<Void> invocation,
|
||||
final ReflectiveInvocationContext<Method> invocationContext,
|
||||
final ExtensionContext extensionContext) throws Throwable {
|
||||
|
||||
try {
|
||||
invocation.proceed();
|
||||
} catch (final Throwable throwable) {
|
||||
if (hasIgnoreOnFailureAnnotation(extensionContext)) {
|
||||
assumeThat(true).as("ignoring failed test with @" + IgnoreOnFailure.class.getSimpleName()).isFalse();
|
||||
} else {
|
||||
throw throwable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasIgnoreOnFailureAnnotation(final ExtensionContext context) {
|
||||
final var hasIgnoreOnFailureAnnotation = context.getTestMethod()
|
||||
.map(method -> method.getAnnotation(IgnoreOnFailure.class))
|
||||
.isPresent();
|
||||
return hasIgnoreOnFailureAnnotation;
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
package net.hostsharing.hsadminng.test;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
public class TestUuidGenerator {
|
||||
|
||||
private static final UUID ZEROES_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
|
||||
private static final List<UUID> GIVEN_UUIDS = List.of(
|
||||
ZEROES_UUID,
|
||||
uuidWithDigit(1),
|
||||
uuidWithDigit(2),
|
||||
uuidWithDigit(3),
|
||||
uuidWithDigit(4),
|
||||
uuidWithDigit(5),
|
||||
uuidWithDigit(6),
|
||||
uuidWithDigit(7),
|
||||
uuidWithDigit(8),
|
||||
uuidWithDigit(9),
|
||||
uuidWithChar('a'),
|
||||
uuidWithChar('b'),
|
||||
uuidWithChar('c'),
|
||||
uuidWithChar('d'),
|
||||
uuidWithChar('e'),
|
||||
uuidWithChar('f')
|
||||
);
|
||||
|
||||
private static Set<Integer> staticallyUsedIndexes = new HashSet<>();
|
||||
|
||||
private Queue<UUID> availableUuids = null;
|
||||
|
||||
|
||||
public static void start(final int firstIndex) {
|
||||
if (staticallyUsedIndexes.contains(firstIndex)) {
|
||||
throw new IllegalArgumentException(firstIndex + " already used statically, try higher and amend references");
|
||||
}
|
||||
availableUuids = new LinkedList<>(GIVEN_UUIDS.subList(firstIndex, GIVEN_UUIDS.size()));
|
||||
}
|
||||
|
||||
public static UUID next() {
|
||||
if (availableUuids == null) {
|
||||
throw new IllegalStateException("UUID generator not started yet, call start() in @BeforeEach.");
|
||||
}
|
||||
if (availableUuids.isEmpty()) {
|
||||
throw new IllegalStateException("No UUIDs available anymore.");
|
||||
}
|
||||
return availableUuids.poll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the UUID as used in static initializers.
|
||||
*
|
||||
* @param index 0..15
|
||||
* @return a constant UUID related to the given index
|
||||
*/
|
||||
public static UUID use(final int index) {
|
||||
staticallyUsedIndexes.add(index);
|
||||
return GIVEN_UUIDS.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* References the UUID from the given index.
|
||||
*
|
||||
* @param index 0..15
|
||||
* @return a constant UUID related to the given index
|
||||
*/
|
||||
public static UUID ref(final int index) {
|
||||
return GIVEN_UUIDS.get(index);
|
||||
}
|
||||
|
||||
private static @NotNull UUID uuidWithDigit(final int digit) {
|
||||
return UUID.fromString(ZEROES_UUID.toString().replace('0', Character.forDigit(digit, 16)));
|
||||
}
|
||||
|
||||
private static @NotNull UUID uuidWithChar(final char hexDigit) {
|
||||
return UUID.fromString(ZEROES_UUID.toString().replace('0', hexDigit));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user