add AccountServiceTast
This commit is contained in:
parent
1ed81aec57
commit
aa103cbf5f
17 changed files with 319 additions and 103 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 ru.clearing.classes.statics.data.account.BankAccount;
|
||||
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.imdg.IMDGDistributedNames;
|
||||
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.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;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
HazelcastServiceTestConfiguration.class})
|
||||
HazelcastServiceTestConfiguration.class,
|
||||
KafkaConfigTest.class})
|
||||
public class BankAccountServiceTest {
|
||||
public static final Matcher<BankAccount> BANK_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
private static final int PARTITION = 0;
|
||||
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_DELETE = Consts.DESTINATION_BANK_ACCOUNT_DELETE;
|
||||
private static Long currentId = 0L;
|
||||
private static final Long ID = currentID.getAndIncrement();
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private HazelcastService hazelcastServiceTest;
|
||||
|
||||
private MockConsumer<String, Object> mockConsumer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockProducerTest")
|
||||
private MockProducer<String, Object> mockProducer;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
|
||||
mockProducer = new MockProducer<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,7 +95,7 @@ public class BankAccountServiceTest {
|
|||
|
||||
BaseRequest<BankAccountNewRequest> baseNewRequest = new BaseRequest<>();
|
||||
baseNewRequest.setRequestPayload(bankAccountNewRequest);
|
||||
baseNewRequest.setId(currentId);
|
||||
baseNewRequest.setId(ID);
|
||||
baseNewRequest.setActionType(ActionType.NEW);
|
||||
String jsonBaseNewRequest;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
|
@ -105,7 +114,15 @@ public class BankAccountServiceTest {
|
|||
predictableResult.setTaxpayerIdentificationNumber("848484848484");
|
||||
predictableResult.setTaxRegistrationReasonCode("886886");
|
||||
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
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION)));
|
||||
|
|
@ -118,24 +135,17 @@ public class BankAccountServiceTest {
|
|||
startOffsets.put(tp, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
||||
|
||||
//ACT
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
|
||||
//service set up
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
//callbacks set up
|
||||
bankAccountService.afterPropertiesSet();
|
||||
Thread.sleep(10000);
|
||||
//waiting for hazelcast map item updates
|
||||
ImapEvent imapEvent = new ImapEvent(iMap);
|
||||
imapEvent.waitHappened();
|
||||
|
||||
//ASSERT
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
BankAccount result = iMap.get(currentId);
|
||||
BankAccount result = iMap.get(ID);
|
||||
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(result, predictableResult);
|
||||
|
||||
//reset hazelcastService for next test
|
||||
iMap.clear();
|
||||
currentId++;
|
||||
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,30 +165,20 @@ public class BankAccountServiceTest {
|
|||
@Test
|
||||
void bankAccountUpdate() throws InterruptedException {
|
||||
//arrange
|
||||
BankAccountNewRequest bankAccountNewRequest = new BankAccountNewRequest();
|
||||
bankAccountNewRequest.setBankName("ooo tinkoff");
|
||||
bankAccountNewRequest.setBankIdentificationCode("99999");
|
||||
bankAccountNewRequest.setCorrespondentAccount("9294189285498598598");
|
||||
bankAccountNewRequest.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||
bankAccountNewRequest.setCurrency("RUB");
|
||||
bankAccountNewRequest.setDestination("OOO ROGA I KOPITA");
|
||||
bankAccountNewRequest.setTaxpayerIdentificationNumber("848484848484");
|
||||
bankAccountNewRequest.setTaxRegistrationReasonCode("886886");
|
||||
bankAccountNewRequest.setAccount("123456789123");
|
||||
BankAccount bankAccountExists = new BankAccount();
|
||||
bankAccountExists.setId(ID);
|
||||
bankAccountExists.setBankName("ooo tinkoff");
|
||||
bankAccountExists.setBankIdentificationCode("99999");
|
||||
bankAccountExists.setCorrespondentAccount("9294189285498598598");
|
||||
bankAccountExists.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||
bankAccountExists.setCurrency("RUB");
|
||||
bankAccountExists.setDestination("OOO ROGA I KOPITA");
|
||||
bankAccountExists.setTaxpayerIdentificationNumber("848484848484");
|
||||
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.setId(currentId);
|
||||
bankAccountUpdateRequest.setId(ID);
|
||||
bankAccountUpdateRequest.setBankName("NEW BUNK NAME");
|
||||
bankAccountUpdateRequest.setBankIdentificationCode("88888");
|
||||
bankAccountUpdateRequest.setCorrespondentAccount("894984646541316");
|
||||
|
|
@ -191,9 +191,10 @@ public class BankAccountServiceTest {
|
|||
|
||||
BaseRequest<BankAccountUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||
baseUpdateRequest.setRequestPayload(bankAccountUpdateRequest);
|
||||
baseUpdateRequest.setId(currentId);
|
||||
baseUpdateRequest.setId(ID);
|
||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||
String jsonBaseUpdateRequest;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
jsonBaseUpdateRequest = objectMapper.writeValueAsString(baseUpdateRequest);
|
||||
} catch (JsonProcessingException e) {
|
||||
|
|
@ -209,25 +210,19 @@ public class BankAccountServiceTest {
|
|||
predictableUpdateResult.setTaxpayerIdentificationNumber("65468461321");
|
||||
predictableUpdateResult.setTaxRegistrationReasonCode("532137");
|
||||
predictableUpdateResult.setAccount("326984656514");
|
||||
predictableUpdateResult.setId(currentId);
|
||||
|
||||
//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);
|
||||
predictableUpdateResult.setId(ID);
|
||||
|
||||
//ACT
|
||||
|
||||
hazelcastServiceTest.waitTillReadyState();
|
||||
//service set up
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
//callbacks set up
|
||||
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
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
|
|
@ -239,16 +234,14 @@ public class BankAccountServiceTest {
|
|||
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||
|
||||
//ASSERT
|
||||
Thread.sleep(10000);
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
BankAccount resultUpdating = iMap.get(currentId);
|
||||
//waiting for hazelcast map item updates
|
||||
imapEvent.waitHappened();
|
||||
|
||||
//ASSERT
|
||||
BankAccount resultUpdating = iMap.get(ID);
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(resultUpdating, predictableUpdateResult);
|
||||
|
||||
//reset hazelcastService for next test
|
||||
iMap.clear();
|
||||
currentId++;
|
||||
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -260,58 +253,42 @@ public class BankAccountServiceTest {
|
|||
@Test
|
||||
void bankAccountDelete() throws InterruptedException {
|
||||
//arrange
|
||||
BankAccountNewRequest bankAccountNewRequest = new BankAccountNewRequest();
|
||||
bankAccountNewRequest.setBankName("ooo tinkoff");
|
||||
bankAccountNewRequest.setBankIdentificationCode("99999");
|
||||
bankAccountNewRequest.setCorrespondentAccount("9294189285498598598");
|
||||
bankAccountNewRequest.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||
bankAccountNewRequest.setCurrency("RUB");
|
||||
bankAccountNewRequest.setDestination("OOO ROGA I KOPITA");
|
||||
bankAccountNewRequest.setTaxpayerIdentificationNumber("848484848484");
|
||||
bankAccountNewRequest.setTaxRegistrationReasonCode("886886");
|
||||
bankAccountNewRequest.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);
|
||||
}
|
||||
BankAccount bankAccountExists = new BankAccount();
|
||||
bankAccountExists.setId(ID);
|
||||
bankAccountExists.setBankName("ooo tinkoff");
|
||||
bankAccountExists.setBankIdentificationCode("99999");
|
||||
bankAccountExists.setCorrespondentAccount("9294189285498598598");
|
||||
bankAccountExists.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||
bankAccountExists.setCurrency("RUB");
|
||||
bankAccountExists.setDestination("OOO ROGA I KOPITA");
|
||||
bankAccountExists.setTaxpayerIdentificationNumber("848484848484");
|
||||
bankAccountExists.setTaxRegistrationReasonCode("886886");
|
||||
bankAccountExists.setAccount("123456789123");
|
||||
|
||||
CommonDeleteRequest commonDeleteRequest = new CommonDeleteRequest();
|
||||
commonDeleteRequest.setId(currentId);
|
||||
commonDeleteRequest.setId(ID);
|
||||
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
||||
baseDeleteRequest.setRequestPayload(commonDeleteRequest);
|
||||
baseDeleteRequest.setId(currentId);
|
||||
baseDeleteRequest.setId(ID);
|
||||
baseDeleteRequest.setActionType(ActionType.DELETE);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String jsonDeleteNewRequest;
|
||||
try {
|
||||
jsonDeleteNewRequest = objectMapper.writeValueAsString(baseDeleteRequest);
|
||||
} catch (JsonProcessingException 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
|
||||
//service set up
|
||||
hazelcastServiceTest.waitTillReadyState();
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
//callbacks set up
|
||||
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
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
|
|
@ -323,13 +300,12 @@ public class BankAccountServiceTest {
|
|||
startOffsetsDeleting.put(tpDeleting, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsetsDeleting);
|
||||
|
||||
//waiting for hazelcast map item updates
|
||||
imapEvent.waitHappened();
|
||||
|
||||
//ASSERT
|
||||
Thread.sleep(10000);
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
Assertions.assertEquals(0, iMap.size());
|
||||
|
||||
//reset hazelcastService for next test
|
||||
iMap.clear();
|
||||
currentId++;
|
||||
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
@Qualifier("iOperator")
|
||||
@Qualifier("iOperatorTest")
|
||||
private IOperator operator;
|
||||
|
||||
@Autowired
|
||||
|
|
@ -11,7 +11,7 @@ import ru.spcex.clearing.backendapi.service.impl.StateLoaderImpl;
|
|||
@Configuration
|
||||
public class DeleteCompanyControllerConfig {
|
||||
@Autowired
|
||||
@Qualifier("iOperator")
|
||||
@Qualifier("iOperatorTest")
|
||||
private IOperator operator;
|
||||
|
||||
@Autowired
|
||||
Loading…
Add table
Reference in a new issue