|
|
@ -16,8 +16,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.web.reactive;
|
|
|
|
package org.springframework.boot.autoconfigure.web.reactive;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.validation.ValidatorFactory;
|
|
|
|
import javax.validation.ValidatorFactory;
|
|
|
|
|
|
|
|
|
|
|
@ -28,6 +31,7 @@ import org.springframework.beans.DirectFieldAccessor;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
|
|
|
|
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
|
|
|
|
|
|
|
|
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
|
|
|
|
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
|
|
|
import org.springframework.boot.web.codec.CodecCustomizer;
|
|
|
|
import org.springframework.boot.web.codec.CodecCustomizer;
|
|
|
|
import org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter;
|
|
|
|
import org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter;
|
|
|
@ -38,6 +42,7 @@ import org.springframework.core.Ordered;
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.format.support.FormattingConversionService;
|
|
|
|
import org.springframework.format.support.FormattingConversionService;
|
|
|
|
|
|
|
|
import org.springframework.http.CacheControl;
|
|
|
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
|
|
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
|
|
|
import org.springframework.http.server.reactive.HttpHandler;
|
|
|
|
import org.springframework.http.server.reactive.HttpHandler;
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
@ -58,6 +63,7 @@ import org.springframework.web.reactive.result.method.annotation.RequestMappingH
|
|
|
|
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
|
|
|
|
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
|
|
|
|
import org.springframework.web.reactive.result.view.ViewResolutionResultHandler;
|
|
|
|
import org.springframework.web.reactive.result.view.ViewResolutionResultHandler;
|
|
|
|
import org.springframework.web.reactive.result.view.ViewResolver;
|
|
|
|
import org.springframework.web.reactive.result.view.ViewResolver;
|
|
|
|
|
|
|
|
import org.springframework.web.util.pattern.PathPattern;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
@ -406,6 +412,53 @@ public class WebFluxAutoConfigurationTests {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void cachePeriod() {
|
|
|
|
|
|
|
|
this.contextRunner.withPropertyValues("spring.resources.cache.period:5")
|
|
|
|
|
|
|
|
.run(this::assertCachePeriod);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void cacheControl() {
|
|
|
|
|
|
|
|
this.contextRunner
|
|
|
|
|
|
|
|
.withPropertyValues("spring.resources.cache.cachecontrol.max-age:5",
|
|
|
|
|
|
|
|
"spring.resources.cache.cachecontrol.proxy-revalidate:true")
|
|
|
|
|
|
|
|
.run(this::assertCacheControl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void assertCachePeriod(AssertableReactiveWebApplicationContext context) {
|
|
|
|
|
|
|
|
Map<PathPattern, Object> handlerMap = getHandlerMap(
|
|
|
|
|
|
|
|
context.getBean("resourceHandlerMapping", HandlerMapping.class));
|
|
|
|
|
|
|
|
assertThat(handlerMap).hasSize(2);
|
|
|
|
|
|
|
|
for (Object handler : handlerMap.values()) {
|
|
|
|
|
|
|
|
if (handler instanceof ResourceWebHandler) {
|
|
|
|
|
|
|
|
assertThat(((ResourceWebHandler) handler).getCacheControl())
|
|
|
|
|
|
|
|
.isEqualToComparingFieldByField(
|
|
|
|
|
|
|
|
CacheControl.maxAge(5, TimeUnit.SECONDS));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<PathPattern, Object> getHandlerMap(HandlerMapping mapping) {
|
|
|
|
|
|
|
|
if (mapping instanceof SimpleUrlHandlerMapping) {
|
|
|
|
|
|
|
|
return ((SimpleUrlHandlerMapping) mapping).getHandlerMap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void assertCacheControl(AssertableReactiveWebApplicationContext context) {
|
|
|
|
|
|
|
|
Map<PathPattern, Object> handlerMap = getHandlerMap(
|
|
|
|
|
|
|
|
context.getBean("resourceHandlerMapping", HandlerMapping.class));
|
|
|
|
|
|
|
|
assertThat(handlerMap).hasSize(2);
|
|
|
|
|
|
|
|
for (Object handler : handlerMap.values()) {
|
|
|
|
|
|
|
|
if (handler instanceof ResourceWebHandler) {
|
|
|
|
|
|
|
|
assertThat(((ResourceWebHandler) handler).getCacheControl())
|
|
|
|
|
|
|
|
.isEqualToComparingFieldByField(CacheControl
|
|
|
|
|
|
|
|
.maxAge(5, TimeUnit.SECONDS).proxyRevalidate());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
protected static class CustomArgumentResolvers {
|
|
|
|
protected static class CustomArgumentResolvers {
|
|
|
|
|
|
|
|
|
|
|
|