diff --git a/clearing-parent/account-service/pom.xml b/clearing-parent/account-service/pom.xml
index aa06e621d..f2bfdaf25 100644
--- a/clearing-parent/account-service/pom.xml
+++ b/clearing-parent/account-service/pom.xml
@@ -60,6 +60,11 @@
assertj-core
test
+
+ org.springframework.boot
+ spring-boot-test
+ test
+
diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java
index 0a7c76a63..992297cf5 100644
--- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java
+++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java
@@ -11,7 +11,6 @@ import org.springframework.stereotype.Service;
import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.account.BankAccount;
import ru.clearing.classes.statics.data.company.relation.Relation;
-import ru.spcex.clearing.account.errors.AccountError;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
import ru.spcex.clearing.platform.messaging.domain.Consts;
@@ -42,7 +41,7 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
private final Imdg relationMap;
private final IMessageResolver messageResolver;
-// private final Imdg userImdg;
+ // private final Imdg userImdg;
// private final Imdg userRoleSessionImdg;
private final Function bankAccountNewRequestValidator;
diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/AccountValidationRule.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/AccountValidationRule.java
index 4595d7005..7072858ac 100644
--- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/AccountValidationRule.java
+++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/validation/AccountValidationRule.java
@@ -52,7 +52,7 @@ public enum AccountValidationRule implements IValidationRule validate(ImdgValidationContext context) {
BankAccountNewRequest accountReq = context.getValidatedObject();
if (StringUtils.isEmpty(accountReq.getCurrency())) {
- return of(AccountError.WrongFieldValue, "Currency");
+ return of(AccountError.WrongFieldValue, "currency");
}
if (StringUtils.isEmpty(accountReq.getBankIdentificationCode())) {
return of(AccountError.WrongFieldValue, "bankIdentificationCode");
diff --git a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/config/HazelcastServiceTestConfiguration.java b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/config/HazelcastServiceTestConfiguration.java
index 60f94af16..7ee4bc8fa 100644
--- a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/config/HazelcastServiceTestConfiguration.java
+++ b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/config/HazelcastServiceTestConfiguration.java
@@ -13,9 +13,11 @@ import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
import java.util.List;
import java.util.Random;
+import java.util.concurrent.atomic.AtomicLong;
@Configuration
public class HazelcastServiceTestConfiguration {
+ public static final AtomicLong currentID = new AtomicLong(0L);
private HazelcastInstance hazelcastInstance;
private static ThreadPoolTaskExecutor createThreadPoolTaskExecutor(int maxPoolSz, boolean waitForCompletion) {
@@ -40,7 +42,7 @@ public class HazelcastServiceTestConfiguration {
joinConfig.setTcpIpConfig(new TcpIpConfig().setEnabled(true).setMembers(List.of("127.0.0.1")));
networkConfig.setJoin(joinConfig);
cfg.setNetworkConfig(networkConfig);
- hazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
+ hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(cfg);
HazelcastHelper.otcSystem_setStorageState(true, hazelcastInstance);
return new HazelcastService(taskExecutorHazelcastClientInitializer, taskExecutorIdGeneratorAwaiter, params);
}
diff --git a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/config/KafkaConfigTest.java b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/config/KafkaConfigTest.java
new file mode 100644
index 000000000..fac49db45
--- /dev/null
+++ b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/config/KafkaConfigTest.java
@@ -0,0 +1,44 @@
+package ru.spcex.clearing.account.config;
+
+
+import org.apache.kafka.clients.consumer.MockConsumer;
+import org.apache.kafka.clients.consumer.OffsetResetStrategy;
+import org.apache.kafka.clients.producer.Producer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Scope;
+import ru.spcex.clearing.imdg.IMDGDistributedNames;
+import ru.spcex.clearing.platform.messaging.service.RequestInfo;
+import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
+import ru.spcex.platform.imdg.api.Imdg;
+import ru.spcex.platform.imdg.api.ImdgId;
+import ru.spcex.platform.imdg.api.ImdgProvider;
+
+@Configuration
+public class KafkaConfigTest {
+
+ @Autowired
+ @Bean(name = "kafkaSenderTest")
+ public KafkaSender kafkaSender(Producer kafkaProducer, @Qualifier("hazelcastServiceTest") ImdgProvider imdgProvider) {
+ ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
+ return KafkaSender
+ .setup()
+ .producer(kafkaProducer)
+ .idGenerator(imdgIdGenerator::nextId)
+ .imdgProvider(s -> {
+ Imdg imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class);
+ return imdg::insert;
+ })
+ .build();
+ }
+
+ @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+ @Bean(name = "mockConsumerTest")
+ public MockConsumer createConsumer() {
+ return new MockConsumer<>(OffsetResetStrategy.EARLIEST);
+ }
+
+}
diff --git a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/AccountServiceTest.java b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/AccountServiceTest.java
new file mode 100644
index 000000000..50e495b0b
--- /dev/null
+++ b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/AccountServiceTest.java
@@ -0,0 +1,146 @@
+package ru.spcex.clearing.account.service;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+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.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
+import ru.spcex.clearing.account.config.KafkaConfigTest;
+import ru.spcex.clearing.account.utils.MatcherFactory;
+import ru.spcex.clearing.imdg.IMDGDistributedNames;
+import ru.spcex.clearing.platform.messaging.domain.ActionType;
+import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
+import ru.spcex.clearing.platform.messaging.domain.Consts;
+import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdf01Request;
+import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdfRequestPart;
+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.RequestInfo;
+import ru.spcex.clearing.platform.messaging.service.Status;
+import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
+import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
+
+import java.util.Collections;
+import java.util.List;
+
+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;
+import static ru.spcex.clearing.account.utils.MatcherFactory.usingIgnoringFieldsComparator;
+import static ru.spcex.clearing.account.utils.TestUtils.addRecordToKafka;
+
+@ExtendWith(SpringExtension.class)
+@ContextConfiguration(classes = {
+ AccountService.class,
+ HazelcastServiceTestConfiguration.class,
+ KafkaConfigTest.class})
+class AccountServiceTest {
+ public static final MatcherFactory.Matcher ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
+ public static final MatcherFactory.Matcher REQUEST_INFO_MATCHER_MATCHER = usingIgnoringFieldsComparator("created");
+ private static final int PARTITION = 0;
+ private static final String TOPIC_ACCOUNT_NEW = Consts.ACCOUNT_NEW;
+ private static final String account = "123456789123";
+ @Autowired
+ AccountService accountService;
+ @Autowired
+ @Qualifier("hazelcastServiceTest")
+ private HazelcastService hazelcastServiceTest;
+
+ @Captor
+ private ArgumentCaptor producerRecord;
+ @SpyBean
+ private MockProducer producer;
+
+ /**
+ * {@link AccountService#accountNew(BaseRequest)}
+ * Тест проверяет создание сущности {@link BaseRequest} в Hazelcast при передаче из Apache Kafka.
+ * Входной запрос {@link AccountSdf01Request}:
+ * {@link AccountSdfRequestPart#setSdfId} - текущий Id
+ * {@link AccountSdfRequestPart#setAccount} - 123456789123
+ * {@link AccountSdfRequestPart#setCompanyId} - текущий Id
+ * {@link AccountSdf01Request#setGroupingSdf01Id} - текущий Id
+ * {@link AccountSdf01Request#setAccounts} - Collections.singletonList(AccountSdfRequestPart)
+ */
+ @Test
+ void accountNew() throws InterruptedException {
+ //ARRANGE
+ Long firstID = currentID.getAndIncrement();
+ Long secondID = currentID.getAndIncrement();
+ AccountSdfRequestPart accountSdfRequestPart = new AccountSdfRequestPart();
+ accountSdfRequestPart.setSdfId(firstID);
+ accountSdfRequestPart.setAccount(account);
+ accountSdfRequestPart.setCompanyId(firstID);
+ AccountSdf01Request accountSdf01Request = new AccountSdf01Request();
+ accountSdf01Request.setGroupingSdf01Id(firstID);
+ accountSdf01Request.setAccounts(Collections.singletonList(accountSdfRequestPart));
+
+ BaseRequest baseNewRequest = new BaseRequest<>();
+ baseNewRequest.setRequestPayload(accountSdf01Request);
+ baseNewRequest.setId(firstID);
+ baseNewRequest.setActionType(ActionType.NEW);
+ String jsonBaseNewRequest;
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ jsonBaseNewRequest = objectMapper.writeValueAsString(baseNewRequest);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+
+ AccountSdfToStatementRequestPart responsePart = new AccountSdfToStatementRequestPart();
+ responsePart.setSdfId(firstID);
+ responsePart.setErrorCode(null);
+ responsePart.setErrorText(null);
+ List accountToStatement = Collections.singletonList(responsePart);
+ StatementRequest statementRequest = new StatementRequest();
+ statementRequest.setGroupId(firstID);
+ statementRequest.setAccountCreationResults(accountToStatement);
+
+ BaseRequest