Adding a simple test case to assert the contract and functional behavior of the <gfe:auto-region-lookup/> element when used in Spring context config coupled with GemFire's native cache.xml configuration file.

This commit is contained in:
John Blum
2014-08-30 14:44:58 -07:00
parent 920e53794e
commit cc9c724fbc
5 changed files with 104 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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

View File

@@ -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"));
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!DOCTYPE cache PUBLIC "-//GemStone Systems, Inc.//GemFire Declarative Caching 7.0//EN"
"http://www.gemstone.com/dtd/cache8_0.dtd">
<cache>
<region name="NativePartitionedRegion" refid="PARTITION"/>
<region name="NativeReplicateParent" refid="REPLICATE">
<region name="NativeReplicateChild" refid="REPLICATE">
<region name="NativeReplicateGrandchild" refid="REPLICATE"/>
</region>
</region>
</cache>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
">
<util:properties id="gemfireProperties">
<prop key="name">AutoRegionLookupIntegrationTests</prop>
<prop key="mcast-port">0</prop>
<prop key="log-level">warning</prop>
</util:properties>
<gfe:cache properties-ref="gemfireProperties" cache-xml-location="/autoregionlookup-cache.xml"/>
<gfe:partitioned-region id="SpringPartitionedRegion" persistent="false"/>
<gfe:replicated-region id="SpringReplicateParent" persistent="false">
<gfe:replicated-region name="SpringReplicateChild" persistent="false"/>
</gfe:replicated-region>
<gfe:auto-region-lookup/>
</beans>