Polish
This commit is contained in:
parent
449515cecd
commit
3882552b43
|
|
@ -26,6 +26,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||
* @author Andy Wilkinson
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ManagementContextFactory {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -93,10 +93,8 @@ public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator
|
|||
@Override
|
||||
public Mono<Health> health() {
|
||||
return Flux.fromIterable(this.indicators.entrySet())
|
||||
.flatMap((entry) -> Mono.zip(
|
||||
Mono.just(entry.getKey()),
|
||||
entry.getValue().health().compose(this.timeoutCompose))
|
||||
)
|
||||
.flatMap((entry) -> Mono.zip(Mono.just(entry.getKey()),
|
||||
entry.getValue().health().compose(this.timeoutCompose)))
|
||||
.collectMap(Tuple2::getT1, Tuple2::getT2)
|
||||
.map(this.healthAggregator::aggregate);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ public final class StaticResourceRequest {
|
|||
|
||||
/**
|
||||
* Returns a matcher that includes all commonly used {@link Location Locations}. The
|
||||
* {@link StaticResourceRequestMatcher#excluding(Location, Location...) excluding} method
|
||||
* can be used to remove specific locations if required. For example:
|
||||
* {@link StaticResourceRequestMatcher#excluding(Location, Location...) excluding}
|
||||
* method can be used to remove specific locations if required. For example:
|
||||
* <pre class="code">
|
||||
* StaticResourceRequest.toCommonLocations().excluding(Location.CSS)
|
||||
* </pre>
|
||||
|
|
@ -140,8 +140,8 @@ public final class StaticResourceRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a new {@link StaticResourceRequestMatcher} based on this one but excluding the
|
||||
* specified locations.
|
||||
* Return a new {@link StaticResourceRequestMatcher} based on this one but
|
||||
* excluding the specified locations.
|
||||
* @param first the first location to exclude
|
||||
* @param rest additional locations to exclude
|
||||
* @return a new {@link StaticResourceRequestMatcher}
|
||||
|
|
@ -151,8 +151,8 @@ public final class StaticResourceRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a new {@link StaticResourceRequestMatcher} based on this one but excluding the
|
||||
* specified locations.
|
||||
* Return a new {@link StaticResourceRequestMatcher} based on this one but
|
||||
* excluding the specified locations.
|
||||
* @param locations the locations to exclude
|
||||
* @return a new {@link StaticResourceRequestMatcher}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public abstract class AbstractSessionAutoConfigurationTests {
|
||||
|
||||
protected <T extends SessionRepository<?>> T validateSessionRepository(
|
||||
AssertableWebApplicationContext context,
|
||||
Class<T> type) {
|
||||
AssertableWebApplicationContext context, Class<T> type) {
|
||||
assertThat(context).hasSingleBean(SessionRepository.class);
|
||||
SessionRepository<?> repository = context.getBean(SessionRepository.class);
|
||||
assertThat(repository).as("Wrong session repository type").isInstanceOf(type);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ public class SessionAutoConfigurationHazelcastTests
|
|||
.withConfiguration(AutoConfigurations.of(SessionAutoConfiguration.class))
|
||||
.withUserConfiguration(HazelcastConfiguration.class);
|
||||
|
||||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast")
|
||||
|
|
@ -60,25 +59,29 @@ public class SessionAutoConfigurationHazelcastTests
|
|||
|
||||
@Test
|
||||
public void customMapName() {
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast",
|
||||
"spring.session.hazelcast.map-name=foo:bar:biz").run((context) -> {
|
||||
validateSessionRepository(context, HazelcastSessionRepository.class);
|
||||
HazelcastInstance hazelcastInstance = context
|
||||
.getBean(HazelcastInstance.class);
|
||||
verify(hazelcastInstance, times(1)).getMap("foo:bar:biz");
|
||||
});
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=hazelcast",
|
||||
"spring.session.hazelcast.map-name=foo:bar:biz")
|
||||
.run((context) -> {
|
||||
validateSessionRepository(context, HazelcastSessionRepository.class);
|
||||
HazelcastInstance hazelcastInstance = context
|
||||
.getBean(HazelcastInstance.class);
|
||||
verify(hazelcastInstance, times(1)).getMap("foo:bar:biz");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customFlushMode() {
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast",
|
||||
"spring.session.hazelcast.flush-mode=immediate").run((context) -> {
|
||||
HazelcastSessionRepository repository = validateSessionRepository(context,
|
||||
HazelcastSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("hazelcastFlushMode"))
|
||||
.isEqualTo(HazelcastFlushMode.IMMEDIATE);
|
||||
});
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=hazelcast",
|
||||
"spring.session.hazelcast.flush-mode=immediate")
|
||||
.run((context) -> {
|
||||
HazelcastSessionRepository repository = validateSessionRepository(
|
||||
context, HazelcastSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("hazelcastFlushMode"))
|
||||
.isEqualTo(HazelcastFlushMode.IMMEDIATE);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
|||
|
|
@ -54,60 +54,63 @@ public class SessionAutoConfigurationJdbcTests
|
|||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(
|
||||
JdbcTemplateAutoConfiguration.class))
|
||||
this.contextRunner
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
|
||||
.withPropertyValues("spring.session.store-type=jdbc").run((context) -> {
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(context,
|
||||
JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName"))
|
||||
.isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
assertThat(context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from SPRING_SESSION")).isEmpty();
|
||||
});
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(
|
||||
context, JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||
.getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
assertThat(context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from SPRING_SESSION")).isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterOrderCanBeCustomized() {
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc",
|
||||
"spring.session.servlet.filter-order=123").run((context) -> {
|
||||
FilterRegistrationBean<?> registration = context
|
||||
.getBean(FilterRegistrationBean.class);
|
||||
assertThat(registration.getOrder()).isEqualTo(123);
|
||||
});
|
||||
"spring.session.servlet.filter-order=123").run((context) -> {
|
||||
FilterRegistrationBean<?> registration = context
|
||||
.getBean(FilterRegistrationBean.class);
|
||||
assertThat(registration.getOrder()).isEqualTo(123);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disableDatabaseInitializer() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.session.store-type=jdbc",
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc",
|
||||
"spring.session.jdbc.initialize-schema=never").run((context) -> {
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(context,
|
||||
JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName"))
|
||||
.isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.NEVER);
|
||||
this.thrown.expect(BadSqlGrammarException.class);
|
||||
context.getBean(JdbcOperations.class).queryForList(
|
||||
"select * from SPRING_SESSION");
|
||||
});
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(
|
||||
context, JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||
.getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.NEVER);
|
||||
this.thrown.expect(BadSqlGrammarException.class);
|
||||
context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from SPRING_SESSION");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customTableName() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.session.store-type=jdbc",
|
||||
"spring.session.jdbc.table-name=FOO_BAR",
|
||||
"spring.session.jdbc.schema=classpath:session/custom-schema-h2.sql")
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=jdbc",
|
||||
"spring.session.jdbc.table-name=FOO_BAR",
|
||||
"spring.session.jdbc.schema=classpath:session/custom-schema-h2.sql")
|
||||
.run((context) -> {
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(context,
|
||||
JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName"))
|
||||
.isEqualTo("FOO_BAR");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(
|
||||
context, JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("tableName")).isEqualTo("FOO_BAR");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||
.getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
assertThat(context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from FOO_BAR")).isEmpty();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ public class SessionAutoConfigurationRedisTests
|
|||
protected final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(SessionAutoConfiguration.class));
|
||||
|
||||
|
||||
@Test
|
||||
public void redisSessionStore() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
this.contextRunner
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.withPropertyValues("spring.session.store-type=redis")
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:created:",
|
||||
RedisFlushMode.ON_SAVE));
|
||||
|
|
@ -56,7 +56,8 @@ public class SessionAutoConfigurationRedisTests
|
|||
|
||||
@Test
|
||||
public void redisSessionStoreWithCustomizations() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
this.contextRunner
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.withPropertyValues("spring.session.store-type=redis",
|
||||
"spring.session.redis.namespace=foo",
|
||||
"spring.session.redis.flush-mode=immediate")
|
||||
|
|
@ -67,12 +68,12 @@ public class SessionAutoConfigurationRedisTests
|
|||
private ContextConsumer<AssertableWebApplicationContext> validateSpringSessionUsesRedis(
|
||||
String sessionCreatedChannelPrefix, RedisFlushMode flushMode) {
|
||||
return context -> {
|
||||
RedisOperationsSessionRepository repository = validateSessionRepository(context,
|
||||
RedisOperationsSessionRepository.class);
|
||||
RedisOperationsSessionRepository repository = validateSessionRepository(
|
||||
context, RedisOperationsSessionRepository.class);
|
||||
assertThat(repository.getSessionCreatedChannelPrefix())
|
||||
.isEqualTo(sessionCreatedChannelPrefix);
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("redisFlushMode"))
|
||||
.isEqualTo(flushMode);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("redisFlushMode")).isEqualTo(flushMode);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,10 +54,10 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|||
public void contextFailsIfStoreTypeNotSet() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"No Spring Session store is configured");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"set the 'spring.session.store-type' property");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("No Spring Session store is configured");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("set the 'spring.session.store-type' property");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -66,11 +66,12 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().isInstanceOf(BeanCreationException.class);
|
||||
assertThat(context).getFailure()
|
||||
.isInstanceOf(BeanCreationException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"No session repository could be auto-configured");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"session store type is 'jdbc'");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("session store type is 'jdbc'");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -85,35 +86,39 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|||
public void backOffIfSessionRepositoryIsPresent() {
|
||||
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
|
||||
.withPropertyValues("spring.session.store-type=redis").run((context) -> {
|
||||
MapSessionRepository repository = validateSessionRepository(context,
|
||||
MapSessionRepository.class);
|
||||
assertThat(context).getBean("mySessionRepository").isSameAs(repository);
|
||||
});
|
||||
MapSessionRepository repository = validateSessionRepository(context,
|
||||
MapSessionRepository.class);
|
||||
assertThat(context).getBean("mySessionRepository")
|
||||
.isSameAs(repository);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springSessionTimeoutIsNotAValidProperty() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.session.timeout=3000").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().isInstanceOf(BeanCreationException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining("Could not bind");
|
||||
});
|
||||
this.contextRunner.withPropertyValues("spring.session.timeout=3000")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.isInstanceOf(BeanCreationException.class);
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("Could not bind");
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void filterIsRegisteredWithAsyncErrorAndRequestDispatcherTypes() {
|
||||
this.contextRunner.withUserConfiguration(
|
||||
SessionRepositoryConfiguration.class).run((context) -> {
|
||||
FilterRegistrationBean<?> registration = context
|
||||
.getBean(FilterRegistrationBean.class);
|
||||
assertThat(registration.getFilter())
|
||||
.isSameAs(context.getBean(SessionRepositoryFilter.class));
|
||||
assertThat((EnumSet<DispatcherType>) ReflectionTestUtils.getField(registration,
|
||||
"dispatcherTypes")).containsOnly(DispatcherType.ASYNC,
|
||||
DispatcherType.ERROR, DispatcherType.REQUEST);
|
||||
});
|
||||
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
|
||||
.run((context) -> {
|
||||
FilterRegistrationBean<?> registration = context
|
||||
.getBean(FilterRegistrationBean.class);
|
||||
assertThat(registration.getFilter())
|
||||
.isSameAs(context.getBean(SessionRepositoryFilter.class));
|
||||
assertThat((EnumSet<DispatcherType>) ReflectionTestUtils
|
||||
.getField(registration, "dispatcherTypes")).containsOnly(
|
||||
DispatcherType.ASYNC, DispatcherType.ERROR,
|
||||
DispatcherType.REQUEST);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -131,13 +136,14 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
|||
@Test
|
||||
public void filterDispatcherTypesCanBeCustomized() {
|
||||
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
|
||||
.withPropertyValues("spring.session.servlet.filter-dispatcher-types=error, request")
|
||||
.withPropertyValues(
|
||||
"spring.session.servlet.filter-dispatcher-types=error, request")
|
||||
.run((context) -> {
|
||||
FilterRegistrationBean<?> registration = context
|
||||
.getBean(FilterRegistrationBean.class);
|
||||
assertThat((EnumSet<DispatcherType>) ReflectionTestUtils.getField(registration,
|
||||
"dispatcherTypes")).containsOnly(DispatcherType.ERROR,
|
||||
DispatcherType.REQUEST);
|
||||
assertThat((EnumSet<DispatcherType>) ReflectionTestUtils
|
||||
.getField(registration, "dispatcherTypes")).containsOnly(
|
||||
DispatcherType.ERROR, DispatcherType.REQUEST);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ public class ValidationAutoConfigurationTests {
|
|||
|
||||
static class TestBeanPostProcessor implements BeanPostProcessor {
|
||||
|
||||
private Set<String> postProcessed = new HashSet<String>();
|
||||
private Set<String> postProcessed = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String name) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue