fixing bug

This commit is contained in:
psemenkov 2022-12-01 14:16:39 +03:00
parent 0920088faf
commit 42529a8eed
12 changed files with 6867 additions and 52 deletions

View file

@ -87,6 +87,11 @@
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test-autoconfigure</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>

View file

@ -8,7 +8,6 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde
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.company.DeleteCompanyController;
import ru.spcex.clearing.backendapi.controller.queue.config.*;
@ -17,14 +16,14 @@ import java.util.concurrent.atomic.AtomicLong;
@SpringJUnitWebConfig(classes = {
WebConfig.class,
WebTestConfig.class,
IOperator.class,
StateLoaderImplConfig.class,
DeleteCompanyController.class,
BankAccountControllerConfig.class,
KafkaConfig.class,
KafkaTestConfig.class,
HazelcastServiceTestConfiguration.class,
Jackson2HttpConverterConfig.class})
Jackson2HttpConverterTestConfig.class})
public abstract class AbstractControllerTest {
protected static final AtomicLong currentId = new AtomicLong();
private static final CharacterEncodingFilter CHARACTER_ENCODING_FILTER = new CharacterEncodingFilter();

View file

@ -1,12 +1,15 @@
package ru.spcex.clearing.backendapi.controller.queue.account;
import com.hazelcast.core.IMap;
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.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@ -14,7 +17,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import ru.clearing.classes.statics.data.account.BankAccount;
import ru.spcex.clearing.backendapi.config.WebConfig;
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;
@ -22,11 +24,13 @@ import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountUp
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
import ru.spcex.clearing.backendapi.controller.response.cud.QueueSuccessResponse;
import ru.spcex.clearing.backendapi.controller.response.entity.account.BankAccountBackendGetById;
import ru.spcex.clearing.backendapi.controller.response.entity.account.BankAccountBackendGetFields;
import ru.spcex.clearing.backendapi.domain.actions.IAction;
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
import ru.spcex.clearing.backendapi.service.impl.StateLoaderImpl;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.ActionType;
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewRequest;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
import javax.annotation.PostConstruct;
import java.util.concurrent.atomic.AtomicLong;
@ -38,14 +42,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static ru.spcex.clearing.backendapi.controller.queue.utils.JsonUtil.writeValue;
@ContextConfiguration(classes = {
WebConfig.class,
WebTestConfig.class,
IOperator.class,
BankAccountControllerConfig.class,
KafkaConfig.class,
KafkaTestConfig.class,
HazelcastServiceTestConfiguration.class,
StateLoaderImplConfig.class,
Jackson2HttpConverterConfig.class})
Jackson2HttpConverterTestConfig.class})
@ExtendWith(SpringExtension.class)
@WebMvcTest(controllers = BankAccountController.class)
@TestPropertySource(properties = "spring.config.location=D:/repo/mfd/clearing/clearing-parent/backend-api/src/main/resources/")
class BankAccountControllerTest {
public static final MatcherFactory.Matcher<CudResponse> CUD_RESPONSE_MATCHER = MatcherFactory.usingIgnoringFieldsComparator(CudResponse.class);
@ -61,8 +67,8 @@ class BankAccountControllerTest {
private MockMvc mockMvc;
@Autowired
@Qualifier("stateLoaderImpl")
private StateLoaderImpl stateLoader;
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastServiceTest;
@Autowired
private WebApplicationContext webApplicationContext;
@ -104,19 +110,19 @@ class BankAccountControllerTest {
"01",
"11111222223333344444");
CudResponse extended = new CudResponse();
extended.setCode(0L);
extended.setMessage("success");
extended.setPayload(new QueueSuccessResponse(ActionType.NEW, currentId.getAndIncrement()));
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.NEW, currentId.getAndIncrement()));
//ACT
mockMvc.perform(MockMvcRequestBuilders.post(REST_URL)
.contentType(MediaType.APPLICATION_JSON)
.content(writeValue(bankAccountNewAction)))
.andDo(print())//output to the log request and response
// ASSERT
//ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(extended)));
.andExpect(content().json(writeValue(expected)));
}
/**
@ -174,10 +180,10 @@ class BankAccountControllerTest {
"01",
"11111222223333344444");
CudResponse extended = new CudResponse();
extended.setCode(0L);
extended.setMessage("success");
extended.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.UPDATE, currentId.getAndIncrement()));
//ACT
mockMvc.perform(MockMvcRequestBuilders.put(REST_URL + "0")
.contentType(MediaType.APPLICATION_JSON)
@ -186,7 +192,7 @@ class BankAccountControllerTest {
// ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(extended)));
.andExpect(content().json(writeValue(expected)));
}
@ -198,10 +204,10 @@ class BankAccountControllerTest {
@Test
void delete() throws Exception {
//ARRANGE
CudResponse extended = new CudResponse();
extended.setCode(0L);
extended.setMessage("success");
extended.setPayload(new QueueSuccessResponse(ActionType.DELETE, currentId.getAndIncrement()));
CudResponse expected = new CudResponse();
expected.setCode(0L);
expected.setMessage("success");
expected.setPayload(new QueueSuccessResponse(ActionType.DELETE, currentId.getAndIncrement()));
//ACT
mockMvc.perform(MockMvcRequestBuilders.delete(REST_URL + "0")
.contentType(MediaType.APPLICATION_JSON))
@ -209,37 +215,48 @@ class BankAccountControllerTest {
// ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(extended)));
.andExpect(content().json(writeValue(expected)));
}
@Test
void getById() throws Exception {
//ARRANGE
BankAccount predictableResult = new BankAccount();
predictableResult.setBankName("ooo tinkoff");
predictableResult.setBankIdentificationCode("99999");
predictableResult.setCorrespondentAccount("9294189285498598598");
predictableResult.setCorrespondentAccountName("BIK OF TINKOFF");
predictableResult.setCurrency("RUB");
predictableResult.setDestination("OOO ROGA I KOPITA");
predictableResult.setTaxpayerIdentificationNumber("848484848484");
predictableResult.setTaxRegistrationReasonCode("886886");
predictableResult.setAccount("123456789123");
predictableResult.setId(currentId.getAndIncrement());
BankAccount existBankAccount = new BankAccount();
existBankAccount.setBankName("ooo tinkoff");
existBankAccount.setBankIdentificationCode("99999");
existBankAccount.setCorrespondentAccount("9294189285498598598");
existBankAccount.setCorrespondentAccountName("BIK OF TINKOFF");
existBankAccount.setCurrency("RUB");
existBankAccount.setDestination("OOO ROGA I KOPITA");
existBankAccount.setTaxpayerIdentificationNumber("848484848484");
existBankAccount.setTaxRegistrationReasonCode("886886");
existBankAccount.setAccount("123456789123");
existBankAccount.setId(currentId.get());
// IMap<Long, ClearingMemberCategory> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_ClearingMemberCategory);
// iMap.put(ID, existsСlearingMemberCategory);
BankAccountBackendGetById extended = new BankAccountBackendGetById();
IMap<Long, BankAccount> iMap = hazelcastServiceTest.getHazelcast().getMap(IMDGDistributedNames.Map_BankAccount);
iMap.put(existBankAccount.getId(), existBankAccount);
BankAccountBackendGetById expected = new BankAccountBackendGetById();
BankAccountBackendGetFields payload = new BankAccountBackendGetFields();
payload.setBankName("ooo tinkoff");
payload.setBankIdentificationCode("99999");
payload.setCorrespondentAccount("9294189285498598598");
payload.setCorrespondentAccountName("BIK OF TINKOFF");
payload.setCurrency("RUB");
payload.setDestination("OOO ROGA I KOPITA");
payload.setTaxpayerIdentificationNumber("848484848484");
payload.setTaxRegistrationReasonCode("886886");
payload.setAccount("123456789123");
payload.setId(existBankAccount.getId());
expected.setPayload(payload);
//ACT
mockMvc.perform(MockMvcRequestBuilders.get(REST_URL + "0")
mockMvc.perform(MockMvcRequestBuilders.get(REST_URL + existBankAccount.getId())
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())//output to the log request and response
// ASSERT
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(content().json(writeValue(extended)));
.andExpect(content().json(writeValue(expected)));
}
@Test

View file

@ -17,7 +17,7 @@ public class IOperator {
private HazelcastService hazelcastServiceTest;
@Autowired
@Bean
@Bean("iOperatorTest")
public OperatorImpl createIOperator(Producer<String, Object> kafka, ActionValidationProvider validationProvider) {
return new OperatorImpl(kafka, hazelcastServiceTest, validationProvider);
}

View file

@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@Configuration
public class Jackson2HttpConverterConfig {
public class Jackson2HttpConverterTestConfig {
@Bean("customJsonHttpConverter")
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
return new MappingJackson2HttpMessageConverter(JacksonObjectMapper.getMapper());

View file

@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
import ru.spcex.clearing.platform.messaging.serialization.JsonSerializer;
@Configuration
public class KafkaConfig {
public class KafkaTestConfig {
@Bean
public Producer<String, Object> createProducer() {

View file

@ -4,19 +4,29 @@ 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 org.springframework.context.annotation.Import;
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
import ru.spcex.clearing.backendapi.meta.GetResponseFactoryTestConfiguration;
import ru.spcex.clearing.backendapi.meta.MetaServer;
import ru.spcex.clearing.backendapi.service.impl.StateLoaderImpl;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@Configuration
@Import({GetResponseFactoryTestConfiguration.class})
public class StateLoaderImplConfig {
@Autowired
@Qualifier("hazelcastServiceTest")
private HazelcastService hazelcastServiceTest;
@Autowired
@Bean(name = "responseFactoryTest")
public GetResponseFactory createStateLoaderImpl(@Qualifier("metaJsonTest") MetaServer meta) {
return new GetResponseFactory(meta);
}
@Bean(name = "stateLoaderImpl")
public StateLoaderImpl createIOperator() {
return new StateLoaderImpl(hazelcastServiceTest);
public StateLoaderImpl createStateLoaderImpl(@Qualifier("responseFactoryTest") GetResponseFactory responseFactory) {
return new StateLoaderImpl(hazelcastServiceTest, responseFactory);
}
}

View file

@ -0,0 +1,34 @@
package ru.spcex.clearing.backendapi.controller.queue.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import ru.spcex.clearing.backendapi.config.WebConfig;
import ru.spcex.clearing.backendapi.config.element.BackendApiSettings;
import ru.spcex.clearing.backendapi.security.element.SecuritySettings;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
@Configuration
@Import({BackendApiSettings.class})
public class WebTestConfig {
@Bean("webConfigTest")
public WebConfig createWebConfig(@Qualifier("customJsonHttpConverter") MappingJackson2HttpMessageConverter customJsonHttpConverter) throws IOException {
String rootPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
String appConfigPath = rootPath + "application.properties";
Properties appProps = new Properties();
appProps.load(new FileInputStream(appConfigPath));
BackendApiSettings backendSettings = new BackendApiSettings();
backendSettings.setSecurity(new SecuritySettings());
backendSettings.getSecurity().setSameSite(appProps.getProperty("backend-api.security.same-site", "no"));
return new WebConfig(customJsonHttpConverter, backendSettings);
}
}

View file

@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static ru.spcex.clearing.backendapi.controller.queue.config.Jackson2HttpConverterConfig.JacksonObjectMapper.getMapper;
import static ru.spcex.clearing.backendapi.controller.queue.config.Jackson2HttpConverterTestConfig.JacksonObjectMapper.getMapper;
public class JsonUtil {

View file

@ -24,7 +24,7 @@ public class GetResponseFactoryTestConfiguration {
return new PathResource(path);
}
// @Value("file:${spring.config.location}/meta.json")
// @Value("file:${spring.config.location}/meta.json")
// private Resource meta;
//
@Bean("metaJsonTestRaw")
@ -32,7 +32,8 @@ public class GetResponseFactoryTestConfiguration {
if (!meta.isReadable()) throw new IllegalStateException("cannot read meta.json from meta " + meta.getFile());
return Files.readString(meta.getFile().toPath());
}
//
//
@Autowired
@Bean("metaJsonTest")
public MetaServer metaServer(@Qualifier("metaJsonTestRaw") String metaJson) throws JsonProcessingException {

View file

@ -0,0 +1,51 @@
server.port=8080
server.servlet.context-path=/backend-api
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:keystore/client.p12
server.ssl.key-store-password=Aa123456
server.ssl.enabled=true
spring.main.web-application-type=servlet
backend-api.example-setting=test
backend-api.hazelcast.cluster-members=127.0.0.1:5701
backend-api.hazelcast.login=dev
backend-api.hazelcast.password=dev-pass
backend-api.kafka-producer.bootstrap-servers=localhost:9092
backend-api.kafka-producer.acks=all
backend-api.kafka-producer.retries=0
backend-api.kafka-producer.batch-size=16384
backend-api.kafka-producer.linger-ms=1
backend-api.kafka-producer.buffer-memory=33554432
backend-api.kafka-consumer.bootstrap-servers=localhost:9092
backend-api.kafka-consumer.group-id=dev-group-backend-api
backend-api.kafka-consumer.enable-auto-commit=true
backend-api.kafka-consumer.session-timeout-ms=30000
backend-api.kafka-consumer.auto-offset-reset=latest
backend-api.kafka-consumer.linger-ms=1
backend-api.kafka-consumer.buffer-memory=33554432
backend-api.security.authorization-disabled=false
##keycloak
##keycloak.auth-server-url=http://10.200.200.147:8080/
##keycloak.realm=master
##keycloak.resource=clearing
##keycloak.public-client=true
##keycloak.credentials.secret=WnOVCxcAmrUYc8IjiFHOuRif5Oesoyfr
##keycloak.security-constraints[0].authRoles[0]=admin
##keycloak.security-constraints[0].securityCollections[0].patterns[0]=/backend-api/users/*
#
#
##keycloak.policy-enforcer-config.paths[0].path=/*
##keycloak.policy-enforcer-config.paths[0].enforcementMode=ENFORCING
##keycloak.policy-enforcer-config.paths[1].path=/backend-api/anonymous/method1
##keycloak.policy-enforcer-config.paths[1].enforcementMode=DISABLED
##keycloak.security-constraints[1].auth-roles[0]=*
##keycloak.security-constraints[1].security-collections[0].patterns[0]=/backend-api/anonymous/method1
#
##keycloak.security-constraints[1].securityCollections[0].name=anonymous-methods
##keycloak.security-constraints[1].securityCollections[0].patterns[0]=/backend-api/anonymous/method1

File diff suppressed because it is too large Load diff