akulikov 2023-09-29 16:58:58 +03:00
parent 646c8c7e77
commit 9ed6a75fe5
5 changed files with 337 additions and 110 deletions

View file

@ -46,6 +46,11 @@
<groupId>ru.spcex.clearing</groupId>
<artifactId>dictionary</artifactId>
</dependency>
<dependency>
<groupId>ru.spcex.clearing</groupId>
<artifactId>test-clearing</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View file

@ -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.CompanySymbols;
import ru.clearing.classes.statics.data.execution.ExecutionCommon;
import ru.clearing.classes.statics.data.execution.ExecutionDeposit;
@ -21,10 +22,13 @@ import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
import ru.spcex.clearing.registry.util.PreClearMap;
import ru.spcex.platform.enumeration.CompanySymbol;
import ru.spcex.platform.enumeration.MoneyFlowSide;
import ru.spcex.platform.enumeration.Side;
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.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.util.Collection;
@ -44,6 +48,7 @@ public class ExecutionRegisterService extends QueueConsumer implements Initializ
private final Imdg<ExecutionFond> executionFondMap;
private final Imdg<ExecutionDeposit> executionDepositMap;
private final Imdg<TradingClearingRegistry> tradingClearingRegistryMap;
private final Imdg<Account> accountImdg;
private final Function<Map<String, ?>, IValidator> fieldValuesValidator;
private final PreClearMap<ExecutionRegister> preClearMap;
@ -58,6 +63,7 @@ public class ExecutionRegisterService extends QueueConsumer implements Initializ
this.executionFondMap = imdgProvider.getImdg(Map_ExecutionFond, ExecutionFond.class);
this.executionDepositMap = imdgProvider.getImdg(Map_ExecutionDeposit, ExecutionDeposit.class);
this.tradingClearingRegistryMap = imdgProvider.getImdg(Map_TradingClearingRegistry, TradingClearingRegistry.class);
this.accountImdg = imdgProvider.getImdg(Map_Account, Account.class);
this.fieldValuesValidator = fieldValuesValidator;
preClearMap = PreClearMap.instanceForLocalDateField(executionRegisterMap, "clearingDate");
}
@ -119,91 +125,112 @@ public class ExecutionRegisterService extends QueueConsumer implements Initializ
private void insertExecutionRegister(Boolean isFond, ExecutionCommon common) {
log.trace("Started generating ExecutionRegister entity...");
/* todo сверить с ТЗ, замечания от 28.09.2023:
executionRegister - Реестр сделок
sellerId - Если executionDeposit/Fond.side=BUY - company.shortName [executionDeposit/Fond.counterPartyId = company.id]. Если executionDeposit/Fond.side=SELL - company.shortName [executionDeposit/Fond.companyId = company.id]
sellerClearingCode - не заполняется
sellerTradingClearingRegister - не заполняется
sellerMoneyAccount - не заполняется
sellerDepoAccount - не заполняется
buyerId - Если executionDeposit/Fond.side=BUY - company.shortName [executionDeposit/Fond.counterPartyId = company.id]. Если executionDeposit/Fond.side=SELL - company.shortName [executionDeposit/Fond.counterPartyId = company.id]
buyerClearingCode - не заполняется
buyerTradingClearingRegister - не заполняется
buyerMoneyAccount - не заполняется
buyerDepoAccount - не заполняется
*/
LocalDate tradingDate = common.getTradingDate();
Long exchangeExecutionId = common.getExchangeExecutionId();
Instant exchangeExecutionTime = common.getExchangeExecutionTime();
Long securityId = common.getSecurityId();
LocalDate clearingDate = common.getClearingDate();
Long sellerId;
String sellerClearingCode = null;
String sellerTradingClearingRegister = null;
String sellerTradingClearingRegister;
String sellerMoneyAccount = null;
String sellerDepoAccount = null;
Long buyerId = common.getSide().equalsIgnoreCase(MoneyFlowSide.BUY.getKey()) ? common.getCompanyId() : common.getCounterPartyId();
Long sellerId = common.getSide().equalsIgnoreCase(MoneyFlowSide.BUY.getKey()) ? common.getCounterPartyId() : common.getCompanyId();
Long buyerId;
String buyerClearingCode = null;
String buyerTradingClearingRegister = null;
String buyerTradingClearingRegister;
String buyerMoneyAccount = null;
String buyerDepoAccount = null;
String side = common.getSide();
Optional<CompanySymbols> companySymbolsByCLRSandCompanyId = getCompanySymbolsByCompanyIdAndCompanySymbol(CompanySymbol.CLRC.getKey(), common.getCompanyId());
Optional<TradingClearingRegistry> tradingClearingRegistryByCodeOfCompanyId = getTradingClearingRegistryByCode(common.getCompanyId().toString());
Optional<CompanySymbols> companySymbolsByCLRSandCounterPartyId = getCompanySymbolsByCompanyIdAndCompanySymbol(CompanySymbol.CLRC.getKey(), common.getCounterPartyId());
Optional<TradingClearingRegistry> tradingClearingRegistryByCodeOfCounterPartyId = getTradingClearingRegistryByCode(common.getCounterPartyId().toString());
Optional<TradingClearingRegistry> tradingClearingRegistryByCompanyIdOfCounterPartyId = getTradingClearingRegistryByCompanyId(common.getCounterPartyId());
if (side.equalsIgnoreCase(MoneyFlowSide.BUY.getKey())) {
if (companySymbolsByCLRSandCounterPartyId.isPresent()) {
sellerClearingCode = companySymbolsByCLRSandCounterPartyId.get().getCompanySymbolValue();
}
if (tradingClearingRegistryByCompanyIdOfCounterPartyId.isPresent()) {
sellerTradingClearingRegister = tradingClearingRegistryByCompanyIdOfCounterPartyId.get().getCode();
}
if (tradingClearingRegistryByCodeOfCounterPartyId.isPresent()) {
TradingClearingRegistry clearingRegistry = tradingClearingRegistryByCodeOfCounterPartyId.get();
sellerMoneyAccount = clearingRegistry.getMoneyAccountId().toString();
if (isFond) {
sellerDepoAccount = clearingRegistry.getDepoAccountId().toString();
}
}
if (companySymbolsByCLRSandCompanyId.isPresent()) {
buyerClearingCode = companySymbolsByCLRSandCompanyId.get().getCompanySymbolValue();
}
buyerTradingClearingRegister = common.getTradingClearingRegistryId().toString();
if (tradingClearingRegistryByCodeOfCompanyId.isPresent()) {
TradingClearingRegistry clearingRegistry = tradingClearingRegistryByCodeOfCompanyId.get();
buyerMoneyAccount = clearingRegistry.getMoneyAccountId().toString();
if (isFond) {
buyerDepoAccount = clearingRegistry.getDepoAccountId().toString();
}
}
} else if (side.equalsIgnoreCase(MoneyFlowSide.SELL.getKey())) {
if (companySymbolsByCLRSandCompanyId.isPresent()) {
sellerClearingCode = companySymbolsByCLRSandCompanyId.get().getCompanySymbolValue();
}
sellerTradingClearingRegister = common.getTradingClearingRegistryId().toString();
if (tradingClearingRegistryByCodeOfCompanyId.isPresent()) {
TradingClearingRegistry clearingRegistry = tradingClearingRegistryByCodeOfCompanyId.get();
sellerMoneyAccount = clearingRegistry.getMoneyAccountId().toString();
if (isFond) {
sellerDepoAccount = clearingRegistry.getDepoAccountId().toString();
}
}
if (companySymbolsByCLRSandCounterPartyId.isPresent()) {
buyerClearingCode = companySymbolsByCLRSandCounterPartyId.get().getCompanySymbolValue();
}
if (tradingClearingRegistryByCodeOfCounterPartyId.isPresent()) {
TradingClearingRegistry clearingRegistry = tradingClearingRegistryByCodeOfCounterPartyId.get();
buyerMoneyAccount = clearingRegistry.getMoneyAccountId().toString();
if (isFond) {
buyerDepoAccount = clearingRegistry.getDepoAccountId().toString();
}
}
if (tradingClearingRegistryByCompanyIdOfCounterPartyId.isPresent()) {
buyerTradingClearingRegister = tradingClearingRegistryByCompanyIdOfCounterPartyId.get().getId().toString();
}
BigDecimal amount;
BigDecimal quantity = null;
if (isFond) {
ExecutionFond executionFond = (ExecutionFond) common;
amount = executionFond.getSettlementAmount();
quantity = executionFond.getQuantity();
} else {
ExecutionDeposit executionDeposit = (ExecutionDeposit) common;
amount = executionDeposit.getFirstLegAmount();
}
TradingClearingRegistry tkrForCounterPartyTkrId = tradingClearingRegistryMap.getSingleObjectByID(
common.getCounterPartyTradingClearingRegistryId()
);
TradingClearingRegistry tkrForTkrId = tradingClearingRegistryMap.getSingleObjectByID(
common.getTradingClearingRegistryId()
);
Account moneyAccountForCounterPartyTkrId = null;
Account depoAccountForCounterPartyTkrId = null;
if (tkrForCounterPartyTkrId != null) {
if (tkrForCounterPartyTkrId.getMoneyAccountId() != null)
moneyAccountForCounterPartyTkrId = accountImdg.getSingleObjectByID(tkrForCounterPartyTkrId.getMoneyAccountId());
if (tkrForCounterPartyTkrId.getDepoAccountId() != null)
depoAccountForCounterPartyTkrId = accountImdg.getSingleObjectByID(tkrForCounterPartyTkrId.getDepoAccountId());
}
Account moneyAccountForTkrId = null;
Account depoAccountForTkrId = null;
if (tkrForTkrId != null) {
if (tkrForTkrId.getMoneyAccountId() != null)
moneyAccountForTkrId = accountImdg.getSingleObjectByID(tkrForTkrId.getMoneyAccountId());
if (tkrForTkrId.getDepoAccountId() != null)
depoAccountForTkrId = accountImdg.getSingleObjectByID(tkrForTkrId.getDepoAccountId());
}
CompanySymbols companySymbolsForCompanyId = companySymbolsMap.getFirstObjectByFieldValues(
Map.of(
"companySymbol", CompanySymbol.CLRC.getKey(),
"companyId", common.getCompanyId()
)
);
CompanySymbols companySymbolsForCounterPartyId = companySymbolsMap.getFirstObjectByFieldValues(
Map.of(
"companySymbol", CompanySymbol.CLRC.getKey(),
"companyId", common.getCounterPartyId()
)
);
String sideStr = common.getSide();
MoneyFlowSide moneyFlowSide = IEnumKey.getEnumByKey(MoneyFlowSide.class, sideStr);
Side side = IEnumKey.getEnumByKey(Side.class, sideStr);
if (moneyFlowSide == MoneyFlowSide.BUY || side == Side.BUY) {
sellerId = common.getCounterPartyId();
buyerId = common.getCompanyId();
if (companySymbolsForCounterPartyId != null) sellerClearingCode = companySymbolsForCounterPartyId.getCompanySymbolValue();
sellerTradingClearingRegister = common.getCounterPartyTradingClearingRegistry();
if (moneyAccountForCounterPartyTkrId != null) sellerMoneyAccount = moneyAccountForCounterPartyTkrId.getAccount();
if (depoAccountForCounterPartyTkrId != null) sellerDepoAccount = depoAccountForCounterPartyTkrId.getAccount();
if (companySymbolsForCompanyId != null) buyerClearingCode = companySymbolsForCompanyId.getCompanySymbolValue();
buyerTradingClearingRegister = common.getPartyTradingClearingRegistry();
if (moneyAccountForTkrId != null) buyerMoneyAccount = moneyAccountForTkrId.getAccount();
if (depoAccountForTkrId != null) buyerDepoAccount = depoAccountForTkrId.getAccount();
} else {
sellerId = common.getCompanyId();
buyerId = common.getCounterPartyId();
if (companySymbolsForCompanyId != null) sellerClearingCode = companySymbolsForCompanyId.getCompanySymbolValue();
sellerTradingClearingRegister = common.getPartyTradingClearingRegistry();
if (moneyAccountForTkrId != null) sellerMoneyAccount = moneyAccountForTkrId.getAccount();
if (depoAccountForTkrId != null) sellerDepoAccount = depoAccountForTkrId.getAccount();
if (companySymbolsForCounterPartyId != null) buyerClearingCode = companySymbolsForCounterPartyId.getCompanySymbolValue();
buyerTradingClearingRegister = common.getCounterPartyTradingClearingRegistry();
if (moneyAccountForCounterPartyTkrId != null) buyerMoneyAccount = moneyAccountForCounterPartyTkrId.getAccount();
if (depoAccountForCounterPartyTkrId != null) buyerDepoAccount = depoAccountForCounterPartyTkrId.getAccount();
}
ExecutionRegister executionRegister = new ExecutionRegister();
executionRegister.setTradingDate(common.getTradingDate());
executionRegister.setExchangeExecutionId(common.getExchangeExecutionId());
executionRegister.setExchangeExecutionTime(common.getExchangeExecutionTime());
executionRegister.setSecurityId(common.getSecurityId());
executionRegister.setTradingDate(tradingDate);
executionRegister.setExchangeExecutionId(exchangeExecutionId);
executionRegister.setExchangeExecutionTime(exchangeExecutionTime);
executionRegister.setSecurityId(securityId);
executionRegister.setSellerId(sellerId);
executionRegister.setSellerClearingCode(sellerClearingCode);
executionRegister.setSellerTradingClearingRegister(sellerTradingClearingRegister);
@ -214,13 +241,9 @@ buyerDepoAccount - не заполняется
executionRegister.setBuyerTradingClearingRegister(buyerTradingClearingRegister);
executionRegister.setBuyerMoneyAccount(buyerMoneyAccount);
executionRegister.setBuyerDepoAccount(buyerDepoAccount);
if (isFond) {
executionRegister.setQuantity(common.getQuantity());
executionRegister.setAmount(((ExecutionFond) common).getSettlementAmount());
} else {
executionRegister.setAmount(((ExecutionDeposit) common).getFirstLegAmount());
}
executionRegister.setClearingDate(common.getClearingDate());
executionRegister.setAmount(amount);
executionRegister.setQuantity(quantity);
executionRegister.setClearingDate(clearingDate);
executionRegister.setCreated(Instant.now());
executionRegisterMap.insert(executionRegister);
log.debug("inserted successfully ExecutionRegister entity with id: {}", executionRegister.getId());
@ -274,30 +297,6 @@ buyerDepoAccount - не заполняется
return common;
}
private Optional<CompanySymbols> getCompanySymbolsByCompanyIdAndCompanySymbol(String companySymbol, Long companyId) {
Map<String, ? extends Comparable<?>> fieldValues = Map.of("companySymbol", companySymbol, "companyId", companyId);
CompanySymbols companySymbols = companySymbolsMap.getFirstObjectByFieldValues(fieldValues);
return Optional.ofNullable(companySymbols);
}
private Optional<CompanySymbols> getCompanySymbolsByCompanyId(Long companyId) {
Map<String, ? extends Comparable<?>> fieldValues = Map.of("companyId", companyId);
CompanySymbols companySymbols = companySymbolsMap.getFirstObjectByFieldValues(fieldValues);
return Optional.ofNullable(companySymbols);
}
private Optional<TradingClearingRegistry> getTradingClearingRegistryByCompanyId(Long companyId) {
Map<String, ? extends Comparable<?>> fieldValues = Map.of("companyId", companyId);
TradingClearingRegistry tradingClearingRegistry = tradingClearingRegistryMap.getFirstObjectByFieldValues(fieldValues);
return Optional.ofNullable(tradingClearingRegistry);
}
private Optional<TradingClearingRegistry> getTradingClearingRegistryByCode(String code) {
Map<String, ? extends Comparable<?>> fieldValues = Map.of("code", code);
TradingClearingRegistry tradingClearingRegistry = tradingClearingRegistryMap.getFirstObjectByFieldValues(fieldValues);
return Optional.ofNullable(tradingClearingRegistry);
}
@Override
public Optional<ExecutionRegister> isDuplicateInMap(ExecutionCommon entity) {
return Optional.empty();

View file

@ -3,10 +3,14 @@ package ru.spcex.clearing.registry.config;
import org.apache.kafka.clients.consumer.MockConsumer;
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.test.mock.mockito.MockReset;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@ -17,6 +21,10 @@ import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgId;
import ru.spcex.platform.imdg.api.ImdgProvider;
import static org.mockito.Mockito.mock;
import static ru.spcex.clearing.registry.utils.TestUtils.setFuture;
import static ru.spcex.clearing.test.config.KafkaTestConfig.producerCaptors;
@Configuration
public class KafkaConfigTest {
@ -41,4 +49,13 @@ public class KafkaConfigTest {
return new MockConsumer<>(OffsetResetStrategy.EARLIEST);
}
@Bean("mockProducer")
public Producer<String, Object> kafkaProducer() {
Producer<String, Object> mockProducer = mock(MockProducer.class, MockReset.withSettings(MockReset.AFTER));
ArgumentCaptor<ProducerRecord> recordArgumentCaptor = ArgumentCaptor.forClass(ProducerRecord.class);
setFuture(recordArgumentCaptor, mockProducer);
producerCaptors.put(mockProducer, recordArgumentCaptor);
return mockProducer;
}
}

View file

@ -0,0 +1,201 @@
package ru.spcex.clearing.registry.service;
import org.apache.kafka.clients.consumer.MockConsumer;
import org.apache.kafka.clients.producer.Producer;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.company.CompanySymbols;
import ru.clearing.classes.statics.data.execution.ExecutionDeposit;
import ru.clearing.classes.statics.data.execution.ExecutionFond;
import ru.clearing.classes.statics.data.register.ExecutionRegister;
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
import ru.spcex.clearing.registry.config.ValidationConfig;
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.Side;
import ru.spcex.platform.enumeration.Task;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Collection;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {
ValidationConfig.class,
ExecutionRegisterService.class,
ImdgTestConfig.class,
KafkaTestConfig.class,
})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class ExecutionRegisterServiceTest {
LocalDate TRADING_DATE = LocalDate.of(2020, 1, 1);
Instant EXCHANGE_EXECUTION_TIME = LocalDate.of(2020, 1, 1).atStartOfDay().toInstant(ZoneOffset.UTC);
Long COUNTER_PARTY_ID = 888L;
Long COMPANY_ID = 777L;
Long EXCHANGE_EXECUTION_ID = 777L;
Long SECURITY_ID = 888L;
BigDecimal SETTLEMENT_AMOUNT = BigDecimal.valueOf(777L);
BigDecimal QUANTITY = BigDecimal.valueOf(888L);
String COMPANY_SYMBOL_VALUE_FOR_COMPANY_ID = "COMPANY_SYMBOL_VALUE_FOR_COMPANY_ID";
String COMPANY_SYMBOL_VALUE_FOR_COUNTER_PARTY_ID = "COMPANY_SYMBOL_VALUE_FOR_COUNTER_PARTY_ID";
Long MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR_ID;
Long MONEY_ACCOUNT_FOR_TKR_ID;
Long DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR_ID;
Long DEPO_ACCOUNT_FOR_TKR_ID;
Long TKR_FOR_COUNTER_PARTY_TKR_ID;
Long TKR_FOR_TKR_ID;
String MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR = "MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR";
String MONEY_ACCOUNT_FOR_TKR = "MONEY_ACCOUNT_FOR_TKR";
String DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR = "DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR";
String DEPO_ACCOUNT_FOR_TKR = "DEPO_ACCOUNT_FOR_TKR";
String COUNTER_PARTY_TKR = "COUNTER_PARTY_TKR";
String PARTY_TKR = "PARTY_TKR";
private static int requestCount = 0;
private Imdg<Account> accountImdg;
private Imdg<ExecutionDeposit> executionDepositImdg;
private Imdg<ExecutionFond> executionFondImdg;
private Imdg<CompanySymbols> companySymbolsImdg;
private Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
private Imdg<ExecutionRegister> executionRegisterImdg;
@Autowired
private ExecutionRegisterService executionRegisterService;
@Autowired
@Qualifier("hazelcastServiceTest")
private ImdgProvider imdgProvider;
@Autowired
@Qualifier("mockProducer")
private Producer<String, Object> producer;
@PostConstruct
private void init() {
ImdgTestConfig.waitAvailableImdgProviderAndAddAdminWithDefaultId();
executionDepositImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionDeposit, ExecutionDeposit.class);
executionFondImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionFond, ExecutionFond.class);
companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
executionRegisterImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionRegister, ExecutionRegister.class);
Account moneyAccountForCounterPartyTkr = new Account();
moneyAccountForCounterPartyTkr.setAccount(MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR);
MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR_ID = accountImdg.insert(moneyAccountForCounterPartyTkr);
Account moneyAccountForTkr = new Account();
moneyAccountForTkr.setAccount(MONEY_ACCOUNT_FOR_TKR);
MONEY_ACCOUNT_FOR_TKR_ID = accountImdg.insert(moneyAccountForTkr);
Account depoAccountForCounterPartyTkr = new Account();
depoAccountForCounterPartyTkr.setAccount(DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR);
DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR_ID = accountImdg.insert(depoAccountForCounterPartyTkr);
Account depoAccountForTkr = new Account();
depoAccountForTkr.setAccount(DEPO_ACCOUNT_FOR_TKR);
DEPO_ACCOUNT_FOR_TKR_ID = accountImdg.insert(depoAccountForTkr);
TradingClearingRegistry tkrForCounterPartyTkrId = new TradingClearingRegistry();
tkrForCounterPartyTkrId.setMoneyAccountId(MONEY_ACCOUNT_FOR_COUNTER_PARTY_TKR_ID);
tkrForCounterPartyTkrId.setDepoAccountId(DEPO_ACCOUNT_FOR_COUNTER_PARTY_TKR_ID);
TKR_FOR_COUNTER_PARTY_TKR_ID = tradingClearingRegistryImdg.insert(tkrForCounterPartyTkrId);
TradingClearingRegistry tkrForTkrId = new TradingClearingRegistry();
tkrForTkrId.setMoneyAccountId(MONEY_ACCOUNT_FOR_TKR_ID);
tkrForTkrId.setDepoAccountId(DEPO_ACCOUNT_FOR_TKR_ID);
TKR_FOR_TKR_ID = tradingClearingRegistryImdg.insert(tkrForTkrId);
CompanySymbols companySymbolsForCompanyId = new CompanySymbols();
companySymbolsForCompanyId.setCompanyId(COMPANY_ID);
companySymbolsForCompanyId.setCompanySymbol(CompanySymbol.CLRC.getKey());
companySymbolsForCompanyId.setCompanySymbolValue(COMPANY_SYMBOL_VALUE_FOR_COMPANY_ID);
companySymbolsImdg.insert(companySymbolsForCompanyId);
CompanySymbols companySymbolsForCounterPartyId = new CompanySymbols();
companySymbolsForCounterPartyId.setCompanyId(COUNTER_PARTY_ID);
companySymbolsForCounterPartyId.setCompanySymbol(CompanySymbol.CLRC.getKey());
companySymbolsForCounterPartyId.setCompanySymbolValue(COMPANY_SYMBOL_VALUE_FOR_COUNTER_PARTY_ID);
companySymbolsImdg.insert(companySymbolsForCounterPartyId);
}
@Test
@Order(1)
void executionRegisterNewForClearingDate() {
ExecutionFond executionFond = new ExecutionFond();
executionFond.setClearingDate(LocalDate.now());
executionFond.setTradingDate(TRADING_DATE);
executionFond.setExchangeExecutionId(EXCHANGE_EXECUTION_ID);
executionFond.setExchangeExecutionTime(EXCHANGE_EXECUTION_TIME);
executionFond.setSecurityId(SECURITY_ID);
executionFond.setSettlementAmount(SETTLEMENT_AMOUNT);
executionFond.setQuantity(QUANTITY);
executionFond.setCounterPartyTradingClearingRegistryId(TKR_FOR_COUNTER_PARTY_TKR_ID);
executionFond.setTradingClearingRegistryId(TKR_FOR_TKR_ID);
executionFond.setCompanyId(COMPANY_ID);
executionFond.setCounterPartyId(COUNTER_PARTY_ID);
executionFond.setSide(Side.BUY.getKey());
executionFond.setCounterPartyTradingClearingRegistry(COUNTER_PARTY_TKR);
executionFond.setPartyTradingClearingRegistry(PARTY_TKR);
executionFondImdg.insert(executionFond);
LauncherCommandRequest launcherCommandRequest = new LauncherCommandRequest();
String jsonString = TestUtils.getJsonStringForSystem(launcherCommandRequest, 0L);
TestUtils.addRecordToKafka((MockConsumer) executionRegisterService.getConsumer(),
Task.createRegistry_ECNR.topic(),
requestCount++,
0,
jsonString);
TestUtils.waitingSendAndCheckRecord(0L, producer);
Collection<ExecutionRegister> allValues = executionRegisterImdg.getAllValues();
ExecutionRegister executionRegister = allValues.iterator().next();
assertEquals(executionRegister.getTradingDate(), TRADING_DATE);
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.getAmount(), SETTLEMENT_AMOUNT);
assertEquals(executionRegister.getQuantity(), QUANTITY);
assertEquals(executionRegister.getClearingDate(), LocalDate.now());
}
}

View file

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.MockConsumer;
import org.apache.kafka.clients.producer.MockProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.TopicPartition;
@ -25,8 +26,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.*;
import static ru.spcex.clearing.platform.messaging.service.Status.Success;
import static ru.spcex.clearing.registry.utils.MatcherFactory.usingIgnoringFieldsComparator;
@ -89,6 +89,11 @@ public class TestUtils {
return jsonBaseRequest;
}
public static void setFuture(ArgumentCaptor<ProducerRecord> captor, Producer<String, Object> mockProducer){
TestUtils.FutureRecordMetadata future = spy(new TestUtils.FutureRecordMetadata());
doReturn(future).when(mockProducer).send(captor.capture());
}
public static <T extends SpcexObjectBase> void clearAllInImdg(Imdg<T> imdg) {
Collection<T> values = imdg.getAllValues();
values.forEach(imdg::delete);