diff --git a/gradle.properties b/gradle.properties index 92dc1c63..7dd77a87 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,5 +8,7 @@ springDataGemFireVersion=2.0.9.RELEASE springDataGeodeVersion=2.0.9.RELEASE springDataGeodeTestVersion=0.0.1.M1 springDataReleaseTrainVersion=Kay-SR9 +springSessionBomVersion=Apple-SR4 +springSessionDataGeodeVersion=2.0.5.RELEASE springShellVersion=1.2.0.RELEASE version=1.0.0.BUILD-SNAPSHOT diff --git a/gradle/dependency-management.gradle b/gradle/dependency-management.gradle index 5d40ed52..995287a0 100644 --- a/gradle/dependency-management.gradle +++ b/gradle/dependency-management.gradle @@ -6,6 +6,7 @@ dependencyManagement { dependency "antlr:antlr:$antlrVersion" dependency "edu.umd.cs.mtc:multithreadedtc:$multithreadedtcVersion" dependency "org.springframework.data:spring-data-geode-test:$springDataGeodeTestVersion" + dependency "org.springframework.session:spring-session-data-geode:$springSessionDataGeodeVersion" dependency "org.springframework.shell:spring-shell:$springShellVersion" } } diff --git a/spring-geode-autoconfigure/spring-geode-autoconfigure.gradle b/spring-geode-autoconfigure/spring-geode-autoconfigure.gradle index 2fa6cf04..9ec46837 100644 --- a/spring-geode-autoconfigure/spring-geode-autoconfigure.gradle +++ b/spring-geode-autoconfigure/spring-geode-autoconfigure.gradle @@ -6,6 +6,10 @@ dependencies { compile project(":spring-geode") + optional "org.springframework.session:spring-session-data-geode" + + provided "javax.servlet:javax.servlet-api" + testCompile "org.assertj:assertj-core" testCompile "junit:junit" testCompile "org.mockito:mockito-core" diff --git a/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/SpringSessionAutoConfiguration.java b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/SpringSessionAutoConfiguration.java new file mode 100644 index 00000000..9dfcf68b --- /dev/null +++ b/spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/SpringSessionAutoConfiguration.java @@ -0,0 +1,54 @@ +/* + * Copyright 2018 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 + * + * http://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.geode.boot.autoconfigure; + +import org.apache.geode.cache.GemFireCache; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Configuration; +import org.springframework.session.Session; +import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession; +import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; +import org.springframework.session.web.http.SessionRepositoryFilter; + +/** + * Spring Boot {@link EnableAutoConfiguration auto-configuration} for configuring either Apache Geode + * or Pivotal GemFire as an (HTTP) {@link Session} state management provider in Spring Session. + * + * @author John Blum + * @see org.apache.geode.cache.GemFireCache + * @see org.springframework.boot.autoconfigure.EnableAutoConfiguration + * @see org.springframework.context.annotation.Configuration + * @see org.springframework.session.Session + * @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession + * @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration + * @see org.springframework.session.web.http.SessionRepositoryFilter + * @since 1.0.0 + */ +@Configuration +@AutoConfigureAfter(ClientCacheAutoConfiguration.class) +@ConditionalOnBean(GemFireCache.class) +@ConditionalOnClass({ GemFireCache.class, GemFireHttpSessionConfiguration.class }) +@ConditionalOnMissingBean(SessionRepositoryFilter.class) +@EnableGemFireHttpSession +@SuppressWarnings("unused") +public class SpringSessionAutoConfiguration { + +} diff --git a/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories index bc138331..48fea698 100644 --- a/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-geode-autoconfigure/src/main/resources/META-INF/spring.factories @@ -8,6 +8,7 @@ org.springframework.geode.boot.autoconfigure.FunctionExecutionAutoConfiguration, org.springframework.geode.boot.autoconfigure.PdxSerializationAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.PeerSecurityAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.RepositoriesAutoConfiguration,\ +org.springframework.geode.boot.autoconfigure.SpringSessionAutoConfiguration,\ org.springframework.geode.boot.autoconfigure.SslAutoConfiguration # Environment Post Processing diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/AutoConfiguredSessionCachingIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/AutoConfiguredSessionCachingIntegrationTests.java new file mode 100644 index 00000000..edc61439 --- /dev/null +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/AutoConfiguredSessionCachingIntegrationTests.java @@ -0,0 +1,128 @@ +/* + * Copyright 2018 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 + * + * http://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.geode.boot.autoconfigure.session; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionAttributes; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.GemfireAccessor; +import org.springframework.data.gemfire.GemfireOperations; +import org.springframework.data.gemfire.GemfireTemplate; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.util.RegionUtils; +import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration; +import org.springframework.session.Session; +import org.springframework.session.SessionRepository; +import org.springframework.session.data.gemfire.GemFireOperationsSessionRepository; +import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests for auto-configuration of Spring Session using either Apache Geode or Pivotal GemFire + * as the {@link Session} state management provider. + * + * This test asserts that the Spring Boot auto-configuration properly configures Spring Session + * with either Apache Geode or Pivotal GemFire + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.Region + * @see org.springframework.boot.autoconfigure.SpringBootApplication + * @see org.springframework.boot.test.context.SpringBootTest + * @see org.springframework.context.ApplicationContext + * @see org.springframework.data.gemfire.GemfireTemplate + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.session.Session + * @see org.springframework.session.SessionRepository + * @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository + * @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.0.0 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) +@SuppressWarnings("unused") +public class AutoConfiguredSessionCachingIntegrationTests { + + @Autowired + private ApplicationContext applicationContext; + + @Before + public void setup() { + + assertThat(this.applicationContext).isNotNull(); + assertThat(this.applicationContext.getBean(GemFireHttpSessionConfiguration.class)).isNotNull(); + } + + @Test + @SuppressWarnings("unchecked") + public void sessionRegionExists() { + + assertThat(this.applicationContext.containsBean(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME)) + .isTrue(); + + Region sessionRegion = + this.applicationContext.getBean(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME, Region.class); + + assertThat(sessionRegion).isNotNull(); + assertThat(sessionRegion.getName()).isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME); + assertThat(sessionRegion.getFullPath()) + .isEqualTo(RegionUtils.toRegionPath(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME)); + + RegionAttributes sessionRegionAttributes = sessionRegion.getAttributes(); + + assertThat(sessionRegionAttributes).isNotNull(); + assertThat(sessionRegionAttributes.getDataPolicy()).isEqualTo(DataPolicy.EMPTY); + } + + @Test + public void sessionRepositoryExists() { + + assertThat(this.applicationContext.containsBean("sessionRepository")).isTrue(); + + SessionRepository sessionRepository = + this.applicationContext.getBean("sessionRepository", SessionRepository.class); + + assertThat(sessionRepository).isInstanceOf(GemFireOperationsSessionRepository.class); + + GemfireOperations gemfireOperations = ((GemFireOperationsSessionRepository) sessionRepository).getTemplate(); + + Region sessionRegion = + this.applicationContext.getBean(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME, Region.class); + + GemfireTemplate sessionRegionTemplate = + this.applicationContext.getBean("sessionRegionTemplate", GemfireTemplate.class); + + assertThat(gemfireOperations).isInstanceOf(GemfireAccessor.class); + assertThat(gemfireOperations).isSameAs(sessionRegionTemplate); + assertThat(((GemfireAccessor) gemfireOperations).getRegion()).isEqualTo(sessionRegion); + } + + @EnableGemFireMockObjects + @SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class) + static class TestConfiguration { } + +} diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/CustomConfiguredSessionCachingIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/CustomConfiguredSessionCachingIntegrationTests.java new file mode 100644 index 00000000..ab91ae68 --- /dev/null +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/CustomConfiguredSessionCachingIntegrationTests.java @@ -0,0 +1,242 @@ +/* + * Copyright 2018 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 + * + * http://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.geode.boot.autoconfigure.session; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException; + +import java.lang.reflect.Method; +import java.util.Optional; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import org.apache.geode.cache.RegionShortcut; +import org.apache.geode.cache.client.ClientRegionShortcut; +import org.junit.Test; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.PropertySource; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration; +import org.springframework.mock.env.MockPropertySource; +import org.springframework.session.Session; +import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; +import org.springframework.session.data.gemfire.config.annotation.web.http.support.SpringSessionGemFireConfigurer; +import org.springframework.session.data.gemfire.serialization.SessionSerializer; +import org.springframework.util.ObjectUtils; +import org.springframework.util.ReflectionUtils; + +/** + * Integration Test for the auto-configuration of Spring Session using either Apache Geode or Pivotal GemFire + * as the {@link Session} state management provider. + * + * This test asserts that the Spring Boot auto-configuration can be customized using either {@link Properties} + * or a {@link SpringSessionGemFireConfigurer}. + * + * @author John Blum + * @see java.util.Properties + * @see org.junit.Test + * @see org.mockito.Mockito + * @see org.springframework.boot.SpringBootConfiguration + * @see org.springframework.boot.autoconfigure.EnableAutoConfiguration + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.Bean + * @see org.springframework.context.annotation.Configuration + * @see org.springframework.core.env.PropertySource + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.session.Session + * @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration + * @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SpringSessionGemFireConfigurer + * @since 1.0.0 + */ +@SuppressWarnings("unused") +public class CustomConfiguredSessionCachingIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { + + private static final String SPRING_SESSION_DATA_GEMFIRE_PROPERTY = "spring.session.data.gemfire"; + + @SuppressWarnings("unchecked") + private T invoke(Object obj, String methodName) { + + return (T) Optional.ofNullable(obj) + .map(Object::getClass) + .map(type -> ReflectionUtils.findMethod(type, methodName)) + .map(this::makeAccessible) + .map(method -> ReflectionUtils.invokeMethod(method, obj)) + .orElseThrow(() -> newIllegalArgumentException("Method [%s] not found on Object of type [%s]", + methodName, ObjectUtils.nullSafeClassName(obj))); + } + + private Method makeAccessible(Method method) { + ReflectionUtils.makeAccessible(method); + return method; + } + + private PropertySource newSpringSessionGemFireProperties() { + + return new MockPropertySource("TestSpringSessionGemFireProperties") + .withProperty(springSessionPropertyName("cache.client.region.shortcut"), "LOCAL") + .withProperty(springSessionPropertyName("session.attributes.indexable"), "one, two") + .withProperty(springSessionPropertyName("session.expiration.max-inactive-interval-seconds"), "600") + .withProperty(springSessionPropertyName("cache.client.pool.name"), "MockPool") + .withProperty(springSessionPropertyName("session.region.name"), "MockRegion") + .withProperty(springSessionPropertyName("cache.server.region.shortcut"), "REPLICATE") + .withProperty(springSessionPropertyName("session.serializer.bean-name"), "MockSessionSerializer"); + } + + @Override + protected ConfigurableApplicationContext processBeforeRefresh(ConfigurableApplicationContext applicationContext) { + + applicationContext.getEnvironment().getPropertySources().addFirst(newSpringSessionGemFireProperties()); + + return applicationContext; + } + + private String springSessionPropertyName(String propertyNameSuffix) { + return String.format("%1$s.%2$s", SPRING_SESSION_DATA_GEMFIRE_PROPERTY, propertyNameSuffix); + } + + @Test + public void springSessionConfigurationCustomizedWithConfigurer() { + + newApplicationContext(TestConfiguration.class, SpringSessionGemFireConfigurerTestConfiguration.class); + + GemFireHttpSessionConfiguration sessionConfiguration = getBean(GemFireHttpSessionConfiguration.class); + + assertThat(sessionConfiguration).isNotNull(); + + assertThat(this.invoke(sessionConfiguration, "getClientRegionShortcut")) + .isEqualTo(ClientRegionShortcut.CACHING_PROXY); + + assertThat(this.invoke(sessionConfiguration, "getIndexableSessionAttributes")) + .contains("two", "four"); + + assertThat(this.invoke(sessionConfiguration, "getMaxInactiveIntervalInSeconds")) + .isEqualTo(900); + + assertThat(this.invoke(sessionConfiguration, "getPoolName")).isEqualTo("TestPool"); + + assertThat(this.invoke(sessionConfiguration, "getServerRegionShortcut")) + .isEqualTo(RegionShortcut.PARTITION_REDUNDANT_PERSISTENT_OVERFLOW); + + assertThat(this.invoke(sessionConfiguration, "getSessionRegionName")) + .isEqualTo("TestRegion"); + + assertThat(this.invoke(sessionConfiguration, "getSessionSerializerBeanName")) + .isEqualTo("TestSessionSerializer"); + } + + @Test + public void springSessionConfigurationCustomizedWithProperties() { + + newApplicationContext(TestConfiguration.class); + + GemFireHttpSessionConfiguration sessionConfiguration = getBean(GemFireHttpSessionConfiguration.class); + + assertThat(sessionConfiguration).isNotNull(); + + assertThat(this.invoke(sessionConfiguration, "getClientRegionShortcut")) + .isEqualTo(ClientRegionShortcut.LOCAL); + + assertThat(this.invoke(sessionConfiguration, "getIndexableSessionAttributes")) + .contains("one", "two"); + + assertThat(this.invoke(sessionConfiguration, "getMaxInactiveIntervalInSeconds")) + .isEqualTo(600); + + assertThat(this.invoke(sessionConfiguration, "getPoolName")).isEqualTo("MockPool"); + + assertThat(this.invoke(sessionConfiguration, "getServerRegionShortcut")) + .isEqualTo(RegionShortcut.REPLICATE); + + assertThat(this.invoke(sessionConfiguration, "getSessionRegionName")) + .isEqualTo("MockRegion"); + + assertThat(this.invoke(sessionConfiguration, "getSessionSerializerBeanName")) + .isEqualTo("MockSessionSerializer"); + } + + @SpringBootConfiguration + @EnableGemFireMockObjects + @EnableAutoConfiguration(exclude = ContinuousQueryAutoConfiguration.class) + //@SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class) + static class TestConfiguration { + + @Bean("MockSessionSerializer") + @SuppressWarnings("unchecked") + SessionSerializer mockSessionSerializer() { + return mock(SessionSerializer.class); + } + } + + @Configuration + static class SpringSessionGemFireConfigurerTestConfiguration { + + @Bean + SpringSessionGemFireConfigurer customSpringSessionGemFireConfiguration() { + + return new SpringSessionGemFireConfigurer() { + + @Override + public ClientRegionShortcut getClientRegionShortcut() { + return ClientRegionShortcut.CACHING_PROXY; + } + + @Override + public String[] getIndexableSessionAttributes() { + return new String[] { "two", "four" }; + } + + @Override + public int getMaxInactiveIntervalInSeconds() { + return Long.valueOf(TimeUnit.MINUTES.toSeconds(15L)).intValue(); + } + + @Override + public String getPoolName() { + return "TestPool"; + } + + @Override + public String getRegionName() { + return "TestRegion"; + } + + @Override + public RegionShortcut getServerRegionShortcut() { + return RegionShortcut.PARTITION_REDUNDANT_PERSISTENT_OVERFLOW; + } + + @Override + public String getSessionSerializerBeanName() { + return "TestSessionSerializer"; + } + }; + } + + @Bean("TestSessionSerializer") + @SuppressWarnings("unchecked") + SessionSerializer testSessionSerializer() { + return mock(SessionSerializer.class); + } + } +} diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/ManuallyConfiguredSessionCachingIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/ManuallyConfiguredSessionCachingIntegrationTests.java new file mode 100644 index 00000000..bf35e88f --- /dev/null +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/session/ManuallyConfiguredSessionCachingIntegrationTests.java @@ -0,0 +1,106 @@ +/* + * Copyright 2018 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 + * + * http://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.geode.boot.autoconfigure.session; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +import org.apache.geode.cache.GemFireCache; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration; +import org.springframework.session.Session; +import org.springframework.session.SessionRepository; +import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession; +import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration; +import org.springframework.session.data.gemfire.GemFireOperationsSessionRepository; +import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests for auto-configuration of Spring Session using a custom Spring Session {@link Session} state + * management provider, asserting that neither Apache Geode nor Pivotal GemFire is configured. + * + * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.GemFireCache + * @see org.springframework.boot.autoconfigure.SpringBootApplication + * @see org.springframework.boot.test.context.SpringBootTest + * @see org.springframework.context.ApplicationContext + * @see org.springframework.context.annotation.Bean + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.session.Session + * @see org.springframework.session.SessionRepository + * @see org.springframework.session.config.annotation.web.http.EnableSpringHttpSession + * @see org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration + * @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository + * @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 1.0.0 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) +@SuppressWarnings("unused") +public class ManuallyConfiguredSessionCachingIntegrationTests { + + @Autowired + private ApplicationContext applicationContext; + + @Before + public void setup() { + + assertThat(this.applicationContext).isNotNull(); + assertThat(this.applicationContext.getBean(SpringHttpSessionConfiguration.class)).isNotNull(); + } + + @Test + public void gemfireSessionRegionAndSessionRepositoryAreNotPresent() { + + assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(this.applicationContext.containsBean("sessionRepository")).isTrue(); + assertThat(this.applicationContext.containsBean(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME)) + .isFalse(); + + GemFireCache gemfireCache = this.applicationContext.getBean(GemFireCache.class); + + assertThat(gemfireCache).isNotNull(); + assertThat(gemfireCache.rootRegions()).isEmpty(); + + SessionRepository sessionRepository = this.applicationContext.getBean(SessionRepository.class); + + assertThat(sessionRepository).isNotNull(); + assertThat(sessionRepository).isNotInstanceOf(GemFireOperationsSessionRepository.class); + } + + @EnableGemFireMockObjects + @EnableSpringHttpSession + @SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class) + static class TestConfiguration { + + @Bean + SessionRepository sessionRepository() { + return mock(SessionRepository.class); + } + } +}