Search in sources :

Example 1 with ReactorHttpServer

use of org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class ContextPathIntegrationTests method multipleWebFluxApps.

@Test
void multipleWebFluxApps() throws Exception {
    AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext(WebAppConfig.class);
    AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext(WebAppConfig.class);
    HttpHandler webApp1Handler = WebHttpHandlerBuilder.applicationContext(context1).build();
    HttpHandler webApp2Handler = WebHttpHandlerBuilder.applicationContext(context2).build();
    ReactorHttpServer server = new ReactorHttpServer();
    server.registerHttpHandler("/webApp1", webApp1Handler);
    server.registerHttpHandler("/webApp2", webApp2Handler);
    server.afterPropertiesSet();
    server.start();
    try {
        RestTemplate restTemplate = new RestTemplate();
        String actual;
        String url = "http://localhost:" + server.getPort() + "/webApp1/test";
        actual = restTemplate.getForObject(url, String.class);
        assertThat(actual).isEqualTo("Tested in /webApp1");
        url = "http://localhost:" + server.getPort() + "/webApp2/test";
        actual = restTemplate.getForObject(url, String.class);
        assertThat(actual).isEqualTo("Tested in /webApp2");
    } finally {
        server.stop();
    }
}
Also used : HttpHandler(org.springframework.http.server.reactive.HttpHandler) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with ReactorHttpServer

use of org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class ZeroCopyIntegrationTests method zeroCopy.

@ParameterizedHttpServerTest
void zeroCopy(HttpServer httpServer) throws Exception {
    assumeTrue(httpServer instanceof ReactorHttpServer || httpServer instanceof UndertowHttpServer, "Zero-copy does not support Servlet");
    startServer(httpServer);
    URI url = new URI("http://localhost:" + port);
    RequestEntity<?> request = RequestEntity.get(url).build();
    ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
    assertThat(response.hasBody()).isTrue();
    assertThat(response.getHeaders().getContentLength()).isEqualTo(springLogoResource.contentLength());
    assertThat(response.getBody().length).isEqualTo(springLogoResource.contentLength());
    assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.IMAGE_PNG);
}
Also used : ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) RestTemplate(org.springframework.web.client.RestTemplate) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) URI(java.net.URI)

Example 3 with ReactorHttpServer

use of org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class HttpServerTests method start.

@BeforeEach
public void start() throws Exception {
    HttpHandler httpHandler = RouterFunctions.toHttpHandler(route(GET("/test"), request -> ServerResponse.ok().bodyValue("It works!")));
    this.server = new ReactorHttpServer();
    this.server.setHandler(httpHandler);
    this.server.afterPropertiesSet();
    this.server.start();
    this.client = WebTestClient.bindToServer().baseUrl("http://localhost:" + this.server.getPort()).build();
}
Also used : Test(org.junit.jupiter.api.Test) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) BeforeEach(org.junit.jupiter.api.BeforeEach) AfterEach(org.junit.jupiter.api.AfterEach) HttpHandler(org.springframework.http.server.reactive.HttpHandler) ServerResponse(org.springframework.web.reactive.function.server.ServerResponse) RouterFunctions(org.springframework.web.reactive.function.server.RouterFunctions) GET(org.springframework.web.reactive.function.server.RequestPredicates.GET) ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) RouterFunctions.route(org.springframework.web.reactive.function.server.RouterFunctions.route) HttpHandler(org.springframework.http.server.reactive.HttpHandler) ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ReactorHttpServer

use of org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class AbstractWebSocketIntegrationTests method arguments.

static Stream<Object[]> arguments() throws IOException {
    WebSocketClient[] clients = new WebSocketClient[] { new TomcatWebSocketClient(), new JettyWebSocketClient(), new ReactorNettyWebSocketClient(), new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY)) };
    Map<HttpServer, Class<?>> servers = new LinkedHashMap<>();
    servers.put(new TomcatHttpServer(TMP_DIR.getAbsolutePath(), WsContextListener.class), TomcatConfig.class);
    servers.put(new JettyHttpServer(), JettyConfig.class);
    servers.put(new ReactorHttpServer(), ReactorNettyConfig.class);
    servers.put(new UndertowHttpServer(), UndertowConfig.class);
    // Try each client once against each server..
    Flux<WebSocketClient> f1 = Flux.fromArray(clients).concatMap(c -> Mono.just(c).repeat(servers.size() - 1));
    Flux<Map.Entry<HttpServer, Class<?>>> f2 = Flux.fromIterable(servers.entrySet()).repeat(clients.length - 1).share();
    return Flux.zip(f1, f2.map(Map.Entry::getKey), f2.map(Map.Entry::getValue)).map(Tuple3::toArray).toStream();
}
Also used : WsContextListener(org.apache.tomcat.websocket.server.WsContextListener) ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) ReactorNettyWebSocketClient(org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient) TomcatWebSocketClient(org.springframework.web.reactive.socket.client.TomcatWebSocketClient) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) WebSocketClient(org.springframework.web.reactive.socket.client.WebSocketClient) ReactorNettyWebSocketClient(org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient) TomcatWebSocketClient(org.springframework.web.reactive.socket.client.TomcatWebSocketClient) UndertowWebSocketClient(org.springframework.web.reactive.socket.client.UndertowWebSocketClient) JettyWebSocketClient(org.springframework.web.reactive.socket.client.JettyWebSocketClient) LinkedHashMap(java.util.LinkedHashMap) JettyWebSocketClient(org.springframework.web.reactive.socket.client.JettyWebSocketClient) TomcatHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer) ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) HttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer) JettyHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) TomcatHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer) UndertowWebSocketClient(org.springframework.web.reactive.socket.client.UndertowWebSocketClient) OptionMap(org.xnio.OptionMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JettyHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer)

Aggregations

ReactorHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer)4 Test (org.junit.jupiter.api.Test)2 HttpHandler (org.springframework.http.server.reactive.HttpHandler)2 RestTemplate (org.springframework.web.client.RestTemplate)2 UndertowHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer)2 URI (java.net.URI)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 WsContextListener (org.apache.tomcat.websocket.server.WsContextListener)1 AfterEach (org.junit.jupiter.api.AfterEach)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)1 GET (org.springframework.web.reactive.function.server.RequestPredicates.GET)1 RouterFunctions (org.springframework.web.reactive.function.server.RouterFunctions)1 RouterFunctions.route (org.springframework.web.reactive.function.server.RouterFunctions.route)1 ServerResponse (org.springframework.web.reactive.function.server.ServerResponse)1 JettyWebSocketClient (org.springframework.web.reactive.socket.client.JettyWebSocketClient)1 ReactorNettyWebSocketClient (org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient)1 TomcatWebSocketClient (org.springframework.web.reactive.socket.client.TomcatWebSocketClient)1