Merge remote-tracking branch 'origin/psemenkov' into psemenkov
# Conflicts: # clearing-parent/backend-api/src/test/ru/spcex/clearing/backendapi/controller/queue/account/BankAccountControllerTest.java # clearing-parent/backend-api/src/test/ru/spcex/clearing/backendapi/controller/queue/config/BankAccountControllerConfig.java # clearing-parent/backend-api/src/test/ru/spcex/clearing/backendapi/controller/queue/config/HazelcastServiceTestConfiguration.java # clearing-parent/backend-api/src/test/ru/spcex/clearing/backendapi/controller/queue/config/IOperator.java
This commit is contained in:
commit
dd7610432a
4 changed files with 48 additions and 24 deletions
|
|
@ -1,13 +1,18 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.NestedExceptionUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||
import ru.spcex.clearing.backendapi.config.WebConfig;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractControllerTest;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.config.*;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.utils.MatcherFactory;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
|
|
@ -17,6 +22,9 @@ import ru.spcex.clearing.backendapi.errors.ActionValidationException;
|
|||
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewRequest;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
|
|
@ -30,8 +38,31 @@ import static ru.spcex.clearing.backendapi.controller.queue.utils.JsonUtil.write
|
|||
KafkaConfig.class,
|
||||
HazelcastServiceTestConfiguration.class,
|
||||
Jackson2HttpConverterConfig.class})
|
||||
class BankAccountControllerTest extends AbstractControllerTest {
|
||||
class BankAccountControllerTest {
|
||||
|
||||
public static final MatcherFactory.Matcher<CudResponse> CUD_RESPONSE_MATCHER = MatcherFactory.usingIgnoringFieldsComparator(CudResponse.class);
|
||||
private static final String REST_URL = "/securities/bank-accounts/";
|
||||
private static final CharacterEncodingFilter CHARACTER_ENCODING_FILTER = new CharacterEncodingFilter();
|
||||
private static final AtomicLong currentId = new AtomicLong();
|
||||
|
||||
static {
|
||||
CHARACTER_ENCODING_FILTER.setEncoding("UTF-8");
|
||||
CHARACTER_ENCODING_FILTER.setForceEncoding(true);
|
||||
}
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
@PostConstruct
|
||||
private void postConstruct() {
|
||||
mockMvc = MockMvcBuilders
|
||||
.webAppContextSetup(webApplicationContext)
|
||||
.addFilter(CHARACTER_ENCODING_FILTER)
|
||||
// .apply(springSecurity())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BankAccountController#add(BankAccountNewAction)}<br>
|
||||
|
|
@ -66,9 +97,9 @@ class BankAccountControllerTest extends AbstractControllerTest {
|
|||
extended.setMessage("success");
|
||||
extended.setPayload(new QueueSuccessResponse(ActionType.NEW, currentId.getAndIncrement()));
|
||||
//ACT
|
||||
perform(MockMvcRequestBuilders.post(REST_URL)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(writeValue(bankAccountNewAction)))
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(REST_URL)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(writeValue(bankAccountNewAction)))
|
||||
.andDo(print())//output to the log request and response
|
||||
// ASSERT
|
||||
.andExpect(status().isOk())
|
||||
|
|
@ -136,9 +167,9 @@ class BankAccountControllerTest extends AbstractControllerTest {
|
|||
extended.setMessage("success");
|
||||
extended.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
|
||||
//ACT
|
||||
perform(MockMvcRequestBuilders.put(REST_URL + "0")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(writeValue(bankAccountNewAction)))
|
||||
mockMvc.perform(MockMvcRequestBuilders.put(REST_URL + "0")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(writeValue(bankAccountNewAction)))
|
||||
.andDo(print())//output to the log request and response
|
||||
// ASSERT
|
||||
.andExpect(status().isOk())
|
||||
|
|
@ -160,8 +191,8 @@ class BankAccountControllerTest extends AbstractControllerTest {
|
|||
extended.setMessage("success");
|
||||
extended.setPayload(new QueueSuccessResponse(ActionType.DELETE, currentId.getAndIncrement()));
|
||||
//ACT
|
||||
perform(MockMvcRequestBuilders.delete(REST_URL + "0")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
mockMvc.perform(MockMvcRequestBuilders.delete(REST_URL + "0")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())//output to the log request and response
|
||||
// ASSERT
|
||||
.andExpect(status().isOk())
|
||||
|
|
@ -172,7 +203,7 @@ class BankAccountControllerTest extends AbstractControllerTest {
|
|||
private void assertThrowsFor(IAction<?> iAction) {
|
||||
assertThrows(ActionValidationException.class, () -> {
|
||||
try {
|
||||
perform(MockMvcRequestBuilders.post(REST_URL).contentType(MediaType.APPLICATION_JSON).content(writeValue(iAction)));
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(REST_URL).contentType(MediaType.APPLICATION_JSON).content(writeValue(iAction)));
|
||||
} catch (Exception e) {
|
||||
Throwable rootCause = NestedExceptionUtils.getRootCause(e);
|
||||
throw rootCause != null ? rootCause : e;
|
||||
|
|
|
|||
|
|
@ -1,26 +1,18 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.account.BankAccountController;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.impl.StateLoaderImpl;
|
||||
|
||||
@Configuration
|
||||
public class BankAccountControllerConfig {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("iOperator")
|
||||
private IOperator operator;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("stateLoaderImpl")
|
||||
private StateLoaderImpl stateLoader;
|
||||
|
||||
@Bean
|
||||
public BankAccountController createBankAccountController() {
|
||||
return new BankAccountController(operator, stateLoader);
|
||||
public BankAccountController createBankAccountController(IOperator operator) {
|
||||
return new BankAccountController(operator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,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.getOrCreateHazelcastInstance(cfg);
|
||||
hazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
|
||||
HazelcastHelper.otcSystem_setStorageState(true, hazelcastInstance);
|
||||
return new HazelcastService(taskExecutorHazelcastClientInitializer, taskExecutorIdGeneratorAwaiter, params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ public class IOperator {
|
|||
private HazelcastService hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
@Bean(name = "iOperator")
|
||||
@Bean
|
||||
public OperatorImpl createIOperator(Producer<String, Object> kafka) {
|
||||
return new OperatorImpl(kafka, hazelcastServiceTest);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue