diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java index d3aedd70a6a..600ae763a03 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/AbstractHttpHandlerIntegrationTests.java @@ -88,7 +88,7 @@ public abstract class AbstractHttpHandlerIntegrationTests { * set the number of buffered to an arbitrary number greater than N. * */ - public static Flux interval(Duration period, int count) { + public static Flux testInterval(Duration period, int count) { return Flux.interval(period).take(count).onBackpressureBuffer(count); } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java index d39d60a45cb..be544021697 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http.server.reactive; import java.net.URI; @@ -27,15 +28,13 @@ import reactor.core.publisher.Mono; import org.springframework.http.HttpCookie; import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseCookie; +import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.equalToIgnoringCase; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; /** * @author Rossen Stoyanchev @@ -43,11 +42,11 @@ import static org.junit.Assert.assertThat; @RunWith(Parameterized.class) public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests { - private CookieHandler cookieHandler; + private final CookieHandler cookieHandler = new CookieHandler(); + @Override protected HttpHandler createHttpHandler() { - this.cookieHandler = new CookieHandler(); return this.cookieHandler; } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java index dd0a4a5ea1a..cc9f16d4b5f 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,14 +26,16 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import static org.junit.Assert.assertArrayEquals; - +import static org.junit.Assert.*; +/** + * @author Arjen Poutsma + */ public class EchoHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { private static final int REQUEST_SIZE = 4096 * 3; - private Random rnd = new Random(); + private final Random rnd = new Random(); @Override diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java index 94ecdfeca12..2de9271c443 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,21 +28,23 @@ import org.springframework.http.server.reactive.bootstrap.ReactorHttpServer; import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assume.assumeFalse; +import static org.junit.Assert.*; +import static org.junit.Assume.*; /** * @author Arjen Poutsma */ public class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { - private ErrorHandler handler = new ErrorHandler(); + private final ErrorHandler handler = new ErrorHandler(); + @Override protected HttpHandler createHttpHandler() { return handler; } + @Test public void responseBodyError() throws Exception { // TODO: fix Reactor @@ -83,6 +85,7 @@ public class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegration assertEquals(HttpStatus.OK, response.getStatusCode()); } + private static class ErrorHandler implements HttpHandler { @Override @@ -101,6 +104,7 @@ public class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegration } } + private static final ResponseErrorHandler NO_OP_ERROR_HANDLER = new ResponseErrorHandler() { @Override diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java index 59789517842..94b4697153a 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,9 @@ import org.springframework.web.client.RestTemplate; import static org.junit.Assert.*; +/** + * @author Arjen Poutsma + */ public class RandomHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { public static final int REQUEST_SIZE = 4096 * 3; diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java index 41efd1a7527..367e5ea2561 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java @@ -28,6 +28,9 @@ import org.springframework.web.client.RestTemplate; import static org.junit.Assert.*; +/** + * @author Sebastien Deleuze + */ public class ServerHttpRequestIntegrationTests extends AbstractHttpHandlerIntegrationTests { @Override @@ -58,4 +61,5 @@ public class ServerHttpRequestIntegrationTests extends AbstractHttpHandlerIntegr return Mono.empty(); } } + } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java index b7bafdfe420..bc2c8fdc512 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,19 +21,16 @@ import java.nio.charset.StandardCharsets; import java.util.Random; import org.junit.Test; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.web.client.RestTemplate; import static org.junit.Assert.*; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - /** * @author Violeta Georgieva * @since 5.0 @@ -52,7 +49,6 @@ public class WriteOnlyHandlerIntegrationTests extends AbstractHttpHandlerIntegra return new WriteOnlyHandler(); } - @Test public void writeOnly() throws Exception { RestTemplate restTemplate = new RestTemplate(); @@ -66,7 +62,6 @@ public class WriteOnlyHandlerIntegrationTests extends AbstractHttpHandlerIntegra assertArrayEquals(body, response.getBody()); } - private byte[] randomBytes() { byte[] buffer = new byte[REQUEST_SIZE]; rnd.nextBytes(buffer); @@ -83,4 +78,5 @@ public class WriteOnlyHandlerIntegrationTests extends AbstractHttpHandlerIntegra return response.writeAndFlushWith(Flux.just(Flux.just(buffer))); } } + } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java index 35bdf8e8e4c..445d52f8151 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java @@ -32,9 +32,8 @@ import org.springframework.http.server.reactive.bootstrap.ReactorHttpServer; import org.springframework.http.server.reactive.bootstrap.UndertowHttpServer; import org.springframework.web.client.RestTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +import static org.junit.Assert.*; +import static org.junit.Assume.*; /** * @author Arjen Poutsma @@ -43,14 +42,15 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest private final ZeroCopyHandler handler = new ZeroCopyHandler(); + @Override protected HttpHandler createHttpHandler() { - return handler; + return this.handler; } + @Test public void zeroCopy() throws Exception { - // Zero-copy only does not support servlet assumeTrue(server instanceof ReactorHttpServer || server instanceof UndertowHttpServer); @@ -64,9 +64,9 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest assertEquals(logo.contentLength(), response.getHeaders().getContentLength()); assertEquals(logo.contentLength(), response.getBody().length); assertEquals(MediaType.IMAGE_PNG, response.getHeaders().getContentType()); - } + private static class ZeroCopyHandler implements HttpHandler { @Override @@ -85,4 +85,4 @@ public class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTest } } -} \ No newline at end of file +} diff --git a/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java index 102756f56d6..f5d6f2ac752 100644 --- a/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/server/session/WebSessionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,31 +38,22 @@ import org.springframework.web.server.WebHandler; import org.springframework.web.server.WebSession; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Integration tests for with a server-side session. + * * @author Rossen Stoyanchev */ public class WebSessionIntegrationTests extends AbstractHttpHandlerIntegrationTests { - private RestTemplate restTemplate; + private final RestTemplate restTemplate = new RestTemplate(); private DefaultWebSessionManager sessionManager; private TestWebHandler handler; - @Override - public void setup() throws Exception { - super.setup(); - this.restTemplate = new RestTemplate(); - } - @Override protected HttpHandler createHttpHandler() { this.sessionManager = new DefaultWebSessionManager(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java index 09bda723f84..567c791af39 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java @@ -123,7 +123,7 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest public Mono handle(ServerHttpRequest request, ServerHttpResponse response) { String path = request.getURI().getPath(); if (path.endsWith("write-and-flush")) { - Flux> responseBody = interval(Duration.ofMillis(50), 2) + Flux> responseBody = testInterval(Duration.ofMillis(50), 2) .map(l -> toDataBuffer("data" + l + "\n", response.bufferFactory())) .map(Flux::just); return response.writeAndFlushWith(responseBody.concatWith(Flux.never())); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java index 340ab32f59d..1f8d4ddbf31 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartIntegrationTests.java @@ -37,14 +37,18 @@ import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; -import static org.junit.Assert.assertEquals; -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; +import static org.junit.Assert.*; +import static org.springframework.web.reactive.function.server.RequestPredicates.*; +import static org.springframework.web.reactive.function.server.RouterFunctions.*; +/** + * @author Sebastien Deleuze + */ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegrationTests { private final WebClient webClient = WebClient.create(); + @Test public void multipartData() { Mono result = webClient @@ -87,6 +91,7 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration .andRoute(POST("/parts"), multipartHandler::parts); } + private static class MultipartHandler { public Mono multipartData(ServerRequest request) { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java index dfa3bd3979f..8ea48c3a2c6 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java @@ -31,7 +31,6 @@ import org.springframework.web.reactive.function.client.WebClient; import static org.junit.Assert.*; import static org.springframework.http.MediaType.*; -import static org.springframework.web.reactive.function.BodyExtractors.*; import static org.springframework.web.reactive.function.BodyInserters.*; import static org.springframework.web.reactive.function.server.RouterFunctions.*; @@ -43,6 +42,12 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn private WebClient webClient; + @Before + public void setup() throws Exception { + super.setup(); + this.webClient = WebClient.create("http://localhost:" + this.port); + } + @Override protected RouterFunction routerFunction() { SseHandler sseHandler = new SseHandler(); @@ -51,12 +56,6 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn .and(route(RequestPredicates.GET("/event"), sseHandler::sse)); } - @Before - public void setup() throws Exception { - super.setup(); - this.webClient = WebClient.create("http://localhost:" + this.port); - } - @Test public void sseAsString() { @@ -118,8 +117,7 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn private static class SseHandler { - private static final Flux INTERVAL = interval(Duration.ofMillis(100), 2); - + private static final Flux INTERVAL = testInterval(Duration.ofMillis(100), 2); Mono string(ServerRequest request) { return ServerResponse.ok() diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java index abdaf45bdbd..9ea01e4129d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,13 +39,12 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.DispatcherHandler; -import org.springframework.web.server.handler.ResponseStatusExceptionHandler; import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; import org.springframework.web.server.WebHandler; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; +import org.springframework.web.server.handler.ResponseStatusExceptionHandler; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Integration tests with requests mapped via @@ -66,6 +65,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler .build(); } + @Test public void testRequestToFooHandler() throws Exception { URI url = new URI("http://localhost:" + this.port + "/foo"); @@ -115,7 +115,6 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler @Configuration - @SuppressWarnings({"unused", "WeakerAccess"}) static class WebConfig { @Bean diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java index 9ee0e3ab56f..c82e8fc917b 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.method.annotation; import java.net.URI; @@ -31,9 +32,7 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.web.client.RestTemplate; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import static org.springframework.http.RequestEntity.get; -import static org.springframework.http.RequestEntity.options; -import static org.springframework.http.RequestEntity.post; +import static org.springframework.http.RequestEntity.*; /** * Base class for integration tests with {@code @RequestMapping methods}. diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java index c5ad949f8d3..3a8d3068270 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result.method.annotation; import org.junit.Test; @@ -29,7 +30,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.config.EnableWebFlux; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * {@code @RequestMapping} integration focusing on controller method parameters. @@ -42,7 +43,6 @@ import static org.junit.Assert.assertEquals; */ public class ControllerInputIntegrationTests extends AbstractRequestMappingIntegrationTests { - @Override protected ApplicationContext initApplicationContext() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); @@ -58,7 +58,7 @@ public class ControllerInputIntegrationTests extends AbstractRequestMappingInteg assertEquals(expected, performGet("/param?name=George", new HttpHeaders(), String.class).getBody()); } - @Test // SPR-15140 + @Test // SPR-15140 public void handleWithEncodedParam() throws Exception { String expected = "Hello + \u00e0!"; assertEquals(expected, performGet("/param?name=%20%2B+%C3%A0", new HttpHeaders(), String.class).getBody()); @@ -77,6 +77,7 @@ public class ControllerInputIntegrationTests extends AbstractRequestMappingInteg static class WebConfig { } + @RestController @SuppressWarnings("unused") private static class TestRestController { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java index bdb7cb90db0..eff3f066e7d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/CrossOriginAnnotationIntegrationTests.java @@ -41,9 +41,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.config.EnableWebFlux; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; /** * Integration tests with {@code @CrossOrigin} and {@code @RequestMapping} @@ -105,7 +103,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin ResponseEntity entity = performGet("/default", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("default", entity.getBody()); } @@ -116,7 +114,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); assertEquals(1800, entity.getHeaders().getAccessControlMaxAge()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); } @Test @@ -133,7 +131,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin ResponseEntity entity = performGet("/customized", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("http://site1.com", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals(-1, entity.getHeaders().getAccessControlMaxAge()); assertEquals("customized", entity.getBody()); } @@ -152,7 +150,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin entity.getHeaders().getAccessControlAllowHeaders().toArray()); assertArrayEquals(new String[] {"header3", "header4"}, entity.getHeaders().getAccessControlExposeHeaders().toArray()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals(123, entity.getHeaders().getAccessControlMaxAge()); } @@ -177,19 +175,19 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin ResponseEntity entity = performGet("/foo", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("foo", entity.getBody()); entity = performGet("/bar", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("*", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(false, entity.getHeaders().getAccessControlAllowCredentials()); + assertFalse(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("bar", entity.getBody()); entity = performGet("/baz", this.headers, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("http://site1.com", entity.getHeaders().getAccessControlAllowOrigin()); - assertEquals(true, entity.getHeaders().getAccessControlAllowCredentials()); + assertTrue(entity.getHeaders().getAccessControlAllowCredentials()); assertEquals("baz", entity.getBody()); } @@ -205,7 +203,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin entity.getHeaders().getAccessControlAllowMethods().toArray()); assertArrayEquals(new String[] {"header1"}, entity.getHeaders().getAccessControlAllowHeaders().toArray()); - assertEquals(true, entity.getHeaders().getAccessControlAllowCredentials()); + assertTrue(entity.getHeaders().getAccessControlAllowCredentials()); } @Test @@ -217,7 +215,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin assertEquals("http://site1.com", entity.getHeaders().getAccessControlAllowOrigin()); assertArrayEquals(new HttpMethod[] {HttpMethod.GET}, entity.getHeaders().getAccessControlAllowMethods().toArray()); - assertEquals(true, entity.getHeaders().getAccessControlAllowCredentials()); + assertTrue(entity.getHeaders().getAccessControlAllowCredentials()); } @@ -228,6 +226,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin static class WebConfig { } + @RestController @SuppressWarnings("unused") private static class MethodLevelController { @@ -254,23 +253,23 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin @CrossOrigin @GetMapping(path = "/ambiguous-header", headers = "header1=a") - public void ambigousHeader1a() { + public void ambiguousHeader1a() { } @CrossOrigin @GetMapping(path = "/ambiguous-header", headers = "header1=b") - public void ambigousHeader1b() { + public void ambiguousHeader1b() { } @CrossOrigin @GetMapping(path = "/ambiguous-produces", produces = "application/xml") - public String ambigousProducesXml() { + public String ambiguousProducesXml() { return ""; } @CrossOrigin @GetMapping(path = "/ambiguous-produces", produces = "application/json") - public String ambigousProducesJson() { + public String ambiguousProducesJson() { return "{}"; } @@ -299,6 +298,7 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin } } + @RestController @CrossOrigin(allowCredentials = "false") @SuppressWarnings("unused") diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java index 44cfd898b09..0f5b75c362d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java @@ -102,7 +102,7 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra @GetMapping(value = "/stream", produces = { APPLICATION_STREAM_JSON_VALUE, "application/stream+x-jackson-smile" }) Flux person() { - return interval(Duration.ofMillis(100), 50).map(l -> new Person("foo " + l)); + return testInterval(Duration.ofMillis(100), 50).map(l -> new Person("foo " + l)); } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java index 04c081e0588..f30799b72bd 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java @@ -73,8 +73,8 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq doTest("/mono-error", "Recovered from error: Argument"); } - @Test // SPR-16051 - public void exceptionAfterSeveralItems() throws Exception { + @Test // SPR-16051 + public void exceptionAfterSeveralItems() { try { performGet("/SPR-16051", new HttpHeaders(), String.class).getBody(); fail(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index b126b32d11a..b325ee0e085 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -86,7 +86,7 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr @GetMapping("/stream") public Publisher stream() { - return interval(Duration.ofMillis(50), 5); + return testInterval(Duration.ofMillis(50), 5); } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java index e9053df21fc..a62a9996dd1 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,7 @@ import org.springframework.web.reactive.config.WebFluxConfigurer; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.server.ServerWebExchange; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; /** * {@code @RequestMapping} integration tests with view resolution scenarios. @@ -78,10 +77,9 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques assertNull(response.getBody()); } - @Test // SPR-15291 + @Test // SPR-15291 public void redirect() throws Exception { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() { - @Override protected void prepareConnection(HttpURLConnection conn, String method) throws IOException { super.prepareConnection(conn, method); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index 932566a7f48..fe77ba79aca 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -57,6 +57,7 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { private WebClient webClient; + @Override @Before public void setup() throws Exception { @@ -64,7 +65,6 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { this.webClient = WebClient.create("http://localhost:" + this.port + "/sse"); } - @Override protected HttpHandler createHttpHandler() { this.wac = new AnnotationConfigApplicationContext(); @@ -177,7 +177,7 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { @RequestMapping("/sse") static class SseController { - private static final Flux INTERVAL = interval(Duration.ofMillis(100), 50); + private static final Flux INTERVAL = testInterval(Duration.ofMillis(100), 50); private MonoProcessor cancellation = MonoProcessor.create(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java index d0c1958fee5..dc5210e99c2 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,11 +39,11 @@ import org.springframework.web.reactive.config.WebFluxConfigurationSupport; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.result.method.annotation.AbstractRequestMappingIntegrationTests; -import org.springframework.web.server.i18n.LocaleContextResolver; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.i18n.FixedLocaleContextResolver; +import org.springframework.web.server.i18n.LocaleContextResolver; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * @author Sebastien Deleuze @@ -52,6 +52,15 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin private final WebClient webClient = WebClient.create(); + + @Override + protected ApplicationContext initApplicationContext() { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.register(WebConfig.class); + context.refresh(); + return context; + } + @Test public void fixedLocale() { Mono result = webClient @@ -67,14 +76,6 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin .verifyComplete(); } - @Override - protected ApplicationContext initApplicationContext() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(WebConfig.class); - context.refresh(); - return context; - } - @Configuration @ComponentScan(resourcePattern = "**/LocaleContextResolverIntegrationTests*.class") @@ -111,9 +112,9 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin return Mono.empty(); } } - } + @Controller @SuppressWarnings("unused") static class TestController { @@ -122,7 +123,6 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin public String foo() { return "foo"; } - } }