добавил Sdf01ExecutorTest пока без реализации
This commit is contained in:
parent
8d2881c3eb
commit
d3657752b2
3 changed files with 127 additions and 27 deletions
|
|
@ -1,19 +1,46 @@
|
|||
package ru.spcex.clearing.balance.service;
|
||||
|
||||
import com.hazelcast.core.IMap;
|
||||
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.spcex.clearing.balance.config.BalanceImdgTestConfig;
|
||||
import ru.spcex.clearing.balance.config.KafkaSenderConfig;
|
||||
import ru.spcex.clearing.balance.config.KafkaTestConfig;
|
||||
import ru.spcex.clearing.balance.config.ValidationConfig;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.spcex.clearing.balance.config.*;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
AccountBalanceService.class,
|
||||
Sdf01Executor.class,
|
||||
LoggingService.class,
|
||||
MessagesConfig.class,
|
||||
ValidationConfig.class,
|
||||
BalanceImdgTestConfig.class,
|
||||
KafkaSenderConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
public abstract class AbstractServiceTest {
|
||||
protected AtomicLong currentId = new AtomicLong(0L);
|
||||
protected IMap<Long, Company> companyMap;
|
||||
protected IMap<Long, Account> accountMap;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcast;
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
hazelcast.waitAvailable();
|
||||
ImdgHazelcast<Company> companyImdg = (ImdgHazelcast<Company>) hazelcast.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
ImdgHazelcast<Account> accountImdg = (ImdgHazelcast<Account>) hazelcast.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
companyMap = companyImdg.getMap();
|
||||
accountMap = accountImdg.getMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,17 @@
|
|||
package ru.spcex.clearing.balance.service;
|
||||
|
||||
import com.hazelcast.core.IMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.AccountBalance;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.spcex.clearing.balance.errors.BalanceError;
|
||||
import ru.spcex.clearing.balance.utils.MatcherFactory.Matcher;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.BalanceAccountType;
|
||||
import ru.spcex.platform.enumeration.Status;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static ru.spcex.clearing.balance.utils.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
|
|
@ -37,22 +31,16 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
private final String cashMovementCurrencyCodeUpdate = "cash";
|
||||
@Autowired
|
||||
AccountBalanceService accountBalanceService;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcast;
|
||||
|
||||
private IMap<Long, Company> companyMap;
|
||||
private IMap<Long, Account> accountMap;
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
hazelcast.waitAvailable();
|
||||
ImdgHazelcast<Company> companyImdg = (ImdgHazelcast<Company>) hazelcast.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
ImdgHazelcast<Account> accountImdg = (ImdgHazelcast<Account>) hazelcast.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
companyMap = companyImdg.getMap();
|
||||
accountMap = accountImdg.getMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link AccountBalanceService#createAccountBalance(Long addresseeId, Long accountId, BigDecimal amount, String cashMovementCurrencyCode)}<br>
|
||||
* Тест проверяет генерацию сущности {@link AccountResult}<br>
|
||||
* Входные параметры:<br>
|
||||
* addresseeId - {@link Company#id}<br>
|
||||
* accountId - {@link Account#id}<br>
|
||||
* amount - сумма<br>
|
||||
* cashMovementCurrencyCode - код<br>
|
||||
*/
|
||||
@Test
|
||||
void createAccountBalance() {
|
||||
Company company = new Company();
|
||||
|
|
@ -108,21 +96,30 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
ACCOUNT_BALANCE_MATCHER.assertMatch(resultUpdate, predictableUpdateResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link AccountBalanceService#createAccountBalance(Long addresseeId, Long accountId, BigDecimal amount, String cashMovementCurrencyCode)}<br>
|
||||
* Тест проверяет валидацию<br>
|
||||
* Входные параметры:<br>
|
||||
* addresseeId - {@link Company#id}<br>
|
||||
* accountId - {@link Account#id}<br>
|
||||
* amount - сумма<br>
|
||||
* cashMovementCurrencyCode - код<br>
|
||||
*/
|
||||
@Test
|
||||
void validatedCreateAccountBalance() {
|
||||
//CompanyNotFound
|
||||
AccountResult predictableResult;
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.CompanyNotFound));
|
||||
|
||||
AccountResult result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCodeNew);
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
||||
//AccountNotPresent accountType=null
|
||||
Company company = new Company();
|
||||
company.setId(addresseeIdNew);
|
||||
companyMap.put(id, company);
|
||||
|
||||
Account account = new Account();
|
||||
account.setId(accountIdNew);
|
||||
// account.setAccountType(AccountType.Clrn.getKey());
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
accountMap.put(id, account);
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.AccountNotPresent));
|
||||
|
|
@ -130,5 +127,29 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCodeNew);
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
||||
//AccountNotPresent id=null
|
||||
account.setId(null);
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
accountMap.put(id, account);
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.AccountNotPresent));
|
||||
|
||||
result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCodeNew);
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
||||
//AccountNotActive accountStatus=null
|
||||
account.setId(accountIdNew);
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
account.setAccountStatus(null);
|
||||
accountMap.put(id, account);
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.AccountNotActive, account.getId()));
|
||||
|
||||
result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCodeNew);
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
accountMap.put(id, account);
|
||||
result = accountBalanceService.createAccountBalance(addresseeIdNew, null, amountNew, cashMovementCurrencyCodeNew);
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package ru.spcex.clearing.balance.service;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf01;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.StatementRequest;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.Status;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collections;
|
||||
|
||||
class Sdf01ExecutorTest extends AbstractServiceTest {
|
||||
|
||||
private final static DateTimeFormatter datFormatter = DateTimeFormatter.ofPattern("dd.MM.yy");
|
||||
@Autowired
|
||||
Sdf01Executor sdf01Executor;
|
||||
private final String deal = "111111111";
|
||||
private final String acc = "123456789";
|
||||
private final Long id = currentId.getAndIncrement();
|
||||
|
||||
@Test
|
||||
void execute() {
|
||||
SDf01 sDf01 = new SDf01();
|
||||
sDf01.setMarket("U");//!"U".equals
|
||||
sDf01.setDeal(deal);//tradingCode
|
||||
sDf01.setAccount(acc);
|
||||
sDf01.setCurr_code("RUR");
|
||||
sDf01.setDat(LocalDate.now().format(datFormatter));
|
||||
sDf01.setAcc_type("A");
|
||||
|
||||
Company company = new Company();
|
||||
company.setTradingCode(deal);
|
||||
companyMap.put(id, company);
|
||||
|
||||
Account account = new Account();
|
||||
account.setId(id);
|
||||
account.setAccount(acc);
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
accountMap.put(id, account);
|
||||
|
||||
StatementRequest statementRequest = new StatementRequest();
|
||||
|
||||
Result predictableResult = new Result();
|
||||
predictableResult.setGenerationId(id);
|
||||
Result result = sdf01Executor.execute(Collections.singletonList(sDf01), statementRequest);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue