Enable SSDG to be configured via spring-session.properties defined and resolvable in the application classpath.
Resolves gh-55.
This commit is contained in:
@@ -111,6 +111,7 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.apache.geode.cache.client.ClientRegionShortcut
|
||||
* @see org.apache.geode.cache.client.Pool
|
||||
* @see org.apache.geode.cache.query.Index
|
||||
* @see org.apache.geode.pdx.PdxSerializer
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor
|
||||
* @see org.springframework.context.annotation.Bean
|
||||
@@ -118,7 +119,12 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.context.annotation.DependsOn
|
||||
* @see org.springframework.context.annotation.Import
|
||||
* @see org.springframework.context.annotation.ImportAware
|
||||
* @see org.springframework.context.annotation.Profile
|
||||
* @see org.springframework.core.annotation.AnnotationAttributes
|
||||
* @see org.springframework.core.env.ConfigurableEnvironment
|
||||
* @see org.springframework.core.env.Environment
|
||||
* @see org.springframework.core.env.PropertiesPropertySource
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.core.type.AnnotationMetadata
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.GemfireOperations
|
||||
@@ -131,16 +137,22 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.AbstractGemFireHttpSessionConfiguration
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionCacheTypeAwareRegionFactoryBean
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionAttributesIndexFactoryBean
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionCacheTypeAwareRegionFactoryBean
|
||||
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SpringSessionGemFireConfigurer
|
||||
* @see org.springframework.session.data.gemfire.expiration.SessionExpirationPolicy
|
||||
* @see org.springframework.session.data.gemfire.expiration.config.SessionExpirationTimeoutAwareBeanPostProcessor
|
||||
* @see org.springframework.session.data.gemfire.expiration.support.SessionExpirationPolicyCustomExpiryAdapter
|
||||
* @see org.springframework.session.data.gemfire.serialization.SessionSerializer
|
||||
* @see org.springframework.session.data.gemfire.serialization.data.provider.DataSerializableSessionSerializer
|
||||
* @see org.springframework.session.data.gemfire.serialization.data.support.DataSerializerSessionSerializerAdapter
|
||||
* @see org.springframework.session.data.gemfire.serialization.pdx.provider.PdxSerializableSessionSerializer
|
||||
* @see org.springframework.session.data.gemfire.serialization.pdx.support.PdxSerializerSessionSerializerAdapter
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Configuration
|
||||
@org.springframework.context.annotation.PropertySource(name = "SpringSessionProperties",
|
||||
value = "classpath:${spring-session-properties-location:spring-session.properties}", ignoreResourceNotFound = true)
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class GemFireHttpSessionConfiguration extends AbstractGemFireHttpSessionConfiguration implements ImportAware {
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.session.data.gemfire.config.annotation.web.http;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.RegionShortcut;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.apache.geode.cache.client.Pool;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Unit Tests testing the configuration of Spring Session for Apache Geode (SSDG)
|
||||
* using {@literal spring-session.properties}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.context.annotation.Bean
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.6.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = GemFireHttpSessionConfigurationWithSpringSessionPropertiesUnitTests.TestConfiguration.class)
|
||||
public class GemFireHttpSessionConfigurationWithSpringSessionPropertiesUnitTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void setSpringSessionPropertiesLocation() {
|
||||
System.setProperty("spring-session-properties-location", "test-spring-session.properties");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clearSpringSessionPropertiesLocation() {
|
||||
System.clearProperty("spring-session-properties-location");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private GemFireHttpSessionConfiguration sessionConfiguration;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
assertThat(this.sessionConfiguration).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springSessionConfigurationIsCorrect() {
|
||||
|
||||
assertThat(this.sessionConfiguration.getClientRegionShortcut()).isEqualTo(ClientRegionShortcut.CACHING_PROXY);
|
||||
assertThat(this.sessionConfiguration.getIndexableSessionAttributes()).containsExactly("username", "userId");
|
||||
assertThat(this.sessionConfiguration.getMaxInactiveIntervalInSeconds()).isEqualTo(300);
|
||||
assertThat(this.sessionConfiguration.getPoolName()).isEqualTo("CarPool");
|
||||
assertThat(this.sessionConfiguration.getServerRegionShortcut()).isEqualTo(RegionShortcut.REPLICATE);
|
||||
assertThat(this.sessionConfiguration.getSessionExpirationPolicyBeanName().orElse(null)).isEqualTo("TestSessionExpirationPolicyBean");
|
||||
assertThat(this.sessionConfiguration.getSessionRegionName()).isEqualTo("TestSessions");
|
||||
assertThat(this.sessionConfiguration.getSessionSerializerBeanName()).isEqualTo(GemFireHttpSessionConfiguration.SESSION_DATA_SERIALIZER_BEAN_NAME);
|
||||
}
|
||||
|
||||
@ClientCacheApplication
|
||||
@EnableGemFireHttpSession
|
||||
@EnableGemFireMockObjects
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean("CarPool")
|
||||
Pool mockPool() {
|
||||
return mock(Pool.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# Test spring-session.properties
|
||||
|
||||
spring.session.data.gemfire.cache.client.pool.name=CarPool
|
||||
spring.session.data.gemfire.cache.client.region.shortcut=CACHING_PROXY
|
||||
spring.session.data.gemfire.cache.server.region.shortcut=REPLICATE
|
||||
spring.session.data.gemfire.session.attributes.indexed=username,userId
|
||||
spring.session.data.gemfire.session.expiration.bean-name=TestSessionExpirationPolicyBean
|
||||
spring.session.data.gemfire.session.expiration.max-inactive-interval-seconds=300
|
||||
spring.session.data.gemfire.session.region.name=TestSessions
|
||||
spring.session.data.gemfire.session.serializer.bean-name=SessionDataSerializer
|
||||
Reference in New Issue
Block a user