add AccountServiceTast
This commit is contained in:
parent
91cba070f6
commit
aef9556b56
17 changed files with 322 additions and 105 deletions
|
|
@ -13,9 +13,11 @@ import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class HazelcastServiceTestConfiguration {
|
public class HazelcastServiceTestConfiguration {
|
||||||
|
public static final AtomicLong currentID = new AtomicLong(0L);
|
||||||
private HazelcastInstance hazelcastInstance;
|
private HazelcastInstance hazelcastInstance;
|
||||||
|
|
||||||
private static ThreadPoolTaskExecutor createThreadPoolTaskExecutor(int maxPoolSz, boolean waitForCompletion) {
|
private static ThreadPoolTaskExecutor createThreadPoolTaskExecutor(int maxPoolSz, boolean waitForCompletion) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
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.MockProducer;
|
||||||
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
|
import org.apache.kafka.common.serialization.StringSerializer;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.serialization.JsonSerializer;
|
||||||
|
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(@Qualifier("mockProducerTest") Producer<String, Object> kafkaProducer, @Qualifier("hazelcastServiceTest") ImdgProvider imdgProvider) {
|
||||||
|
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
||||||
|
return KafkaSender
|
||||||
|
.setup()
|
||||||
|
.producer(kafkaProducer)
|
||||||
|
.idGenerator(imdgIdGenerator::nextId)
|
||||||
|
.imdgProvider(s -> {
|
||||||
|
Imdg<RequestInfo> imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class);
|
||||||
|
return imdg::insert;
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "mockConsumerTest")
|
||||||
|
public MockConsumer<String, Object> createConsumer() {
|
||||||
|
return new MockConsumer<>(OffsetResetStrategy.EARLIEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "mockProducerTest")
|
||||||
|
public MockProducer<String, Object> createProducer() {
|
||||||
|
return new MockProducer<>(true, new StringSerializer(), new JsonSerializer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,140 @@
|
||||||
|
package ru.spcex.clearing.account.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.hazelcast.core.IMap;
|
||||||
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
|
import org.apache.kafka.common.TopicPartition;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
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.ImapEvent;
|
||||||
|
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.clearing.platform.messaging.service.sender.KafkaSender;
|
||||||
|
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration.currentID;
|
||||||
|
import static ru.spcex.clearing.account.utils.MatcherFactory.usingIgnoringFieldsComparator;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@ContextConfiguration(classes = {
|
||||||
|
HazelcastServiceTestConfiguration.class,
|
||||||
|
KafkaConfigTest.class})
|
||||||
|
class AccountServiceTest {
|
||||||
|
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||||
|
public static final MatcherFactory.Matcher<RequestInfo> REQUEST_INFO_MATCHER_MATCHER = usingIgnoringFieldsComparator("created");
|
||||||
|
private static final int PARTITION = 0;
|
||||||
|
private static final String TOPIC_ACCOUNT_NEW = Consts.ACCOUNT_NEW;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
private HazelcastService hazelcastServiceTest;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("kafkaSenderTest")
|
||||||
|
private KafkaSender kafkaSender;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("mockConsumerTest")
|
||||||
|
private MockConsumer<String, Object> mockConsumer;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void accountNew() throws InterruptedException {
|
||||||
|
//arrange
|
||||||
|
Long firstID = currentID.getAndIncrement();
|
||||||
|
Long secondID = currentID.getAndIncrement();
|
||||||
|
AccountSdfRequestPart accountSdfRequestPart = new AccountSdfRequestPart();
|
||||||
|
accountSdfRequestPart.setSdfId(firstID);
|
||||||
|
accountSdfRequestPart.setAccount("123456789123");
|
||||||
|
accountSdfRequestPart.setCompanyId(firstID);
|
||||||
|
AccountSdf01Request accountSdf01Request = new AccountSdf01Request();
|
||||||
|
accountSdf01Request.setGroupingSdf01Id(firstID);
|
||||||
|
accountSdf01Request.setAccounts(Collections.singletonList(accountSdfRequestPart));
|
||||||
|
|
||||||
|
BaseRequest<AccountSdf01Request> 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<AccountSdfToStatementRequestPart> accountToStatement = Collections.singletonList(responsePart);
|
||||||
|
StatementRequest statementRequest = new StatementRequest();
|
||||||
|
statementRequest.setGroupId(firstID);
|
||||||
|
statementRequest.setAccountCreationResults(accountToStatement);
|
||||||
|
|
||||||
|
BaseRequest<Object> baseRequest = new BaseRequest<>();
|
||||||
|
baseRequest.setId(secondID);
|
||||||
|
baseRequest.setActionType(ActionType.SYSTEM);
|
||||||
|
baseRequest.setRequestPayload(statementRequest);
|
||||||
|
|
||||||
|
Account predictableAccount = new Account();
|
||||||
|
predictableAccount.setAccount("123456789123");
|
||||||
|
predictableAccount.setId(firstID);
|
||||||
|
|
||||||
|
RequestInfo predictableRequestInfo = new RequestInfo();
|
||||||
|
predictableRequestInfo.setId(secondID);
|
||||||
|
predictableRequestInfo.setStatus(Status.Processing);
|
||||||
|
|
||||||
|
|
||||||
|
//ACT
|
||||||
|
|
||||||
|
hazelcastServiceTest.waitTillReadyState();
|
||||||
|
//service set up
|
||||||
|
AccountService accountService = new AccountService(mockConsumer, hazelcastServiceTest, kafkaSender);
|
||||||
|
//callbacks set up
|
||||||
|
accountService.afterPropertiesSet();
|
||||||
|
|
||||||
|
//KAFKA
|
||||||
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION)));
|
||||||
|
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_ACCOUNT_NEW, PARTITION, 0, "key", jsonBaseNewRequest));
|
||||||
|
});
|
||||||
|
HashMap<TopicPartition, Long> startOffsets = new HashMap<>();
|
||||||
|
TopicPartition tp = new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION);
|
||||||
|
startOffsets.put(tp, 0L);
|
||||||
|
mockConsumer.updateBeginningOffsets(startOffsets);
|
||||||
|
|
||||||
|
IMap<Long, Account> accountIMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Account);
|
||||||
|
IMap<Long, RequestInfo> requestInfoIMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_RequestInfo);
|
||||||
|
|
||||||
|
ImapEvent imapEvent = new ImapEvent(requestInfoIMap);
|
||||||
|
imapEvent.waitHappened();
|
||||||
|
//ASSERT
|
||||||
|
Account accountResult = accountIMap.get(firstID);
|
||||||
|
RequestInfo requestInfoResult = requestInfoIMap.get(secondID);
|
||||||
|
|
||||||
|
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||||
|
REQUEST_INFO_MATCHER_MATCHER.assertMatch(requestInfoResult, predictableRequestInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,8 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||||
import ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
|
import ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
|
||||||
|
import ru.spcex.clearing.account.config.KafkaConfigTest;
|
||||||
|
import ru.spcex.clearing.account.utils.ImapEvent;
|
||||||
import ru.spcex.clearing.account.utils.MatcherFactory.Matcher;
|
import ru.spcex.clearing.account.utils.MatcherFactory.Matcher;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||||
|
|
@ -31,29 +33,36 @@ import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
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.MatcherFactory.usingIgnoringFieldsComparator;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = {
|
@ContextConfiguration(classes = {
|
||||||
HazelcastServiceTestConfiguration.class})
|
HazelcastServiceTestConfiguration.class,
|
||||||
|
KafkaConfigTest.class})
|
||||||
public class BankAccountServiceTest {
|
public class BankAccountServiceTest {
|
||||||
public static final Matcher<BankAccount> BANK_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
public static final Matcher<BankAccount> BANK_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final String TOPIC_ACCOUNT_NEW = Consts.DESTINATION_BANK_ACCOUNT_NEW;
|
private static final String TOPIC_ACCOUNT_NEW = Consts.DESTINATION_BANK_ACCOUNT_NEW;
|
||||||
private static final String TOPIC_ACCOUNT_UPDATE = Consts.DESTINATION_BANK_ACCOUNT_UPDATE;
|
private static final String TOPIC_ACCOUNT_UPDATE = Consts.DESTINATION_BANK_ACCOUNT_UPDATE;
|
||||||
private static final String TOPIC_ACCOUNT_DELETE = Consts.DESTINATION_BANK_ACCOUNT_DELETE;
|
private static final String TOPIC_ACCOUNT_DELETE = Consts.DESTINATION_BANK_ACCOUNT_DELETE;
|
||||||
private static Long currentId = 0L;
|
private static final Long ID = currentID.getAndIncrement();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("hazelcastServiceTest")
|
@Qualifier("hazelcastServiceTest")
|
||||||
private HazelcastService hazelcastServiceTest;
|
private HazelcastService hazelcastServiceTest;
|
||||||
|
|
||||||
private MockConsumer<String, Object> mockConsumer;
|
private MockConsumer<String, Object> mockConsumer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("mockProducerTest")
|
||||||
private MockProducer<String, Object> mockProducer;
|
private MockProducer<String, Object> mockProducer;
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
|
mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
|
||||||
mockProducer = new MockProducer<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -86,7 +95,7 @@ public class BankAccountServiceTest {
|
||||||
|
|
||||||
BaseRequest<BankAccountNewRequest> baseNewRequest = new BaseRequest<>();
|
BaseRequest<BankAccountNewRequest> baseNewRequest = new BaseRequest<>();
|
||||||
baseNewRequest.setRequestPayload(bankAccountNewRequest);
|
baseNewRequest.setRequestPayload(bankAccountNewRequest);
|
||||||
baseNewRequest.setId(currentId);
|
baseNewRequest.setId(ID);
|
||||||
baseNewRequest.setActionType(ActionType.NEW);
|
baseNewRequest.setActionType(ActionType.NEW);
|
||||||
String jsonBaseNewRequest;
|
String jsonBaseNewRequest;
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
@ -105,7 +114,15 @@ public class BankAccountServiceTest {
|
||||||
predictableResult.setTaxpayerIdentificationNumber("848484848484");
|
predictableResult.setTaxpayerIdentificationNumber("848484848484");
|
||||||
predictableResult.setTaxRegistrationReasonCode("886886");
|
predictableResult.setTaxRegistrationReasonCode("886886");
|
||||||
predictableResult.setAccount("123456789123");
|
predictableResult.setAccount("123456789123");
|
||||||
predictableResult.setId(currentId);
|
predictableResult.setId(ID);
|
||||||
|
|
||||||
|
//ACT
|
||||||
|
hazelcastServiceTest.waitTillReadyState();
|
||||||
|
//service set up
|
||||||
|
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
||||||
|
//callbacks set up
|
||||||
|
bankAccountService.afterPropertiesSet();
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION)));
|
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION)));
|
||||||
|
|
@ -118,24 +135,17 @@ public class BankAccountServiceTest {
|
||||||
startOffsets.put(tp, 0L);
|
startOffsets.put(tp, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
mockConsumer.updateBeginningOffsets(startOffsets);
|
||||||
|
|
||||||
//ACT
|
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||||
|
|
||||||
//service set up
|
//waiting for hazelcast map item updates
|
||||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
ImapEvent imapEvent = new ImapEvent(iMap);
|
||||||
Thread.sleep(10000);
|
imapEvent.waitHappened();
|
||||||
//callbacks set up
|
|
||||||
bankAccountService.afterPropertiesSet();
|
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
BankAccount result = iMap.get(ID);
|
||||||
BankAccount result = iMap.get(currentId);
|
|
||||||
|
|
||||||
BANK_ACCOUNT_MATCHER.assertMatch(result, predictableResult);
|
BANK_ACCOUNT_MATCHER.assertMatch(result, predictableResult);
|
||||||
|
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||||
//reset hazelcastService for next test
|
|
||||||
iMap.clear();
|
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -155,30 +165,20 @@ public class BankAccountServiceTest {
|
||||||
@Test
|
@Test
|
||||||
void bankAccountUpdate() throws InterruptedException {
|
void bankAccountUpdate() throws InterruptedException {
|
||||||
//arrange
|
//arrange
|
||||||
BankAccountNewRequest bankAccountNewRequest = new BankAccountNewRequest();
|
BankAccount bankAccountExists = new BankAccount();
|
||||||
bankAccountNewRequest.setBankName("ooo tinkoff");
|
bankAccountExists.setId(ID);
|
||||||
bankAccountNewRequest.setBankIdentificationCode("99999");
|
bankAccountExists.setBankName("ooo tinkoff");
|
||||||
bankAccountNewRequest.setCorrespondentAccount("9294189285498598598");
|
bankAccountExists.setBankIdentificationCode("99999");
|
||||||
bankAccountNewRequest.setCorrespondentAccountName("BIK OF TINKOFF");
|
bankAccountExists.setCorrespondentAccount("9294189285498598598");
|
||||||
bankAccountNewRequest.setCurrency("RUB");
|
bankAccountExists.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||||
bankAccountNewRequest.setDestination("OOO ROGA I KOPITA");
|
bankAccountExists.setCurrency("RUB");
|
||||||
bankAccountNewRequest.setTaxpayerIdentificationNumber("848484848484");
|
bankAccountExists.setDestination("OOO ROGA I KOPITA");
|
||||||
bankAccountNewRequest.setTaxRegistrationReasonCode("886886");
|
bankAccountExists.setTaxpayerIdentificationNumber("848484848484");
|
||||||
bankAccountNewRequest.setAccount("123456789123");
|
bankAccountExists.setTaxRegistrationReasonCode("886886");
|
||||||
|
bankAccountExists.setAccount("123456789123");
|
||||||
|
|
||||||
BaseRequest<BankAccountNewRequest> baseNewRequest = new BaseRequest<>();
|
|
||||||
baseNewRequest.setRequestPayload(bankAccountNewRequest);
|
|
||||||
baseNewRequest.setId(currentId);
|
|
||||||
baseNewRequest.setActionType(ActionType.NEW);
|
|
||||||
String jsonBaseNewRequest;
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
try {
|
|
||||||
jsonBaseNewRequest = objectMapper.writeValueAsString(baseNewRequest);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
BankAccountUpdateRequest bankAccountUpdateRequest = new BankAccountUpdateRequest();
|
BankAccountUpdateRequest bankAccountUpdateRequest = new BankAccountUpdateRequest();
|
||||||
bankAccountUpdateRequest.setId(currentId);
|
bankAccountUpdateRequest.setId(ID);
|
||||||
bankAccountUpdateRequest.setBankName("NEW BUNK NAME");
|
bankAccountUpdateRequest.setBankName("NEW BUNK NAME");
|
||||||
bankAccountUpdateRequest.setBankIdentificationCode("88888");
|
bankAccountUpdateRequest.setBankIdentificationCode("88888");
|
||||||
bankAccountUpdateRequest.setCorrespondentAccount("894984646541316");
|
bankAccountUpdateRequest.setCorrespondentAccount("894984646541316");
|
||||||
|
|
@ -191,9 +191,10 @@ public class BankAccountServiceTest {
|
||||||
|
|
||||||
BaseRequest<BankAccountUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
BaseRequest<BankAccountUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||||
baseUpdateRequest.setRequestPayload(bankAccountUpdateRequest);
|
baseUpdateRequest.setRequestPayload(bankAccountUpdateRequest);
|
||||||
baseUpdateRequest.setId(currentId);
|
baseUpdateRequest.setId(ID);
|
||||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||||
String jsonBaseUpdateRequest;
|
String jsonBaseUpdateRequest;
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
try {
|
try {
|
||||||
jsonBaseUpdateRequest = objectMapper.writeValueAsString(baseUpdateRequest);
|
jsonBaseUpdateRequest = objectMapper.writeValueAsString(baseUpdateRequest);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
|
|
@ -209,25 +210,19 @@ public class BankAccountServiceTest {
|
||||||
predictableUpdateResult.setTaxpayerIdentificationNumber("65468461321");
|
predictableUpdateResult.setTaxpayerIdentificationNumber("65468461321");
|
||||||
predictableUpdateResult.setTaxRegistrationReasonCode("532137");
|
predictableUpdateResult.setTaxRegistrationReasonCode("532137");
|
||||||
predictableUpdateResult.setAccount("326984656514");
|
predictableUpdateResult.setAccount("326984656514");
|
||||||
predictableUpdateResult.setId(currentId);
|
predictableUpdateResult.setId(ID);
|
||||||
|
|
||||||
//KAFKA
|
|
||||||
mockConsumer.schedulePollTask(() -> {
|
|
||||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION)));
|
|
||||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_ACCOUNT_NEW, PARTITION, 0, "key", jsonBaseNewRequest));
|
|
||||||
});
|
|
||||||
HashMap<TopicPartition, Long> startOffsets = new HashMap<>();
|
|
||||||
TopicPartition tp = new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION);
|
|
||||||
startOffsets.put(tp, 0L);
|
|
||||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
|
||||||
|
|
||||||
//ACT
|
//ACT
|
||||||
|
|
||||||
|
hazelcastServiceTest.waitTillReadyState();
|
||||||
//service set up
|
//service set up
|
||||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
bankAccountService.afterPropertiesSet();
|
bankAccountService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||||
|
iMap.put(ID, bankAccountExists);
|
||||||
|
ImapEvent imapEvent = new ImapEvent(iMap);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -239,16 +234,14 @@ public class BankAccountServiceTest {
|
||||||
startOffsetsUpdating.put(tpUpdating, 0L);
|
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
//ASSERT
|
//waiting for hazelcast map item updates
|
||||||
Thread.sleep(10000);
|
imapEvent.waitHappened();
|
||||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
|
||||||
BankAccount resultUpdating = iMap.get(currentId);
|
|
||||||
|
|
||||||
|
//ASSERT
|
||||||
|
BankAccount resultUpdating = iMap.get(ID);
|
||||||
BANK_ACCOUNT_MATCHER.assertMatch(resultUpdating, predictableUpdateResult);
|
BANK_ACCOUNT_MATCHER.assertMatch(resultUpdating, predictableUpdateResult);
|
||||||
|
|
||||||
//reset hazelcastService for next test
|
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||||
iMap.clear();
|
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -260,58 +253,42 @@ public class BankAccountServiceTest {
|
||||||
@Test
|
@Test
|
||||||
void bankAccountDelete() throws InterruptedException {
|
void bankAccountDelete() throws InterruptedException {
|
||||||
//arrange
|
//arrange
|
||||||
BankAccountNewRequest bankAccountNewRequest = new BankAccountNewRequest();
|
BankAccount bankAccountExists = new BankAccount();
|
||||||
bankAccountNewRequest.setBankName("ooo tinkoff");
|
bankAccountExists.setId(ID);
|
||||||
bankAccountNewRequest.setBankIdentificationCode("99999");
|
bankAccountExists.setBankName("ooo tinkoff");
|
||||||
bankAccountNewRequest.setCorrespondentAccount("9294189285498598598");
|
bankAccountExists.setBankIdentificationCode("99999");
|
||||||
bankAccountNewRequest.setCorrespondentAccountName("BIK OF TINKOFF");
|
bankAccountExists.setCorrespondentAccount("9294189285498598598");
|
||||||
bankAccountNewRequest.setCurrency("RUB");
|
bankAccountExists.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||||
bankAccountNewRequest.setDestination("OOO ROGA I KOPITA");
|
bankAccountExists.setCurrency("RUB");
|
||||||
bankAccountNewRequest.setTaxpayerIdentificationNumber("848484848484");
|
bankAccountExists.setDestination("OOO ROGA I KOPITA");
|
||||||
bankAccountNewRequest.setTaxRegistrationReasonCode("886886");
|
bankAccountExists.setTaxpayerIdentificationNumber("848484848484");
|
||||||
bankAccountNewRequest.setAccount("123456789123");
|
bankAccountExists.setTaxRegistrationReasonCode("886886");
|
||||||
|
bankAccountExists.setAccount("123456789123");
|
||||||
BaseRequest<BankAccountNewRequest> baseNewRequest = new BaseRequest<>();
|
|
||||||
baseNewRequest.setRequestPayload(bankAccountNewRequest);
|
|
||||||
baseNewRequest.setId(currentId);
|
|
||||||
baseNewRequest.setActionType(ActionType.NEW);
|
|
||||||
String jsonBaseNewRequest;
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
try {
|
|
||||||
jsonBaseNewRequest = objectMapper.writeValueAsString(baseNewRequest);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
CommonDeleteRequest commonDeleteRequest = new CommonDeleteRequest();
|
CommonDeleteRequest commonDeleteRequest = new CommonDeleteRequest();
|
||||||
commonDeleteRequest.setId(currentId);
|
commonDeleteRequest.setId(ID);
|
||||||
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
||||||
baseDeleteRequest.setRequestPayload(commonDeleteRequest);
|
baseDeleteRequest.setRequestPayload(commonDeleteRequest);
|
||||||
baseDeleteRequest.setId(currentId);
|
baseDeleteRequest.setId(ID);
|
||||||
baseDeleteRequest.setActionType(ActionType.DELETE);
|
baseDeleteRequest.setActionType(ActionType.DELETE);
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String jsonDeleteNewRequest;
|
String jsonDeleteNewRequest;
|
||||||
try {
|
try {
|
||||||
jsonDeleteNewRequest = objectMapper.writeValueAsString(baseDeleteRequest);
|
jsonDeleteNewRequest = objectMapper.writeValueAsString(baseDeleteRequest);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
//KAFKA
|
|
||||||
mockConsumer.schedulePollTask(() -> {
|
|
||||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION)));
|
|
||||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_ACCOUNT_NEW, PARTITION, 0, "key", jsonBaseNewRequest));
|
|
||||||
});
|
|
||||||
HashMap<TopicPartition, Long> startOffsets = new HashMap<>();
|
|
||||||
TopicPartition tp = new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION);
|
|
||||||
startOffsets.put(tp, 0L);
|
|
||||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
|
||||||
|
|
||||||
//ACT
|
//ACT
|
||||||
//service set up
|
//service set up
|
||||||
|
hazelcastServiceTest.waitTillReadyState();
|
||||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
||||||
Thread.sleep(10000);
|
|
||||||
//callbacks set up
|
//callbacks set up
|
||||||
bankAccountService.afterPropertiesSet();
|
bankAccountService.afterPropertiesSet();
|
||||||
Thread.sleep(10000);
|
|
||||||
|
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||||
|
iMap.put(ID, bankAccountExists);
|
||||||
|
ImapEvent imapEvent = new ImapEvent(iMap);
|
||||||
|
|
||||||
//KAFKA
|
//KAFKA
|
||||||
mockConsumer.schedulePollTask(() -> {
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
|
@ -323,13 +300,12 @@ public class BankAccountServiceTest {
|
||||||
startOffsetsDeleting.put(tpDeleting, 0L);
|
startOffsetsDeleting.put(tpDeleting, 0L);
|
||||||
mockConsumer.updateBeginningOffsets(startOffsetsDeleting);
|
mockConsumer.updateBeginningOffsets(startOffsetsDeleting);
|
||||||
|
|
||||||
|
//waiting for hazelcast map item updates
|
||||||
|
imapEvent.waitHappened();
|
||||||
|
|
||||||
//ASSERT
|
//ASSERT
|
||||||
Thread.sleep(10000);
|
|
||||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
|
||||||
Assertions.assertEquals(0, iMap.size());
|
Assertions.assertEquals(0, iMap.size());
|
||||||
|
|
||||||
//reset hazelcastService for next test
|
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||||
iMap.clear();
|
|
||||||
currentId++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
package ru.spcex.clearing.account.utils;
|
||||||
|
|
||||||
|
import com.hazelcast.core.IMap;
|
||||||
|
import com.hazelcast.map.listener.EntryAddedListener;
|
||||||
|
import com.hazelcast.map.listener.EntryRemovedListener;
|
||||||
|
import com.hazelcast.map.listener.EntryUpdatedListener;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class ImapEvent<T> {
|
||||||
|
private final IMap<Long, T> iMap;
|
||||||
|
private final String listenerAdding;
|
||||||
|
private final String listenerUpdating;
|
||||||
|
private final String listenerRemoving;
|
||||||
|
private final AtomicBoolean checkEventHappened = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
public ImapEvent(IMap<Long, T> iMap) {
|
||||||
|
this.iMap = iMap;
|
||||||
|
listenerAdding = iMap.addEntryListener((EntryAddedListener<Long, T>) entryEvent -> {
|
||||||
|
synchronized (checkEventHappened) {
|
||||||
|
checkEventHappened.set(true);
|
||||||
|
checkEventHappened.notify();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
listenerUpdating = iMap.addEntryListener((EntryUpdatedListener<Long, T>) entryEvent -> {
|
||||||
|
synchronized (checkEventHappened) {
|
||||||
|
checkEventHappened.set(true);
|
||||||
|
checkEventHappened.notify();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
listenerRemoving = iMap.addEntryListener((EntryRemovedListener<Long, T>) entryEvent -> {
|
||||||
|
synchronized (checkEventHappened) {
|
||||||
|
checkEventHappened.set(true);
|
||||||
|
checkEventHappened.notify();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void waitHappened() throws InterruptedException {
|
||||||
|
synchronized (checkEventHappened) {
|
||||||
|
while (!checkEventHappened.get()) {
|
||||||
|
checkEventHappened.wait(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//preparing hazelcastImdgProvider for next test
|
||||||
|
iMap.removeEntryListener(listenerAdding);
|
||||||
|
iMap.removeEntryListener(listenerUpdating);
|
||||||
|
iMap.removeEntryListener(listenerRemoving);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ public class BankAccountControllerConfig {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
||||||
@Qualifier("iOperator")
|
@Qualifier("iOperatorTest")
|
||||||
private IOperator operator;
|
private IOperator operator;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -11,7 +11,7 @@ import ru.spcex.clearing.backendapi.service.impl.StateLoaderImpl;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class DeleteCompanyControllerConfig {
|
public class DeleteCompanyControllerConfig {
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("iOperator")
|
@Qualifier("iOperatorTest")
|
||||||
private IOperator operator;
|
private IOperator operator;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import ru.spcex.clearing.backendapi.service.impl.OperatorImpl;
|
import ru.spcex.clearing.backendapi.service.impl.OperatorImpl;
|
||||||
|
import ru.spcex.clearing.backendapi.service.validation.ActionValidationProvider;
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
@ -16,9 +17,9 @@ public class IOperator {
|
||||||
private HazelcastService hazelcastServiceTest;
|
private HazelcastService hazelcastServiceTest;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Bean
|
@Bean(name = "iOperatorTest")
|
||||||
public OperatorImpl createIOperator(Producer<String, Object> kafka) {
|
public OperatorImpl createIOperator(Producer<String, Object> kafka) {
|
||||||
return new OperatorImpl(kafka, hazelcastServiceTest);
|
return new OperatorImpl(kafka, hazelcastServiceTest, new ActionValidationProvider(hazelcastServiceTest));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue