parent
49fe74ea60
commit
bb49709287
3 changed files with 65 additions and 41 deletions
|
|
@ -54,6 +54,7 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
bankAccount.setDestination(req.getDestination());
|
||||
bankAccount.setTaxpayerIdentificationNumber(req.getTaxpayerIdentificationNumber());
|
||||
bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode());
|
||||
bankAccount.setAccount(req.getAccount());
|
||||
|
||||
bankAccountMap.insert(bankAccount);
|
||||
log.debug("successfully processed, new id {}", bankAccount.getId());
|
||||
|
|
|
|||
|
|
@ -16,22 +16,24 @@ 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.utils.MatcherFactory.Matcher;
|
||||
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.BankAccountNewRequest;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static ru.spcex.clearing.account.utils.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
HazelcastServiceTestConfiguration.class})
|
||||
public class BankAccountServiceTest {
|
||||
|
||||
public static final Matcher<BankAccount> BANK_ACCOUNT_MATCHER = usingIgnoringFieldsComparator("id");
|
||||
private static final int PARTITION = 0;
|
||||
private static final String TOPIC = Consts.DESTINATION_BANK_ACCOUNT_NEW;
|
||||
private final String jsonBaseRequest;
|
||||
|
|
@ -73,41 +75,6 @@ public class BankAccountServiceTest {
|
|||
@Test
|
||||
public void bankAccountNew() throws InterruptedException {
|
||||
//arrange
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC, PARTITION)));
|
||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC, PARTITION, 0, "key", jsonBaseRequest));
|
||||
});
|
||||
mockConsumer.schedulePollTask(() -> mockConsumer.wakeup());
|
||||
|
||||
HashMap<TopicPartition, Long> startOffsets = new HashMap<>();
|
||||
TopicPartition tp = new TopicPartition(TOPIC, PARTITION);
|
||||
startOffsets.put(tp, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
||||
|
||||
|
||||
// ImdgProvider imdgProvider = Mockito.mock(ImdgProvider.class);
|
||||
//
|
||||
// ImdgHazelcast bankAccountMap = Mockito.mock(ImdgHazelcast.class);
|
||||
//
|
||||
// ArgumentCaptor<BankAccount> bankAccountCaptor = ArgumentCaptor.forClass(BankAccount.class);
|
||||
//
|
||||
// doReturn(bankAccountMap).when(imdgProvider).getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
//мапа которую проверял Илья
|
||||
Imdg<BankAccount> imdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
// IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, hazelcastServiceTest);
|
||||
try {
|
||||
// hazelcastServiceTest.init();
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
bankAccountService.afterPropertiesSet();
|
||||
|
||||
|
||||
Thread.sleep(10000);
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
|
||||
BankAccount predictableResult = new BankAccount();
|
||||
predictableResult.setBankName("ooo tinkoff");
|
||||
predictableResult.setBankIdentificationCode("99999");
|
||||
|
|
@ -118,14 +85,32 @@ public class BankAccountServiceTest {
|
|||
predictableResult.setTaxpayerIdentificationNumber("848484848484");
|
||||
predictableResult.setTaxRegistrationReasonCode("886886");
|
||||
predictableResult.setAccount("123456789123");
|
||||
predictableResult.setId(0L);
|
||||
//KAFKA
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC, PARTITION)));
|
||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC, PARTITION, 0, "key", jsonBaseRequest));
|
||||
});
|
||||
|
||||
|
||||
HashMap<TopicPartition, Long> startOffsets = new HashMap<>();
|
||||
TopicPartition tp = new TopicPartition(TOPIC, PARTITION);
|
||||
startOffsets.put(tp, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsets);
|
||||
|
||||
// Mockito.verify(bankAccountMap).insert(bankAccountCaptor.capture());
|
||||
//ACT
|
||||
|
||||
// BankAccount bankAccount = bankAccountCaptor.getValue();
|
||||
//assert
|
||||
//service set up
|
||||
BankAccountService bankAccountService = new BankAccountService(mockConsumer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
//callbacks set up
|
||||
bankAccountService.afterPropertiesSet();
|
||||
Thread.sleep(10000);
|
||||
|
||||
//ASSERT
|
||||
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
|
||||
BankAccount result = iMap.get(0L);
|
||||
|
||||
// assertThat(bankAccount).isEqualTo(predictableResult);
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(result, predictableResult);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package ru.spcex.clearing.account.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Factory for creating test matchers.
|
||||
* <p>
|
||||
* Comparing actual and expected objects via AssertJ
|
||||
*/
|
||||
public class MatcherFactory {
|
||||
|
||||
public static <T> Matcher<T> usingIgnoringFieldsComparator(String... fieldsToIgnore) {
|
||||
return new Matcher<>(fieldsToIgnore);
|
||||
}
|
||||
|
||||
public static class Matcher<T> {
|
||||
private final String[] fieldsToIgnore;
|
||||
|
||||
private Matcher(String... fieldsToIgnore) {
|
||||
this.fieldsToIgnore = fieldsToIgnore;
|
||||
}
|
||||
|
||||
public void assertMatch(T actual, T expected) {
|
||||
assertThat(actual).usingRecursiveComparison().ignoringFields(fieldsToIgnore).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public final void assertMatch(Iterable<T> actual, T... expected) {
|
||||
assertMatch(actual, Arrays.asList(expected));
|
||||
}
|
||||
|
||||
public void assertMatch(Iterable<T> actual, Iterable<T> expected) {
|
||||
assertThat(actual).usingRecursiveFieldByFieldElementComparatorIgnoringFields(fieldsToIgnore).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue