Add Mock kafka producer. Fixing test in account-service.
This commit is contained in:
parent
a915121c3f
commit
264719263c
12 changed files with 302 additions and 230 deletions
|
|
@ -60,6 +60,11 @@
|
|||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,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;
|
||||
|
|
@ -41,7 +40,7 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
private final Imdg<Relation> relationMap;
|
||||
private final IMessageResolver messageResolver;
|
||||
|
||||
// private final Imdg<User> userImdg;
|
||||
// private final Imdg<User> userImdg;
|
||||
// private final Imdg<UserRoleSession> userRoleSessionImdg;
|
||||
private final Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,14 @@ 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.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.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;
|
||||
|
|
@ -23,7 +22,7 @@ public class KafkaConfigTest {
|
|||
|
||||
@Autowired
|
||||
@Bean(name = "kafkaSenderTest")
|
||||
public KafkaSender kafkaSender(@Qualifier("mockProducerTest") Producer<String, Object> kafkaProducer, @Qualifier("hazelcastServiceTest") ImdgProvider imdgProvider) {
|
||||
public KafkaSender kafkaSender(Producer<String, Object> kafkaProducer, @Qualifier("hazelcastServiceTest") ImdgProvider imdgProvider) {
|
||||
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
||||
return KafkaSender
|
||||
.setup()
|
||||
|
|
@ -36,13 +35,10 @@ public class KafkaConfigTest {
|
|||
.build();
|
||||
}
|
||||
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,20 +2,21 @@ 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.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.ImapEvent;
|
||||
import ru.spcex.clearing.account.utils.MatcherFactory;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||
|
|
@ -27,18 +28,22 @@ import ru.spcex.clearing.platform.messaging.domain.cud.balance.AccountSdfToState
|
|||
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.adapter.ImdgHazelcast;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
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.MockKafkaUtils.addRecordToKafka;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
AccountService.class,
|
||||
HazelcastServiceTestConfiguration.class,
|
||||
KafkaConfigTest.class})
|
||||
class AccountServiceTest {
|
||||
|
|
@ -46,18 +51,17 @@ class AccountServiceTest {
|
|||
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;
|
||||
|
||||
private static final String account = "123456789123";
|
||||
@Autowired
|
||||
AccountService accountService;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private HazelcastService hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("kafkaSenderTest")
|
||||
private KafkaSender kafkaSender;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockConsumerTest")
|
||||
private MockConsumer<String, Object> mockConsumer;
|
||||
@Captor
|
||||
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||
@SpyBean
|
||||
private MockProducer<String, Object> producer;
|
||||
|
||||
/**
|
||||
* {@link AccountService#accountNew(BaseRequest)}<br>
|
||||
|
|
@ -71,12 +75,12 @@ class AccountServiceTest {
|
|||
*/
|
||||
@Test
|
||||
void accountNew() throws InterruptedException {
|
||||
//arrange
|
||||
//ARRANGE
|
||||
Long firstID = currentID.getAndIncrement();
|
||||
Long secondID = currentID.getAndIncrement();
|
||||
AccountSdfRequestPart accountSdfRequestPart = new AccountSdfRequestPart();
|
||||
accountSdfRequestPart.setSdfId(firstID);
|
||||
accountSdfRequestPart.setAccount("123456789123");
|
||||
accountSdfRequestPart.setAccount(account);
|
||||
accountSdfRequestPart.setCompanyId(firstID);
|
||||
AccountSdf01Request accountSdf01Request = new AccountSdf01Request();
|
||||
accountSdf01Request.setGroupingSdf01Id(firstID);
|
||||
|
|
@ -109,41 +113,33 @@ class AccountServiceTest {
|
|||
baseRequest.setRequestPayload(statementRequest);
|
||||
|
||||
Account predictableAccount = new Account();
|
||||
predictableAccount.setAccount("123456789123");
|
||||
predictableAccount.setAccount(account);
|
||||
predictableAccount.setId(firstID);
|
||||
predictableAccount.setCompanyId(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);
|
||||
addRecordToKafka((MockConsumer) accountService.getConsumer(), TOPIC_ACCOUNT_NEW, PARTITION, 0, jsonBaseNewRequest);
|
||||
|
||||
IMap<Long, Account> accountIMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Account);
|
||||
IMap<Long, RequestInfo> requestInfoIMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_RequestInfo);
|
||||
//waiting for kafka producer send message (finale event)
|
||||
verify(producer, timeout(30_000L).times(1))
|
||||
.send(producerRecord.capture());
|
||||
BaseRequest<Object> baseRequestObject = (BaseRequest<Object>) producerRecord.getValue().value();
|
||||
|
||||
ImdgHazelcast<Account> accountImdg = (ImdgHazelcast<Account>) hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
ImdgHazelcast<RequestInfo> requestInfoImdg = (ImdgHazelcast<RequestInfo>) hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class);
|
||||
|
||||
ImapEvent imapEvent = new ImapEvent(requestInfoIMap);
|
||||
imapEvent.waitWhenHappened();
|
||||
//ASSERT
|
||||
Account accountResult = accountIMap.get(firstID);
|
||||
RequestInfo requestInfoResult = requestInfoIMap.get(secondID);
|
||||
Account accountResult = accountImdg.getSingleObjectBySQL(String.format("account = %s", account));
|
||||
RequestInfo requestInfoResult = requestInfoImdg.getSingleObjectByID(baseRequestObject.getId());
|
||||
|
||||
assertEquals(Consts.STATEMENT_PROCESS, producerRecord.getValue().topic());
|
||||
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||
REQUEST_INFO_MATCHER_MATCHER.assertMatch(requestInfoResult, predictableRequestInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,24 +2,26 @@ 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.clients.consumer.OffsetResetStrategy;
|
||||
import org.apache.kafka.clients.producer.MockProducer;
|
||||
import org.apache.kafka.common.TopicPartition;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.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.HazelcastServiceTestConfiguration;
|
||||
import ru.spcex.clearing.account.config.KafkaConfigTest;
|
||||
import ru.spcex.clearing.account.utils.ImapEvent;
|
||||
import ru.spcex.clearing.account.config.ValidationConfig;
|
||||
import ru.spcex.clearing.account.utils.MatcherFactory.Matcher;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||
|
|
@ -28,46 +30,64 @@ import ru.spcex.clearing.platform.messaging.domain.Consts;
|
|||
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.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.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
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.utils.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.account.utils.MockKafkaUtils.addRecordToKafka;
|
||||
import static ru.spcex.clearing.platform.messaging.service.Status.Success;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
ErrorResolverConfig.class,
|
||||
BankAccountService.class,
|
||||
ValidationConfig.class,
|
||||
HazelcastServiceTestConfiguration.class,
|
||||
KafkaConfigTest.class})
|
||||
public class BankAccountServiceTest {
|
||||
public static final Matcher<BankAccount> BANK_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final Matcher<BaseRequest<Object>> BASE_REQUEST_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 final Long ID = 0L;
|
||||
private static final Long accountId = 12L;
|
||||
protected final Long addresseeIdNew = 2L;
|
||||
protected final String deal = "111111111";
|
||||
private final String acc = "0123456789";
|
||||
protected Imdg<Company> companyImdg;
|
||||
private Imdg<BankAccount> bankAccountImdg;
|
||||
private Imdg<Account> accountImdg;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private HazelcastService hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
private IMessageResolver messageResolver;
|
||||
private BankAccountService bankAccountService;
|
||||
|
||||
@Autowired
|
||||
private Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator;
|
||||
@Captor
|
||||
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||
@SpyBean
|
||||
private MockProducer<String, Object> producer;
|
||||
|
||||
private MockConsumer<String, Object> mockConsumer;
|
||||
private MockProducer<String, Object> mockProducer;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
|
||||
mockProducer = new MockProducer<>();
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
companyImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
bankAccountImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
accountImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,19 +104,32 @@ public class BankAccountServiceTest {
|
|||
* {@link BankAccountNewRequest#taxRegistrationReasonCode} - 886886<br>
|
||||
* {@link BankAccountNewRequest#account} - 123456789123<br>
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public void bankAccountNew() throws InterruptedException {
|
||||
//arrange
|
||||
//ARRANGE
|
||||
BaseRequest<Object> predictableBaseRequest = new BaseRequest<>();
|
||||
predictableBaseRequest.setId(ID);
|
||||
predictableBaseRequest.setActionType(ActionType.SYSTEM);
|
||||
RequestInfoUpdate requestInfoUpdate = new RequestInfoUpdate();
|
||||
requestInfoUpdate.setId(ID);
|
||||
requestInfoUpdate.setStatus(Success);
|
||||
predictableBaseRequest.setRequestPayload(requestInfoUpdate);
|
||||
|
||||
BankAccount predictableBankAccount = getBankAccount();
|
||||
Company company = getTestCompany();
|
||||
companyImdg.insert(company);
|
||||
Account predictableAccount = getTestAccount(accountId, acc);
|
||||
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");
|
||||
bankAccountNewRequest.setBankName(predictableBankAccount.getBankName());
|
||||
bankAccountNewRequest.setBankIdentificationCode(predictableBankAccount.getBankIdentificationCode());
|
||||
bankAccountNewRequest.setCorrespondentAccount(predictableBankAccount.getCorrespondentAccount());
|
||||
bankAccountNewRequest.setCorrespondentAccountName(predictableBankAccount.getCorrespondentAccountName());
|
||||
bankAccountNewRequest.setCurrency(predictableBankAccount.getCurrency());
|
||||
bankAccountNewRequest.setDestination(predictableBankAccount.getDestination());
|
||||
bankAccountNewRequest.setTaxpayerIdentificationNumber(predictableBankAccount.getTaxpayerIdentificationNumber());
|
||||
bankAccountNewRequest.setTaxRegistrationReasonCode(predictableBankAccount.getTaxRegistrationReasonCode());
|
||||
bankAccountNewRequest.setAccount(predictableBankAccount.getAccount());
|
||||
bankAccountNewRequest.setCompanyId(predictableBankAccount.getCompanyId());
|
||||
|
||||
BaseRequest<BankAccountNewRequest> baseNewRequest = new BaseRequest<>();
|
||||
baseNewRequest.setRequestPayload(bankAccountNewRequest);
|
||||
|
|
@ -109,47 +142,26 @@ public class BankAccountServiceTest {
|
|||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
BankAccount predictableResult = new BankAccount();
|
||||
predictableResult.setBankName("ooo tinkoff");
|
||||
predictableResult.setBankIdentificationCode("99999");
|
||||
predictableResult.setCorrespondentAccount("9294189285498598598");
|
||||
predictableResult.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||
predictableResult.setCurrency("RUB");
|
||||
predictableResult.setDestination("OOO ROGA I KOPITA");
|
||||
predictableResult.setTaxpayerIdentificationNumber("848484848484");
|
||||
predictableResult.setTaxRegistrationReasonCode("886886");
|
||||
predictableResult.setId(ID);
|
||||
|
||||
//ACT
|
||||
hazelcastServiceTest.waitTillReadyState();
|
||||
//service set up
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest, messageResolver, bankAccountNewRequestValidator);
|
||||
//callbacks set up
|
||||
bankAccountService.afterPropertiesSet();
|
||||
addRecordToKafka((MockConsumer) bankAccountService.getConsumer(), TOPIC_ACCOUNT_NEW, PARTITION, 0, jsonBaseNewRequest);
|
||||
|
||||
//KAFKA
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION)));
|
||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_ACCOUNT_NEW, PARTITION, 0, "key", jsonBaseNewRequest));
|
||||
});
|
||||
//waiting for kafka producer send message (finale event)
|
||||
verify(producer, timeout(30_000L).times(1))
|
||||
.send(producerRecord.capture());
|
||||
BaseRequest<Object> baseRequestResult = (BaseRequest<Object>) producerRecord.getValue().value();
|
||||
|
||||
|
||||
HashMap<TopicPartition, Long> startOffsets = new HashMap<>();
|
||||
TopicPartition tp = new TopicPartition(TOPIC_ACCOUNT_NEW, PARTITION);
|
||||
startOffsets.put(tp, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
||||
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
|
||||
//waiting for hazelcast map item updates
|
||||
ImapEvent imapEvent = new ImapEvent(iMap);
|
||||
imapEvent.waitWhenHappened();
|
||||
Account accountResult = accountImdg.getSingleObjectBySQL(String.format("account = %s", acc));
|
||||
BankAccount bankAccountResult = bankAccountImdg.getSingleObjectBySQL(String.format("account = %s or companyId = %s", acc, addresseeIdNew));
|
||||
predictableBankAccount.setAccountId(accountResult.getId());
|
||||
predictableBankAccount.setId(bankAccountResult.getId());
|
||||
setSameValueToField(accountResult, predictableAccount);
|
||||
|
||||
//ASSERT
|
||||
BankAccount result = iMap.get(ID);
|
||||
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(result, predictableResult);
|
||||
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||
assertEquals(Consts.REQUEST_INFO_UPDATE, producerRecord.getValue().topic());
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(bankAccountResult, predictableBankAccount);
|
||||
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||
BASE_REQUEST_MATCHER.assertMatch(baseRequestResult, predictableBaseRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -166,31 +178,48 @@ public class BankAccountServiceTest {
|
|||
* {@link BankAccountUpdateRequest#taxRegistrationReasonCode} - 532137<br>
|
||||
* {@link BankAccountUpdateRequest#account} - 326984656514<br>
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
void bankAccountUpdate() throws InterruptedException {
|
||||
//arrange
|
||||
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");
|
||||
//ARRANGE
|
||||
//ARRANGE
|
||||
BaseRequest<Object> predictableBaseRequest = new BaseRequest<>();
|
||||
predictableBaseRequest.setId(ID);
|
||||
predictableBaseRequest.setActionType(ActionType.SYSTEM);
|
||||
RequestInfoUpdate requestInfoUpdate = new RequestInfoUpdate();
|
||||
requestInfoUpdate.setId(ID);
|
||||
requestInfoUpdate.setStatus(Success);
|
||||
predictableBaseRequest.setRequestPayload(requestInfoUpdate);
|
||||
|
||||
// Company company = getTestCompany();
|
||||
// companyImdg.insert(company);
|
||||
Account predictableAccount = getTestAccount(accountId, acc);
|
||||
accountImdg.insert(predictableAccount);
|
||||
|
||||
BankAccount bankAccountExists = getBankAccount();
|
||||
bankAccountImdg.insert(bankAccountExists);
|
||||
BankAccount predictableUpdateBankAccount = new BankAccount();
|
||||
predictableUpdateBankAccount.setBankName("NEW BUNK NAME");
|
||||
predictableUpdateBankAccount.setBankIdentificationCode("88888");
|
||||
predictableUpdateBankAccount.setCorrespondentAccount("894984646541316");
|
||||
predictableUpdateBankAccount.setCorrespondentAccountName("BIK OF NEW BUNK");
|
||||
predictableUpdateBankAccount.setCurrency("EU");
|
||||
predictableUpdateBankAccount.setDestination("OOO NEW BUNK");
|
||||
predictableUpdateBankAccount.setTaxpayerIdentificationNumber("65468461321");
|
||||
predictableUpdateBankAccount.setTaxRegistrationReasonCode("532137");
|
||||
predictableUpdateBankAccount.setAccount(acc);
|
||||
predictableUpdateBankAccount.setId(ID);
|
||||
|
||||
BankAccountUpdateRequest bankAccountUpdateRequest = new BankAccountUpdateRequest();
|
||||
bankAccountUpdateRequest.setId(ID);
|
||||
bankAccountUpdateRequest.setBankName("NEW BUNK NAME");
|
||||
bankAccountUpdateRequest.setBankIdentificationCode("88888");
|
||||
bankAccountUpdateRequest.setCorrespondentAccount("894984646541316");
|
||||
bankAccountUpdateRequest.setCorrespondentAccountName("BIK OF NEW BUNK");
|
||||
bankAccountUpdateRequest.setCurrency("EU");
|
||||
bankAccountUpdateRequest.setDestination("OOO NEW BUNK");
|
||||
bankAccountUpdateRequest.setTaxpayerIdentificationNumber("65468461321");
|
||||
bankAccountUpdateRequest.setTaxRegistrationReasonCode("532137");
|
||||
bankAccountUpdateRequest.setAccount("326984656514");
|
||||
bankAccountUpdateRequest.setId(predictableUpdateBankAccount.getId());
|
||||
bankAccountUpdateRequest.setBankName(predictableUpdateBankAccount.getBankName());
|
||||
bankAccountUpdateRequest.setBankIdentificationCode(predictableUpdateBankAccount.getBankIdentificationCode());
|
||||
bankAccountUpdateRequest.setCorrespondentAccount(predictableUpdateBankAccount.getCorrespondentAccount());
|
||||
bankAccountUpdateRequest.setCorrespondentAccountName(predictableUpdateBankAccount.getCorrespondentAccountName());
|
||||
bankAccountUpdateRequest.setCurrency(predictableUpdateBankAccount.getCurrency());
|
||||
bankAccountUpdateRequest.setDestination(predictableUpdateBankAccount.getDestination());
|
||||
bankAccountUpdateRequest.setTaxpayerIdentificationNumber(predictableUpdateBankAccount.getTaxpayerIdentificationNumber());
|
||||
bankAccountUpdateRequest.setTaxRegistrationReasonCode(predictableUpdateBankAccount.getTaxRegistrationReasonCode());
|
||||
bankAccountUpdateRequest.setAccount(predictableUpdateBankAccount.getAccount());
|
||||
|
||||
BaseRequest<BankAccountUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||
baseUpdateRequest.setRequestPayload(bankAccountUpdateRequest);
|
||||
|
|
@ -203,47 +232,29 @@ public class BankAccountServiceTest {
|
|||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
BankAccount predictableUpdateResult = new BankAccount();
|
||||
predictableUpdateResult.setBankName("NEW BUNK NAME");
|
||||
predictableUpdateResult.setBankIdentificationCode("88888");
|
||||
predictableUpdateResult.setCorrespondentAccount("894984646541316");
|
||||
predictableUpdateResult.setCorrespondentAccountName("BIK OF NEW BUNK");
|
||||
predictableUpdateResult.setCurrency("EU");
|
||||
predictableUpdateResult.setDestination("OOO NEW BUNK");
|
||||
predictableUpdateResult.setTaxpayerIdentificationNumber("65468461321");
|
||||
predictableUpdateResult.setTaxRegistrationReasonCode("532137");
|
||||
predictableUpdateResult.setId(ID);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) bankAccountService.getConsumer(), TOPIC_ACCOUNT_UPDATE, PARTITION, 0, jsonBaseUpdateRequest);
|
||||
|
||||
hazelcastServiceTest.waitTillReadyState();
|
||||
//service set up
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest, messageResolver, bankAccountNewRequestValidator);
|
||||
//callbacks set up
|
||||
bankAccountService.afterPropertiesSet();
|
||||
//waiting for kafka producer send message (finale event)
|
||||
verify(producer, timeout(30_000L).times(1))
|
||||
.send(producerRecord.capture());
|
||||
BaseRequest<Object> baseRequestResult = (BaseRequest<Object>) producerRecord.getValue().value();
|
||||
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
iMap.put(ID, bankAccountExists);
|
||||
ImapEvent imapEvent = new ImapEvent(iMap);
|
||||
|
||||
//KAFKA
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_UPDATE, PARTITION)));
|
||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_ACCOUNT_UPDATE, PARTITION, 0, "key", jsonBaseUpdateRequest));
|
||||
});
|
||||
HashMap<TopicPartition, Long> startOffsetsUpdating = new HashMap<>();
|
||||
TopicPartition tpUpdating = new TopicPartition(TOPIC_ACCOUNT_UPDATE, PARTITION);
|
||||
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||
|
||||
//waiting for hazelcast map item updates
|
||||
imapEvent.waitWhenHappened();
|
||||
Account accountResult = accountImdg.getSingleObjectBySQL(String.format("account = %s", acc));
|
||||
BankAccount resultUpdating = bankAccountImdg.getSingleObjectBySQL(String.format("account = %s or companyId = %s", acc, addresseeIdNew));
|
||||
predictableUpdateBankAccount.setAccountId(resultUpdating.getAccountId());
|
||||
predictableUpdateBankAccount.setCompanyId(resultUpdating.getCompanyId());
|
||||
predictableAccount.setUpdated(accountResult.getUpdated());
|
||||
|
||||
//ASSERT
|
||||
BankAccount resultUpdating = iMap.get(ID);
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(resultUpdating, predictableUpdateResult);
|
||||
assertEquals(Consts.REQUEST_INFO_UPDATE, producerRecord.getValue().topic());
|
||||
|
||||
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||
//ASSERT
|
||||
assertEquals(Consts.REQUEST_INFO_UPDATE, producerRecord.getValue().topic());
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(resultUpdating, predictableUpdateBankAccount);
|
||||
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||
BASE_REQUEST_MATCHER.assertMatch(baseRequestResult, predictableBaseRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -254,17 +265,12 @@ public class BankAccountServiceTest {
|
|||
*/
|
||||
@Test
|
||||
void bankAccountDelete() throws InterruptedException {
|
||||
//arrange
|
||||
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");
|
||||
//ARRANGE
|
||||
BankAccount bankAccountExists = getBankAccount();
|
||||
bankAccountImdg.insert(bankAccountExists);
|
||||
Account account = new Account();
|
||||
account.setId(accountId);
|
||||
accountImdg.insert(account);
|
||||
|
||||
CommonDeleteRequest commonDeleteRequest = new CommonDeleteRequest();
|
||||
commonDeleteRequest.setId(ID);
|
||||
|
|
@ -281,32 +287,58 @@ public class BankAccountServiceTest {
|
|||
}
|
||||
|
||||
//ACT
|
||||
//service set up
|
||||
hazelcastServiceTest.waitTillReadyState();
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, mockProducer, hazelcastServiceTest, messageResolver, bankAccountNewRequestValidator);
|
||||
//callbacks set up
|
||||
bankAccountService.afterPropertiesSet();
|
||||
addRecordToKafka((MockConsumer) bankAccountService.getConsumer(), TOPIC_ACCOUNT_DELETE, PARTITION, 0, jsonDeleteNewRequest);
|
||||
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
iMap.put(ID, bankAccountExists);
|
||||
ImapEvent imapEvent = new ImapEvent(iMap);
|
||||
|
||||
//KAFKA
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_ACCOUNT_DELETE, PARTITION)));
|
||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_ACCOUNT_DELETE, PARTITION, 0, "key", jsonDeleteNewRequest));
|
||||
});
|
||||
HashMap<TopicPartition, Long> startOffsetsDeleting = new HashMap<>();
|
||||
TopicPartition tpDeleting = new TopicPartition(TOPIC_ACCOUNT_DELETE, PARTITION);
|
||||
startOffsetsDeleting.put(tpDeleting, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsetsDeleting);
|
||||
|
||||
//waiting for hazelcast map item updates
|
||||
imapEvent.waitWhenHappened();
|
||||
//waiting for kafka producer send message (finale event)
|
||||
verify(producer, timeout(30_000L).times(1))
|
||||
.send(producerRecord.capture());
|
||||
|
||||
//ASSERT
|
||||
Assertions.assertEquals(0, iMap.size());
|
||||
BankAccount bankAccount = bankAccountImdg.getSingleObjectByID(baseDeleteRequest.getId());
|
||||
Assertions.assertNull(bankAccount);
|
||||
assertEquals(Consts.REQUEST_INFO_UPDATE, producerRecord.getValue().topic());
|
||||
}
|
||||
|
||||
assertTrue(mockProducer.history().get(0).topic().equalsIgnoreCase(Consts.REQUEST_INFO_UPDATE));
|
||||
private Company getTestCompany() {
|
||||
Company company = new Company();
|
||||
company.setId(addresseeIdNew);
|
||||
company.setWorkflowStatus(Status.Active.getKey());
|
||||
company.setTradingCode(deal);
|
||||
company.setShortName("ShortName");
|
||||
company.setFullName("FullName");
|
||||
return company;
|
||||
}
|
||||
|
||||
private Account getTestAccount(Long id, String acc) {
|
||||
Account account = new Account();
|
||||
account.setId(id);
|
||||
account.setAccount(acc);
|
||||
account.setAccountType(AccountType.Bank.getKey());
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
account.setProcessingSign(Allowed.ALLOWED.getKey());
|
||||
return account;
|
||||
}
|
||||
|
||||
private void setSameValueToField(Account from, Account to) {
|
||||
to.setCreated(from.getCreated());
|
||||
to.setUpdated(from.getUpdated());
|
||||
to.setId(from.getId());
|
||||
}
|
||||
|
||||
private BankAccount getBankAccount() {
|
||||
BankAccount bankAccount = new BankAccount();
|
||||
bankAccount.setAccountId(accountId);
|
||||
bankAccount.setAccount(acc);
|
||||
bankAccount.setCompanyId(addresseeIdNew);
|
||||
bankAccount.setId(ID);
|
||||
bankAccount.setBankName("ooo tinkoff");
|
||||
bankAccount.setBankIdentificationCode("99999");
|
||||
bankAccount.setCorrespondentAccount("9294189285498598598");
|
||||
bankAccount.setCorrespondentAccountName("BIK OF TINKOFF");
|
||||
bankAccount.setCurrency("RUB");
|
||||
bankAccount.setDestination("OOO ROGA I KOPITA");
|
||||
bankAccount.setTaxpayerIdentificationNumber("848484848484");
|
||||
bankAccount.setTaxRegistrationReasonCode("886886");
|
||||
return bankAccount;
|
||||
}
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ public class ImapEvent<T> {
|
|||
checkEventHappened.set(secondRan);//если что-то пойдет не так не тормозить основной поток
|
||||
secondRan = true;
|
||||
}
|
||||
}, 0, 60 * 1000);
|
||||
}, 0, 30 * 1000);
|
||||
synchronized (checkEventHappened) {
|
||||
while (!checkEventHappened.get()) {
|
||||
checkEventHappened.wait(100);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package ru.spcex.clearing.account.utils;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
import org.apache.kafka.common.TopicPartition;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class MockKafkaUtils {
|
||||
public static void addRecordToKafka(MockConsumer mockConsumer, String topic, int partition, long offset, String jsonValue) {
|
||||
TopicPartition tp = new TopicPartition(topic, partition);
|
||||
HashMap<TopicPartition, Long> startOffsets = new HashMap<>();
|
||||
startOffsets.put(tp, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(tp));
|
||||
mockConsumer.addRecord(new ConsumerRecord<>(topic, partition, offset, "key", jsonValue));
|
||||
});
|
||||
}
|
||||
|
||||
public static class FutureRecordMetadata implements Future<RecordMetadata> {
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordMetadata get() throws InterruptedException, ExecutionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordMetadata get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,7 @@ public abstract class AbstractServiceTest {
|
|||
protected static ImdgHazelcast<SDf17> sdf17Imdg;
|
||||
protected static ImdgHazelcast<AccountBalance> accountBalanceImdg;
|
||||
protected static ImdgHazelcast<Company> companyImdg;
|
||||
protected static ImdgHazelcast<Account> accountImdg;
|
||||
protected final Long accountIdNew = 10L;
|
||||
protected final Long addresseeIdNew = 2L;
|
||||
protected final String deal = "111111111";
|
||||
|
|
@ -77,7 +78,7 @@ public abstract class AbstractServiceTest {
|
|||
hazelcast.waitAvailable();
|
||||
companyImdg = (ImdgHazelcast<Company>) hazelcast.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
ImdgHazelcast<CompanySymbols> companySymbolsImdg = (ImdgHazelcast<CompanySymbols>) hazelcast.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
ImdgHazelcast<Account> accountImdg = (ImdgHazelcast<Account>) hazelcast.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
accountImdg = (ImdgHazelcast<Account>) hazelcast.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
requestInfoImdg = (ImdgHazelcast<RequestInfo>) hazelcast.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class);
|
||||
statementImdg = (ImdgHazelcast<Statement>) hazelcast.getImdg(IMDGDistributedNames.Map_Statement, Statement.class);
|
||||
sdf01Imdg = (ImdgHazelcast<SDf01>) hazelcast.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class);
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
@Test
|
||||
void createAccountBalance() {
|
||||
Company company = getTestCompany();
|
||||
companyMap.put(addresseeIdNew, company);
|
||||
companyImdg.insert(company);
|
||||
Account account = getTestAccount(accountIdNew, acc);
|
||||
accountMap.put(accountIdNew, account);
|
||||
accountImdg.insert(account);
|
||||
|
||||
AccountResult predictableNewResult = getTestAccountResult(accountIdNew, account, company);
|
||||
AccountResult resultNew = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCode);
|
||||
|
|
@ -96,7 +96,8 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
//CompanyNotFound
|
||||
AccountResult predictableResult;
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.CompanyNotFound));
|
||||
companyMap.delete(addresseeIdNew);
|
||||
Company company = getTestCompany();
|
||||
companyImdg.delete(company);
|
||||
|
||||
AccountResult result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCode);
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
|
@ -105,11 +106,11 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
||||
//AccountNotPresent accountType=null
|
||||
companyMap.put(addresseeIdNew, getTestCompany());
|
||||
companyImdg.insert(company);
|
||||
Account account = new Account();
|
||||
account.setId(accountIdNew);
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
accountMap.put(accountIdNew, account);
|
||||
accountImdg.insert(account);
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.AccountNotPresent));
|
||||
|
||||
result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCode);
|
||||
|
|
@ -119,7 +120,7 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
account.setId(null);
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
accountMap.put(accountIdNew, account);
|
||||
accountImdg.insert(account);
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.AccountNotPresent));
|
||||
|
||||
result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCode);
|
||||
|
|
@ -129,14 +130,14 @@ class AccountBalanceServiceTest extends AbstractServiceTest {
|
|||
account.setId(accountIdNew);
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
account.setAccountStatus(null);
|
||||
accountMap.put(accountIdNew, account);
|
||||
accountImdg.insert(account);
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.AccountNotActive, account.getId()));
|
||||
|
||||
result = accountBalanceService.createAccountBalance(addresseeIdNew, accountIdNew, amountNew, cashMovementCurrencyCode);
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
||||
account.setAccountStatus(Status.Active.getKey());
|
||||
accountMap.put(accountIdNew, account);
|
||||
accountImdg.insert(account);
|
||||
result = accountBalanceService.createAccountBalance(addresseeIdNew, null, amountNew, cashMovementCurrencyCode);
|
||||
predictableResult = new AccountResult(new EnumMessage(BalanceError.AccountNotPresent));
|
||||
ACCOUNT_BALANCE_MATCHER.assertMatch(result, predictableResult);
|
||||
|
|
|
|||
|
|
@ -36,14 +36,11 @@ class StatementServiceServiceTest extends AbstractServiceTest {
|
|||
private final Long ID = 11L;
|
||||
@Autowired
|
||||
StatementService statementService;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<ProducerRecord> producerRecord;
|
||||
|
||||
private MockConsumer<String, Object> mockConsumer;
|
||||
private SDf01 sDf01;
|
||||
private Company company;
|
||||
|
||||
@SpyBean
|
||||
private MockProducer<String, Object> producer;
|
||||
|
||||
|
|
@ -89,14 +86,10 @@ class StatementServiceServiceTest extends AbstractServiceTest {
|
|||
verify(producer, timeout(30_000L).times(1))
|
||||
.send(producerRecord.capture());
|
||||
|
||||
// Collection<RequestInfo> resultsRequestInfo = requestInfoImdg.getCollectionObjectsByFieldValues(Map.of("status", Status.Processing));
|
||||
// RequestInfo requestInfo = resultsRequestInfo.stream().max((entry1, entry2) -> entry1.getId() > entry2.getId() ? 1 : -1).get();
|
||||
|
||||
assertEquals(Consts.EXPORT_PROCESS, producerRecord.getValue().topic());
|
||||
BaseRequest<Object> baseRequest = (BaseRequest<Object>) producerRecord.getValue().value();
|
||||
|
||||
RequestInfo resultRequestInfo = requestInfoImdg.getSingleObjectByID(baseRequest.getId());
|
||||
|
||||
assertEquals(Consts.EXPORT_PROCESS, producerRecord.getValue().topic());
|
||||
assertNotNull(baseRequest);
|
||||
assertNotNull(resultRequestInfo);
|
||||
}
|
||||
|
|
@ -134,14 +127,10 @@ class StatementServiceServiceTest extends AbstractServiceTest {
|
|||
verify(producer, timeout(30_000L).times(1))
|
||||
.send(producerRecord.capture());
|
||||
|
||||
// Collection<RequestInfo> resultsRequestInfo = requestInfoImdg.getCollectionObjectsByFieldValues(Map.of("status", Status.Processing));
|
||||
// RequestInfo requestInfo = resultsRequestInfo.stream().max((entry1, entry2) -> entry1.getId() > entry2.getId() ? 1 : -1).get();
|
||||
|
||||
assertEquals(Consts.ACCOUNT_NEW, producerRecord.getValue().topic());
|
||||
BaseRequest<Object> baseRequest = (BaseRequest<Object>) producerRecord.getValue().value();
|
||||
|
||||
RequestInfo resultRequestInfo = requestInfoImdg.getSingleObjectByID(baseRequest.getId());
|
||||
|
||||
assertEquals(Consts.ACCOUNT_NEW, producerRecord.getValue().topic());
|
||||
assertNotNull(baseRequest);
|
||||
assertNotNull(resultRequestInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class QueueConsumer implements AutoCloseable {
|
|||
}
|
||||
} catch (Throwable e) {
|
||||
log.error(ExceptionUtils.getStackTrace(e));
|
||||
if (producer != null) {
|
||||
if (producer != null && o != null) {
|
||||
sendErrorResponse((BaseRequest<?>) o);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue