Browse Source
Adapt the controller test base to Spring Boot 4
pull/16341/head
Viacheslav Klimov
2 months ago
Failed to extract signature
2 changed files with
8 additions and
5 deletions
-
application/src/test/java/org/thingsboard/server/controller/AbstractControllerTest.java
-
application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java
|
|
|
@ -7,9 +7,9 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.boot.test.context.SpringBootContextLoader; |
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
import org.springframework.boot.test.web.server.LocalServerPort; |
|
|
|
import org.springframework.context.annotation.ComponentScan; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.test.annotation.DirtiesContext; |
|
|
|
@ -63,7 +63,8 @@ public abstract class AbstractControllerTest extends AbstractNotifyEntityTest { |
|
|
|
|
|
|
|
public static final String WS_URL = "ws://localhost:"; |
|
|
|
|
|
|
|
@LocalServerPort |
|
|
|
// This class is also the context's configuration bean, which is created before the server port is known
|
|
|
|
@Value("${local.server.port:0}") |
|
|
|
protected int serverPort; |
|
|
|
|
|
|
|
protected volatile TbTestWebSocketClient wsClient; // lazy
|
|
|
|
|
|
|
|
@ -53,6 +53,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.rule.engine.api.MailService; |
|
|
|
import org.thingsboard.server.actors.DefaultTbActorSystem; |
|
|
|
@ -335,14 +336,15 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { |
|
|
|
}; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
void setConverters(HttpMessageConverter<?>[] converters) { |
|
|
|
void setConverters(RequestMappingHandlerAdapter handlerAdapter) { |
|
|
|
List<HttpMessageConverter<?>> converters = handlerAdapter.getMessageConverters(); |
|
|
|
|
|
|
|
this.mappingJackson2HttpMessageConverter = Arrays.stream(converters) |
|
|
|
this.mappingJackson2HttpMessageConverter = converters.stream() |
|
|
|
.filter(hmc -> hmc instanceof MappingJackson2HttpMessageConverter) |
|
|
|
.findAny() |
|
|
|
.get(); |
|
|
|
|
|
|
|
this.stringHttpMessageConverter = Arrays.stream(converters) |
|
|
|
this.stringHttpMessageConverter = converters.stream() |
|
|
|
.filter(hmc -> hmc instanceof StringHttpMessageConverter) |
|
|
|
.findAny() |
|
|
|
.get(); |
|
|
|
|