clearingAccountNew test
This commit is contained in:
parent
a42f767698
commit
09b65585c4
5 changed files with 194 additions and 5 deletions
|
|
@ -4,10 +4,12 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import ru.clearing.classes.statics.data.account.Account;
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
import ru.clearing.classes.statics.data.company.Company;
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.platform.dictionary.ClearingAccountTypeDictionary;
|
||||||
import ru.spcex.clearing.account.errors.AccountError;
|
import ru.spcex.clearing.account.errors.AccountError;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountNewRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountNewRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest;
|
||||||
|
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||||
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
||||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||||
|
|
@ -29,6 +31,7 @@ import java.util.function.Function;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ClearingAccountValidationConfig {
|
public class ClearingAccountValidationConfig {
|
||||||
|
|
||||||
|
// todo add validation for clearingAccountType from dictionary
|
||||||
@Bean("clearingAccountNewRequestValidator")
|
@Bean("clearingAccountNewRequestValidator")
|
||||||
public Function<ClearingAccountNewRequest, IValidator> clearingAccountNewRequestValidator(
|
public Function<ClearingAccountNewRequest, IValidator> clearingAccountNewRequestValidator(
|
||||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||||
|
|
@ -37,8 +40,10 @@ public class ClearingAccountValidationConfig {
|
||||||
ImdgValidationContext<ClearingAccountNewRequest> context = new ImdgValidationContext<>();
|
ImdgValidationContext<ClearingAccountNewRequest> context = new ImdgValidationContext<>();
|
||||||
context.setValidatedObject(clearingAccountNewRequest);
|
context.setValidatedObject(clearingAccountNewRequest);
|
||||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccount);
|
addImdg.accept(IMDGDistributedNames.Map_ClearingAccount);
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_ClearingAccountTypeDictionary);
|
||||||
return new ValidatorImpl<>(context,
|
return new ValidatorImpl<>(context,
|
||||||
IdPresentRule.instance("companyId",
|
IdPresentRule.instance("companyId",
|
||||||
ClearingAccountNewRequest::getCompanyId,
|
ClearingAccountNewRequest::getCompanyId,
|
||||||
|
|
@ -62,12 +67,15 @@ public class ClearingAccountValidationConfig {
|
||||||
accountStatusPredicate,
|
accountStatusPredicate,
|
||||||
accountTypePredicate);
|
accountTypePredicate);
|
||||||
Collection<Account> accounts = accountImdg.getCollectionObjectsByPredicate(finalPredicate);
|
Collection<Account> accounts = accountImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||||
if (!accounts.isEmpty()) return null;
|
if (accounts.isEmpty()) return null;
|
||||||
return AccountError.AccountAlreadyExist;
|
return AccountError.AccountAlreadyExist;
|
||||||
}),
|
}),
|
||||||
FieldRequiredRule.instance("clearingAccountType",
|
DictionaryPresentRule.instance("clearingAccountType",
|
||||||
ClearingAccountNewRequest::getClearingAccountType,
|
ClearingAccountNewRequest::getClearingAccountType,
|
||||||
AccountError.RequiredFieldEmpty)
|
IMDGDistributedNames.Map_ClearingAccountTypeDictionary,
|
||||||
|
ClearingAccountTypeDictionary.class,
|
||||||
|
AccountError.RequiredFieldEmpty,
|
||||||
|
AccountError.WrongFieldValue)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||||
import ru.clearing.classes.statics.data.company.Company;
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.platform.dictionary.ClearingAccountTypeDictionary;
|
||||||
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
|
|
@ -31,6 +32,7 @@ public class ValidationConfig {
|
||||||
|
|
||||||
addImdg.accept(IMDGDistributedNames.Map_Company, Company.class);
|
addImdg.accept(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
addImdg.accept(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_ClearingAccountTypeDictionary, ClearingAccountTypeDictionary.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_Account, Account.class);
|
addImdg.accept(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
addImdg.accept(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary, Account.class);
|
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary, Account.class);
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
||||||
ClearingAccount clearingAccount = new ClearingAccount();
|
ClearingAccount clearingAccount = new ClearingAccount();
|
||||||
clearingAccount.setCompanyId(req.getCompanyId());
|
clearingAccount.setCompanyId(req.getCompanyId());
|
||||||
clearingAccount.setAccountId(accountId);
|
clearingAccount.setAccountId(accountId);
|
||||||
|
clearingAccount.setClearingAccountType(req.getClearingAccountType());
|
||||||
clearingAccountId = clearingAccountImdg.insert(clearingAccount);
|
clearingAccountId = clearingAccountImdg.insert(clearingAccount);
|
||||||
txOk = true;
|
txOk = true;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,178 @@
|
||||||
|
package ru.spcex.clearing.account.service;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
|
import org.apache.kafka.clients.producer.MockProducer;
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||||
|
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.account.ClearingAccount;
|
||||||
|
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||||
|
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||||
|
import ru.clearing.platform.dictionary.ClearingAccountTypeDictionary;
|
||||||
|
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||||
|
import ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
|
||||||
|
import ru.spcex.clearing.account.config.KafkaConfigTest;
|
||||||
|
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||||
|
import ru.spcex.clearing.account.config.validation.ClearingAccountValidationConfig;
|
||||||
|
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||||
|
import ru.spcex.clearing.account.utils.MatcherFactory;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountNewRequest;
|
||||||
|
import ru.spcex.platform.enumeration.*;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static ru.spcex.clearing.account.utils.MatcherFactory.usingIgnoringFieldsComparator;
|
||||||
|
import static ru.spcex.clearing.account.utils.TestUtils.*;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@ContextConfiguration(classes = {
|
||||||
|
BeanConfiguration.class,
|
||||||
|
ValidationConfig.class,
|
||||||
|
ClearingAccountValidationConfig.class,
|
||||||
|
AccountValidationConfig.class,
|
||||||
|
AccountService.class,
|
||||||
|
ClearingAccountService.class,
|
||||||
|
HazelcastServiceTestConfiguration.class,
|
||||||
|
KafkaConfigTest.class})
|
||||||
|
class ClearingAccountServiceTest {
|
||||||
|
public static final MatcherFactory.Matcher<ClearingAccount> INFORMATION_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||||
|
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator("created", "updated");
|
||||||
|
private static final int PARTITION = 0;
|
||||||
|
private static final Long companyId = 0L;
|
||||||
|
private static final Long relationId = 0L;
|
||||||
|
private static final String CLEARING_ACCOUNT_TYPE_DICT = "A";
|
||||||
|
private static final String ACCOUNT_VALUE = "account-value";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ClearingAccountService clearingAccountService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
private HazelcastService hazelcastServiceTest;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||||
|
@SpyBean
|
||||||
|
private MockProducer<String, Object> producer;
|
||||||
|
|
||||||
|
private Imdg<ClearingAccount> clearingAccountImdg;
|
||||||
|
private Imdg<Account> accountImdg;
|
||||||
|
private Imdg<Company> companyImdg;
|
||||||
|
private Imdg<ClearingAccountTypeDictionary> clearingAccountTypeDictionaryImdg;
|
||||||
|
private Imdg<AccountTypeDictionary> accountTypeDictionaryImdg;
|
||||||
|
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||||
|
private Imdg<Relation> relationImdg;
|
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
hazelcastServiceTest.waitAvailable();
|
||||||
|
clearingAccountImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class
|
||||||
|
);
|
||||||
|
accountImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Account, Account.class
|
||||||
|
);
|
||||||
|
|
||||||
|
companyImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Company, Company.class
|
||||||
|
);
|
||||||
|
accountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class
|
||||||
|
);
|
||||||
|
clearingAccountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_ClearingAccountTypeDictionary, ClearingAccountTypeDictionary.class
|
||||||
|
);
|
||||||
|
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||||
|
);
|
||||||
|
relationImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Relation, Relation.class
|
||||||
|
);
|
||||||
|
|
||||||
|
Company company = new Company();
|
||||||
|
company.setId(companyId);
|
||||||
|
company.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||||
|
companyImdg.insert(company);
|
||||||
|
|
||||||
|
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
||||||
|
accountTypeDictionary.setCode(AccountType.Clrn.getKey());
|
||||||
|
accountTypeDictionary.setName(AccountType.Clrn.getKey());
|
||||||
|
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
||||||
|
|
||||||
|
ClearingAccountTypeDictionary clearingAccountTypeDictionary = new ClearingAccountTypeDictionary();
|
||||||
|
clearingAccountTypeDictionary.setName(CLEARING_ACCOUNT_TYPE_DICT);
|
||||||
|
clearingAccountTypeDictionary.setCode(CLEARING_ACCOUNT_TYPE_DICT);
|
||||||
|
clearingAccountTypeDictionaryImdg.insert(clearingAccountTypeDictionary);
|
||||||
|
|
||||||
|
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||||
|
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||||
|
clearingMemberCategory.setCompanyId(companyId);
|
||||||
|
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||||
|
|
||||||
|
Relation relation = new Relation();
|
||||||
|
relation.setId(relationId);
|
||||||
|
relation.setConsumerId(companyId);
|
||||||
|
relation.setService(Service.MKR.getKey());
|
||||||
|
relationImdg.insert(relation);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void clearingAccountNew() {
|
||||||
|
ClearingAccountNewRequest clearingAccountNewRequest = new ClearingAccountNewRequest();
|
||||||
|
clearingAccountNewRequest.setAccount(ACCOUNT_VALUE);
|
||||||
|
clearingAccountNewRequest.setCompanyId(companyId);
|
||||||
|
clearingAccountNewRequest.setClearingAccountType(CLEARING_ACCOUNT_TYPE_DICT);
|
||||||
|
|
||||||
|
String jsonString = getJsonStringForNew(clearingAccountNewRequest, 0L);
|
||||||
|
|
||||||
|
addRecordToKafka((MockConsumer) clearingAccountService.getConsumer(),
|
||||||
|
Consts.DESTINATION_CLEARING_ACCOUNT_NEW,
|
||||||
|
PARTITION,
|
||||||
|
0,
|
||||||
|
jsonString);
|
||||||
|
|
||||||
|
waitingWhenAddedRecordAndCheckIt(0L, producer, producerRecord);
|
||||||
|
|
||||||
|
Account predictableAccount = new Account();
|
||||||
|
predictableAccount.setAccount(ACCOUNT_VALUE);
|
||||||
|
predictableAccount.setAccountType(AccountType.Clrn.getKey());
|
||||||
|
predictableAccount.setStatus(AccountStatus.ACTIVE.getKey());
|
||||||
|
predictableAccount.setRelationId(relationId);
|
||||||
|
predictableAccount.setCompanyId(companyId);
|
||||||
|
|
||||||
|
ClearingAccount predictableClearingAccount = new ClearingAccount();
|
||||||
|
predictableClearingAccount.setCompanyId(companyId);
|
||||||
|
predictableClearingAccount.setClearingAccountType(CLEARING_ACCOUNT_TYPE_DICT);
|
||||||
|
|
||||||
|
Account resultAccountNew = accountImdg.getSingleObjectByFieldValues(Map.of("accountType", AccountType.Clrn.getKey()));
|
||||||
|
ClearingAccount resultClearingAccountNew = clearingAccountImdg.getSingleObjectByFieldValues(Map.of("accountId", resultAccountNew.getId()));
|
||||||
|
|
||||||
|
predictableAccount.setId(resultAccountNew.getId());
|
||||||
|
predictableClearingAccount.setAccountId(resultAccountNew.getId());
|
||||||
|
predictableClearingAccount.setId(resultClearingAccountNew.getId());
|
||||||
|
|
||||||
|
ACCOUNT_MATCHER.assertMatch(resultAccountNew, predictableAccount);
|
||||||
|
INFORMATION_ACCOUNT_MATCHER.assertMatch(resultClearingAccountNew, predictableClearingAccount);
|
||||||
|
|
||||||
|
clearingAccountImdg.delete(resultClearingAccountNew);
|
||||||
|
accountImdg.delete(resultAccountNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -106,8 +106,8 @@ class InformationAccountServiceTest {
|
||||||
companyImdg.insert(company);
|
companyImdg.insert(company);
|
||||||
|
|
||||||
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
||||||
accountTypeDictionary.setCode(AccountType.Corr.getKey());
|
accountTypeDictionary.setCode(AccountType.Info.getKey());
|
||||||
accountTypeDictionary.setName(AccountType.Corr.getKey());
|
accountTypeDictionary.setName(AccountType.Info.getKey());
|
||||||
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
||||||
|
|
||||||
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue