diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfiguration.java index a6489a04..82e5f4f9 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfiguration.java @@ -351,6 +351,7 @@ public abstract class AbstractCacheConfiguration extends AbstractAnnotationConfi gemfireCache.setProperties(gemfireProperties()); gemfireCache.setTransactionListeners(getTransactionListeners()); gemfireCache.setTransactionWriter(getTransactionWriter()); + gemfireCache.setUseBeanFactoryLocator(useBeanFactoryLocator()); return gemfireCache; } diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/BeanFactoryLocatorConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/BeanFactoryLocatorConfiguration.java index 4d6ba6e6..4f5c722d 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/BeanFactoryLocatorConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/BeanFactoryLocatorConfiguration.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import org.springframework.beans.BeansException; @@ -21,6 +20,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.client.ClientCacheFactoryBean; import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator; /** @@ -33,6 +33,9 @@ import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator; * @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Configuration * @see org.springframework.data.gemfire.CacheFactoryBean + * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean + * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer + * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer * @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator * @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator * @since 2.0.0 @@ -42,19 +45,19 @@ import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator; public class BeanFactoryLocatorConfiguration { /** - * Declares and registers a Spring {@link BeanPostProcessor} and post processes a Spring Data GemFire/Geode - * {@link CacheFactoryBean} by setting the {@literal useBeanFactoryLocator} property to {@literal true}. + * Declares and registers a Spring {@link BeanPostProcessor} bean to post process a Spring Data Geode + * {@link CacheFactoryBean} or {@link ClientCacheFactoryBean} by setting the {@literal useBeanFactoryLocator} + * property to {@literal true}. * - * @return a Spring {@link BeanPostProcessor} used to post process the SDG {@link CacheFactoryBean}. + * @return a Spring {@link BeanPostProcessor} used to post process an SDG {@link CacheFactoryBean}. * @see org.springframework.beans.factory.config.BeanPostProcessor */ @Bean - public BeanPostProcessor cacheFactoryBeanPostProcessor() { + public BeanPostProcessor useBeanFactoryLocatorBeanPostProcessor() { return new BeanPostProcessor() { @Override - @SuppressWarnings("all") public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof CacheFactoryBean) { @@ -65,4 +68,30 @@ public class BeanFactoryLocatorConfiguration { } }; } + + /** + * Declares and registers a {@link ClientCacheConfigurer} bean to configure a {@link ClientCacheFactoryBean} + * by setting the {@literal useBeanFactoryLocator} property to {@literal true}. + * + * @return a {@link ClientCacheConfigurer} used to configure and set the SDG {@link ClientCacheFactoryBean}'s + * {@literal useBeanFactoryLocator} property to {@literal true}. + * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer + */ + @Bean + public ClientCacheConfigurer useBeanFactoryLocatorClientCacheConfigurer() { + return (beanName, bean) -> bean.setUseBeanFactoryLocator(true); + } + + /** + * Declares and registers a {@link PeerCacheConfigurer} bean to configure a {@link CacheFactoryBean} + * by setting the {@literal useBeanFactoryLocator} property to {@literal true}. + * + * @return a {@link PeerCacheConfigurer} used to configure and set the SDG {@link CacheFactoryBean}'s + * {@literal useBeanFactoryLocator} property to {@literal true}. + * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer + */ + @Bean + public PeerCacheConfigurer useBeanFactoryLocatorPeerCacheConfigurer() { + return (beanName, bean) -> bean.setUseBeanFactoryLocator(true); + } } diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableSecurity.java b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableSecurity.java index d02035ca..1ca35dca 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/EnableSecurity.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/EnableSecurity.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.annotation; import java.lang.annotation.Documented; diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfiguration.java index a1e6f3a5..1b8c18fe 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/PeerCacheConfiguration.java @@ -90,7 +90,6 @@ public class PeerCacheConfiguration extends AbstractCacheConfiguration { gemfireCache.setMessageSyncInterval(messageSyncInterval()); gemfireCache.setPeerCacheConfigurers(resolvePeerCacheConfigurers()); gemfireCache.setSearchTimeout(searchTimeout()); - gemfireCache.setUseBeanFactoryLocator(useBeanFactoryLocator()); gemfireCache.setUseClusterConfiguration(useClusterConfiguration()); return gemfireCache; diff --git a/src/main/java/org/springframework/data/gemfire/server/CacheServerFactoryBean.java b/src/main/java/org/springframework/data/gemfire/server/CacheServerFactoryBean.java index baf802cf..055c4cdf 100644 --- a/src/main/java/org/springframework/data/gemfire/server/CacheServerFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/server/CacheServerFactoryBean.java @@ -105,7 +105,6 @@ public class CacheServerFactoryBean extends AbstractFactoryBeanSupport jndiDataSources = Collections.emptyList(); + List transactionListeners = Collections.singletonList(mock(TransactionListener.class)); + + Properties gemfireProperties = new Properties(); + + Resource mockResource = mock(Resource.class); + + TransactionWriter mockTransactionWriter = mock(TransactionWriter.class); + + doReturn(gemfireProperties).when(this.cacheConfiguration).gemfireProperties(); + + this.cacheConfiguration.setBeanClassLoader(testBeanClassLoader); + this.cacheConfiguration.setBeanFactory(mockBeanFactory); + this.cacheConfiguration.setCacheXml(mockResource); + this.cacheConfiguration.setClose(false); + this.cacheConfiguration.setCopyOnRead(true); + this.cacheConfiguration.setCriticalHeapPercentage(0.90f); + this.cacheConfiguration.setCriticalOffHeapPercentage(0.85f); + this.cacheConfiguration.setEvictionHeapPercentage(0.75f); + this.cacheConfiguration.setEvictionOffHeapPercentage(0.55f); + this.cacheConfiguration.setGatewayConflictResolver(mockGatewayConflictResolver); + this.cacheConfiguration.setJndiDataSources(jndiDataSources); + this.cacheConfiguration.setTransactionListeners(transactionListeners); + this.cacheConfiguration.setTransactionWriter(mockTransactionWriter); + this.cacheConfiguration.setUseBeanFactoryLocator(true); + + assertThat(this.cacheConfiguration.configureCacheFactoryBean(cacheFactoryBean)).isEqualTo(cacheFactoryBean); + + verify(cacheFactoryBean, times(1)).setBeanClassLoader(eq(testBeanClassLoader)); + verify(cacheFactoryBean, times(1)).setBeanFactory(eq(mockBeanFactory)); + verify(cacheFactoryBean, times(1)).setClose(eq(false)); + verify(cacheFactoryBean, times(1)).setCopyOnRead(eq(true)); + verify(cacheFactoryBean, times(1)).setCriticalHeapPercentage(eq(0.90f)); + verify(cacheFactoryBean, times(1)).setCriticalOffHeapPercentage(eq(0.85f)); + verify(cacheFactoryBean, times(1)).setEvictionHeapPercentage(eq(0.75f)); + verify(cacheFactoryBean, times(1)).setEvictionOffHeapPercentage(eq(0.55f)); + verify(cacheFactoryBean, times(1)).setGatewayConflictResolver(eq(mockGatewayConflictResolver)); + verify(cacheFactoryBean, times(1)).setJndiDataSources(eq(jndiDataSources)); + verify(cacheFactoryBean, times(1)).setTransactionListeners(eq(transactionListeners)); + verify(cacheFactoryBean, times(1)).setTransactionWriter(eq(mockTransactionWriter)); + verify(cacheFactoryBean, times(1)).setUseBeanFactoryLocator(eq(true)); + } } diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java index 8782ce39..efaaaee9 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -22,15 +21,15 @@ import static org.mockito.Mockito.mock; import java.util.Optional; import java.util.Properties; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.Pool; import org.apache.geode.cache.client.PoolFactory; import org.apache.geode.cache.control.ResourceManager; import org.apache.geode.pdx.PdxSerializer; -import org.junit.After; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -41,11 +40,13 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb import org.springframework.mock.env.MockPropertySource; /** - * Integration tests for {@link ClientCacheApplication}. + * Integration Tests for {@link ClientCacheApplication}. * * @author John Blum * @see java.util.Properties * @see org.junit.Test + * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.client.Pool * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication @@ -103,6 +104,12 @@ public class ClientCachePropertiesIntegrationTests { assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue(); + ClientCacheFactoryBean testClientCacheFactoryBean = + this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class); + + assertThat(testClientCacheFactoryBean).isNotNull(); + assertThat(testClientCacheFactoryBean.isUseBeanFactoryLocator()).isFalse(); + ClientCache testClientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class); assertThat(testClientCache).isNotNull(); @@ -153,6 +160,7 @@ public class ClientCachePropertiesIntegrationTests { public void dynamicClientCacheConfiguration() { MockPropertySource testPropertySource = new MockPropertySource() + .withProperty("spring.data.gemfire.use-bean-factory-locator", true) .withProperty("spring.data.gemfire.cache.copy-on-read", true) .withProperty("spring.data.gemfire.cache.critical-heap-percentage", 90.0f) .withProperty("spring.data.gemfire.cache.eviction-heap-percentage", 75.0f) @@ -191,19 +199,24 @@ public class ClientCachePropertiesIntegrationTests { assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue(); - PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class); - ClientCacheFactoryBean clientCacheFactoryBean = this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class); + assertThat(clientCacheFactoryBean).isNotNull(); + ClientCache clientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class); + assertThat(clientCache).isNotNull(); + + PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class); + assertThat(mockPdxSerializer).isNotNull(); - assertThat(clientCacheFactoryBean).isNotNull(); assertThat(clientCacheFactoryBean.getDurableClientId()).isEqualTo("123"); assertThat(clientCacheFactoryBean.getDurableClientTimeout()).isEqualTo(600); + assertThat(clientCacheFactoryBean.getUseClusterConfiguration()).isFalse(); assertThat(clientCacheFactoryBean.isKeepAlive()).isTrue(); assertThat(clientCacheFactoryBean.isReadyForEvents()).isTrue(); + assertThat(clientCacheFactoryBean.isUseBeanFactoryLocator()).isTrue(); assertThat(clientCache).isNotNull(); assertThat(clientCache.getCopyOnRead()).isTrue(); assertThat(clientCache.getDistributedSystem()).isNotNull(); @@ -249,7 +262,7 @@ public class ClientCachePropertiesIntegrationTests { assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(75.0f); } - // TODO add more tests! + // TODO add more tests @EnableGemFireMockObjects @ClientCacheApplication(name = "TestClientCache", copyOnRead = true, diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java index 295c00c5..f508764e 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -26,15 +25,17 @@ import org.junit.Test; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator; import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; /** - * Integration test for {@link EnableBeanFactoryLocator} and {@link BeanFactoryLocatorConfiguration}. + * Integration Tests for {@link EnableBeanFactoryLocator} and {@link BeanFactoryLocatorConfiguration}. * * @author John Blum * @see org.junit.Test * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.CacheFactoryBean + * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.BeanFactoryLocatorConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects @@ -46,19 +47,27 @@ public class EnableBeanFactoryLocatorConfigurationIntegrationTests { @After public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); + + Optional.ofNullable(this.applicationContext). + ifPresent(ConfigurableApplicationContext::close); + + GemfireBeanFactoryLocator.clear(); } private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); + + ConfigurableApplicationContext applicationContext = + new AnnotationConfigApplicationContext(annotatedClasses); + applicationContext.registerShutdownHook(); + return applicationContext; } - @Test - public void gemfireBeanFactoryLocatorIsDisabled() { + private void testGemFireCacheBeanFactoryLocator(Class configuration, + Class cacheFactoryBeanType, boolean beanFactoryLocatorEnabled) { - this.applicationContext = newApplicationContext(TestBeanFactoryLocatorDisabledConfiguration.class); + this.applicationContext = newApplicationContext(configuration); assertThat(this.applicationContext).isNotNull(); assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); @@ -66,31 +75,50 @@ public class EnableBeanFactoryLocatorConfigurationIntegrationTests { CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); assertThat(gemfireCache).isNotNull(); - assertThat(gemfireCache.isUseBeanFactoryLocator()).isFalse(); + assertThat(gemfireCache).isInstanceOf(cacheFactoryBeanType); + assertThat(gemfireCache.isUseBeanFactoryLocator()).isEqualTo(beanFactoryLocatorEnabled); } @Test - public void gemfireBeanFactoryLocatorIsEnabled() { - - this.applicationContext = newApplicationContext(TestBeanFactoryLocatorEnabledConfiguration.class); - - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - - CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); - - assertThat(gemfireCache).isNotNull(); - assertThat(gemfireCache.isUseBeanFactoryLocator()).isTrue(); + public void gemfireClientCacheBeanFactoryLocatorIsDisabled() { + testGemFireCacheBeanFactoryLocator(TestClientCacheBeanFactoryLocatorDisabledConfiguration.class, + CacheFactoryBean.class, false); } + @Test + public void gemfireClientCacheBeanFactoryLocatorIsEnabled() { + testGemFireCacheBeanFactoryLocator(TestClientCacheBeanFactoryLocatorEnabledConfiguration.class, + CacheFactoryBean.class, true); + } + + @Test + public void gemfirePeerCacheBeanFactoryLocatorIsDisabled() { + testGemFireCacheBeanFactoryLocator(TestPeerCacheBeanFactoryLocatorDisabledConfiguration.class, + CacheFactoryBean.class, false); + } + + @Test + public void gemfirePeerCacheBeanFactoryLocatorIsEnabled() { + testGemFireCacheBeanFactoryLocator(TestPeerCacheBeanFactoryLocatorEnabledConfiguration.class, + CacheFactoryBean.class, true); + } + + @ClientCacheApplication + @EnableGemFireMockObjects + static class TestClientCacheBeanFactoryLocatorDisabledConfiguration { } + + @ClientCacheApplication + @EnableBeanFactoryLocator + @EnableGemFireMockObjects + static class TestClientCacheBeanFactoryLocatorEnabledConfiguration { } + @EnableGemFireMockObjects @PeerCacheApplication - static class TestBeanFactoryLocatorDisabledConfiguration { - } + static class TestPeerCacheBeanFactoryLocatorDisabledConfiguration { } @EnableGemFireMockObjects @EnableBeanFactoryLocator @PeerCacheApplication - static class TestBeanFactoryLocatorEnabledConfiguration { - } + static class TestPeerCacheBeanFactoryLocatorEnabledConfiguration { } + } diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationUnitTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationUnitTests.java new file mode 100644 index 00000000..4e9f7d29 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationUnitTests.java @@ -0,0 +1,99 @@ +/* + * Copyright 2019 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.data.gemfire.config.annotation; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.client.ClientCacheFactoryBean; + +/** + * Unit Tests for {@link EnableBeanFactoryLocator} and {@link BeanFactoryLocatorConfiguration}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.CacheFactoryBean + * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean + * @see org.springframework.data.gemfire.config.annotation.BeanFactoryLocatorConfiguration + * @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator + * @since 2.2.1 + */ +public class EnableBeanFactoryLocatorConfigurationUnitTests { + + private BeanFactoryLocatorConfiguration configuration = new BeanFactoryLocatorConfiguration(); + + private void testUseBeanFactoryLocatorBeanPostProcessorProcessesBean(Object cacheBean) { + + BeanPostProcessor beanPostProcessor = this.configuration.useBeanFactoryLocatorBeanPostProcessor(); + + assertThat(beanPostProcessor).isNotNull(); + assertThat(beanPostProcessor.postProcessBeforeInitialization(cacheBean, "TestCache")) + .isEqualTo(cacheBean); + } + + @Test + public void useBeanFactoryLocatorBeanPostProcessorProcessesCacheFactoryBean() { + + CacheFactoryBean cacheFactoryBean = new CacheFactoryBean(); + + assertThat(cacheFactoryBean.isUseBeanFactoryLocator()).isFalse(); + + testUseBeanFactoryLocatorBeanPostProcessorProcessesBean(cacheFactoryBean); + + assertThat(cacheFactoryBean.isUseBeanFactoryLocator()).isTrue(); + } + + @Test + public void useBeanFactoryLocatorBeanPostProcessorProcessesClientCacheFactoryBean() { + + ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean(); + + assertThat(clientCacheFactoryBean.isUseBeanFactoryLocator()).isFalse(); + + testUseBeanFactoryLocatorBeanPostProcessorProcessesBean(clientCacheFactoryBean); + + assertThat(clientCacheFactoryBean.isUseBeanFactoryLocator()).isTrue(); + } + + @Test + public void useBeanFactoryLocatorClientCacheConfigurerIsCorrect() throws Exception { + + ClientCacheFactoryBean factoryBean = new ClientCacheFactoryBean(); + + assertThat(factoryBean.isUseBeanFactoryLocator()).isFalse(); + + factoryBean.setClientCacheConfigurers(this.configuration.useBeanFactoryLocatorClientCacheConfigurer()); + factoryBean.afterPropertiesSet(); + + assertThat(factoryBean.isUseBeanFactoryLocator()).isTrue(); + } + + @Test + public void useBeanFactoryLocatorPeerCacheConfigurerIsCorrect() throws Exception { + + CacheFactoryBean factoryBean = new CacheFactoryBean(); + + assertThat(factoryBean.isUseBeanFactoryLocator()).isFalse(); + + factoryBean.setPeerCacheConfigurers(this.configuration.useBeanFactoryLocatorPeerCacheConfigurer()); + factoryBean.afterPropertiesSet(); + + assertThat(factoryBean.isUseBeanFactoryLocator()).isTrue(); + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java index 185f5899..87f228e7 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java @@ -21,13 +21,13 @@ import static org.mockito.Mockito.mock; import java.util.Optional; import java.util.Properties; +import org.junit.After; +import org.junit.Test; + import org.apache.geode.cache.Cache; import org.apache.geode.cache.control.ResourceManager; import org.apache.geode.pdx.PdxSerializer; -import org.junit.After; -import org.junit.Test; - import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -38,14 +38,16 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockOb import org.springframework.mock.env.MockPropertySource; /** - * Integration tests for {@link PeerCacheApplication}. + * Integration Tests for {@link PeerCacheApplication}. * * @author John Blum * @see java.util.Properties * @see org.junit.Test + * @see org.apache.geode.cache.Cache * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.core.env.PropertySource + * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource @@ -58,9 +60,7 @@ public class PeerCachePropertiesIntegrationTests { @After public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); + Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); } private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, @@ -175,7 +175,7 @@ public class PeerCachePropertiesIntegrationTests { assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(80.0f); } - //TODO add more tests + // TODO add more tests @EnableGemFireMockObjects @EnablePdx(ignoreUnreadFields = true, readSerialized = true, serializerBeanName = "mockPdxSerializer")