pull/5836/merge
Phillip Webb 9 years ago
parent 322b1b2f65
commit 6466c0afa5

@ -36,13 +36,14 @@ import org.springframework.session.config.annotation.web.http.EnableSpringHttpSe
class HashMapSessionConfiguration {
@Bean
public SessionRepository<ExpiringSession> sessionRepository(SessionProperties sessionProperties) {
MapSessionRepository sessionRepository = new MapSessionRepository();
Integer timeout = sessionProperties.getTimeout();
public SessionRepository<ExpiringSession> sessionRepository(
SessionProperties properties) {
MapSessionRepository repository = new MapSessionRepository();
Integer timeout = properties.getTimeout();
if (timeout != null) {
sessionRepository.setDefaultMaxInactiveInterval(timeout);
repository.setDefaultMaxInactiveInterval(timeout);
}
return sessionRepository;
return repository;
}
}

@ -30,4 +30,5 @@ import org.springframework.session.SessionRepository;
@ConditionalOnMissingBean(SessionRepository.class)
@Conditional(SessionCondition.class)
class NoOpSessionConfiguration {
}

@ -45,8 +45,9 @@ public abstract class AbstractSessionAutoConfigurationTests {
}
}
protected <T extends SessionRepository<?>> T validateSessionRepository(Class<T> type) {
SessionRepository cacheManager = this.context.getBean(SessionRepository.class);
protected <T extends SessionRepository<?>> T validateSessionRepository(
Class<T> type) {
SessionRepository<?> cacheManager = this.context.getBean(SessionRepository.class);
assertThat(cacheManager).as("Wrong session repository type").isInstanceOf(type);
return type.cast(cacheManager);
}

@ -55,8 +55,7 @@ public class SessionAutoConfigurationRedisTests
@Test
public void redisSessionStoreWithCustomizations() {
load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class),
"spring.session.store-type=redis",
"spring.session.redis.namespace=foo",
"spring.session.store-type=redis", "spring.session.redis.namespace=foo",
"spring.session.redis.flush-mode=immediate");
RedisOperationsSessionRepository repository = validateSessionRepository(
RedisOperationsSessionRepository.class);

@ -72,8 +72,7 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
@Test
public void hashMapSessionStoreCustomTimeout() {
load("spring.session.store-type=hash-map",
"server.session.timeout=3000");
load("spring.session.store-type=hash-map", "server.session.timeout=3000");
MapSessionRepository repository = validateSessionRepository(
MapSessionRepository.class);
assertThat(getSessionTimeout(repository)).isEqualTo(3000);
@ -81,8 +80,7 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
@Test
public void springSessionTimeoutIsNotAValidProperty() {
load("spring.session.store-type=hash-map",
"spring.session.timeout=3000");
load("spring.session.store-type=hash-map", "spring.session.timeout=3000");
MapSessionRepository repository = validateSessionRepository(
MapSessionRepository.class);
assertThat(getSessionTimeout(repository)).isNull();
@ -130,7 +128,8 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
"spring.session.store-type=hazelcast",
"spring.session.hazelcast.map-name=foo:bar:biz");
validateSessionRepository(MapSessionRepository.class);
HazelcastInstance hazelcastInstance = this.context.getBean(HazelcastInstance.class);
HazelcastInstance hazelcastInstance = this.context
.getBean(HazelcastInstance.class);
verify(hazelcastInstance, times(1)).getMap("foo:bar:biz");
}
@ -154,13 +153,13 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
.isEqualTo("foobar");
}
@Configuration
static class SessionRepositoryConfiguration {
@Bean
public SessionRepository<?> mySessionRepository() {
return new MapSessionRepository(Collections.<String, ExpiringSession>emptyMap());
return new MapSessionRepository(
Collections.<String, ExpiringSession>emptyMap());
}
}
@ -179,8 +178,9 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
static class HazelcastSpecificMap {
@Bean
@SuppressWarnings("unchecked")
public HazelcastInstance hazelcastInstance() {
IMap map = mock(IMap.class);
IMap<Object, Object> map = mock(IMap.class);
HazelcastInstance mock = mock(HazelcastInstance.class);
given(mock.getMap("foo:bar:biz")).willReturn(map);
return mock;

@ -84,11 +84,12 @@ public class FilterOrderingIntegrationTests {
private void load() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.session.store-type=hash-map");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.session.store-type=hash-map");
this.context.register(MockEmbeddedServletContainerConfiguration.class,
TestRedisConfiguration.class, WebMvcAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class,
SecurityAutoConfiguration.class, SessionAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class, SecurityAutoConfiguration.class,
SessionAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HttpEncodingAutoConfiguration.class);

Loading…
Cancel
Save