fix tests

This commit is contained in:
akulikov 2023-04-24 19:03:44 +03:00
parent 2716196bf7
commit 6e6d866445
5 changed files with 78 additions and 83 deletions

View file

@ -5,11 +5,13 @@ import org.springframework.context.annotation.Configuration;
import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.account.BankAccount;
import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
import ru.spcex.clearing.account.errors.AccountError;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountUpdateRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
import ru.spcex.clearing.validation.common.rules.EnumPresentRule;
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
@ -72,14 +74,12 @@ public class BankAccountValidationConfig {
CurrencyCode.values(),
AccountError.WrongFieldValue,
AccountError.RequiredFieldEmpty),
// todo currency codes not present in currency_code_dictionary, uncomment when present
//
// DictionaryPresentRule.instance("currency",
// BankAccountNewRequest::getCurrency,
// IMDGDistributedNames.Map_CurrencyCodeDictionary,
// CurrencyCodeDictionary.class,
// AccountError.RequiredFieldEmpty,
// AccountError.WrongFieldValue),
DictionaryPresentRule.instance("currency",
BankAccountNewRequest::getCurrency,
IMDGDistributedNames.Map_CurrencyCodeDictionary,
CurrencyCodeDictionary.class,
AccountError.RequiredFieldEmpty,
AccountError.WrongFieldValue),
FieldRequiredRule.instance("bankIdentificationCode",
BankAccountNewRequest::getBankIdentificationCode,
AccountError.RequiredFieldEmpty),
@ -128,16 +128,14 @@ public class BankAccountValidationConfig {
CurrencyCode.values(),
false,
AccountError.WrongFieldValue,
AccountError.RequiredFieldEmpty)
// todo currency codes not present in currency_code_dictionary, uncomment when present
//
// DictionaryPresentRule.instance("currency",
// BankAccountUpdateRequest::getCurrency,
// IMDGDistributedNames.Map_CurrencyCodeDictionary,
// CurrencyCodeDictionary.class,
// AccountError.RequiredFieldEmpty,
// AccountError.WrongFieldValue,
// false)
AccountError.RequiredFieldEmpty),
DictionaryPresentRule.instance("currency",
BankAccountUpdateRequest::getCurrency,
IMDGDistributedNames.Map_CurrencyCodeDictionary,
CurrencyCodeDictionary.class,
AccountError.RequiredFieldEmpty,
AccountError.WrongFieldValue,
false)
);
};
}

View file

