BankAccountServiceTest
This commit is contained in:
parent
c00ea6be31
commit
0545a84229
6 changed files with 123 additions and 154 deletions
|
|
@ -1,70 +0,0 @@
|
|||
package ru.spcex.clearing.account.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.spcex.clearing.account.validation.AccountValidationRule;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewRequest;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class ValidationConfig {
|
||||
Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Map<String, Imdg<? extends SpcexObjectBase>> imdgs;
|
||||
|
||||
public ValidationConfig(ImdgProvider imdgProvider) {
|
||||
log.debug("Init validator config");
|
||||
this.imdgs = new HashMap<>();
|
||||
BiConsumer<String, Class<? extends SpcexObjectBase>> addImdg = (s, aClass) -> imdgs.put(s, imdgProvider.getImdg(s, aClass));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account, Account.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company, Company.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountBalance, AccountBalance.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* чтобы во всех валидаторах был один экземпляр Imdg
|
||||
*/
|
||||
private Imdg<?> getImdg(String key) {
|
||||
return imdgs.get(key);
|
||||
}
|
||||
|
||||
@Bean("bankAccountNewRequestValidator")
|
||||
public Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator() {
|
||||
log.debug("Create validator bankAccountNewRequestValidator");
|
||||
return bankAccountNewRequest -> {
|
||||
ImdgValidationContext<BankAccountNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(bankAccountNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, getImdg(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountBalance);
|
||||
|
||||
return new ValidatorImpl<>(context,
|
||||
AccountValidationRule.RequiredFields,
|
||||
AccountValidationRule.RubRequiredFields,
|
||||
AccountValidationRule.AccountIsNew,
|
||||
AccountValidationRule.CompanyPresent
|
||||
);
|
||||
};
|
||||
//todo после слияния ветки CLR_51_57 переписать на использование DictionaryPresentRule, FieldRequiredRule
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,13 +5,11 @@ 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;
|
||||
|
|
@ -74,12 +72,14 @@ public class BankAccountValidationConfig {
|
|||
CurrencyCode.values(),
|
||||
AccountError.WrongFieldValue,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
DictionaryPresentRule.instance("currency",
|
||||
BankAccountNewRequest::getCurrency,
|
||||
IMDGDistributedNames.Map_CurrencyCodeDictionary,
|
||||
CurrencyCodeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.WrongFieldValue),
|
||||
// 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),
|
||||
FieldRequiredRule.instance("bankIdentificationCode",
|
||||
BankAccountNewRequest::getBankIdentificationCode,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
|
|
@ -168,19 +168,21 @@ public class BankAccountValidationConfig {
|
|||
CurrencyCode.values(),
|
||||
false,
|
||||
AccountError.WrongFieldValue,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
DictionaryPresentRule.instance("currency",
|
||||
BankAccountUpdateRequest::getCurrency,
|
||||
IMDGDistributedNames.Map_CurrencyCodeDictionary,
|
||||
CurrencyCodeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.WrongFieldValue,
|
||||
false)
|
||||
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)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("bankAccountUpdateRequestValidator")
|
||||
@Bean("bankAccountDeleteRequestValidator")
|
||||
public Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
|
|
@ -189,6 +191,7 @@ public class BankAccountValidationConfig {
|
|||
context.setValidatedObject(bankAccountDeleteRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_BankAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("id",
|
||||
CommonDeleteRequest::getId,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdfR
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.AccountSdfToStatementRequestPart;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.StatementRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
|
@ -43,9 +44,12 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
|||
init();
|
||||
}
|
||||
|
||||
public void accountNew(BaseRequest<AccountSdf01Request> userRequest) {
|
||||
AccountSdf01Request req = userRequest.getRequestPayload();
|
||||
public RequestInfoUpdate accountNew(BaseRequest<AccountSdf01Request> userRequest) {
|
||||
log.debug("AccountSdf01Request received");
|
||||
|
||||
// todo add validation (create task for that?)
|
||||
|
||||
AccountSdf01Request req = userRequest.getRequestPayload();
|
||||
List<AccountSdfToStatementRequestPart> accountToStatement = new ArrayList<>();
|
||||
for (AccountSdfRequestPart accountReq : req.getAccounts()) {
|
||||
Account account = new Account();
|
||||
|
|
@ -58,6 +62,8 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
sendStatementRequestBack(req.getGroupingSdf01Id(), accountToStatement);
|
||||
log.debug("successfully processed, grouping id={}, processed number={}", req.getGroupingSdf01Id(), accountToStatement.size());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void accountUpdateWithBrake(BaseRequest<AccountSdf01Request> userRequest) {
|
||||
|
|
|
|||
|
|
@ -19,18 +19,17 @@ import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountUpdate
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.AccountStatus;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.Allowed;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
|
|
@ -41,27 +40,37 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
private final Imdg<Relation> relationMap;
|
||||
private final IMessageResolver messageResolver;
|
||||
|
||||
private UserRoleVerification userRoleVerification;
|
||||
private ValidationHelper validationHelper;
|
||||
// private final Imdg<User> userImdg;
|
||||
// private final Imdg<UserRoleSession> userRoleSessionImdg;
|
||||
private final Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator;
|
||||
private final Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator;
|
||||
private final Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator;
|
||||
|
||||
@Autowired
|
||||
public BankAccountService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
ImdgProvider imdgProvider,
|
||||
IMessageResolver messageResolver,
|
||||
|
||||
UserRoleVerification userRoleVerification,
|
||||
ValidationHelper validationHelper,
|
||||
@Qualifier("bankAccountNewRequestValidator")
|
||||
Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator) {
|
||||
Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator,
|
||||
@Qualifier("bankAccountUpdateRequestValidator")
|
||||
Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator,
|
||||
@Qualifier("bankAccountDeleteRequestValidator")
|
||||
Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.bankAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.relationMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
this.messageResolver = messageResolver;
|
||||
|
||||
// this.userImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_User, User.class);
|
||||
// this.userRoleSessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_UserRoleSession, UserRoleSession.class);
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.validationHelper = validationHelper;
|
||||
this.bankAccountNewRequestValidator = bankAccountNewRequestValidator;
|
||||
this.bankAccountUpdateRequestValidator = bankAccountUpdateRequestValidator;
|
||||
this.bankAccountDeleteRequestValidator = bankAccountDeleteRequestValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -78,36 +87,17 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
init();
|
||||
}
|
||||
|
||||
// protected Optional<EnumMessage> checkUserRole(Long userId) {
|
||||
// User user = userImdg.getSingleObjectByID(userId);
|
||||
// if (user == null) {
|
||||
// return Optional.of(new EnumMessage(AccountError.userNotFound(5007)));
|
||||
// }
|
||||
// UserRoleSession role=userRoleSessionImdg.getSingleObjectBySql("userId="+userId+" and userRoleSessions.userRole='ADMN'");
|
||||
// if (role == null) {
|
||||
// return Optional.of(new EnumMessage(AccountError.userNotFound(5001))); // Нет прав на проведение данной операции».
|
||||
// }
|
||||
// return Optional.empty();
|
||||
// }
|
||||
|
||||
private RequestInfoUpdate bankAccountNew(BaseRequest<BankAccountNewRequest> userRequest) {
|
||||
BankAccountNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
// // проверка прав
|
||||
// checkUserRole(req.getUserId());
|
||||
// валидация
|
||||
IValidator validator = bankAccountNewRequestValidator.apply(req);
|
||||
Optional<EnumMessage> error = validator.tillFirstError();
|
||||
if (error.isPresent()) {
|
||||
log.warn("BankAccountNewRequest[{}] validation error: {}", userRequest.getId(), error.get());
|
||||
String errorMsg = messageResolver.resolve(error.get());
|
||||
return new RequestInfoUpdate()
|
||||
.setId(userRequest.getId())
|
||||
.setStatus(Status.Error)
|
||||
.setMessage(errorMsg);
|
||||
}
|
||||
|
||||
public RequestInfoUpdate bankAccountNew(BaseRequest<BankAccountNewRequest> userRequest) {
|
||||
log.debug("BankAccountNewRequest received");
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
BankAccountNewRequest req = userRequest.getRequestPayload();
|
||||
BankAccount bankAccount = new BankAccount();
|
||||
bankAccount.setBankIdentificationCode(req.getBankIdentificationCode());
|
||||
bankAccount.setBankName(req.getBankName());
|
||||
|
|
@ -141,14 +131,21 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
accountMap.insert(account);
|
||||
|
||||
bankAccount.setAccountId(account.getId());
|
||||
bankAccountMap.insert(bankAccount);
|
||||
log.debug("successfully processed, new id {}", bankAccount.getId());
|
||||
Long bankAccountId = bankAccountMap.insert(bankAccount);
|
||||
log.debug("successfully processed, new id {}", bankAccountId);
|
||||
return null;
|
||||
}
|
||||
|
||||
private RequestInfoUpdate bankAccountUpdate(BaseRequest<BankAccountUpdateRequest> userRequest) {
|
||||
BankAccountUpdateRequest req = userRequest.getRequestPayload();
|
||||
log.debug("BankAccountUpdateRequest received id = {}", req.getId());
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountUpdateRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
BankAccount bankAccount = bankAccountMap.getSingleObjectByID(req.getId());
|
||||
bankAccount.setBankIdentificationCode(req.getBankIdentificationCode());
|
||||
bankAccount.setBankName(req.getBankName());
|
||||
|
|
@ -172,6 +169,13 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
|
||||
private RequestInfoUpdate bankAccountDelete(BaseRequest<CommonDeleteRequest> userRequest) {
|
||||
CommonDeleteRequest req = userRequest.getRequestPayload();
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountDeleteRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
log.debug("CommonDeleteRequest received id = {}", req.getId());
|
||||
BankAccount bankAccount = bankAccountMap.getSingleObjectByID(req.getId());
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,12 @@ 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.spcex.clearing.account.config.ErrorResolverConfig;
|
||||
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.ValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.BankAccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.account.utils.MatcherFactory.Matcher;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||
|
|
@ -32,8 +34,11 @@ import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
|||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.Allowed;
|
||||
import ru.spcex.platform.enumeration.Status;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
|
@ -47,9 +52,10 @@ import static ru.spcex.clearing.platform.messaging.service.Status.Error;
|
|||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
ErrorResolverConfig.class,
|
||||
BankAccountService.class,
|
||||
ValidationConfig.class,
|
||||
BankAccountValidationConfig.class,
|
||||
BeanConfiguration.class,
|
||||
HazelcastServiceTestConfiguration.class,
|
||||
KafkaConfigTest.class})
|
||||
public class BankAccountServiceTest {
|
||||
|
|
@ -78,6 +84,9 @@ public class BankAccountServiceTest {
|
|||
private Imdg<BankAccount> bankAccountImdg;
|
||||
private Imdg<Account> accountImdg;
|
||||
|
||||
@Autowired
|
||||
private IMessageResolver messageResolver;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private HazelcastService hazelcastServiceTest;
|
||||
|
|
@ -116,6 +125,7 @@ public class BankAccountServiceTest {
|
|||
public void bankAccountNew() {
|
||||
//ARRANGE
|
||||
BankAccount predictableBankAccount = getBankAccount();
|
||||
|
||||
Company company = getTestCompany();
|
||||
companyImdg.insert(company);
|
||||
Account predictableAccount = getTestAccount(accountId, acc);
|
||||
|
|
@ -160,60 +170,77 @@ public class BankAccountServiceTest {
|
|||
companyImdg.insert(company);
|
||||
BankAccountNewRequest bankAccountNewRequest = getBankAccountNewRequest(predictableBankAccount);
|
||||
|
||||
String errMsg;
|
||||
//AccountValidationRule.RequiredFields
|
||||
//WrongFieldValue
|
||||
bankAccountNewRequest.setCurrency(null);
|
||||
checkError("(5004) args [currency]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "currency"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setCurrency("TT0");
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.WrongFieldValue, "currency"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setCurrency(currency);
|
||||
bankAccountNewRequest.setBankIdentificationCode(null);
|
||||
checkError("(5004) args [bankIdentificationCode]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "bankIdentificationCode"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setBankIdentificationCode(bankIdentificationCode);
|
||||
bankAccountNewRequest.setBankName(null);
|
||||
checkError("(5004) args [bankName]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "bankName"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setBankName(bankName);
|
||||
bankAccountNewRequest.setAccount(null);
|
||||
checkError("(5004) args [account]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "account"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setAccount(acc);
|
||||
bankAccountNewRequest.setDestination(null);
|
||||
checkError("(5004) args [destination]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "destination"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setDestination(destination);
|
||||
bankAccountNewRequest.setCompanyId(null);
|
||||
checkError("(5004) args [companyId]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "companyId"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
bankAccountNewRequest.setCompanyId(addresseeIdNew);
|
||||
|
||||
//AccountValidationRule.RubRequiredFields
|
||||
//WrongFieldValue
|
||||
//RequiredFieldEmpty
|
||||
bankAccountNewRequest.setCorrespondentAccount(null);
|
||||
checkError("(5004) args [correspondentAccount]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "correspondentAccount"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setCorrespondentAccount(correspondentAccount);
|
||||
bankAccountNewRequest.setCorrespondentAccountName(null);
|
||||
checkError("(5004) args [correspondentAccountName]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "correspondentAccountName"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setCorrespondentAccountName(correspondentAccountName);
|
||||
bankAccountNewRequest.setTaxpayerIdentificationNumber(null);
|
||||
checkError("(5004) args [taxpayerIdentificationNumber]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "taxpayerIdentificationNumber"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setTaxpayerIdentificationNumber(taxpayerIdentificationNumber);
|
||||
bankAccountNewRequest.setTaxRegistrationReasonCode(null);
|
||||
checkError("(5004) args [taxRegistrationReasonCode]", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "taxRegistrationReasonCode"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
bankAccountNewRequest.setTaxRegistrationReasonCode(taxRegistrationReasonCode);
|
||||
|
||||
//AccountValidationRule.CompanyPresent
|
||||
//CompanyNotFound
|
||||
bankAccountNewRequest.setCompanyId(999924535239L);
|
||||
checkError("(5013) args []", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.CompanyNotFound, "companyId"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
//CompanyNotActive
|
||||
company.setWorkflowStatus(Status.Blocked.getKey());
|
||||
companyImdg.insert(company);
|
||||
bankAccountNewRequest.setCompanyId(company.getId());
|
||||
checkError("(5014) args []", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.CompanyNotActive, "companyId"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
//AccountValidationRule.AccountIsNew
|
||||
//AccountAlreadyExist
|
||||
|
|
@ -221,7 +248,8 @@ public class BankAccountServiceTest {
|
|||
companyImdg.insert(company);
|
||||
Account existAccount = getTestAccount(accountId, acc);
|
||||
accountImdg.insert(existAccount);
|
||||
checkError("(5010) args []", bankAccountNewRequest);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.AccountAlreadyExist, "account"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
accountImdg.delete(existAccount);
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +310,7 @@ public class BankAccountServiceTest {
|
|||
predictableUpdateBankAccount.setBankIdentificationCode("88888");
|
||||
predictableUpdateBankAccount.setCorrespondentAccount("894984646541316");
|
||||
predictableUpdateBankAccount.setCorrespondentAccountName("BIK OF NEW BUNK");
|
||||
predictableUpdateBankAccount.setCurrency("EU");
|
||||
predictableUpdateBankAccount.setCurrency("RUB");
|
||||
predictableUpdateBankAccount.setDestination("OOO NEW BUNK");
|
||||
predictableUpdateBankAccount.setTaxpayerIdentificationNumber("65468461321");
|
||||
predictableUpdateBankAccount.setTaxRegistrationReasonCode("532137");
|
||||
|
|
@ -332,6 +360,7 @@ public class BankAccountServiceTest {
|
|||
bankAccountImdg.insert(bankAccountExists);
|
||||
Account account = new Account();
|
||||
account.setId(accountId);
|
||||
account.setAccountStatus(WorkflowStatus.Active.getKey());
|
||||
accountImdg.insert(account);
|
||||
|
||||
CommonDeleteRequest commonDeleteRequest = new CommonDeleteRequest();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.function.Function;
|
|||
* @param fieldName Название поля
|
||||
* @param getter Метод получения значения
|
||||
* @param errorEmptyRequiredValue Ошибка, которая будет возвращена, если поле пустое
|
||||
* @param additionalChecks Дополнительные проверки, связанные с этим полем. Выполняются при required == true
|
||||
* @param additionalChecks Дополнительные проверки, связанные с этим полем
|
||||
* @param required Флаг обязательности поля
|
||||
* @param <R> Класс проверяемого объекта
|
||||
* @param <V> Класс проверяемого значения
|
||||
|
|
@ -32,7 +32,7 @@ public record FieldRequiredRule<R, V>(
|
|||
* @param fieldName Название поля
|
||||
* @param getter Метод получения значения
|
||||
* @param errorEmptyRequiredValue Ошибка, которая будет возвращена, если поле пустое
|
||||
* @param additionalChecks Дополнительные проверки, связанные с этим полем. Выполняются при required == true
|
||||
* @param additionalChecks Дополнительные проверки, связанные с этим полем
|
||||
* @param required Флаг обязательности поля
|
||||
* @param <R> Класс проверяемого объекта
|
||||
* @param <V> Класс проверяемого значения
|
||||
|
|
@ -68,13 +68,10 @@ public record FieldRequiredRule<R, V>(
|
|||
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
||||
R validatedObject = context.getValidatedObject();
|
||||
V value = getter.apply(validatedObject);
|
||||
if (required) {
|
||||
if (value == null) return of(errorEmptyRequiredValue, fieldName);
|
||||
for (Function<V, IErrorEnumId> additionalCheck : additionalChecks) {
|
||||
IErrorEnumId validationError = additionalCheck.apply(value);
|
||||
if (validationError != null)
|
||||
return of(validationError, fieldName);
|
||||
}
|
||||
if (required && value == null) return of(errorEmptyRequiredValue, fieldName);
|
||||
for (Function<V, IErrorEnumId> additionalCheck : additionalChecks) {
|
||||
IErrorEnumId validationError = additionalCheck.apply(value);
|
||||
if (validationError != null) return of(validationError, fieldName);
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue