From 2fc7c7e18046fe795df5897aa938846cfaac373e Mon Sep 17 00:00:00 2001 From: akulikov Date: Tue, 2 May 2023 16:19:51 +0300 Subject: [PATCH] clearingAccountUpdate test --- .../ClearingAccountValidationConfig.java | 2 + .../service/ClearingAccountServiceTest.java | 44 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClearingAccountValidationConfig.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClearingAccountValidationConfig.java index 29b3a3e98..1c8c88154 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClearingAccountValidationConfig.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/ClearingAccountValidationConfig.java @@ -89,8 +89,10 @@ public class ClearingAccountValidationConfig { ImdgValidationContext context = new ImdgValidationContext<>(); context.setValidatedObject(clearingAccountUpdateRequest); Consumer addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s)); + addImdg.accept(IMDGDistributedNames.Map_Account); addImdg.accept(IMDGDistributedNames.Map_Company); addImdg.accept(IMDGDistributedNames.Map_ClearingAccount); + addImdg.accept(IMDGDistributedNames.Map_ClearingAccountTypeDictionary); return new ValidatorImpl<>(context, FieldRequiredRule.instance("account", ClearingAccountUpdateRequest::getAccount, diff --git a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/ClearingAccountServiceTest.java b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/ClearingAccountServiceTest.java index c50e7b194..da67ac384 100644 --- a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/ClearingAccountServiceTest.java +++ b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/ClearingAccountServiceTest.java @@ -29,6 +29,7 @@ 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.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest; import ru.spcex.platform.enumeration.*; import ru.spcex.platform.imdg.api.Imdg; import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService; @@ -50,13 +51,14 @@ import static ru.spcex.clearing.account.utils.TestUtils.*; HazelcastServiceTestConfiguration.class, KafkaConfigTest.class}) class ClearingAccountServiceTest { - public static final MatcherFactory.Matcher INFORMATION_ACCOUNT_MATCHER = usingIgnoringFieldsComparator(); + public static final MatcherFactory.Matcher CLEARING_ACCOUNT_MATCHER = usingIgnoringFieldsComparator(); public static final MatcherFactory.Matcher 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"; + private static final String TRADING_CODE = "trading-code"; @Autowired ClearingAccountService clearingAccountService; @@ -108,6 +110,7 @@ class ClearingAccountServiceTest { Company company = new Company(); company.setId(companyId); company.setWorkflowStatus(WorkflowStatus.Active.getKey()); + company.setTradingCode(TRADING_CODE); companyImdg.insert(company); AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary(); @@ -169,10 +172,47 @@ class ClearingAccountServiceTest { predictableClearingAccount.setId(resultClearingAccountNew.getId()); ACCOUNT_MATCHER.assertMatch(resultAccountNew, predictableAccount); - INFORMATION_ACCOUNT_MATCHER.assertMatch(resultClearingAccountNew, predictableClearingAccount); + CLEARING_ACCOUNT_MATCHER.assertMatch(resultClearingAccountNew, predictableClearingAccount); clearingAccountImdg.delete(resultClearingAccountNew); accountImdg.delete(resultAccountNew); } + @Test + void clearingAccountUpdate() { + Account existAccount = new Account(); + existAccount.setAccount(ACCOUNT_VALUE); + existAccount.setStatus(AccountStatus.ACTIVE.getKey()); + existAccount.setAccountType(AccountType.Clrn.getKey()); + Long accountId = accountImdg.insert(existAccount); + + ClearingAccount existClearingAccount = new ClearingAccount(); + existClearingAccount.setAccountId(accountId); + existClearingAccount.setClearingAccountType(CLEARING_ACCOUNT_TYPE_DICT); + existClearingAccount.setCompanyId(companyId); + + Account predictableAccount = new Account(); + predictableAccount.setAccount(ACCOUNT_VALUE); + predictableAccount.setStatus(AccountStatus.BLOCKED.getKey()); + predictableAccount.setAccountType(AccountType.Clrn.getKey()); + + clearingAccountImdg.insert(existClearingAccount); + + ClearingAccountUpdateRequest clearingAccountUpdateRequest = new ClearingAccountUpdateRequest(); + clearingAccountUpdateRequest.setAccount(ACCOUNT_VALUE); + clearingAccountUpdateRequest.setStatus(0); + clearingAccountUpdateRequest.setDeal(TRADING_CODE); + + String jsonString = getJsonStringForUPDATE(clearingAccountUpdateRequest, 0L); + + addRecordToKafka((MockConsumer) clearingAccountService.getConsumer(), Consts.DESTINATION_CLEARING_ACCOUNT_UPDATE, PARTITION, 0, jsonString); + waitingWhenAddedRecordAndCheckIt(0L, producer, producerRecord); + + Account accountResult = accountImdg.getSingleObjectByID(accountId); + predictableAccount.setId(accountResult.getId()); + predictableAccount.setUpdated(accountResult.getUpdated()); + + ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount); + } + } \ No newline at end of file