---
CompanyInfoServiceTest test done
This commit is contained in:
parent
225dc45046
commit
b0a28cfb6c
2 changed files with 142 additions and 4 deletions
|
|
@ -36,7 +36,7 @@ import static ru.spcex.clearing.company.utils.MatcherFactory.usingIgnoringFields
|
|||
HazelcastServiceTestConfiguration.class})
|
||||
class ClearingMemberCategoryServiceTest {
|
||||
|
||||
public static final Matcher<ClearingMemberCategory> MEMBER_CATEGORY_MATCHER = usingIgnoringFieldsComparator("id");
|
||||
public static final Matcher<ClearingMemberCategory> MEMBER_CATEGORY_MATCHER = usingIgnoringFieldsComparator();
|
||||
private static final int PARTITION = 0;
|
||||
private static final String TOPIC_MEMBER_CATEGORY_UPDATE = Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_UPDATE;
|
||||
private static final String TOPIC_MEMBER_CATEGORY_DELETE = Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_DELETE;
|
||||
|
|
@ -65,7 +65,7 @@ class ClearingMemberCategoryServiceTest {
|
|||
BaseRequest<ClearingMemberCategoryUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||
baseUpdateRequest.setRequestPayload(memberCategoryUpdateRequest);
|
||||
baseUpdateRequest.setId(currentId);
|
||||
baseUpdateRequest.setActionType(ActionType.NEW);
|
||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||
String jsonBaseForUpdatingRequest;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
|
|
@ -103,7 +103,6 @@ class ClearingMemberCategoryServiceTest {
|
|||
Thread.sleep(10000);
|
||||
ClearingMemberCategory resultUpdating = iMap.get(currentId);
|
||||
MEMBER_CATEGORY_MATCHER.assertMatch(resultUpdating, predictableClearingMemberCategory);
|
||||
// Assertions.assertEquals(0, iMap.size());
|
||||
|
||||
//preparing hazelcastImdgProvider for next test
|
||||
iMap.clear();
|
||||
|
|
@ -123,7 +122,7 @@ class ClearingMemberCategoryServiceTest {
|
|||
BaseRequest<CommonDeleteRequest> baseDeleteRequest = new BaseRequest<>();
|
||||
baseDeleteRequest.setRequestPayload(memberCategoryDeleteRequest);
|
||||
baseDeleteRequest.setId(currentId);
|
||||
baseDeleteRequest.setActionType(ActionType.NEW);
|
||||
baseDeleteRequest.setActionType(ActionType.DELETE);
|
||||
String jsonBaseForDeleteRequest;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,139 @@
|
|||
package ru.spcex.clearing.company.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.common.TopicPartition;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.profile.CompanyInfo;
|
||||
import ru.spcex.clearing.company.config.HazelcastServiceTestConfiguration;
|
||||
import ru.spcex.clearing.company.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.company.CompanyInfoUpdateRequest;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static ru.spcex.clearing.company.utils.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
HazelcastServiceTestConfiguration.class})
|
||||
class CompanyInfoServiceTest {
|
||||
|
||||
public static final MatcherFactory.Matcher<CompanyInfo> COMPANY_INFO_MATCHER = usingIgnoringFieldsComparator();
|
||||
private static final int PARTITION = 0;
|
||||
private static final String TOPIC_COMPANY_INFO_UPDATE = Consts.DESTINATION_COMPANY_INFO_UPDATE;
|
||||
private static Long currentId = 0L;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private HazelcastService hazelcastServiceTest;
|
||||
private MockConsumer<String, Object> mockConsumer;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void companyInfoUpdate() throws InterruptedException {
|
||||
//ARRANGE
|
||||
CompanyInfo existsCompanyInfo = new CompanyInfo();
|
||||
existsCompanyInfo.setId(currentId);
|
||||
existsCompanyInfo.setCorporationSoleType("0000");
|
||||
existsCompanyInfo.setCountryCode("0000");
|
||||
existsCompanyInfo.setDescription("exists description");
|
||||
existsCompanyInfo.setProfessionalSign("0000");
|
||||
existsCompanyInfo.setLegalKind("0000");
|
||||
existsCompanyInfo.setOrganizationType("0000");
|
||||
existsCompanyInfo.setResidence("0000");
|
||||
existsCompanyInfo.setShortNameEng("exists shortNameEng");
|
||||
existsCompanyInfo.setFullNameEng("exists fullNameEng");
|
||||
existsCompanyInfo.setShortName("exists shortName");
|
||||
existsCompanyInfo.setFullName("exists fullName");
|
||||
|
||||
CompanyInfoUpdateRequest companyInfoUpdateRequest = new CompanyInfoUpdateRequest();
|
||||
companyInfoUpdateRequest.setId(currentId);
|
||||
companyInfoUpdateRequest.setCorporationSoleType("1234");
|
||||
companyInfoUpdateRequest.setCountryCode("1234");
|
||||
companyInfoUpdateRequest.setDescription("updated description");
|
||||
companyInfoUpdateRequest.setProfessionalSign("1234");
|
||||
companyInfoUpdateRequest.setLegalKind("1234");
|
||||
companyInfoUpdateRequest.setOrganizationType("1234");
|
||||
companyInfoUpdateRequest.setResidence("1234");
|
||||
companyInfoUpdateRequest.setShortNameEng("updated shortNameEng");
|
||||
companyInfoUpdateRequest.setFullNameEng("updated fullNameEng");
|
||||
companyInfoUpdateRequest.setShortName("updated shortName");
|
||||
companyInfoUpdateRequest.setFullName("updated fullName");
|
||||
|
||||
BaseRequest<CompanyInfoUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||
baseUpdateRequest.setRequestPayload(companyInfoUpdateRequest);
|
||||
baseUpdateRequest.setId(currentId);
|
||||
baseUpdateRequest.setActionType(ActionType.UPDATE);
|
||||
String jsonBaseForUpdatingRequest;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
jsonBaseForUpdatingRequest = objectMapper.writeValueAsString(baseUpdateRequest);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
CompanyInfo predictableCompanyInfo = new CompanyInfo();
|
||||
predictableCompanyInfo.setId(currentId);
|
||||
predictableCompanyInfo.setCorporationSoleType("1234");
|
||||
predictableCompanyInfo.setCountryCode("1234");
|
||||
predictableCompanyInfo.setDescription("updated description");
|
||||
predictableCompanyInfo.setProfessionalSign("1234");
|
||||
predictableCompanyInfo.setLegalKind("1234");
|
||||
predictableCompanyInfo.setOrganizationType("1234");
|
||||
predictableCompanyInfo.setResidence("1234");
|
||||
predictableCompanyInfo.setShortNameEng("updated shortNameEng");
|
||||
predictableCompanyInfo.setFullNameEng("updated fullNameEng");
|
||||
predictableCompanyInfo.setShortName("updated shortName");
|
||||
predictableCompanyInfo.setFullName("updated fullName");
|
||||
|
||||
//ACT
|
||||
//service set up
|
||||
CompanyInfoService clearingMemberCategoryService = new CompanyInfoService(mockConsumer, hazelcastServiceTest);
|
||||
Thread.sleep(10000);
|
||||
//callbacks set up
|
||||
clearingMemberCategoryService.afterPropertiesSet();
|
||||
Thread.sleep(10000);
|
||||
|
||||
IMap<Long, CompanyInfo> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_Company);
|
||||
iMap.put(currentId, existsCompanyInfo);
|
||||
|
||||
//KAFKA
|
||||
mockConsumer.schedulePollTask(() -> {
|
||||
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_COMPANY_INFO_UPDATE, PARTITION)));
|
||||
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_COMPANY_INFO_UPDATE, PARTITION, 0, "key", jsonBaseForUpdatingRequest));
|
||||
});
|
||||
HashMap<TopicPartition, Long> startOffsetsUpdating = new HashMap<>();
|
||||
TopicPartition tpUpdating = new TopicPartition(TOPIC_COMPANY_INFO_UPDATE, PARTITION);
|
||||
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||
|
||||
//ASSERT
|
||||
Thread.sleep(10000);
|
||||
CompanyInfo resultUpdating = iMap.get(currentId);
|
||||
COMPANY_INFO_MATCHER.assertMatch(resultUpdating, predictableCompanyInfo);
|
||||
|
||||
//preparing hazelcastImdgProvider for next test
|
||||
iMap.clear();
|
||||
currentId++;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue