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();
}
}
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);
}
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();
}
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();
}
Aggregations