Browse Source

Polishing

pull/1331/merge
Juergen Hoeller 9 years ago
parent
commit
1ddf8ec625
  1. 7
      spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java
  2. 9
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonHintsIntegrationTests.java
  3. 7
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingDataBindingIntegrationTests.java
  4. 8
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java
  5. 10
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java
  6. 13
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java
  7. 16
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java

7
spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java

@ -19,7 +19,6 @@ package org.springframework.web.filter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
@ -72,8 +71,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
* Set whether the ETag value written to the response should be weak, as per RFC 7232. * Set whether the ETag value written to the response should be weak, as per RFC 7232.
* <p>Should be configured using an {@code <init-param>} for parameter name * <p>Should be configured using an {@code <init-param>} for parameter name
* "writeWeakETag" in the filter definition in {@code web.xml}. * "writeWeakETag" in the filter definition in {@code web.xml}.
* @see <a href="https://tools.ietf.org/html/rfc7232#section-2.3">RFC 7232 section 2.3</a>
* @since 4.3 * @since 4.3
* @see <a href="https://tools.ietf.org/html/rfc7232#section-2.3">RFC 7232 section 2.3</a>
*/ */
public void setWriteWeakETag(boolean writeWeakETag) { public void setWriteWeakETag(boolean writeWeakETag) {
this.writeWeakETag = writeWeakETag; this.writeWeakETag = writeWeakETag;
@ -89,8 +88,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
/** /**
* The default value is "false" so that the filter may delay the generation of * The default value is {@code false} so that the filter may delay the generation
* an ETag until the last asynchronously dispatched thread. * of an ETag until the last asynchronously dispatched thread.
*/ */
@Override @Override
protected boolean shouldNotFilterAsyncDispatch() { protected boolean shouldNotFilterAsyncDispatch() {

9
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonHintsIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -36,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
import static org.junit.Assert.*;
/** /**
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
@ -49,6 +50,7 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
return wac; return wac;
} }
@Test @Test
public void jsonViewResponse() throws Exception { public void jsonViewResponse() throws Exception {
String expected = "{\"withView1\":\"with\"}"; String expected = "{\"withView1\":\"with\"}";
@ -98,6 +100,7 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
static class WebConfig { static class WebConfig {
} }
@RestController @RestController
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static class JsonViewRestController { private static class JsonViewRestController {
@ -188,4 +191,4 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
} }
} }
} }

7
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingDataBindingIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,8 +42,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
/** /**
* Data binding and type conversion related integration tests for * Data binding and type conversion related integration tests for
@ -89,6 +88,7 @@ public class RequestMappingDataBindingIntegrationTests extends AbstractRequestMa
static class WebConfig { static class WebConfig {
} }
@RestController @RestController
@SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"}) @SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"})
private static class TestController { private static class TestController {
@ -120,6 +120,7 @@ public class RequestMappingDataBindingIntegrationTests extends AbstractRequestMa
} }
} }
private static class Foo { private static class Foo {
private final Long id; private final Long id;

8
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,8 +31,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
/** /**
* {@code @RequestMapping} integration tests with exception handling scenarios. * {@code @RequestMapping} integration tests with exception handling scenarios.
@ -41,7 +40,6 @@ import static org.junit.Assert.assertEquals;
*/ */
public class RequestMappingExceptionHandlingIntegrationTests extends AbstractRequestMappingIntegrationTests { public class RequestMappingExceptionHandlingIntegrationTests extends AbstractRequestMappingIntegrationTests {
@Override @Override
protected ApplicationContext initApplicationContext() { protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
@ -69,7 +67,6 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq
@ComponentScan(resourcePattern = "**/RequestMappingExceptionHandlingIntegrationTests$*.class") @ComponentScan(resourcePattern = "**/RequestMappingExceptionHandlingIntegrationTests$*.class")
@SuppressWarnings({"unused", "WeakerAccess"}) @SuppressWarnings({"unused", "WeakerAccess"})
static class WebConfig { static class WebConfig {
} }
@ -96,7 +93,6 @@ public class RequestMappingExceptionHandlingIntegrationTests extends AbstractReq
public ResponseEntity<Publisher<String>> handleStateException(IllegalStateException ex) { public ResponseEntity<Publisher<String>> handleStateException(IllegalStateException ex) {
return ResponseEntity.ok(Mono.just("Recovered from error: " + ex.getMessage())); return ResponseEntity.ok(Mono.just("Recovered from error: " + ex.getMessage()));
} }
} }
} }

10
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,9 +31,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/** /**
* Integration tests with {@code @RequestMapping} handler methods. * Integration tests with {@code @RequestMapping} handler methods.
@ -54,6 +52,7 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr
return wac; return wac;
} }
@Test @Test
public void handleWithParam() throws Exception { public void handleWithParam() throws Exception {
String expected = "Hello George!"; String expected = "Hello George!";
@ -86,6 +85,7 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr
static class WebConfig { static class WebConfig {
} }
@RestController @RestController
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static class TestRestController { private static class TestRestController {
@ -104,9 +104,9 @@ public class RequestMappingIntegrationTests extends AbstractRequestMappingIntegr
public Publisher<Foo> objectStreamResponseBody() { public Publisher<Foo> objectStreamResponseBody() {
return Flux.just(new Foo("bar")); return Flux.just(new Foo("bar"));
} }
} }
private static class Foo { private static class Foo {
private String name; private String name;

13
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,10 +39,7 @@ import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNull;
import static org.springframework.http.RequestEntity.get;
/** /**
* {@code @RequestMapping} integration tests with view resolution scenarios. * {@code @RequestMapping} integration tests with view resolution scenarios.
@ -51,7 +48,6 @@ import static org.springframework.http.RequestEntity.get;
*/ */
public class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappingIntegrationTests { public class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappingIntegrationTests {
@Override @Override
protected ApplicationContext initApplicationContext() { protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
@ -70,7 +66,7 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
@Test @Test
public void etagCheckWithNotModifiedResponse() throws Exception { public void etagCheckWithNotModifiedResponse() throws Exception {
URI uri = new URI("http://localhost:" + this.port + "/html"); URI uri = new URI("http://localhost:" + this.port + "/html");
RequestEntity<Void> request = get(uri).ifNoneMatch("\"deadb33f8badf00d\"").build(); RequestEntity<Void> request = RequestEntity.get(uri).ifNoneMatch("\"deadb33f8badf00d\"").build();
ResponseEntity<String> response = getRestTemplate().exchange(request, String.class); ResponseEntity<String> response = getRestTemplate().exchange(request, String.class);
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode()); assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
@ -95,9 +91,9 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
configurer.setTemplateLoaderPath("classpath*:org/springframework/web/reactive/view/freemarker/"); configurer.setTemplateLoaderPath("classpath*:org/springframework/web/reactive/view/freemarker/");
return configurer; return configurer;
} }
} }
@Controller @Controller
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static class TestController { private static class TestController {
@ -112,7 +108,6 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
model.addAttribute("hello", "Hello: " + name.orElse("<no name>") + "!"); model.addAttribute("hello", "Hello: " + name.orElse("<no name>") + "!");
return "test"; return "test";
} }
} }
} }

16
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java

@ -50,25 +50,27 @@ import static org.junit.Assert.*;
*/ */
public class ServletRequestMethodArgumentResolverTests { public class ServletRequestMethodArgumentResolverTests {
private final ServletRequestMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); private ServletRequestMethodArgumentResolver resolver;
private Method method;
private ModelAndViewContainer mavContainer; private ModelAndViewContainer mavContainer;
private MockHttpServletRequest servletRequest;
private ServletWebRequest webRequest; private ServletWebRequest webRequest;
private MockHttpServletRequest servletRequest; private Method method;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class, resolver = new ServletRequestMethodArgumentResolver();
HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class,
WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class);
mavContainer = new ModelAndViewContainer(); mavContainer = new ModelAndViewContainer();
servletRequest = new MockHttpServletRequest("GET", ""); servletRequest = new MockHttpServletRequest("GET", "");
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse()); webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class,
HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class,
WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class);
} }

Loading…
Cancel
Save