@ -40,6 +40,7 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import ru.spcex.platform.utils.validation.IValidator;
import java.time.Instant;
import java.util.*;
import java.util.function.Function;
@ -156,6 +157,7 @@ public class AccountService extends QueueConsumer implements InitializingBean {
Collection<Account> companies = accountMap.getCollectionObjectsByFieldValues(Map.of("companyId", companyId));
Instant now = Instant.now();
Account account = new Account();
account.setAccount(req.getAccount());
account.setAccountType(req.getAccountType());
@ -163,7 +165,9 @@ public class AccountService extends QueueConsumer implements InitializingBean {
account.setStatus(req.getStatus());
// todo выяснить у репортера, что писать в это поле если это не первый счет компании
account.setProcessingSign(companies.isEmpty() ? Allowed.ALLOWED.getKey() : null);
account.setCompanyId(req.getCompanyId());
account.setCompanyId(relation.getConsumerId());
account.setCreated(now);
account.setUpdated(now);
Long id = accountMap.insert(account);
log.debug("successfully processed, new account id {}", id);
@ -194,6 +198,8 @@ public class AccountService extends QueueConsumer implements InitializingBean {
if (request.getStatus() != null && !account.getStatus().equalsIgnoreCase(request.getStatus()))
return makeError(AccountError.WrongFieldValue, "status", userRequest.getId());
account.setUpdated(Instant.now());
accountMap.update(account);
log.debug("successfully processed, update account id {}", account.getId());
@ -213,6 +219,7 @@ public class AccountService extends QueueConsumer implements InitializingBean {
Account account = accountMap.getSingleObjectByID(request.getId());
account.setStatus(AccountStatus.BLOCKED.getKey());
account.setUpdated(Instant.now());
accountMap.update(account);

View file

@ -98,6 +98,31 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
if (requestInfoUpdate != null) return requestInfoUpdate;
BankAccountNewRequest req = userRequest.getRequestPayload();
Long relationId = null;
Long consumerId = null;
String relationSqlCondition = String.format("consumerId = %s and service = %s", req.companyId,
ru.spcex.platform.enumeration.Service.MKR.getKey());
Relation relationByCompany = relationMap.getSingleObjectBySQL(relationSqlCondition);
if (relationByCompany != null) {
relationId = relationByCompany.getId();
consumerId = relationByCompany.getConsumerId();
} else {
log.warn("Not found relation by condition: {}", relationSqlCondition);
}
Instant now = Instant.now();
Account account = new Account();
account.setAccount(req.getAccount());
account.setAccountType(AccountType.Bank.getKey());
account.setStatus(AccountStatus.ACTIVE.getKey());
account.setRelationId(relationId);
account.setCompanyId(consumerId);
account.setProcessingSign(Allowed.ALLOWED.getKey());
account.setCreated(now);
account.setUpdated(now);
accountMap.insert(account);
BankAccount bankAccount = new BankAccount();
bankAccount.setBankIdentificationCode(req.getBankIdentificationCode());
bankAccount.setBankName(req.getBankName());
@ -109,27 +134,6 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode());
bankAccount.setAccount(req.getAccount());
bankAccount.setCompanyId(req.getCompanyId());
Account account = new Account();
account.setAccount(req.account);
account.setAccountType(AccountType.Bank.getKey());
String relationSqlCondition = String.format("consumerId = %s and service = %s", req.companyId,
ru.spcex.platform.enumeration.Service.MKR.getKey());
Relation relationByCompany = relationMap.getSingleObjectBySQL(relationSqlCondition);
if (relationByCompany != null) {
account.setRelationId(relationByCompany.getId());
account.setCompanyId(relationByCompany.getConsumerId());
} else {
log.warn("Not found relation by condition: {}", relationSqlCondition);
}
account.setStatus(AccountStatus.ACTIVE.getKey());
account.setProcessingSign(Allowed.ALLOWED.getKey());
account.setCreated(Instant.now());
account.setUpdated(Instant.now());
accountMap.insert(account);
bankAccount.setAccountId(account.getId());
Long bankAccountId = bankAccountMap.insert(bankAccount);
log.debug("successfully processed, new id {}", bankAccountId);

View file

@ -47,8 +47,8 @@ import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration.currentID;
@ -131,14 +131,16 @@ class AccountServiceTest {
@Test
void accountCorrespondentNew() {
String uniqueAccount = account + UUID.randomUUID();
AccountCorrespondentNewRequest accountCorrespondentNewRequest = new AccountCorrespondentNewRequest();
accountCorrespondentNewRequest.setAccount(account);
accountCorrespondentNewRequest.setAccount(uniqueAccount);
accountCorrespondentNewRequest.setAccountType(AccountType.Corr.getKey());
accountCorrespondentNewRequest.setCompanyId(companyId);
accountCorrespondentNewRequest.setStatus(AccountStatus.ACTIVE.getKey());
Account predictableAccount = new Account();
predictableAccount.setAccount(account);
predictableAccount.setAccount(uniqueAccount);
predictableAccount.setAccountType(AccountType.Corr.getKey());
predictableAccount.setCompanyId(companyId);
predictableAccount.setProcessingSign(Allowed.ALLOWED.getKey());
@ -155,10 +157,12 @@ class AccountServiceTest {
waitingWhenAddedRecordAndCheckIt(0L, producer, producerRecord);
Account resultNew = accountImdg.getCollectionObjectsByFieldValues(Map.of("companyId", companyId)).iterator().next();
Account resultNew = accountImdg.getCollectionObjectsByFieldValues(Map.of("account", uniqueAccount)).iterator().next();
predictableAccount.setId(resultNew.getId());
predictableAccount.setUpdated(resultNew.getUpdated());
predictableAccount.setCreated(resultNew.getCreated());
ACCOUNT_MATCHER.assertMatch(resultNew, predictableAccount);
accountImdg.delete(resultNew);
}
@Test
@ -195,7 +199,9 @@ class AccountServiceTest {
existAccount.setAccount(updatedAccount);
Account resultUpdating = accountImdg.getSingleObjectByID(accountId);
existAccount.setUpdated(resultUpdating.getUpdated());
ACCOUNT_MATCHER.assertMatch(resultUpdating, existAccount);
accountImdg.delete(resultUpdating);
}
@Test
@ -224,8 +230,10 @@ class AccountServiceTest {
Account resultBlock = accountImdg.getSingleObjectByID(accountId);
existAccount.setStatus(AccountStatus.BLOCKED.getKey());
existAccount.setUpdated(resultBlock.getUpdated());
ACCOUNT_MATCHER.assertMatch(existAccount, resultBlock);
accountImdg.delete(resultBlock);
}
/**
@ -250,7 +258,6 @@ class AccountServiceTest {
AccountSdf01Request accountSdf01Request = new AccountSdf01Request();
accountSdf01Request.setGroupingSdf01Id(firstID);
accountSdf01Request.setAccounts(Collections.singletonList(accountSdfRequestPart));
BaseRequest<AccountSdf01Request> baseNewRequest = new BaseRequest<>();
baseNewRequest.setRequestPayload(accountSdf01Request);
baseNewRequest.setId(firstID);
@ -279,33 +286,25 @@ class AccountServiceTest {
Account predictableAccount = new Account();
predictableAccount.setAccount(account);
predictableAccount.setId(firstID);
predictableAccount.setCompanyId(firstID);
RequestInfo predictableRequestInfo = new RequestInfo();
predictableRequestInfo.setId(secondID);
predictableRequestInfo.setStatus(Status.Processing);
//ACT
hazelcastServiceTest.waitTillReadyState();
//KAFKA
addRecordToKafka((MockConsumer) accountService.getConsumer(), TOPIC_ACCOUNT_NEW, PARTITION, 0, jsonBaseNewRequest);
//waiting for kafka producer send message (finale event)
verify(producer, timeout(30_000L).times(1))
verify(producer, timeout(30_000L).times(2))
.send(producerRecord.capture());
BaseRequest<Object> baseRequestObject = (BaseRequest<Object>) producerRecord.getValue().value();
ImdgHazelcast<Account> accountImdg = (ImdgHazelcast<Account>) hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
ImdgHazelcast<RequestInfo> requestInfoImdg = (ImdgHazelcast<RequestInfo>) hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class);
//ASSERT
Account accountResult = accountImdg.getSingleObjectBySQL(String.format("account = %s", account));
RequestInfo requestInfoResult = requestInfoImdg.getSingleObjectByID(baseRequestObject.getId());
assertEquals(Consts.STATEMENT_PROCESS, producerRecord.getValue().topic());
predictableAccount.setId(accountResult.getId());
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
REQUEST_INFO_MATCHER_MATCHER.assertMatch(requestInfoResult, predictableRequestInfo);
accountImdg.delete(accountResult);
}
}

View file

@ -16,6 +16,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.account.BankAccount;
import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
import ru.spcex.clearing.account.config.BeanConfiguration;
import ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
import ru.spcex.clearing.account.config.KafkaConfigTest;
@ -83,6 +84,7 @@ public class BankAccountServiceTest {
protected Imdg<Company> companyImdg;
private Imdg<BankAccount> bankAccountImdg;
private Imdg<Account> accountImdg;
private Imdg<CurrencyCodeDictionary> currencyCodeDictionaryImdg;
@Autowired
private IMessageResolver messageResolver;
@ -105,6 +107,13 @@ public class BankAccountServiceTest {
companyImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Company, Company.class);
bankAccountImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
accountImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
currencyCodeDictionaryImdg = hazelcastServiceTest.getImdg(
IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class
);
CurrencyCodeDictionary currencyCodeDictionary = new CurrencyCodeDictionary();
currencyCodeDictionary.setCode("RUB");
currencyCodeDictionary.setName("RUB");
currencyCodeDictionaryImdg.insert(currencyCodeDictionary);
}
/**
@ -207,28 +216,6 @@ public class BankAccountServiceTest {
checkError(errMsg, bankAccountNewRequest);
bankAccountNewRequest.setCompanyId(addresseeIdNew);
//AccountValidationRule.RubRequiredFields
//RequiredFieldEmpty
bankAccountNewRequest.setCorrespondentAccount(null);
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "correspondentAccount"));
checkError(errMsg, bankAccountNewRequest);
bankAccountNewRequest.setCorrespondentAccount(correspondentAccount);
bankAccountNewRequest.setCorrespondentAccountName(null);
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "correspondentAccountName"));
checkError(errMsg, bankAccountNewRequest);
bankAccountNewRequest.setCorrespondentAccountName(correspondentAccountName);
bankAccountNewRequest.setTaxpayerIdentificationNumber(null);
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "taxpayerIdentificationNumber"));
checkError(errMsg, bankAccountNewRequest);
bankAccountNewRequest.setTaxpayerIdentificationNumber(taxpayerIdentificationNumber);
bankAccountNewRequest.setTaxRegistrationReasonCode(null);
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "taxRegistrationReasonCode"));
checkError(errMsg, bankAccountNewRequest);
bankAccountNewRequest.setTaxRegistrationReasonCode(taxRegistrationReasonCode);
//AccountValidationRule.CompanyPresent
//CompanyNotFound
bankAccountNewRequest.setCompanyId(999924535239L);
@ -297,6 +284,7 @@ public class BankAccountServiceTest {
*/
@Test
void bankAccountUpdate() {
clearImdg(accountImdg);
//ARRANGE
// Company company = getTestCompany();
// companyImdg.insert(company);
@ -337,12 +325,11 @@ public class BankAccountServiceTest {
//ASSERT
waitingWhenAddedRecordAndCheckIt(ID, producer, producerRecord);
Account accountResult = accountImdg.getSingleObjectBySQL(String.format("account = %s", acc));
BankAccount resultUpdating = bankAccountImdg.getSingleObjectBySQL(String.format("account = %s or companyId = %s", acc, addresseeIdNew));
Account accountResult = accountImdg.getSingleObjectByID(predictableAccount.getId());
BankAccount resultUpdating = bankAccountImdg.getSingleObjectByID(predictableUpdateBankAccount.getId());
predictableAccount.setUpdated(accountResult.getUpdated());
predictableUpdateBankAccount.setAccountId(resultUpdating.getAccountId());
predictableUpdateBankAccount.setCompanyId(resultUpdating.getCompanyId());
predictableAccount.setUpdated(accountResult.getUpdated());
BANK_ACCOUNT_MATCHER.assertMatch(resultUpdating, predictableUpdateBankAccount);
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
}