Search in sources :

Example 1 with TomcatHttpServer

use of org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer 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)

Example 2 with TomcatHttpServer

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

the class ContextPathIntegrationTests method servletPathMapping.

@Test
void servletPathMapping() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebAppConfig.class);
    TomcatHttpServer server = new TomcatHttpServer();
    server.setContextPath("/app");
    server.setServletMapping("/api/*");
    HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
    server.setHandler(httpHandler);
    server.afterPropertiesSet();
    server.start();
    try {
        String url = "http://localhost:" + server.getPort() + "/app/api/test";
        String actual = new RestTemplate().getForObject(url, String.class);
        assertThat(actual).isEqualTo("Tested in /app/api");
    } finally {
        server.stop();
    }
}
Also used : TomcatHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer) HttpHandler(org.springframework.http.server.reactive.HttpHandler) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

TomcatHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 WsContextListener (org.apache.tomcat.websocket.server.WsContextListener)1 Test (org.junit.jupiter.api.Test)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 HttpHandler (org.springframework.http.server.reactive.HttpHandler)1 RestTemplate (org.springframework.web.client.RestTemplate)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 UndertowWebSocketClient (org.springframework.web.reactive.socket.client.UndertowWebSocketClient)1 WebSocketClient (org.springframework.web.reactive.socket.client.WebSocketClient)1 HttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer)1 JettyHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer)1 ReactorHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer)1 UndertowHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer)1 OptionMap (org.xnio.OptionMap)1