registry-service http://jira.mfd.msk:8088/browse/CLS-280, поправил unit-тест
This commit is contained in:
parent
894408354b
commit
50ebdbacb9
3 changed files with 75 additions and 41 deletions
|
|
@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
|
||||
import ru.clearing.classes.statics.data.register.DepoPaymentInstructionRegister;
|
||||
|
|
@ -17,11 +18,13 @@ import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.registry.util.PreClearMap;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
|
@ -39,6 +42,7 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme
|
|||
private final Imdg<Session> sessionMap;
|
||||
private final Imdg<TradingClearingRegistry> tradingClearingRegistryMap;
|
||||
private final Imdg<InOutDirectionDictionary> InOutDirectionDictionaryMap;
|
||||
private final Imdg<Account> accountMap;
|
||||
private final Function<Map<String, ?>, IValidator> fieldValuesValidator;
|
||||
private final PreClearMap<DepoPaymentInstructionRegister> preClearMap;
|
||||
|
||||
|
|
@ -53,6 +57,7 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme
|
|||
this.sessionMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
|
||||
this.tradingClearingRegistryMap = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
this.InOutDirectionDictionaryMap = imdgProvider.getImdg(IMDGDistributedNames.Map_InOutDirectionDictionary, InOutDirectionDictionary.class);
|
||||
this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.fieldValuesValidator = fieldValuesValidator;
|
||||
preClearMap = PreClearMap.instanceForInstantField(depoPaymentInstructionRegisterMap, "created");
|
||||
}
|
||||
|
|
@ -68,25 +73,32 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme
|
|||
|
||||
public void depoPaymentInstructionRegisterNew(BaseRequest<LauncherCommandRequest> userRequest) {
|
||||
log.debug("LauncherCommandRequest received from {}", createRegistry_GORR.topic());
|
||||
Map<String, String> sessionQuery = Map.of("section", "FOND");
|
||||
Collection<Session> actualSessions = sessionMap.getCollectionObjectsByFieldValues(sessionQuery);
|
||||
if (actualSessions.isEmpty()) {
|
||||
log.debug("No Session with such conditions section = FOND");
|
||||
return;
|
||||
}
|
||||
log.debug("Select {} Session by query {}", actualSessions.size(), sessionQuery);
|
||||
preClearMap.preClearMap();
|
||||
for (Session session : actualSessions) {
|
||||
Map<String, ? extends Comparable<?>> fieldValues = Map.of("sessionId", session.getId());
|
||||
Collection<PaymentInstruction> paymentInstructionBySessionId =
|
||||
paymentInstructionMap.getCollectionObjectsByFieldValues(fieldValues);
|
||||
log.debug("Select {} PaymentInstruction by query {}", paymentInstructionBySessionId.size(), fieldValues);
|
||||
for (PaymentInstruction paymentInstruction : paymentInstructionBySessionId) {
|
||||
if (isDuplicateInMap(paymentInstruction).isEmpty()) {
|
||||
insertDepoPaymentInstructionRegister(paymentInstruction);
|
||||
|
||||
Collection<PaymentInstruction> paymentInstructions = paymentInstructionMap.getAllValues();
|
||||
log.debug("Selected {} PaymentInstruction, do filter by account...", paymentInstructions.size());
|
||||
Collection<PaymentInstruction> depoPaymentInstructions = new ArrayList<>();
|
||||
for (PaymentInstruction paymentInstruction : paymentInstructions) {
|
||||
// filter by accountType
|
||||
if (paymentInstruction.getCreditLeg_accountId() != null) {
|
||||
Account account = accountMap.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
|
||||
if (account == null)
|
||||
log.warn("Account id={} not found for paymentInstruction.id={}",
|
||||
paymentInstruction.getCreditLeg_accountId(), paymentInstruction.getId());
|
||||
else {
|
||||
if (AccountType.Depo.equalsByKey(account.getAccountType())) {
|
||||
depoPaymentInstructions.add(paymentInstruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
paymentInstructions = null;
|
||||
log.debug("Filtered {} PaymentInstruction, with depo account's", depoPaymentInstructions.size());
|
||||
preClearMap.preClearMap();
|
||||
for (PaymentInstruction paymentInstruction : depoPaymentInstructions) {
|
||||
if (isDuplicateInMap(paymentInstruction).isEmpty()) {
|
||||
insertDepoPaymentInstructionRegister(paymentInstruction);
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("successfully processed");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
|
||||
|
|
@ -16,11 +17,14 @@ import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.registry.util.PreClearMap;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
|
@ -37,6 +41,7 @@ public class MoneyPaymentInstructionRegisterService extends QueueConsumer implem
|
|||
private final Imdg<Session> sessionMap;
|
||||
private final Function<Map<String, ?>, IValidator> fieldValuesValidator;
|
||||
private final Imdg<Company> companyMap;
|
||||
private final Imdg<Account> accountMap;
|
||||
private final PreClearMap<MoneyPaymentInstructionRegister> preClearMap;
|
||||
|
||||
@Autowired
|
||||
|
|
@ -49,6 +54,7 @@ public class MoneyPaymentInstructionRegisterService extends QueueConsumer implem
|
|||
this.paymentInstructionMap = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
|
||||
this.sessionMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
|
||||
this.companyMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.fieldValuesValidator = fieldValuesValidator;
|
||||
preClearMap = PreClearMap.instanceForLocalDateField(moneyPaymentInstructionRegisterMap, "clearingDate");
|
||||
}
|
||||
|
|
@ -63,21 +69,33 @@ public class MoneyPaymentInstructionRegisterService extends QueueConsumer implem
|
|||
|
||||
public void moneyPaymentInstructionRegisterNew(BaseRequest<LauncherCommandRequest> userRequest) {
|
||||
log.debug("LauncherCommandRequest received from {}", TOPIC_NAME);
|
||||
Map<String, ? extends Comparable<?>> fieldValuesSectionMkr = Map.of("section", "MKR");
|
||||
Collection<Session> actualSessions = sessionMap.getCollectionObjectsByFieldValues(fieldValuesSectionMkr);
|
||||
log.debug("Selected {} Session by query {}", actualSessions.size(), fieldValuesSectionMkr);
|
||||
preClearMap.preClearMap();
|
||||
actualSessions.forEach(session -> {
|
||||
Map<String, ? extends Comparable<?>> fieldValuesSessionId = Map.of("sessionId", session.getId());
|
||||
Collection<PaymentInstruction> paymentInstructionBySessionId =
|
||||
paymentInstructionMap.getCollectionObjectsByFieldValues(fieldValuesSessionId);
|
||||
log.debug("Selected {} PaymentInstruction by query {}", paymentInstructionBySessionId.size(), fieldValuesSessionId);
|
||||
for (PaymentInstruction paymentInstruction : paymentInstructionBySessionId) {
|
||||
if (isDuplicateInMap(paymentInstruction).isEmpty()) {
|
||||
insertMoneyPaymentInstructionRegister(paymentInstruction);
|
||||
|
||||
Collection<PaymentInstruction> paymentInstructions = paymentInstructionMap.getAllValues();
|
||||
log.debug("Selected {} PaymentInstruction, do filter by account...", paymentInstructions.size());
|
||||
Collection<PaymentInstruction> moneyPaymentInstructions = new ArrayList<>();
|
||||
for (PaymentInstruction paymentInstruction : paymentInstructions) {
|
||||
// filter by accountType
|
||||
if (paymentInstruction.getCreditLeg_accountId() != null) {
|
||||
Account account = accountMap.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
|
||||
if (account == null)
|
||||
log.warn("Account id={} not found for paymentInstruction.id={}",
|
||||
paymentInstruction.getCreditLeg_accountId(), paymentInstruction.getId());
|
||||
else {
|
||||
if (IEnumKey.contains(account.getAccountType(), AccountType.Clrn, AccountType.Info, AccountType.Anlt, AccountType.Tran)) {
|
||||
moneyPaymentInstructions.add(paymentInstruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
paymentInstructions = null;
|
||||
log.debug("Filtered {} PaymentInstruction, with money account's", moneyPaymentInstructions.size());
|
||||
|
||||
preClearMap.preClearMap();
|
||||
for (PaymentInstruction paymentInstruction : moneyPaymentInstructions) {
|
||||
if (isDuplicateInMap(paymentInstruction).isEmpty()) {
|
||||
insertMoneyPaymentInstructionRegister(paymentInstruction);
|
||||
}
|
||||
}
|
||||
log.debug("successfully processed");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,12 @@ import ru.spcex.clearing.test.TestUtils;
|
|||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||
import ru.spcex.platform.enumeration.MoneyFlowSide;
|
||||
import ru.spcex.platform.enumeration.Side;
|
||||
import ru.spcex.platform.enumeration.Task;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -162,10 +164,11 @@ class ExecutionRegisterServiceTest {
|
|||
executionFond.setTradingClearingRegistryId(TKR_FOR_TKR_ID);
|
||||
executionFond.setCompanyId(COMPANY_ID);
|
||||
executionFond.setCounterPartyId(COUNTER_PARTY_ID);
|
||||
executionFond.setSide(Side.BUY.getKey());
|
||||
executionFond.setSide(Side.SELL.getKey());
|
||||
executionFond.setCounterPartyTradingClearingRegistry(COUNTER_PARTY_TKR);
|
||||
executionFond.setPartyTradingClearingRegistry(PARTY_TKR);
|
||||
executionFondImdg.insert(executionFond);
|
||||
((ImdgHazelcast)executionDepositImdg).clear(); // чтобы не влиял второй тест
|
||||
|
||||
LauncherCommandRequest launcherCommandRequest = new LauncherCommandRequest();
|
||||
|
||||
|
|
@ -185,16 +188,16 @@ class ExecutionRegisterServiceTest {
|
|||
assertEquals(executionRegister.getExchangeExecutionId(), EXCHANGE_EXECUTION_ID);
|
||||
assertEquals(executionRegister.getExchangeExecutionTime(), EXCHANGE_EXECUTION_TIME);
|
||||
assertEquals(executionRegister.getSecurityId(), SECURITY_ID);
|
||||
assertEquals(executionRegister.getSellerId(), COUNTER_PARTY_ID);
|
||||
assertEquals(executionRegister.getSellerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COUNTER_PARTY_ID);
|
||||
assertEquals(executionRegister.getSellerTradingClearingRegister(), COUNTER_PARTY_TKR);
|
||||
assertEquals(executionRegister.getSellerMoneyAccount(), MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR);
|
||||
assertEquals(executionRegister.getSellerDepoAccount(), DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR);
|
||||
assertEquals(executionRegister.getBuyerId(), COMPANY_ID);
|
||||
assertEquals(executionRegister.getBuyerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COMPANY_ID);
|
||||
assertEquals(executionRegister.getBuyerTradingClearingRegister(), PARTY_TKR);
|
||||
assertEquals(executionRegister.getBuyerMoneyAccount(), MONEY_ACCOUNT_FOR_TKR);
|
||||
assertEquals(executionRegister.getBuyerDepoAccount(), DEPO_ACCOUNT_FOR_TKR);
|
||||
assertEquals(executionRegister.getSellerId(), COMPANY_ID);
|
||||
assertEquals(executionRegister.getSellerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COMPANY_ID);
|
||||
assertEquals(executionRegister.getSellerTradingClearingRegister(), PARTY_TKR);
|
||||
assertEquals(executionRegister.getSellerMoneyAccount(), MONEY_ACCOUNT_FOR_TKR);
|
||||
assertEquals(executionRegister.getSellerDepoAccount(), DEPO_ACCOUNT_FOR_TKR);
|
||||
assertEquals(executionRegister.getBuyerId(), COUNTER_PARTY_ID);
|
||||
assertEquals(executionRegister.getBuyerClearingCode(), COMPANY_SYMBOL_VALUE_FOR_COUNTER_PARTY_ID);
|
||||
assertEquals(executionRegister.getBuyerTradingClearingRegister(), COUNTER_PARTY_TKR);
|
||||
assertEquals(executionRegister.getBuyerMoneyAccount(), MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR);
|
||||
assertEquals(executionRegister.getBuyerDepoAccount(), DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR);
|
||||
assertEquals(executionRegister.getAmount(), SETTLEMENT_AMOUNT);
|
||||
assertEquals(executionRegister.getQuantity(), QUANTITY);
|
||||
assertEquals(executionRegister.getClearingDate(), LocalDate.now());
|
||||
|
|
@ -217,10 +220,11 @@ class ExecutionRegisterServiceTest {
|
|||
executionDeposit.setTradingClearingRegistryId(TKR_FOR_TKR_ID);
|
||||
executionDeposit.setCompanyId(COMPANY_ID);
|
||||
executionDeposit.setCounterPartyId(COUNTER_PARTY_ID);
|
||||
executionDeposit.setSide(Side.SELL.getKey());
|
||||
executionDeposit.setSide(MoneyFlowSide.SELL.getKey());
|
||||
executionDeposit.setCounterPartyTradingClearingRegistry(COUNTER_PARTY_TKR);
|
||||
executionDeposit.setPartyTradingClearingRegistry(PARTY_TKR);
|
||||
executionDepositImdg.insert(executionDeposit);
|
||||
((ImdgHazelcast)executionFondImdg).clear(); // чтобы не влиял первый тест
|
||||
|
||||
LauncherCommandRequest launcherCommandRequest = new LauncherCommandRequest();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue