WIP: add advanced scenario-tests for coop-assets #123
@ -99,7 +99,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE
|
|||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
// Optionally, the UUID of the corresponding transaction for a reversal transaction.
|
// Optionally, the UUID of the corresponding transaction for a reversal transaction.
|
||||||
@OneToOne
|
@OneToOne(cascade = CascadeType.PERSIST) // TODO.impl: can probably be removed after office data migration
|
||||||
@JoinColumn(name = "revertedassettxuuid")
|
@JoinColumn(name = "revertedassettxuuid")
|
||||||
private HsOfficeCoopAssetsTransactionEntity revertedAssetTx;
|
private HsOfficeCoopAssetsTransactionEntity revertedAssetTx;
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, BaseE
|
|||||||
private HsOfficeCoopAssetsTransactionEntity assetReversalTx;
|
private HsOfficeCoopAssetsTransactionEntity assetReversalTx;
|
||||||
|
|
||||||
// Optionally, the UUID of the corresponding transaction for a transfer transaction.
|
// Optionally, the UUID of the corresponding transaction for a transfer transaction.
|
||||||
@OneToOne
|
@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 assetAdoptionAssetTx;
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
1094=CoopAssetsTransaction(M-1000300: 2023-10-06, DEPOSIT, 3072, 1000300, Kapitalerhoehung - Ueberweisung),
|
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),
|
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),
|
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),
|
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),
|
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),
|
34002=CoopAssetsTransaction(M-1002000: 2016-12-31, DISBURSAL, -100.00, 1002000, for cancellation D),
|
||||||
@ -864,21 +864,44 @@ public abstract class BaseOfficeDataImport extends CsvDataImport {
|
|||||||
.comment(rec.getString("comment"))
|
.comment(rec.getString("comment"))
|
||||||
.reference(member.getMemberNumber().toString())
|
.reference(member.getMemberNumber().toString())
|
||||||
.build();
|
.build();
|
||||||
|
coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
coopAssets.values().forEach(assetTransaction -> {
|
||||||
if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.REVERSAL) {
|
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 negativeValue = assetTransaction.getAssetValue().negate();
|
||||||
final var reversalAssetTx = coopAssets.values().stream().filter(a ->
|
final var revertedAssetTx = coopAssets.values().stream().filter(a ->
|
||||||
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.REVERSAL &&
|
a.getTransactionType() != HsOfficeCoopAssetsTransactionType.REVERSAL &&
|
||||||
a.getMembership() == assetTransaction.getMembership() &&
|
a.getMembership() == assetTransaction.getMembership() &&
|
||||||
a.getAssetValue().equals(negativeValue))
|
a.getAssetValue().equals(negativeValue))
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseThrow(() -> new IllegalStateException(
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
"cannot determine asset reverse entry for reversal " + assetTransaction));
|
"cannot determine asset reverse entry for reversal " + assetTransaction));
|
||||||
assetTransaction.setAssetReversalTx(reversalAssetTx);
|
assetTransaction.setRevertedAssetTx(revertedAssetTx);
|
||||||
|
//revertedAssetTx.setAssetReversalTx(assetTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
coopAssets.put(rec.getInteger("member_asset_id"), 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.setAssetAdoptionAssetTx(adoptionAssetTx);
|
||||||
|
//adoptionAssetTx.setAssetTransferTx(assetTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HsOfficeMembershipEntity createOnDemandMembership(final Integer bpId) {
|
private static HsOfficeMembershipEntity createOnDemandMembership(final Integer bpId) {
|
||||||
|
@ -172,10 +172,14 @@ public class CsvDataImport extends ContextBasedTest {
|
|||||||
public <T extends BaseEntity> T persistViaEM(final Integer id, final T entity) {
|
public <T extends BaseEntity> T persistViaEM(final Integer id, final T entity) {
|
||||||
//System.out.println("persisting #" + entity.hashCode() + ": " + entity);
|
//System.out.println("persisting #" + entity.hashCode() + ": " + entity);
|
||||||
em.persist(entity);
|
em.persist(entity);
|
||||||
// uncomment for debugging purposes
|
// uncomment for debugging purposes FIXME
|
||||||
// em.flush(); // makes it slow, but produces better error messages
|
try {
|
||||||
// System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid());
|
em.flush(); // makes it slow, but produces better error messages
|
||||||
|
System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid());
|
||||||
return entity;
|
return entity;
|
||||||
|
} catch (final Exception exc) {
|
||||||
|
throw exc; // for breakpoints
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.coopassets;
|
package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
|
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||||
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
import net.hostsharing.hsadminng.mapper.StandardMapper;
|
||||||
import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
|
import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
@ -35,6 +36,9 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
|||||||
@MockBean
|
@MockBean
|
||||||
HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo;
|
HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
HsOfficeMembershipRepository membershipRepo;
|
||||||
|
|
||||||
static final String VALID_INSERT_REQUEST_BODY = """
|
static final String VALID_INSERT_REQUEST_BODY = """
|
||||||
{
|
{
|
||||||
"membership.uuid": "%s",
|
"membership.uuid": "%s",
|
||||||
|
Loading…
Reference in New Issue
Block a user