Skip to content

Commit

Permalink
Extend the STDG o.s.d.g.tests.integration.IntegrationTestsSupport abs…
Browse files Browse the repository at this point in the history
…tract base class in all Integration-based Tests.

This applies to test classes in particular that bootstrap and configure Apache Geode in a Spring ApplicationContext using the JUnit4 SpringRunner class.

Resolves spring-projectsgh-296.
  • Loading branch information
jxblum committed Sep 17, 2021
1 parent a584b40 commit ddcd019
Show file tree
Hide file tree
Showing 128 changed files with 1,073 additions and 958 deletions.
Expand Up @@ -43,6 +43,7 @@
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.Order;
import org.springframework.core.annotation.OrderUtils;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.util.CollectionUtils;
import org.springframework.data.gemfire.util.SpringUtils;
import org.springframework.data.gemfire.util.StreamUtils;
Expand All @@ -52,22 +53,23 @@
import org.springframework.test.context.junit4.SpringRunner;

/**
* Integration Tests testing the bean ordering applied by the Spring {@link ApplicationContext}
* Integration Tests asserting the bean ordering applied by the Spring {@link ApplicationContext}
* or Spring {@link BeanFactory} when using the {@link Order} annotation or implementing the {@link Ordered} interface.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.beans.factory.ListableBeanFactory
* @see org.springframework.core.Ordered
* @see org.springframework.core.annotation.Order
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 2.3.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class ApplicationContextBeanOrderingIntegrationTests {
public class ApplicationContextBeanOrderingIntegrationTests extends IntegrationTestsSupport {

@Autowired
private ConfigurableApplicationContext applicationContext;
Expand Down
Expand Up @@ -13,45 +13,49 @@
* 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 static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.apache.geode.cache.Region;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Integration tests to test the contract and functionality of Spring Data GemFire's Auto Region Lookup functionality.
* Integration Tests for SDG Auto {@link Region} Lookup functionality.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.apache.geode.cache.Region
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class AutoRegionLookupIntegrationTests {
public class AutoRegionLookupIntegrationTests extends IntegrationTestsSupport {

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

assertThat(this.applicationContext.containsBean("SpringPartitionedRegion")).isTrue();
assertThat(this.applicationContext.containsBean("SpringReplicateParent")).isTrue();
assertThat(this.applicationContext.containsBean("/SpringReplicateParent/SpringReplicateChild")).isTrue();
assertThat(this.applicationContext.containsBean("NativePartitionedRegion")).isTrue();
assertThat(this.applicationContext.containsBean("NativeReplicateParent")).isTrue();
assertThat(this.applicationContext.containsBean("/NativeReplicateParent/NativeReplicateChild")).isTrue();
assertThat(this.applicationContext.containsBean("/NativeReplicateParent/NativeReplicateChild/NativeReplicateGrandchild")).isTrue();
}
}
Expand Up @@ -13,44 +13,40 @@
* 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 static org.assertj.core.api.Assertions.assertThat;

import javax.annotation.Resource;

import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Integration tests to test the behavior of Spring Data GemFire's Auto Region Lookup functionality
* when combined with Spring's component auto-wiring capabilities.
* Integration Tests for SDG's Auto {@link 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.apache.geode.cache.Region
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class AutoRegionLookupWithAutowiringIntegrationTests {

@Autowired
private TestComponent testComponent;
public class AutoRegionLookupWithAutowiringIntegrationTests extends IntegrationTestsSupport {

private static void assertRegionMetaData(Region<?, ?> region, String expectedName, DataPolicy expectedDataPolicy) {
assertRegionMetaData(region, expectedName, Region.SEPARATOR + expectedName, expectedDataPolicy);
Expand All @@ -59,14 +55,24 @@ private static void assertRegionMetaData(Region<?, ?> region, String expectedNam
private static void assertRegionMetaData(Region<?, ?> region, String expectedName, String expectedFullPath,
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());
assertThat(region)
.describedAs(String.format("Region (%1$s) was not properly configured and initialized!", expectedName))
.isNotNull();

assertThat(region.getName()).isEqualTo(expectedName);
assertThat(region.getFullPath()).isEqualTo(expectedFullPath);

assertThat(region.getAttributes())
.describedAs(String.format("Region (%1$s) must have RegionAttributes defined!", expectedName))
.isNotNull();

assertThat(region.getAttributes().getDataPolicy()).isEqualTo(expectedDataPolicy);
assertThat(region.getAttributes().getDataPolicy().withPersistence()).isFalse();
}

@Autowired
private TestComponent testComponent;

@Test
public void testAutowiredNativeRegions() {

Expand Down
Expand Up @@ -13,44 +13,47 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.data.gemfire;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.apache.geode.cache.Region;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Integration tests to test the behavior of Spring Data GemFire's Auto Region Lookup behavior
* with Spring component scanning functionality.
* Integration Tests for SDG's Auto {@link Region} Lookup behavior with Spring component scanning functionality.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.apache.geode.cache.Region
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class AutoRegionLookupWithComponentScanningIntegrationTests {
public class AutoRegionLookupWithComponentScanningIntegrationTests extends IntegrationTestsSupport {

@Autowired
private ApplicationContext applicationContext;

@Test
public void testAutowiredNativeRegions() {

assertTrue("The 'autoRegionLookupDao' Spring bean DAO was not properly configured an initialized!",
this.applicationContext.containsBean("autoRegionLookupDao"));
assertNotNull(this.applicationContext.getBean("autoRegionLookupDao", AutoRegionLookupDao.class));
assertThat(this.applicationContext.containsBean("autoRegionLookupDao"))
.describedAs("The 'autoRegionLookupDao' Spring bean DAO was not properly configured an initialized!")
.isTrue();

assertThat(this.applicationContext.getBean("autoRegionLookupDao", AutoRegionLookupDao.class)).isNotNull();
}
}
Expand Up @@ -13,70 +13,72 @@
* 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 org.apache.geode.cache.Cache;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.apache.geode.cache.Cache;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Integration test trying various basic configurations of GemFire through
* Spring.
*
* Made abstract to avoid multiple caches running at the same time.
* Integration Tests trying various basic configurations of Apache Geode caches with Spring.
*
* @author Costin Leau
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.Cache
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = "basic-cache.xml")
public class CacheIntegrationTest {
public class CacheIntegrationTests extends IntegrationTestsSupport {

@Autowired
ApplicationContext applicationContext;
private ApplicationContext applicationContext;

Cache cache;
private Cache cache;

@After
public void tearDown() {
GemfireUtils.close(this.cache);
}

@Test
public void testBasicCache() throws Exception {
cache = applicationContext.getBean("default-cache",Cache.class);
public void testBasicCache() {
this.cache = this.applicationContext.getBean("default-cache",Cache.class);
}

@Test
public void testCacheWithProps() throws Exception {
public void testCacheWithProps() {
cache = applicationContext.getBean("cache-with-props", Cache.class);

// the name property seems to be ignored
assertEquals("cache-with-props", cache.getDistributedSystem().getName());
assertEquals("cache-with-props", cache.getName());
assertThat(cache.getDistributedSystem().getName()).isEqualTo("cache-with-props");
assertThat(cache.getName()).isEqualTo("cache-with-props");
}

@Test
public void testNamedCache() throws Exception {
public void testNamedCache() {

cache = applicationContext.getBean("named-cache", Cache.class);
this.cache = this.applicationContext.getBean("named-cache", Cache.class);

assertEquals("named-cache", cache.getDistributedSystem().getName());
assertEquals("named-cache", cache.getName());
assertThat(cache.getDistributedSystem().getName()).isEqualTo("named-cache");
assertThat(cache.getName()).isEqualTo("named-cache");
}

@Test
public void testCacheWithXml() throws Exception {
applicationContext.getBean("cache-with-xml", Cache.class);
public void testCacheWithXml() {
this.applicationContext.getBean("cache-with-xml", Cache.class);
}
}
Expand Up @@ -43,6 +43,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.gemfire.repository.sample.User;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.util.CacheUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -56,16 +57,18 @@
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.query.SelectResults
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.GemfireTemplate
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.4.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class GemfireTemplateIntegrationTests {
public class GemfireTemplateIntegrationTests extends IntegrationTestsSupport {

protected static final String DEFAULT_GEMFIRE_LOG_LEVEL = "error";

Expand Down
Expand Up @@ -61,22 +61,24 @@
import lombok.RequiredArgsConstructor;

/**
* Integrations Tests for {@link GemfireTemplate} testing the proper function and behavior of executing (OQL) queries
* from a cache client application using the {@link GemfireTemplate} to a cluster of GemFire servers that have
* Integrations Tests for {@link GemfireTemplate} testing the proper function and behavior of executing OQL queries
* from a cache client application using the {@link GemfireTemplate} to a cluster of Apache Geode servers that have
* been grouped according to business function and data access in order to distribute the load.
*
* Each GemFire {@link Pool} is configured to target a specific server group. Each group of servers in the cluster
* defines specific {@link Region Regions} to manage data independently and separately from other data that might
* garner high frequency access.
* Each Apache Geode {@link Pool} is configured to target a specific server group. Each group of servers in the cluster
* defines specific {@link Region Regions} to manage data independently and separately from other data that might garner
* high frequency access.
*
* Spring Data GemFire's {@link GemfireTemplate} should intelligently employ the right
* Spring Data for Apache Geode's {@link GemfireTemplate} should intelligently employ the right
* {@link org.apache.geode.cache.query.QueryService} configured with the {@link Region Region's} {@link Pool}
* metadata when executing the query in order to ensure the right servers containing the {@link Region Region's}
* with the data of interest are targeted.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
* @see org.springframework.data.gemfire.GemfireTemplate
* @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
Expand Down

0 comments on commit ddcd019

Please sign in to comment.