diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/beans/factory/config/GemFireMockObjectsBeanPostProcessor.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/beans/factory/config/GemFireMockObjectsBeanPostProcessor.java index 4033d2c..a013ff5 100644 --- a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/beans/factory/config/GemFireMockObjectsBeanPostProcessor.java +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/mock/beans/factory/config/GemFireMockObjectsBeanPostProcessor.java @@ -46,6 +46,7 @@ import org.springframework.lang.Nullable; * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.client.ClientCacheFactory * @see org.apache.geode.cache.client.PoolFactory + * @see org.apache.geode.distributed.DistributedSystem * @see org.springframework.beans.factory.config.BeanPostProcessor * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean @@ -116,7 +117,14 @@ public class GemFireMockObjectsBeanPostProcessor implements BeanPostProcessor { DistributedSystem distributedSystem = gemfireCache.getDistributedSystem(); - doReturn(getGemFireProperties()).when(distributedSystem).getProperties(); + Properties distributedSystemProperties = distributedSystem.getProperties(); + + if (distributedSystemProperties != null) { + distributedSystemProperties.putAll(getGemFireProperties()); + } + else { + doReturn(getGemFireProperties()).when(distributedSystem).getProperties(); + } } return bean; diff --git a/spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/MockPeerCacheApplicationXmlConfigurationIntegrationTests.java b/spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/MockPeerCacheApplicationXmlConfigurationIntegrationTests.java new file mode 100644 index 0000000..0271560 --- /dev/null +++ b/spring-data-geode-test/src/test/java/org/springframework/data/gemfire/tests/MockPeerCacheApplicationXmlConfigurationIntegrationTests.java @@ -0,0 +1,84 @@ +/* + * 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.tests; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Properties; + +import javax.annotation.Resource; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; +import org.apache.geode.distributed.DistributedSystem; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests for an Apache Geode mock peer {@link Cache} application. + * + * @author John Blum + * @see java.util.Properties + * @see org.junit.Test + * @see org.apache.geode.cache.Cache + * @see org.apache.geode.cache.GemFireCache + * @see org.apache.geode.distributed.DistributedSystem + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @since 0.0.26 + */ +@RunWith(SpringRunner.class) +@GemFireUnitTest +@SuppressWarnings("unused") +public class MockPeerCacheApplicationXmlConfigurationIntegrationTests extends IntegrationTestsSupport { + + @Autowired + private GemFireCache cache; + + @Resource(name = "Example") + private Region example; + + @Test + public void gemfireCacheConfigurationIsCorrect() { + + assertThat(this.cache).isNotNull(); + assertThat(this.cache.getName()) + .isEqualTo(MockPeerCacheApplicationXmlConfigurationIntegrationTests.class.getSimpleName()); + assertThat(this.example).isNotNull(); + assertThat(this.example.getName()).isEqualTo("Example"); + assertThat(this.cache.getRegion(this.example.getFullPath())).isEqualTo(this.example); + + DistributedSystem distributedSystem = this.cache.getDistributedSystem(); + + assertThat(distributedSystem).isNotNull(); + assertThat(distributedSystem.getName()).isEqualTo(this.cache.getName()); + + Properties distributedSystemProperties = distributedSystem.getProperties(); + + assertThat(distributedSystemProperties).isNotNull(); + assertThat(distributedSystemProperties.containsKey("disable-auto-reconnect")).isTrue(); + assertThat(Boolean.parseBoolean(distributedSystemProperties.getProperty("disable-auto-reconnect"))).isTrue(); + assertThat(distributedSystemProperties.containsKey("use-cluster-configuration")).isTrue(); + assertThat(Boolean.parseBoolean(distributedSystemProperties.getProperty("use-cluster-configuration"))).isFalse(); + } +} diff --git a/spring-data-geode-test/src/test/resources/org/springframework/data/gemfire/tests/MockPeerCacheApplicationXmlConfigurationIntegrationTests-context.xml b/spring-data-geode-test/src/test/resources/org/springframework/data/gemfire/tests/MockPeerCacheApplicationXmlConfigurationIntegrationTests-context.xml new file mode 100644 index 0000000..600b1a9 --- /dev/null +++ b/spring-data-geode-test/src/test/resources/org/springframework/data/gemfire/tests/MockPeerCacheApplicationXmlConfigurationIntegrationTests-context.xml @@ -0,0 +1,21 @@ + + + + + MockPeerCacheApplicationXmlConfigurationIntegrationTests + error + + + + + + +