|  | 
| 16 | 16 | 
 | 
| 17 | 17 | package org.springframework.boot.autoconfigure.web.reactive; | 
| 18 | 18 | 
 | 
|  | 19 | +import java.util.Collections; | 
| 19 | 20 | import java.util.Date; | 
| 20 | 21 | import java.util.List; | 
|  | 22 | +import java.util.Map; | 
|  | 23 | +import java.util.concurrent.TimeUnit; | 
| 21 | 24 | 
 | 
| 22 | 25 | import javax.validation.ValidatorFactory; | 
| 23 | 26 | 
 | 
|  | 
| 28 | 31 | import org.springframework.boot.autoconfigure.AutoConfigurations; | 
| 29 | 32 | import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; | 
| 30 | 33 | import org.springframework.boot.autoconfigure.validation.ValidatorAdapter; | 
|  | 34 | +import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext; | 
| 31 | 35 | import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; | 
| 32 | 36 | import org.springframework.boot.web.codec.CodecCustomizer; | 
| 33 | 37 | import org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter; | 
|  | 
| 38 | 42 | import org.springframework.core.annotation.Order; | 
| 39 | 43 | import org.springframework.core.io.ClassPathResource; | 
| 40 | 44 | import org.springframework.format.support.FormattingConversionService; | 
|  | 45 | +import org.springframework.http.CacheControl; | 
| 41 | 46 | import org.springframework.http.codec.ServerCodecConfigurer; | 
| 42 | 47 | import org.springframework.http.server.reactive.HttpHandler; | 
| 43 | 48 | import org.springframework.test.util.ReflectionTestUtils; | 
|  | 
| 58 | 63 | import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping; | 
| 59 | 64 | import org.springframework.web.reactive.result.view.ViewResolutionResultHandler; | 
| 60 | 65 | import org.springframework.web.reactive.result.view.ViewResolver; | 
|  | 66 | +import org.springframework.web.util.pattern.PathPattern; | 
| 61 | 67 | 
 | 
| 62 | 68 | import static org.assertj.core.api.Assertions.assertThat; | 
| 63 | 69 | import static org.mockito.ArgumentMatchers.any; | 
| @@ -406,6 +412,53 @@ public void multipleWebFluxRegistrations() { | 
| 406 | 412 | 				}); | 
| 407 | 413 | 	} | 
| 408 | 414 | 
 | 
|  | 415 | +	@Test | 
|  | 416 | +	public void cachePeriod() { | 
|  | 417 | +		this.contextRunner.withPropertyValues("spring.resources.cache.period:5") | 
|  | 418 | +				.run(this::assertCachePeriod); | 
|  | 419 | +	} | 
|  | 420 | + | 
|  | 421 | +	@Test | 
|  | 422 | +	public void cacheControl() { | 
|  | 423 | +		this.contextRunner | 
|  | 424 | +				.withPropertyValues("spring.resources.cache.cachecontrol.max-age:5", | 
|  | 425 | +						"spring.resources.cache.cachecontrol.proxy-revalidate:true") | 
|  | 426 | +				.run(this::assertCacheControl); | 
|  | 427 | +	} | 
|  | 428 | + | 
|  | 429 | +	private void assertCachePeriod(AssertableReactiveWebApplicationContext context) { | 
|  | 430 | +		Map<PathPattern, Object> handlerMap = getHandlerMap( | 
|  | 431 | +				context.getBean("resourceHandlerMapping", HandlerMapping.class)); | 
|  | 432 | +		assertThat(handlerMap).hasSize(2); | 
|  | 433 | +		for (Object handler : handlerMap.values()) { | 
|  | 434 | +			if (handler instanceof ResourceWebHandler) { | 
|  | 435 | +				assertThat(((ResourceWebHandler) handler).getCacheControl()) | 
|  | 436 | +						.isEqualToComparingFieldByField( | 
|  | 437 | +								CacheControl.maxAge(5, TimeUnit.SECONDS)); | 
|  | 438 | +			} | 
|  | 439 | +		} | 
|  | 440 | +	} | 
|  | 441 | + | 
|  | 442 | +	private Map<PathPattern, Object> getHandlerMap(HandlerMapping mapping) { | 
|  | 443 | +		if (mapping instanceof SimpleUrlHandlerMapping) { | 
|  | 444 | +			return ((SimpleUrlHandlerMapping) mapping).getHandlerMap(); | 
|  | 445 | +		} | 
|  | 446 | +		return Collections.emptyMap(); | 
|  | 447 | +	} | 
|  | 448 | + | 
|  | 449 | +	private void assertCacheControl(AssertableReactiveWebApplicationContext context) { | 
|  | 450 | +		Map<PathPattern, Object> handlerMap = getHandlerMap( | 
|  | 451 | +				context.getBean("resourceHandlerMapping", HandlerMapping.class)); | 
|  | 452 | +		assertThat(handlerMap).hasSize(2); | 
|  | 453 | +		for (Object handler : handlerMap.values()) { | 
|  | 454 | +			if (handler instanceof ResourceWebHandler) { | 
|  | 455 | +				assertThat(((ResourceWebHandler) handler).getCacheControl()) | 
|  | 456 | +						.isEqualToComparingFieldByField(CacheControl | 
|  | 457 | +								.maxAge(5, TimeUnit.SECONDS).proxyRevalidate()); | 
|  | 458 | +			} | 
|  | 459 | +		} | 
|  | 460 | +	} | 
|  | 461 | + | 
| 409 | 462 | 	@Configuration | 
| 410 | 463 | 	protected static class CustomArgumentResolvers { | 
| 411 | 464 | 
 | 
|  | 
0 commit comments