Additional test case to test SDG's auto Region lookup behavior with Spring's auto-wiring functionality.

(cherry picked from commit 37428e2ba7)

Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
John Blum
2014-08-31 23:01:08 -07:00
parent b902027f04
commit 96914bf282
2 changed files with 134 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
/*
* 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.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
/**
* The AutoRegionLookupWithAutowiringIntegrationTests class is a test suite class testing the behavior of
* Spring Data GemFire's auto Region lookup functionality when combined with Spring's component auto-wiring capabilities.
*
* @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 AutoRegionLookupWithAutowiringIntegrationTests {
@Autowired
private TestComponent testComponent;
protected static void assertRegionMetaData(final Region<?, ?> region,
final String expectedName, final DataPolicy expectedDataPolicy) {
assertRegionMetaData(region, expectedName, Region.SEPARATOR + expectedName, expectedDataPolicy);
}
protected static void assertRegionMetaData(final Region<?, ?> region, final String expectedName,
final String expectedFullPath, final DataPolicy expectedDataPolicy) {
assertNotNull(String.format("Region (%1$s) was not properly configured and initialized!", expectedName), region);
assertEquals(expectedName, region.getName());
assertEquals(expectedFullPath, region.getFullPath());
assertNotNull(String.format("Region (%1$s) must have RegionAttributes defined!", expectedName),
region.getAttributes());
assertEquals(expectedDataPolicy, region.getAttributes().getDataPolicy());
assertFalse(region.getAttributes().getDataPolicy().withPersistence());
}
@Test
public void testAutowiredNativeRegions() {
assertRegionMetaData(testComponent.nativePartitionedRegion, "NativePartitionedRegion", DataPolicy.PARTITION);
assertRegionMetaData(testComponent.nativeReplicateParent, "NativeReplicateParent", DataPolicy.REPLICATE);
assertRegionMetaData(testComponent.nativeReplicateChild, "NativeReplicateChild",
"/NativeReplicateParent/NativeReplicateChild", DataPolicy.REPLICATE);
assertRegionMetaData(testComponent.nativeReplicateGrandchild, "NativeReplicateGrandchild",
"/NativeReplicateParent/NativeReplicateChild/NativeReplicateGrandchild", DataPolicy.REPLICATE);
}
@Component
public static final class TestComponent {
@Resource(name = "NativePartitionedRegion")
Region<?, ?> nativePartitionedRegion;
@Resource(name = "NativeReplicateParent")
Region<?, ?> nativeReplicateParent;
@Resource(name = "/NativeReplicateParent/NativeReplicateChild")
Region<?, ?> nativeReplicateChild;
@Resource(name = "/NativeReplicateParent/NativeReplicateChild/NativeReplicateGrandchild")
Region<?, ?> nativeReplicateGrandchild;
}
}

View File

@@ -0,0 +1,37 @@
<?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
">
<bean class="org.springframework.data.gemfire.AutoRegionLookupWithAutowiringIntegrationTests$TestComponent"
depends-on="gemfireCache"/>
<util:properties id="gemfireProperties">
<prop key="name">AutoRegionLookupWithAutowiringIntegrationTests</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:auto-region-lookup/>
<!--
TestComponent bean creation fails since the test class has a dependency on the TestComponent class, which has
dependencies on all the GemFire native Regions defined in cache.xml, which have not been defined yet since
the test class's dependency on TestComponent forces an early creation of TestComponent before the GemFire Cache
as been instantiated, configured and initialized. Therefore, it does not matter what order the bean definitions
are specified in the Spring context configuration meta-data, the developer must use the 'depends-on' attribute
to force the correct initialization order.
-->
<!--
<bean class="org.springframework.data.gemfire.AutoRegionLookupWithAutowiringIntegrationTests$TestComponent"/>
-->
</beans>