From cc9c724fbc752fffea9d0097a3b763ab652bb0b6 Mon Sep 17 00:00:00 2001 From: John Blum Date: Sat, 30 Aug 2014 14:44:58 -0700 Subject: [PATCH] Adding a simple test case to assert the contract and functional behavior of the element when used in Spring context config coupled with GemFire's native cache.xml configuration file. --- .../AutoRegionLookupBeanDefinitionParser.java | 7 ++- .../AutoRegionLookupBeanPostProcessor.java | 2 +- .../AutoRegionLookupIntegrationTests.java | 58 +++++++++++++++++++ src/test/resources/autoregionlookup-cache.xml | 12 ++++ ...toRegionLookupIntegrationTests-context.xml | 28 +++++++++ 5 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests.java create mode 100644 src/test/resources/autoregionlookup-cache.xml create mode 100644 src/test/resources/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests-context.xml diff --git a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanDefinitionParser.java b/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanDefinitionParser.java index 33d36b6f..2f0909ff 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanDefinitionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanDefinitionParser.java @@ -25,7 +25,9 @@ import org.springframework.beans.factory.xml.ParserContext; import org.w3c.dom.Element; /** - * The AutoRegionLookupBeanDefinitionParser class... + * The AutoRegionLookupBeanDefinitionParser class is a Spring BeanDefinitionParser that registers a BeanPostProcessor + * that auto registers Regions defined in GemFire's native cache.xml format, or when using GemFire 8's cluster-based + * configuration service to define Regions, creating corresponding beans in the Spring context. * * @author John Blum * @see org.springframework.beans.factory.config.BeanDefinition @@ -33,10 +35,11 @@ import org.w3c.dom.Element; * @see org.springframework.beans.factory.support.BeanDefinitionBuilder * @see org.springframework.beans.factory.xml.BeanDefinitionParser * @see org.springframework.beans.factory.xml.ParserContext + * @see org.springframework.data.gemfire.config.AutoRegionLookupBeanPostProcessor * @see org.w3c.dom.Element * @since 1.5.0 */ -public class AutoRegionLookupBeanDefinitionParser implements BeanDefinitionParser { +class AutoRegionLookupBeanDefinitionParser implements BeanDefinitionParser { @Override public BeanDefinition parse(final Element element, final ParserContext parserContext) { diff --git a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanPostProcessor.java index 4fc5f785..7865a4cc 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanPostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanPostProcessor.java @@ -33,7 +33,7 @@ import com.gemstone.gemfire.cache.Region; /** * The AutoRegionLookupBeanPostProcessor class is a Spring BeanPostProcessor that post processes a GemFireCache by * registering all Cache Regions that have not been explicitly defined in the Spring application context. This is - * usually the case for Regions that have been defined in GemFire native cache.xml or defined use GemFire 8's new + * usually the case for Regions that have been defined in GemFire's native cache.xml or defined use GemFire 8's new * cluster-based configuration service. * * @author John Blum diff --git a/src/test/java/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests.java new file mode 100644 index 00000000..276d8c68 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2013 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.data.gemfire; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * The AutoRegionLookupIntegrationTests class is a test suite of test cases testing the contract and functionality + * of Spring Data GemFire's new auto Region lookup feature. + * + * @author John Blum + * @see org.junit.Test + * @see org.junit.runner.RunWith + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner + * @since 1.5.0 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +@SuppressWarnings("unused") +public class AutoRegionLookupIntegrationTests { + + @Autowired + private ApplicationContext applicationContext; + + @Test + public void testAutoRegionLookup() { + assertTrue(applicationContext.containsBean("SpringPartitionedRegion")); + assertTrue(applicationContext.containsBean("SpringReplicateParent")); + assertTrue(applicationContext.containsBean("/SpringReplicateParent/SpringReplicateChild")); + assertTrue(applicationContext.containsBean("NativePartitionedRegion")); + assertTrue(applicationContext.containsBean("NativeReplicateParent")); + assertTrue(applicationContext.containsBean("/NativeReplicateParent/NativeReplicateChild")); + assertTrue(applicationContext.containsBean("/NativeReplicateParent/NativeReplicateChild/NativeReplicateGrandchild")); + } + +} diff --git a/src/test/resources/autoregionlookup-cache.xml b/src/test/resources/autoregionlookup-cache.xml new file mode 100644 index 00000000..45736335 --- /dev/null +++ b/src/test/resources/autoregionlookup-cache.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests-context.xml b/src/test/resources/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests-context.xml new file mode 100644 index 00000000..cb652e12 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/AutoRegionLookupIntegrationTests-context.xml @@ -0,0 +1,28 @@ + + + + + AutoRegionLookupIntegrationTests + 0 + warning + + + + + + + + + + + + +