Rename properties that have - in their prefix
Rename `reactive-repositories` to `reactiverepositories` and replace `spring.resources.cache-control` with `spring.resources.cache.control`. Fixes gh-11090
This commit is contained in:
@@ -39,7 +39,7 @@ import org.springframework.data.cassandra.repository.support.ReactiveCassandraRe
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ ReactiveSession.class, ReactiveCassandraRepository.class })
|
||||
@ConditionalOnProperty(prefix = "spring.data.cassandra.reactive-repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.data.cassandra.reactiverepositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnMissingBean(ReactiveCassandraRepositoryFactoryBean.class)
|
||||
@Import(CassandraReactiveRepositoriesAutoConfigureRegistrar.class)
|
||||
@AutoConfigureAfter(CassandraReactiveDataAutoConfiguration.class)
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRe
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Bucket.class, ReactiveCouchbaseRepository.class })
|
||||
@ConditionalOnProperty(prefix = "spring.data.couchbase.reactive-repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.data.couchbase.reactiverepositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnBean(ReactiveRepositoryOperationsMapping.class)
|
||||
@ConditionalOnMissingBean(ReactiveCouchbaseRepositoryFactoryBean.class)
|
||||
@Import(CouchbaseReactiveRepositoriesAutoConfigureRegistrar.class)
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.springframework.data.mongodb.repository.support.ReactiveMongoReposito
|
||||
@ConditionalOnClass({ MongoClient.class, ReactiveMongoRepository.class })
|
||||
@ConditionalOnMissingBean({ ReactiveMongoRepositoryFactoryBean.class,
|
||||
ReactiveMongoRepositoryConfigurationExtension.class })
|
||||
@ConditionalOnProperty(prefix = "spring.data.mongodb.reactive-repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.data.mongodb.reactiverepositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@Import(MongoReactiveRepositoriesAutoConfigureRegistrar.class)
|
||||
@AutoConfigureAfter(MongoReactiveDataAutoConfiguration.class)
|
||||
public class MongoReactiveRepositoriesAutoConfiguration {
|
||||
|
||||
@@ -48,20 +48,6 @@ public class ResourceProperties {
|
||||
*/
|
||||
private String[] staticLocations = CLASSPATH_RESOURCE_LOCATIONS;
|
||||
|
||||
/**
|
||||
* Cache period for the resources served by the resource handler. If a duration suffix
|
||||
* is not specified, seconds will be used. Can be overridden by the 'cache-control'
|
||||
* property.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration cachePeriod;
|
||||
|
||||
/**
|
||||
* Cache control HTTP headers, only allows valid directive combinations. Overrides the
|
||||
* 'cache-period' property.
|
||||
*/
|
||||
private CacheControlProperties cacheControl = new CacheControlProperties();
|
||||
|
||||
/**
|
||||
* Whether to enable default resource handling.
|
||||
*/
|
||||
@@ -69,6 +55,8 @@ public class ResourceProperties {
|
||||
|
||||
private final Chain chain = new Chain();
|
||||
|
||||
private final Cache cache = new Cache();
|
||||
|
||||
public String[] getStaticLocations() {
|
||||
return this.staticLocations;
|
||||
}
|
||||
@@ -86,22 +74,6 @@ public class ResourceProperties {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
public Duration getCachePeriod() {
|
||||
return this.cachePeriod;
|
||||
}
|
||||
|
||||
public void setCachePeriod(Duration cachePeriod) {
|
||||
this.cachePeriod = cachePeriod;
|
||||
}
|
||||
|
||||
public CacheControlProperties getCacheControl() {
|
||||
return this.cacheControl;
|
||||
}
|
||||
|
||||
public void setCacheControl(CacheControlProperties cacheControl) {
|
||||
this.cacheControl = cacheControl;
|
||||
}
|
||||
|
||||
public boolean isAddMappings() {
|
||||
return this.addMappings;
|
||||
}
|
||||
@@ -114,6 +86,10 @@ public class ResourceProperties {
|
||||
return this.chain;
|
||||
}
|
||||
|
||||
public Cache getCache() {
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for the Spring Resource Handling chain.
|
||||
*/
|
||||
@@ -292,204 +268,240 @@ public class ResourceProperties {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for the Cache Control HTTP header.
|
||||
* Cache configuration.
|
||||
*/
|
||||
public static class CacheControlProperties {
|
||||
public static class Cache {
|
||||
|
||||
/**
|
||||
* Maximum time the response should be cached, in seconds if no duration suffix is
|
||||
* not specified.
|
||||
* Cache period for the resources served by the resource handler. If a duration
|
||||
* suffix is not specified, seconds will be used. Can be overridden by the
|
||||
* 'spring.resources.cache.control' properties.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration maxAge;
|
||||
private Duration period;
|
||||
|
||||
/**
|
||||
* Indicate that the cached response can be reused only if re-validated with the
|
||||
* server.
|
||||
* Cache control HTTP headers, only allows valid directive combinations. Overrides
|
||||
* the 'spring.resources.cache.period' property.
|
||||
*/
|
||||
private Boolean noCache;
|
||||
private final Control control = new Control();
|
||||
|
||||
public Duration getPeriod() {
|
||||
return this.period;
|
||||
}
|
||||
|
||||
public void setPeriod(Duration period) {
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
public Control getControl() {
|
||||
return this.control;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate to not cache the response in any case.
|
||||
* Cache Control HTTP header configuration.
|
||||
*/
|
||||
private Boolean noStore;
|
||||
public static class Control {
|
||||
|
||||
/**
|
||||
* Indicate that once it has become stale, a cache must not use the response
|
||||
* without re-validating it with the server.
|
||||
*/
|
||||
private Boolean mustRevalidate;
|
||||
/**
|
||||
* Maximum time the response should be cached, in seconds if no duration
|
||||
* suffix is not specified.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration maxAge;
|
||||
|
||||
/**
|
||||
* Indicate intermediaries (caches and others) that they should not transform the
|
||||
* response content.
|
||||
*/
|
||||
private Boolean noTransform;
|
||||
/**
|
||||
* Indicate that the cached response can be reused only if re-validated with
|
||||
* the server.
|
||||
*/
|
||||
private Boolean noCache;
|
||||
|
||||
/**
|
||||
* Indicate that any cache may store the response.
|
||||
*/
|
||||
private Boolean cachePublic;
|
||||
/**
|
||||
* Indicate to not cache the response in any case.
|
||||
*/
|
||||
private Boolean noStore;
|
||||
|
||||
/**
|
||||
* Indicate that the response message is intended for a single user and must not
|
||||
* be stored by a shared cache.
|
||||
*/
|
||||
private Boolean cachePrivate;
|
||||
/**
|
||||
* Indicate that once it has become stale, a cache must not use the response
|
||||
* without re-validating it with the server.
|
||||
*/
|
||||
private Boolean mustRevalidate;
|
||||
|
||||
/**
|
||||
* Same meaning as the "must-revalidate" directive, except that it does not apply
|
||||
* to private caches.
|
||||
*/
|
||||
private Boolean proxyRevalidate;
|
||||
/**
|
||||
* Indicate intermediaries (caches and others) that they should not transform
|
||||
* the response content.
|
||||
*/
|
||||
private Boolean noTransform;
|
||||
|
||||
/**
|
||||
* Maximum time the response can be served after it becomes stale, in seconds if
|
||||
* no duration suffix is not specified.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration staleWhileRevalidate;
|
||||
/**
|
||||
* Indicate that any cache may store the response.
|
||||
*/
|
||||
private Boolean cachePublic;
|
||||
|
||||
/**
|
||||
* Maximum time the response may be used when errors are encountered, in seconds
|
||||
* if no duration suffix is not specified.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration staleIfError;
|
||||
/**
|
||||
* Indicate that the response message is intended for a single user and must
|
||||
* not be stored by a shared cache.
|
||||
*/
|
||||
private Boolean cachePrivate;
|
||||
|
||||
/**
|
||||
* Maximum time the response should be cached by shared caches, in seconds if no
|
||||
* duration suffix is not specified.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration sMaxAge;
|
||||
/**
|
||||
* Same meaning as the "must-revalidate" directive, except that it does not
|
||||
* apply to private caches.
|
||||
*/
|
||||
private Boolean proxyRevalidate;
|
||||
|
||||
public Duration getMaxAge() {
|
||||
return this.maxAge;
|
||||
}
|
||||
/**
|
||||
* Maximum time the response can be served after it becomes stale, in seconds
|
||||
* if no duration suffix is not specified.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration staleWhileRevalidate;
|
||||
|
||||
public void setMaxAge(Duration maxAge) {
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
/**
|
||||
* Maximum time the response may be used when errors are encountered, in
|
||||
* seconds if no duration suffix is not specified.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration staleIfError;
|
||||
|
||||
public Boolean getNoCache() {
|
||||
return this.noCache;
|
||||
}
|
||||
/**
|
||||
* Maximum time the response should be cached by shared caches, in seconds if
|
||||
* no duration suffix is not specified.
|
||||
*/
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration sMaxAge;
|
||||
|
||||
public void setNoCache(Boolean noCache) {
|
||||
this.noCache = noCache;
|
||||
}
|
||||
|
||||
public Boolean getNoStore() {
|
||||
return this.noStore;
|
||||
}
|
||||
|
||||
public void setNoStore(Boolean noStore) {
|
||||
this.noStore = noStore;
|
||||
}
|
||||
|
||||
public Boolean getMustRevalidate() {
|
||||
return this.mustRevalidate;
|
||||
}
|
||||
|
||||
public void setMustRevalidate(Boolean mustRevalidate) {
|
||||
this.mustRevalidate = mustRevalidate;
|
||||
}
|
||||
|
||||
public Boolean getNoTransform() {
|
||||
return this.noTransform;
|
||||
}
|
||||
|
||||
public void setNoTransform(Boolean noTransform) {
|
||||
this.noTransform = noTransform;
|
||||
}
|
||||
|
||||
public Boolean getCachePublic() {
|
||||
return this.cachePublic;
|
||||
}
|
||||
|
||||
public void setCachePublic(Boolean cachePublic) {
|
||||
this.cachePublic = cachePublic;
|
||||
}
|
||||
|
||||
public Boolean getCachePrivate() {
|
||||
return this.cachePrivate;
|
||||
}
|
||||
|
||||
public void setCachePrivate(Boolean cachePrivate) {
|
||||
this.cachePrivate = cachePrivate;
|
||||
}
|
||||
|
||||
public Boolean getProxyRevalidate() {
|
||||
return this.proxyRevalidate;
|
||||
}
|
||||
|
||||
public void setProxyRevalidate(Boolean proxyRevalidate) {
|
||||
this.proxyRevalidate = proxyRevalidate;
|
||||
}
|
||||
|
||||
public Duration getStaleWhileRevalidate() {
|
||||
return this.staleWhileRevalidate;
|
||||
}
|
||||
|
||||
public void setStaleWhileRevalidate(Duration staleWhileRevalidate) {
|
||||
this.staleWhileRevalidate = staleWhileRevalidate;
|
||||
}
|
||||
|
||||
public Duration getStaleIfError() {
|
||||
return this.staleIfError;
|
||||
}
|
||||
|
||||
public void setStaleIfError(Duration staleIfError) {
|
||||
this.staleIfError = staleIfError;
|
||||
}
|
||||
|
||||
public Duration getSMaxAge() {
|
||||
return this.sMaxAge;
|
||||
}
|
||||
|
||||
public void setSMaxAge(Duration sMaxAge) {
|
||||
this.sMaxAge = sMaxAge;
|
||||
}
|
||||
|
||||
public CacheControl toHttpCacheControl() {
|
||||
CacheControl cacheControl = createCacheControl();
|
||||
callIfTrue(this.mustRevalidate, cacheControl, CacheControl::mustRevalidate);
|
||||
callIfTrue(this.noTransform, cacheControl, CacheControl::noTransform);
|
||||
callIfTrue(this.cachePublic, cacheControl, CacheControl::cachePublic);
|
||||
callIfTrue(this.cachePrivate, cacheControl, CacheControl::cachePrivate);
|
||||
callIfTrue(this.proxyRevalidate, cacheControl, CacheControl::proxyRevalidate);
|
||||
if (this.staleWhileRevalidate != null) {
|
||||
cacheControl.staleWhileRevalidate(this.staleWhileRevalidate.getSeconds(),
|
||||
TimeUnit.SECONDS);
|
||||
public Duration getMaxAge() {
|
||||
return this.maxAge;
|
||||
}
|
||||
if (this.staleIfError != null) {
|
||||
cacheControl.staleIfError(this.staleIfError.getSeconds(),
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
if (this.sMaxAge != null) {
|
||||
cacheControl.sMaxAge(this.sMaxAge.getSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
return cacheControl;
|
||||
}
|
||||
|
||||
private CacheControl createCacheControl() {
|
||||
if (Boolean.TRUE.equals(this.noStore)) {
|
||||
return CacheControl.noStore();
|
||||
public void setMaxAge(Duration maxAge) {
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
if (Boolean.TRUE.equals(this.noCache)) {
|
||||
return CacheControl.noCache();
|
||||
}
|
||||
if (this.maxAge != null) {
|
||||
return CacheControl.maxAge(this.maxAge.getSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
return CacheControl.empty();
|
||||
}
|
||||
|
||||
private <T> void callIfTrue(Boolean property, T instance, Consumer<T> call) {
|
||||
if (Boolean.TRUE.equals(property)) {
|
||||
call.accept(instance);
|
||||
public Boolean getNoCache() {
|
||||
return this.noCache;
|
||||
}
|
||||
|
||||
public void setNoCache(Boolean noCache) {
|
||||
this.noCache = noCache;
|
||||
}
|
||||
|
||||
public Boolean getNoStore() {
|
||||
return this.noStore;
|
||||
}
|
||||
|
||||
public void setNoStore(Boolean noStore) {
|
||||
this.noStore = noStore;
|
||||
}
|
||||
|
||||
public Boolean getMustRevalidate() {
|
||||
return this.mustRevalidate;
|
||||
}
|
||||
|
||||
public void setMustRevalidate(Boolean mustRevalidate) {
|
||||
this.mustRevalidate = mustRevalidate;
|
||||
}
|
||||
|
||||
public Boolean getNoTransform() {
|
||||
return this.noTransform;
|
||||
}
|
||||
|
||||
public void setNoTransform(Boolean noTransform) {
|
||||
this.noTransform = noTransform;
|
||||
}
|
||||
|
||||
public Boolean getCachePublic() {
|
||||
return this.cachePublic;
|
||||
}
|
||||
|
||||
public void setCachePublic(Boolean cachePublic) {
|
||||
this.cachePublic = cachePublic;
|
||||
}
|
||||
|
||||
public Boolean getCachePrivate() {
|
||||
return this.cachePrivate;
|
||||
}
|
||||
|
||||
public void setCachePrivate(Boolean cachePrivate) {
|
||||
this.cachePrivate = cachePrivate;
|
||||
}
|
||||
|
||||
public Boolean getProxyRevalidate() {
|
||||
return this.proxyRevalidate;
|
||||
}
|
||||
|
||||
public void setProxyRevalidate(Boolean proxyRevalidate) {
|
||||
this.proxyRevalidate = proxyRevalidate;
|
||||
}
|
||||
|
||||
public Duration getStaleWhileRevalidate() {
|
||||
return this.staleWhileRevalidate;
|
||||
}
|
||||
|
||||
public void setStaleWhileRevalidate(Duration staleWhileRevalidate) {
|
||||
this.staleWhileRevalidate = staleWhileRevalidate;
|
||||
}
|
||||
|
||||
public Duration getStaleIfError() {
|
||||
return this.staleIfError;
|
||||
}
|
||||
|
||||
public void setStaleIfError(Duration staleIfError) {
|
||||
this.staleIfError = staleIfError;
|
||||
}
|
||||
|
||||
public Duration getSMaxAge() {
|
||||
return this.sMaxAge;
|
||||
}
|
||||
|
||||
public void setSMaxAge(Duration sMaxAge) {
|
||||
this.sMaxAge = sMaxAge;
|
||||
}
|
||||
|
||||
public CacheControl toHttpCacheControl() {
|
||||
CacheControl cacheControl = createCacheControl();
|
||||
callIfTrue(this.mustRevalidate, cacheControl,
|
||||
CacheControl::mustRevalidate);
|
||||
callIfTrue(this.noTransform, cacheControl, CacheControl::noTransform);
|
||||
callIfTrue(this.cachePublic, cacheControl, CacheControl::cachePublic);
|
||||
callIfTrue(this.cachePrivate, cacheControl, CacheControl::cachePrivate);
|
||||
callIfTrue(this.proxyRevalidate, cacheControl,
|
||||
CacheControl::proxyRevalidate);
|
||||
if (this.staleWhileRevalidate != null) {
|
||||
cacheControl.staleWhileRevalidate(
|
||||
this.staleWhileRevalidate.getSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
if (this.staleIfError != null) {
|
||||
cacheControl.staleIfError(this.staleIfError.getSeconds(),
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
if (this.sMaxAge != null) {
|
||||
cacheControl.sMaxAge(this.sMaxAge.getSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
return cacheControl;
|
||||
}
|
||||
|
||||
private CacheControl createCacheControl() {
|
||||
if (Boolean.TRUE.equals(this.noStore)) {
|
||||
return CacheControl.noStore();
|
||||
}
|
||||
if (Boolean.TRUE.equals(this.noCache)) {
|
||||
return CacheControl.noCache();
|
||||
}
|
||||
if (this.maxAge != null) {
|
||||
return CacheControl.maxAge(this.maxAge.getSeconds(),
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
return CacheControl.empty();
|
||||
}
|
||||
|
||||
private <T> void callIfTrue(Boolean property, T instance, Consumer<T> call) {
|
||||
if (Boolean.TRUE.equals(property)) {
|
||||
call.accept(instance);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class WebFluxAutoConfiguration {
|
||||
logger.debug("Default resource handling disabled");
|
||||
return;
|
||||
}
|
||||
Duration cachePeriod = this.resourceProperties.getCachePeriod();
|
||||
Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
ResourceHandlerRegistration registration = registry
|
||||
.addResourceHandler("/webjars/**")
|
||||
|
||||
@@ -306,8 +306,8 @@ public class WebMvcAutoConfiguration {
|
||||
logger.debug("Default resource handling disabled");
|
||||
return;
|
||||
}
|
||||
Duration cachePeriod = this.resourceProperties.getCachePeriod();
|
||||
CacheControl cacheControl = this.resourceProperties.getCacheControl()
|
||||
Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
|
||||
CacheControl cacheControl = this.resourceProperties.getCache().getControl()
|
||||
.toHttpCacheControl();
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
customizeResourceHandlerRegistration(
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
"defaultValue": "none"
|
||||
},
|
||||
{
|
||||
"name": "spring.data.cassandra.reactive-repositories.enabled",
|
||||
"name": "spring.data.cassandra.reactiverepositories.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to enable Cassandra reactive repositories.",
|
||||
"defaultValue": true
|
||||
@@ -110,7 +110,7 @@
|
||||
"defaultValue": "read-your-own-writes"
|
||||
},
|
||||
{
|
||||
"name": "spring.data.couchbase.reactive-repositories.enabled",
|
||||
"name": "spring.data.couchbase.reactiverepositories.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to enable Couchbase reactive repositories.",
|
||||
"defaultValue": true
|
||||
@@ -140,7 +140,7 @@
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "spring.data.mongodb.reactive-repositories.enabled",
|
||||
"name": "spring.data.mongodb.reactiverepositories.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to enable Mongo reactive repositories.",
|
||||
"defaultValue": true
|
||||
@@ -1197,6 +1197,15 @@
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.resources.cach-period",
|
||||
"type": "java.lang.Integer",
|
||||
"description": "Cache period for the resources served by the resource handler. If a duration suffix is not specified, seconds will be used.",
|
||||
"deprecation": {
|
||||
"replacement": "spring.resources.cach-period",
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.sendgrid.password",
|
||||
"type": "java.lang.String",
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CouchbaseReactiveRepositoriesAutoConfigurationTests {
|
||||
@Test
|
||||
public void disableReactiveRepository() {
|
||||
load(DefaultConfiguration.class,
|
||||
"spring.data.couchbase.reactive-repositories.enabled=false",
|
||||
"spring.data.couchbase.reactiverepositories.enabled=false",
|
||||
"spring.data.couchbase.repositories.enabled=false");
|
||||
assertThat(this.context.getBeansOfType(ReactiveCityRepository.class)).hasSize(0);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.autoconfigure.web.ResourceProperties.CacheControlProperties;
|
||||
import org.springframework.boot.autoconfigure.web.ResourceProperties.Cache;
|
||||
import org.springframework.boot.testsupport.assertj.Matched;
|
||||
import org.springframework.http.CacheControl;
|
||||
|
||||
@@ -79,28 +79,24 @@ public class ResourcePropertiesTests {
|
||||
|
||||
@Test
|
||||
public void emptyCacheControl() {
|
||||
CacheControlProperties cacheControlProperties = new CacheControlProperties();
|
||||
this.properties.setCacheControl(cacheControlProperties);
|
||||
CacheControl cacheControl = this.properties.getCacheControl()
|
||||
CacheControl cacheControl = this.properties.getCache().getControl()
|
||||
.toHttpCacheControl();
|
||||
assertThat(cacheControl.getHeaderValue()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheControlAllPropertiesSet() {
|
||||
CacheControlProperties cacheControlProperties = new CacheControlProperties();
|
||||
cacheControlProperties.setMaxAge(Duration.ofSeconds(4));
|
||||
cacheControlProperties.setCachePrivate(true);
|
||||
cacheControlProperties.setCachePublic(true);
|
||||
cacheControlProperties.setMustRevalidate(true);
|
||||
cacheControlProperties.setNoTransform(true);
|
||||
cacheControlProperties.setProxyRevalidate(true);
|
||||
cacheControlProperties.setSMaxAge(Duration.ofSeconds(5));
|
||||
cacheControlProperties.setStaleIfError(Duration.ofSeconds(6));
|
||||
cacheControlProperties.setStaleWhileRevalidate(Duration.ofSeconds(7));
|
||||
this.properties.setCacheControl(cacheControlProperties);
|
||||
CacheControl cacheControl = this.properties.getCacheControl()
|
||||
.toHttpCacheControl();
|
||||
Cache.Control properties = this.properties.getCache().getControl();
|
||||
properties.setMaxAge(Duration.ofSeconds(4));
|
||||
properties.setCachePrivate(true);
|
||||
properties.setCachePublic(true);
|
||||
properties.setMustRevalidate(true);
|
||||
properties.setNoTransform(true);
|
||||
properties.setProxyRevalidate(true);
|
||||
properties.setSMaxAge(Duration.ofSeconds(5));
|
||||
properties.setStaleIfError(Duration.ofSeconds(6));
|
||||
properties.setStaleWhileRevalidate(Duration.ofSeconds(7));
|
||||
CacheControl cacheControl = properties.toHttpCacheControl();
|
||||
assertThat(cacheControl.getHeaderValue()).isEqualTo(
|
||||
"max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate,"
|
||||
+ " s-maxage=5, stale-if-error=6, stale-while-revalidate=7");
|
||||
@@ -108,12 +104,10 @@ public class ResourcePropertiesTests {
|
||||
|
||||
@Test
|
||||
public void invalidCacheControlCombination() {
|
||||
CacheControlProperties cacheControlProperties = new CacheControlProperties();
|
||||
cacheControlProperties.setMaxAge(Duration.ofSeconds(4));
|
||||
cacheControlProperties.setNoStore(true);
|
||||
this.properties.setCacheControl(cacheControlProperties);
|
||||
CacheControl cacheControl = this.properties.getCacheControl()
|
||||
.toHttpCacheControl();
|
||||
Cache.Control properties = this.properties.getCache().getControl();
|
||||
properties.setMaxAge(Duration.ofSeconds(4));
|
||||
properties.setNoStore(true);
|
||||
CacheControl cacheControl = properties.toHttpCacheControl();
|
||||
assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store");
|
||||
}
|
||||
|
||||
|
||||
@@ -711,7 +711,7 @@ public class WebMvcAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void cachePeriod() throws Exception {
|
||||
this.contextRunner.withPropertyValues("spring.resources.cache-period:5")
|
||||
this.contextRunner.withPropertyValues("spring.resources.cache.period:5")
|
||||
.run((context) -> assertCachePeriod(context));
|
||||
}
|
||||
|
||||
@@ -733,8 +733,8 @@ public class WebMvcAutoConfigurationTests {
|
||||
@Test
|
||||
public void cacheControl() throws Exception {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.resources.cache-control.max-age:5",
|
||||
"spring.resources.cache-control.proxy-revalidate:true")
|
||||
.withPropertyValues("spring.resources.cache.control.max-age:5",
|
||||
"spring.resources.cache.control.proxy-revalidate:true")
|
||||
.run((context) -> assertCacheControl(context));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user