--- CompanySymbolServiceTest test done
This commit is contained in:
parent
f3c8470f50
commit
dd395f36aa
3 changed files with 224 additions and 1 deletions
|
|
@ -39,7 +39,7 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
||||||
CompanySymbolUpdateRequest req = userRequest.getRequestPayload();
|
CompanySymbolUpdateRequest req = userRequest.getRequestPayload();
|
||||||
log.debug("CompanySymbolUpdateRequest received");
|
log.debug("CompanySymbolUpdateRequest received");
|
||||||
CompanySymbols companySymbols = companySymbolsMap.getSingleObjectByID(req.getId());
|
CompanySymbols companySymbols = companySymbolsMap.getSingleObjectByID(req.getId());
|
||||||
companySymbols.setCompanySymbol(req.getCompanySymbol());
|
// companySymbols.setCompanySymbol(req.getCompanySymbol()); по ТЗ не должен менятся при обновлении
|
||||||
companySymbols.setCompanySymbolValue(req.getCompanySymbolValue());
|
companySymbols.setCompanySymbolValue(req.getCompanySymbolValue());
|
||||||
|
|
||||||
companySymbolsMap.update(companySymbols);
|
companySymbolsMap.update(companySymbols);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
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.company.CompanySymbols;
|
||||||
|
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.CompanySymbolUpdateRequest;
|
||||||
|
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 CompanySymbolServiceTest {
|
||||||
|
|
||||||
|
public static final MatcherFactory.Matcher<CompanySymbols> COMPANY_SYMBOL_MATCHER = usingIgnoringFieldsComparator();
|
||||||
|
private static final int PARTITION = 0;
|
||||||
|
private static final String TOPIC_COMPANY_SYMBOL_UPDATE = Consts.DESTINATION_COMPANY_SYMBOL_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 companySymbolUpdate() throws InterruptedException {
|
||||||
|
//ARRANGE
|
||||||
|
CompanySymbols existsCompanySymbols = new CompanySymbols();
|
||||||
|
existsCompanySymbols.setId(currentId);
|
||||||
|
existsCompanySymbols.setCompanyId(currentId);
|
||||||
|
existsCompanySymbols.setCompanySymbol("0000");
|
||||||
|
existsCompanySymbols.setCompanySymbolValue("exists companySymbolValue");
|
||||||
|
|
||||||
|
CompanySymbolUpdateRequest companySymbolUpdateRequest = new CompanySymbolUpdateRequest();
|
||||||
|
companySymbolUpdateRequest.setId(currentId);
|
||||||
|
companySymbolUpdateRequest.setCompanyId(currentId);
|
||||||
|
companySymbolUpdateRequest.setCompanySymbol("1234");
|
||||||
|
companySymbolUpdateRequest.setCompanySymbolValue("new companySymbolValue");
|
||||||
|
|
||||||
|
BaseRequest<CompanySymbolUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||||
|
baseUpdateRequest.setRequestPayload(companySymbolUpdateRequest);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
CompanySymbols predictableCompanySymbols = new CompanySymbols();
|
||||||
|
predictableCompanySymbols.setId(currentId);
|
||||||
|
predictableCompanySymbols.setCompanyId(currentId);
|
||||||
|
predictableCompanySymbols.setCompanySymbol("0000");
|
||||||
|
predictableCompanySymbols.setCompanySymbolValue("new companySymbolValue");
|
||||||
|
|
||||||
|
//ACT
|
||||||
|
//service set up
|
||||||
|
CompanySymbolService companySymbolService = new CompanySymbolService(mockConsumer, hazelcastServiceTest);
|
||||||
|
Thread.sleep(10000);
|
||||||
|
//callbacks set up
|
||||||
|
companySymbolService.afterPropertiesSet();
|
||||||
|
Thread.sleep(10000);
|
||||||
|
|
||||||
|
IMap<Long, CompanySymbols> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_CompanySymbols);
|
||||||
|
iMap.put(currentId, existsCompanySymbols);
|
||||||
|
|
||||||
|
//KAFKA
|
||||||
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_COMPANY_SYMBOL_UPDATE, PARTITION)));
|
||||||
|
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_COMPANY_SYMBOL_UPDATE, PARTITION, 0, "key", jsonBaseForUpdatingRequest));
|
||||||
|
});
|
||||||
|
HashMap<TopicPartition, Long> startOffsetsUpdating = new HashMap<>();
|
||||||
|
TopicPartition tpUpdating = new TopicPartition(TOPIC_COMPANY_SYMBOL_UPDATE, PARTITION);
|
||||||
|
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||||
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
|
//ASSERT
|
||||||
|
Thread.sleep(10000);
|
||||||
|
CompanySymbols resultUpdating = iMap.get(currentId);
|
||||||
|
COMPANY_SYMBOL_MATCHER.assertMatch(resultUpdating, predictableCompanySymbols);
|
||||||
|
|
||||||
|
//preparing hazelcastImdgProvider for next test
|
||||||
|
iMap.clear();
|
||||||
|
currentId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
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.generated.ClearingMemberCategory;
|
||||||
|
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.ClearingMemberCategoryUpdateRequest;
|
||||||
|
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 ContactServiceTest {
|
||||||
|
|
||||||
|
public static final MatcherFactory.Matcher<ClearingMemberCategory> CONTACT_MATCHER = usingIgnoringFieldsComparator();
|
||||||
|
private static final int PARTITION = 0;
|
||||||
|
private static final String TOPIC_CONTACT_UPDATE = Consts.DESTINATION_CONTACT_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 contactUpdate() throws InterruptedException {
|
||||||
|
//ARRANGE
|
||||||
|
ClearingMemberCategory existsСlearingMemberCategory = new ClearingMemberCategory();
|
||||||
|
existsСlearingMemberCategory.setId(currentId);
|
||||||
|
existsСlearingMemberCategory.setClearingMemberCategory("0000");
|
||||||
|
|
||||||
|
ClearingMemberCategoryUpdateRequest memberCategoryUpdateRequest = new ClearingMemberCategoryUpdateRequest();
|
||||||
|
memberCategoryUpdateRequest.setId(currentId);
|
||||||
|
memberCategoryUpdateRequest.setClearingMemberCategory("1234");
|
||||||
|
BaseRequest<ClearingMemberCategoryUpdateRequest> baseUpdateRequest = new BaseRequest<>();
|
||||||
|
baseUpdateRequest.setRequestPayload(memberCategoryUpdateRequest);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClearingMemberCategory predictableClearingMemberCategory = new ClearingMemberCategory();
|
||||||
|
predictableClearingMemberCategory.setId(currentId);
|
||||||
|
predictableClearingMemberCategory.setClearingMemberCategory("1234");
|
||||||
|
|
||||||
|
//ACT
|
||||||
|
//service set up
|
||||||
|
ClearingMemberCategoryService clearingMemberCategoryService = new ClearingMemberCategoryService(mockConsumer, hazelcastServiceTest);
|
||||||
|
Thread.sleep(10000);
|
||||||
|
//callbacks set up
|
||||||
|
clearingMemberCategoryService.afterPropertiesSet();
|
||||||
|
Thread.sleep(10000);
|
||||||
|
|
||||||
|
IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
|
||||||
|
iMap.put(currentId, existsСlearingMemberCategory);
|
||||||
|
|
||||||
|
//KAFKA
|
||||||
|
mockConsumer.schedulePollTask(() -> {
|
||||||
|
mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC_CONTACT_UPDATE, PARTITION)));
|
||||||
|
mockConsumer.addRecord(new ConsumerRecord<>(TOPIC_CONTACT_UPDATE, PARTITION, 0, "key", jsonBaseForUpdatingRequest));
|
||||||
|
});
|
||||||
|
HashMap<TopicPartition, Long> startOffsetsUpdating = new HashMap<>();
|
||||||
|
TopicPartition tpUpdating = new TopicPartition(TOPIC_CONTACT_UPDATE, PARTITION);
|
||||||
|
startOffsetsUpdating.put(tpUpdating, 0L);
|
||||||
|
mockConsumer.updateBeginningOffsets(startOffsetsUpdating);
|
||||||
|
|
||||||
|
//ASSERT
|
||||||
|
Thread.sleep(10000);
|
||||||
|
ClearingMemberCategory resultUpdating = iMap.get(currentId);
|
||||||
|
CONTACT_MATCHER.assertMatch(resultUpdating, predictableClearingMemberCategory);
|
||||||
|
|
||||||
|
//preparing hazelcastImdgProvider for next test
|
||||||
|
iMap.clear();
|
||||||
|
currentId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue