Search in sources :

Example 1 with HttpServer

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

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

the class WebSocketIntegrationTests method customHeader.

@ParameterizedWebSocketTest
void customHeader(WebSocketClient client, HttpServer server, Class<?> serverConfigClass) throws Exception {
    startServer(client, server, serverConfigClass);
    HttpHeaders headers = new HttpHeaders();
    headers.add("my-header", "my-value");
    AtomicReference<Object> headerRef = new AtomicReference<>();
    this.client.execute(getUrl("/custom-header"), headers, session -> session.receive().map(WebSocketMessage::getPayloadAsText).doOnNext(headerRef::set).doOnError(headerRef::set).then()).block(TIMEOUT);
    assertThat(headerRef.get()).isEqualTo("my-header:my-value");
}
Also used : Retry(reactor.util.retry.Retry) HttpHeaders(org.springframework.http.HttpHeaders) WebSocketClient(org.springframework.web.reactive.socket.client.WebSocketClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) ServerWebExchangeContextFilter(org.springframework.web.filter.reactive.ServerWebExchangeContextFilter) TomcatHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) List(java.util.List) WebFilter(org.springframework.web.server.WebFilter) Duration(java.time.Duration) Map(java.util.Map) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) HandlerMapping(org.springframework.web.reactive.HandlerMapping) ResponseCookie(org.springframework.http.ResponseCookie) SimpleUrlHandlerMapping(org.springframework.web.reactive.handler.SimpleUrlHandlerMapping) HttpHeaders(org.springframework.http.HttpHeaders) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 3 with HttpServer

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

the class MultipartIntegrationTests method transferTo.

@ParameterizedHttpServerTest
void transferTo(HttpServer httpServer) throws Exception {
    // TODO Determine why Undertow fails: https://github.com/spring-projects/spring-framework/issues/25310
    assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails with transferTo");
    startServer(httpServer);
    Flux<String> result = webClient.post().uri("/transferTo").bodyValue(generateBody()).retrieve().bodyToFlux(String.class);
    StepVerifier.create(result).consumeNextWith(filename -> verifyContents(Paths.get(filename), new ClassPathResource("foo.txt", MultipartHttpMessageReader.class))).consumeNextWith(filename -> verifyContents(Paths.get(filename), new ClassPathResource("logo.png", getClass()))).verifyComplete();
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) FilePart(org.springframework.http.codec.multipart.FilePart) FormFieldPart(org.springframework.http.codec.multipart.FormFieldPart) StepVerifier(reactor.test.StepVerifier) WebHttpHandlerBuilder(org.springframework.web.server.adapter.WebHttpHandlerBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClassPathResource(org.springframework.core.io.ClassPathResource) WebClient(org.springframework.web.reactive.function.client.WebClient) RequestPart(org.springframework.web.bind.annotation.RequestPart) DispatcherHandler(org.springframework.web.reactive.DispatcherHandler) HttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer) RequestBody(org.springframework.web.bind.annotation.RequestBody) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) EnableWebFlux(org.springframework.web.reactive.config.EnableWebFlux) Part(org.springframework.http.codec.multipart.Part) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) Schedulers(reactor.core.scheduler.Schedulers) MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) AbstractHttpHandlerIntegrationTests(org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpHandlerIntegrationTests) Path(java.nio.file.Path) Resource(org.springframework.core.io.Resource) PostMapping(org.springframework.web.bind.annotation.PostMapping) Files(java.nio.file.Files) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) HttpHandler(org.springframework.http.server.reactive.HttpHandler) Paths(java.nio.file.Paths) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) ResponseEntity(org.springframework.http.ResponseEntity) Bean(org.springframework.context.annotation.Bean) FileCopyUtils(org.springframework.util.FileCopyUtils) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

HttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer)3 List (java.util.List)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Bean (org.springframework.context.annotation.Bean)2 Configuration (org.springframework.context.annotation.Configuration)2 WebSocketClient (org.springframework.web.reactive.socket.client.WebSocketClient)2 TomcatHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer)2 UndertowHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1