diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java index b95313fd0..176a6a35a 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java @@ -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()); diff --git a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/BankAccountServiceTest.java b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/BankAccountServiceTest.java index ff35a61f7..b0864cef4 100644 --- a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/BankAccountServiceTest.java +++ b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/service/BankAccountServiceTest.java @@ -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 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 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 bankAccountCaptor = ArgumentCaptor.forClass(BankAccount.class); -// -// doReturn(bankAccountMap).when(imdgProvider).getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class); - //мапа которую проверял Илья - Imdg imdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class); -// IMap 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 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 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 iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount); + BankAccount result = iMap.get(0L); -// assertThat(bankAccount).isEqualTo(predictableResult); + BANK_ACCOUNT_MATCHER.assertMatch(result, predictableResult); } } \ No newline at end of file diff --git a/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/utils/MatcherFactory.java b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/utils/MatcherFactory.java new file mode 100644 index 000000000..b2d1a4fdc --- /dev/null +++ b/clearing-parent/account-service/src/test/java/ru/spcex/clearing/account/utils/MatcherFactory.java @@ -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. + *

+ * Comparing actual and expected objects via AssertJ + */ +public class MatcherFactory { + + public static Matcher usingIgnoringFieldsComparator(String... fieldsToIgnore) { + return new Matcher<>(fieldsToIgnore); + } + + public static class Matcher { + 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 actual, T... expected) { + assertMatch(actual, Arrays.asList(expected)); + } + + public void assertMatch(Iterable actual, Iterable expected) { + assertThat(actual).usingRecursiveFieldByFieldElementComparatorIgnoringFields(fieldsToIgnore).isEqualTo(expected); + } + } +}