implement coop-asset-TRANSFER-transaction reversal #125

Merged
hsh-michaelhoennig merged 7 commits from feature/implement-coop-asset-transaction-reversal into master 2024-11-28 07:10:36 +01:00
Showing only changes of commit 021c286c63 - Show all commits

View File

@ -10,6 +10,7 @@ import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
import net.hostsharing.hsadminng.rbac.test.JsonBuilder; import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
import net.hostsharing.hsadminng.test.TestUuidGenerator; import net.hostsharing.hsadminng.test.TestUuidGenerator;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.EnumSource;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -24,10 +25,15 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.ADOPTION;
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.DISBURSAL;
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.REVERSAL;
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.TRANSFER;
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 net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assumptions.assumeThat; import static org.assertj.core.api.Assumptions.assumeThat;
@ -47,6 +53,8 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
// set SINGLE_TEST_CASE_EXECUTION to true and make sure you do NOT EVER commit it to git! // set SINGLE_TEST_CASE_EXECUTION to true and make sure you do NOT EVER commit it to git!
private static final boolean SINGLE_TEST_CASE_EXECUTION = false; private static final boolean SINGLE_TEST_CASE_EXECUTION = false;
private static int DYNAMIC_UUID_START_INDEX = 13;
private static final UUID UNAVAILABLE_MEMBERSHIP_UUID = TestUuidGenerator.use(0); private static final UUID UNAVAILABLE_MEMBERSHIP_UUID = TestUuidGenerator.use(0);
private static final String UNAVAILABLE_MEMBER_NUMBER = "M-1234699"; private static final String UNAVAILABLE_MEMBER_NUMBER = "M-1234699";
@ -73,8 +81,8 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
// The following refs depend on the implementation of the respective implementation and might change if it changes. // The following refs depend on the implementation of the respective implementation and might change if it changes.
// The same TestUuidGenerator.ref(#) does NOT mean the UUIDs refer to the same entity, // The same TestUuidGenerator.ref(#) does NOT mean the UUIDs refer to the same entity,
// its rather coincidence because different test-cases have different execution paths in the production code. // its rather coincidence because different test-cases have different execution paths in the production code.
private static final UUID NEW_EXPLICITLY_CREATED_REVERSAL_ASSET_TX_UUID = TestUuidGenerator.ref(6); private static final UUID NEW_EXPLICITLY_CREATED_REVERSAL_ASSET_TX_UUID = TestUuidGenerator.ref(DYNAMIC_UUID_START_INDEX);
private static final UUID NEW_EXPLICITLY_CREATED_TRANSFER_ASSET_TX_UUID = TestUuidGenerator.ref(6); private static final UUID NEW_EXPLICITLY_CREATED_TRANSFER_ASSET_TX_UUID = TestUuidGenerator.ref(DYNAMIC_UUID_START_INDEX);
private static final UUID SOME_EXISTING_LOSS_ASSET_TX_UUID = TestUuidGenerator.use(3); private static final UUID SOME_EXISTING_LOSS_ASSET_TX_UUID = TestUuidGenerator.use(3);
public final HsOfficeCoopAssetsTransactionEntity SOME_EXISTING_LOSS_ASSET_TX_ENTITY = HsOfficeCoopAssetsTransactionEntity.builder() public final HsOfficeCoopAssetsTransactionEntity SOME_EXISTING_LOSS_ASSET_TX_ENTITY = HsOfficeCoopAssetsTransactionEntity.builder()
@ -109,11 +117,352 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
.valueDate(LocalDate.parse("2024-10-15")) .valueDate(LocalDate.parse("2024-10-15"))
.transferAssetTx(SOME_EXISTING_TRANSFER_ASSET_TX_ENTITY) .transferAssetTx(SOME_EXISTING_TRANSFER_ASSET_TX_ENTITY)
.build(); .build();
{ {
SOME_EXISTING_TRANSFER_ASSET_TX_ENTITY.setAdoptionAssetTx(SOME_EXISTING_ADOPTION_ASSET_TX_ENTITY); SOME_EXISTING_TRANSFER_ASSET_TX_ENTITY.setAdoptionAssetTx(SOME_EXISTING_ADOPTION_ASSET_TX_ENTITY);
} }
private final static UUID SOME_REVERTED_DISBURSAL_ASSET_TX_UUID = TestUuidGenerator.use(7);
private final static UUID SOME_DISBURSAL_REVERSAL_ASSET_TX_UUID = TestUuidGenerator.use(8);
private final HsOfficeCoopAssetsTransactionEntity SOME_REVERTED_DISBURSAL_ASSET_TX_ENTITY = HsOfficeCoopAssetsTransactionEntity.builder()
.uuid(SOME_REVERTED_DISBURSAL_ASSET_TX_UUID)
.membership(ORIGIN_TARGET_MEMBER_ENTITY)
.transactionType(DISBURSAL)
.assetValue(BigDecimal.valueOf(-128.00))
.valueDate(LocalDate.parse("2024-10-15"))
.reference("some disbursal")
.comment("some disbursal to get reverted")
.reversalAssetTx(
HsOfficeCoopAssetsTransactionEntity.builder()
.uuid(SOME_DISBURSAL_REVERSAL_ASSET_TX_UUID)
.membership(ORIGIN_TARGET_MEMBER_ENTITY)
.transactionType(REVERSAL)
.assetValue(BigDecimal.valueOf(128.00))
.valueDate(LocalDate.parse("2024-10-20"))
.reference("some reversal")
.comment("some reversal of a disbursal asset tx")
.build()
)
.build();
{
SOME_REVERTED_DISBURSAL_ASSET_TX_ENTITY.getReversalAssetTx().setRevertedAssetTx(SOME_REVERTED_DISBURSAL_ASSET_TX_ENTITY);
}
private final static UUID SOME_REVERTED_TRANSFER_ASSET_TX_UUID = TestUuidGenerator.use(9);
private final static UUID SOME_TRANSFER_REVERSAL_ASSET_TX_UUID = TestUuidGenerator.use(10);
private final static UUID SOME_REVERTED_ADOPTION_ASSET_TX_UUID = TestUuidGenerator.use(11);
private final static UUID SOME_ADOPTION_REVERSAL_ASSET_TX_UUID = TestUuidGenerator.use(12);
final HsOfficeCoopAssetsTransactionEntity SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY = HsOfficeCoopAssetsTransactionEntity.builder()
.uuid(SOME_REVERTED_TRANSFER_ASSET_TX_UUID)
.membership(ORIGIN_TARGET_MEMBER_ENTITY)
.transactionType(TRANSFER)
.assetValue(BigDecimal.valueOf(-1024))
.valueDate(LocalDate.parse("2024-11-10"))
.reference("some transfer")
.comment("some transfer to get reverted")
.adoptionAssetTx(
HsOfficeCoopAssetsTransactionEntity.builder()
.uuid(SOME_REVERTED_ADOPTION_ASSET_TX_UUID)
.membership(AVAILABLE_MEMBER_ENTITY)
.transactionType(ADOPTION)
.assetValue(BigDecimal.valueOf(1024))
.valueDate(LocalDate.parse("2024-11-10"))
.reference("related adoption")
.comment("some reversal of a transfer asset tx")
.reversalAssetTx(
HsOfficeCoopAssetsTransactionEntity.builder()
.uuid(SOME_ADOPTION_REVERSAL_ASSET_TX_UUID)
.membership(AVAILABLE_MEMBER_ENTITY)
.transactionType(REVERSAL)
.assetValue(BigDecimal.valueOf(1024))
.valueDate(LocalDate.parse("2024-11-11"))
.reference("some reversal")
.comment("some adoption asset tx reversal")
.build()
)
.build()
)
.reversalAssetTx(
HsOfficeCoopAssetsTransactionEntity.builder()
.uuid(SOME_TRANSFER_REVERSAL_ASSET_TX_UUID)
.membership(ORIGIN_TARGET_MEMBER_ENTITY)
.transactionType(REVERSAL)
.assetValue(BigDecimal.valueOf(1024))
.valueDate(LocalDate.parse("2024-11-11"))
.reference("some transfer")
.comment("some transfer asset tx reversal")
.build()
)
.build();
{
SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getAdoptionAssetTx()
.setTransferAssetTx(SOME_REVERTED_DISBURSAL_ASSET_TX_ENTITY);
SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getReversalAssetTx()
.setRevertedAssetTx(SOME_REVERTED_DISBURSAL_ASSET_TX_ENTITY);
SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getAdoptionAssetTx().getReversalAssetTx()
.setRevertedAssetTx(SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getAdoptionAssetTx());
}
private static final String EXPECTED_RESULT_FROM_GET_LIST = """
[
{
"uuid": "33333333-3333-3333-3333-333333333333",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "LOSS",
"assetValue": -64,
"valueDate": "2024-10-15",
"reference": "some loss asset tx ref",
"comment": "some loss asset tx comment",
"adoptionAssetTx": null,
"transferAssetTx": null,
"revertedAssetTx": null,
"reversalAssetTx": null
},
{
"uuid": "44444444-4444-4444-4444-444444444444",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "TRANSFER",
"assetValue": -256,
"valueDate": "2024-10-15",
"reference": "some transfer asset tx ref",
"comment": "some transfer asset tx comment",
"adoptionAssetTx": {
"uuid": "55555555-5555-5555-5555-555555555555",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "TRANSFER",
"assetValue": 256,
"valueDate": "2024-10-15",
"reference": "some adoption asset tx ref",
"comment": "some adoption asset tx comment",
"adoptionAssetTx.uuid": null,
"transferAssetTx.uuid": "44444444-4444-4444-4444-444444444444",
"revertedAssetTx.uuid": null,
"reversalAssetTx.uuid": null
},
"transferAssetTx": null,
"revertedAssetTx": null,
"reversalAssetTx": null
},
{
"uuid": "55555555-5555-5555-5555-555555555555",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "TRANSFER",
"assetValue": 256,
"valueDate": "2024-10-15",
"reference": "some adoption asset tx ref",
"comment": "some adoption asset tx comment",
"adoptionAssetTx": null,
"transferAssetTx": {
"uuid": "44444444-4444-4444-4444-444444444444",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "TRANSFER",
"assetValue": -256,
"valueDate": "2024-10-15",
"reference": "some transfer asset tx ref",
"comment": "some transfer asset tx comment",
"adoptionAssetTx.uuid": "55555555-5555-5555-5555-555555555555",
"transferAssetTx.uuid": null,
"revertedAssetTx.uuid": null,
"reversalAssetTx.uuid": null
},
"revertedAssetTx": null,
"reversalAssetTx": null
},
{
"uuid": "77777777-7777-7777-7777-777777777777",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "DISBURSAL",
"assetValue": -128.0,
"valueDate": "2024-10-15",
"reference": "some disbursal",
"comment": "some disbursal to get reverted",
"adoptionAssetTx": null,
"transferAssetTx": null,
"revertedAssetTx": null,
"reversalAssetTx": {
"uuid": "88888888-8888-8888-8888-888888888888",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "REVERSAL",
"assetValue": 128.0,
"valueDate": "2024-10-20",
"reference": "some reversal",
"comment": "some reversal of a disbursal asset tx",
"adoptionAssetTx.uuid": null,
"transferAssetTx.uuid": null,
"revertedAssetTx.uuid": "77777777-7777-7777-7777-777777777777",
"reversalAssetTx.uuid": null
}
},
{
"uuid": "88888888-8888-8888-8888-888888888888",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "REVERSAL",
"assetValue": 128.0,
"valueDate": "2024-10-20",
"reference": "some reversal",
"comment": "some reversal of a disbursal asset tx",
"adoptionAssetTx": null,
"transferAssetTx": null,
"revertedAssetTx": {
"uuid": "77777777-7777-7777-7777-777777777777",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "DISBURSAL",
"assetValue": -128.0,
"valueDate": "2024-10-15",
"reference": "some disbursal",
"comment": "some disbursal to get reverted",
"adoptionAssetTx.uuid": null,
"transferAssetTx.uuid": null,
"revertedAssetTx.uuid": null,
"reversalAssetTx.uuid": "88888888-8888-8888-8888-888888888888"
},
"reversalAssetTx": null
},
{
"uuid": "99999999-9999-9999-9999-999999999999",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "TRANSFER",
"assetValue": -1024,
"valueDate": "2024-11-10",
"reference": "some transfer",
"comment": "some transfer to get reverted",
"adoptionAssetTx": {
"uuid": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"membership.uuid": "22222222-2222-2222-2222-222222222222",
"membership.memberNumber": "M-1234500",
"transactionType": "ADOPTION",
"assetValue": 1024,
"valueDate": "2024-11-10",
"reference": "related adoption",
"comment": "some reversal of a transfer asset tx",
"adoptionAssetTx.uuid": null,
"transferAssetTx.uuid": "99999999-9999-9999-9999-999999999999",
"revertedAssetTx.uuid": null,
"reversalAssetTx.uuid": "cccccccc-cccc-cccc-cccc-cccccccccccc"
},
"transferAssetTx": null,
"revertedAssetTx": null,
"reversalAssetTx": {
"uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "REVERSAL",
"assetValue": 1024,
"valueDate": "2024-11-11",
"reference": "some transfer",
"comment": "some transfer asset tx reversal",
"adoptionAssetTx.uuid": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"transferAssetTx.uuid": null,
"revertedAssetTx.uuid": "99999999-9999-9999-9999-999999999999",
"reversalAssetTx.uuid": null
}
},
{
"uuid": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"membership.uuid": "22222222-2222-2222-2222-222222222222",
"membership.memberNumber": "M-1234500",
"transactionType": "ADOPTION",
"assetValue": 1024,
hsh-michaelhoennig marked this conversation as resolved Outdated

reversalAssetTx: null fehlt

reversalAssetTx: null fehlt
"valueDate": "2024-11-10",
"reference": "related adoption",
"comment": "some reversal of a transfer asset tx",
"adoptionAssetTx": null,
"transferAssetTx": {
"uuid": "77777777-7777-7777-7777-777777777777",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "DISBURSAL",
"assetValue": -128.0,
"valueDate": "2024-10-15",
"reference": "some disbursal",
"comment": "some disbursal to get reverted",
"adoptionAssetTx.uuid": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"transferAssetTx.uuid": null,
"revertedAssetTx.uuid": null,
"reversalAssetTx.uuid": "88888888-8888-8888-8888-888888888888"
},
"revertedAssetTx": null,
"reversalAssetTx": {
"uuid": "cccccccc-cccc-cccc-cccc-cccccccccccc",
"membership.uuid": "22222222-2222-2222-2222-222222222222",
"membership.memberNumber": "M-1234500",
"transactionType": "REVERSAL",
"assetValue": 1024,
"valueDate": "2024-11-11",
"reference": "some reversal",
"comment": "some adoption asset tx reversal",
"adoptionAssetTx.uuid": null,
"transferAssetTx.uuid": "77777777-7777-7777-7777-777777777777",
"revertedAssetTx.uuid": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"reversalAssetTx.uuid": null
}
},
{
"uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "REVERSAL",
"assetValue": 1024,
"valueDate": "2024-11-11",
"reference": "some transfer",
"comment": "some transfer asset tx reversal",
"adoptionAssetTx": null,
"transferAssetTx": null,
"revertedAssetTx": {
"uuid": "77777777-7777-7777-7777-777777777777",
"membership.uuid": "11111111-1111-1111-1111-111111111111",
"membership.memberNumber": "M-1111100",
"transactionType": "DISBURSAL",
"assetValue": -128.0,
"valueDate": "2024-10-15",
"reference": "some disbursal",
"comment": "some disbursal to get reverted",
"adoptionAssetTx.uuid": null,
"transferAssetTx.uuid": null,
"revertedAssetTx.uuid": null,
"reversalAssetTx.uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
},
"reversalAssetTx": null
},
{
"uuid": "cccccccc-cccc-cccc-cccc-cccccccccccc",
"membership.uuid": "22222222-2222-2222-2222-222222222222",
"membership.memberNumber": "M-1234500",
"transactionType": "REVERSAL",
"assetValue": 1024,
"valueDate": "2024-11-11",
"reference": "some reversal",
"comment": "some adoption asset tx reversal",
"adoptionAssetTx": null,
"transferAssetTx": null,
"revertedAssetTx": {
"uuid": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"membership.uuid": "22222222-2222-2222-2222-222222222222",
"membership.memberNumber": "M-1234500",
"transactionType": "ADOPTION",
"assetValue": 1024,
"valueDate": "2024-11-10",
"reference": "related adoption",
"comment": "some reversal of a transfer asset tx",
"adoptionAssetTx.uuid": null,
"transferAssetTx.uuid": "77777777-7777-7777-7777-777777777777",
"revertedAssetTx.uuid": null,
"reversalAssetTx.uuid": "cccccccc-cccc-cccc-cccc-cccccccccccc"
},
"reversalAssetTx": null
}
]
""";
@Autowired @Autowired
MockMvc mockMvc; MockMvc mockMvc;
@ -308,6 +657,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
"reference": "reversal of loss ref", "reference": "reversal of loss ref",
"comment": "reversal of loss asset tx comment", "comment": "reversal of loss asset tx comment",
"adoptionAssetTx": null, "adoptionAssetTx": null,
"reversalAssetTx": null,
"transferAssetTx": null, "transferAssetTx": null,
"revertedAssetTx": { "revertedAssetTx": {
"uuid": "%{SOME_EXISTING_LOSS_ASSET_TX_UUID}", "uuid": "%{SOME_EXISTING_LOSS_ASSET_TX_UUID}",
@ -416,9 +766,36 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
.andExpect(jsonPath("$", lenientlyEquals(testCase.expectedResponseBody))); .andExpect(jsonPath("$", lenientlyEquals(testCase.expectedResponseBody)));
} }
@Test
void getListGeneratesProperJson() throws Exception {
// given
when(coopAssetsTransactionRepo.findCoopAssetsTransactionByOptionalMembershipUuidAndDateRange(null, null, null))
.thenReturn(List.of(
SOME_EXISTING_LOSS_ASSET_TX_ENTITY,
SOME_EXISTING_TRANSFER_ASSET_TX_ENTITY,
SOME_EXISTING_ADOPTION_ASSET_TX_ENTITY,
SOME_REVERTED_DISBURSAL_ASSET_TX_ENTITY,
SOME_REVERTED_DISBURSAL_ASSET_TX_ENTITY.getReversalAssetTx(),
SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY,
SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getAdoptionAssetTx(),
SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getReversalAssetTx(),
SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getAdoptionAssetTx().getReversalAssetTx()
));
// when
mockMvc.perform(MockMvcRequestBuilders
.get("/api/hs/office/coopassetstransactions")
.header("current-subject", "superuser-alex@hostsharing.net")
.contentType(MediaType.APPLICATION_JSON))
// then
.andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("$", lenientlyEquals(EXPECTED_RESULT_FROM_GET_LIST)));
}
@BeforeEach @BeforeEach
void initMocks() { void initMocks() {
TestUuidGenerator.start(6); TestUuidGenerator.start(DYNAMIC_UUID_START_INDEX);
when(emw.find(eq(HsOfficeMembershipEntity.class), eq(ORIGIN_MEMBERSHIP_UUID))).thenReturn(ORIGIN_TARGET_MEMBER_ENTITY); 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( when(emw.find(eq(HsOfficeMembershipEntity.class), eq(AVAILABLE_TARGET_MEMBERSHIP_UUID))).thenReturn(