Merge pull request #4833 from amit2103/BAEL-7608-1
[BAEL-7608] - Fixed spring-5-reactive integration tests
This commit is contained in:
commit
e6cea7449a
|
@ -34,8 +34,7 @@ public class FormHandler {
|
||||||
|
|
||||||
private AtomicLong extractData(List<DataBuffer> dataBuffers) {
|
private AtomicLong extractData(List<DataBuffer> dataBuffers) {
|
||||||
AtomicLong atomicLong = new AtomicLong(0);
|
AtomicLong atomicLong = new AtomicLong(0);
|
||||||
dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer()
|
dataBuffers.forEach(d -> atomicLong.addAndGet(d.readableByteCount()));
|
||||||
.array().length));
|
|
||||||
return atomicLong;
|
return atomicLong;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import org.apache.catalina.Context;
|
import org.apache.catalina.Context;
|
||||||
|
import org.apache.catalina.Wrapper;
|
||||||
import org.apache.catalina.startup.Tomcat;
|
import org.apache.catalina.startup.Tomcat;
|
||||||
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
|
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
|
||||||
import org.springframework.boot.web.server.WebServer;
|
import org.springframework.boot.web.server.WebServer;
|
||||||
|
@ -61,7 +62,8 @@ public class FunctionalWebApplication {
|
||||||
tomcat.setPort(9090);
|
tomcat.setPort(9090);
|
||||||
Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
|
Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
|
||||||
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
|
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
|
||||||
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
|
Wrapper servletWrapper = Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
|
||||||
|
servletWrapper.setAsyncSupported(true);
|
||||||
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
|
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
|
||||||
|
|
||||||
TomcatWebServer server = new TomcatWebServer(tomcat);
|
TomcatWebServer server = new TomcatWebServer(tomcat);
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@RestController
|
@RestController("FurtherCorsConfigsController-cors-on-global-config-and-more")
|
||||||
@RequestMapping("/cors-on-global-config-and-more")
|
@RequestMapping("/cors-on-global-config-and-more")
|
||||||
public class FurtherCorsConfigsController {
|
public class FurtherCorsConfigsController {
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@RestController
|
@RestController("RegularRestController-cors-on-global-config")
|
||||||
@RequestMapping("/cors-on-global-config")
|
@RequestMapping("/cors-on-global-config")
|
||||||
public class RegularRestController {
|
public class RegularRestController {
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.t
|
||||||
import static org.springframework.web.reactive.function.server.ServerResponse.ok;
|
import static org.springframework.web.reactive.function.server.ServerResponse.ok;
|
||||||
|
|
||||||
import org.apache.catalina.Context;
|
import org.apache.catalina.Context;
|
||||||
|
import org.apache.catalina.Wrapper;
|
||||||
import org.apache.catalina.startup.Tomcat;
|
import org.apache.catalina.startup.Tomcat;
|
||||||
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
|
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
|
||||||
import org.springframework.boot.web.server.WebServer;
|
import org.springframework.boot.web.server.WebServer;
|
||||||
|
@ -41,7 +42,8 @@ public class ExploreSpring5URLPatternUsingRouterFunctions {
|
||||||
tomcat.setPort(9090);
|
tomcat.setPort(9090);
|
||||||
Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
|
Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
|
||||||
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
|
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
|
||||||
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
|
Wrapper servletWrapper = Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
|
||||||
|
servletWrapper.setAsyncSupported(true);
|
||||||
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
|
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
|
||||||
|
|
||||||
TomcatWebServer server = new TomcatWebServer(tomcat);
|
TomcatWebServer server = new TomcatWebServer(tomcat);
|
||||||
|
|
|
@ -4,8 +4,12 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
|
||||||
public class EmployeeCreationEvent {
|
public class EmployeeCreationEvent {
|
||||||
private String employeeId;
|
private String employeeId;
|
||||||
private String creationTime;
|
private String creationTime;
|
||||||
|
public EmployeeCreationEvent(String employeeId, String creationTime) {
|
||||||
|
super();
|
||||||
|
this.employeeId = employeeId;
|
||||||
|
this.creationTime = creationTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@Component
|
@Component("EmployeeWebSocketHandler")
|
||||||
public class EmployeeWebSocketHandler implements WebSocketHandler {
|
public class EmployeeWebSocketHandler implements WebSocketHandler {
|
||||||
|
|
||||||
ObjectMapper om = new ObjectMapper();
|
ObjectMapper om = new ObjectMapper();
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
package com.baeldung.websocket;
|
package com.baeldung.websocket;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.reactive.HandlerMapping;
|
import org.springframework.web.reactive.HandlerMapping;
|
||||||
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
||||||
import org.springframework.web.reactive.socket.WebSocketHandler;
|
import org.springframework.web.reactive.socket.WebSocketHandler;
|
||||||
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter;
|
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ReactiveWebSocketConfiguration {
|
public class ReactiveWebSocketConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@Qualifier("ReactiveWebSocketHandler")
|
||||||
private WebSocketHandler webSocketHandler;
|
private WebSocketHandler webSocketHandler;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.time.Duration;
|
||||||
import static java.time.LocalDateTime.now;
|
import static java.time.LocalDateTime.now;
|
||||||
import static java.util.UUID.randomUUID;
|
import static java.util.UUID.randomUUID;
|
||||||
|
|
||||||
@Component
|
@Component("ReactiveWebSocketHandler")
|
||||||
public class ReactiveWebSocketHandler implements WebSocketHandler {
|
public class ReactiveWebSocketHandler implements WebSocketHandler {
|
||||||
|
|
||||||
private static final ObjectMapper json = new ObjectMapper();
|
private static final ObjectMapper json = new ObjectMapper();
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.baeldung.functional;
|
package com.baeldung.functional;
|
||||||
|
|
||||||
|
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
||||||
|
import static org.springframework.web.reactive.function.BodyInserters.fromResource;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -12,9 +15,6 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.reactive.function.BodyInserters;
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
|
|
||||||
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
|
|
||||||
import static org.springframework.web.reactive.function.BodyInserters.fromResource;
|
|
||||||
|
|
||||||
public class FunctionalWebApplicationIntegrationTest {
|
public class FunctionalWebApplicationIntegrationTest {
|
||||||
|
|
||||||
private static WebTestClient client;
|
private static WebTestClient client;
|
||||||
|
|
|
@ -6,8 +6,6 @@ import org.junit.Test;
|
||||||
import org.springframework.boot.web.server.WebServer;
|
import org.springframework.boot.web.server.WebServer;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
|
|
||||||
import com.baeldung.reactive.urlmatch.ExploreSpring5URLPatternUsingRouterFunctions;
|
|
||||||
|
|
||||||
public class ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest {
|
public class ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest {
|
||||||
|
|
||||||
private static WebTestClient client;
|
private static WebTestClient client;
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class SecurityIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenNoCredentials_thenRedirectToLogin() {
|
public void whenNoCredentials_thenRedirectToLogin() {
|
||||||
this.rest.get().uri("/").exchange().expectStatus().is3xxRedirection();
|
this.rest.get().uri("/").exchange().expectStatus().is4xxClientError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class WebTestClientIntegrationTest {
|
||||||
.uri("/resource")
|
.uri("/resource")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.is3xxRedirection()
|
.isOk()
|
||||||
.expectBody();
|
.expectBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Loading…
Reference in New Issue