From 8e67fa3804189dc40b04de5a10f85ee59f0cc40a Mon Sep 17 00:00:00 2001 From: John Blum Date: Fri, 23 Jul 2021 12:37:59 -0700 Subject: [PATCH] Replace all uses of SpringJUnit4ClassRunner with SpringRunner. Extends STDG's IntegrationTestsSupport abstract base class for Integration Tests. Resolves gh-296. --- ...undCachePutCacheEvictIntegrationTests.java | 43 +++++++++++++------ .../MembershipAttributesIntegrationTests.java | 15 +++++-- .../PersonRepositoryIntegrationTests.java | 37 ++++++++-------- ...sitoryQueriesWithJoinsIntegrationTest.java | 32 +++++++++----- 4 files changed, 81 insertions(+), 46 deletions(-) diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java index 5abe034c..ef27db77 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.cache; import static org.assertj.core.api.Assertions.assertThat; @@ -47,18 +46,19 @@ import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.mapping.GemfireMappingContext; import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.support.IdentifierSequence; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import lombok.Data; import lombok.NonNull; import lombok.RequiredArgsConstructor; /** - * Integration tests testing the contractual behavior and combination of using Spring'a {@link CachePut} annotation + * Integration Tests testing the contractual behavior and combination of using Spring'a {@link CachePut} annotation * followed by a {@link CacheEvict} annotation on an application {@link @Service} component. * * @author John Blum @@ -67,18 +67,19 @@ import lombok.RequiredArgsConstructor; * @see org.springframework.cache.annotation.CachePut * @see org.springframework.cache.annotation.Caching * @see org.springframework.cache.annotation.EnableCaching + * @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 * @see GemfireCache#evict(Object) * @see GemfireCache#put(Object, Object) * @see Gemfire EntryNotFoundException on @CacheEvict * @see Change GemfireCache.evict(key) to call Region.remove(key) * @since 1.9.0 */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration(classes = CompoundCachePutCacheEvictIntegrationTests.ApplicationTestConfiguration.class) @SuppressWarnings("unused") -public class CompoundCachePutCacheEvictIntegrationTests { +public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTestsSupport { private Person janeDoe; private Person jonDoe; @@ -153,10 +154,16 @@ public class CompoundCachePutCacheEvictIntegrationTests { @Bean GemfireCacheManager cacheManager(GemFireCache gemfireCache) { + GemfireCacheManager cacheManager = new GemfireCacheManager() { - @Override protected org.springframework.cache.Cache decorateCache(org.springframework.cache.Cache cache) { + + @Override + protected org.springframework.cache.Cache decorateCache(org.springframework.cache.Cache cache) { + return new GemfireCache((org.apache.geode.cache.Region) cache.getNativeCache()) { - @Override public void evict(Object key) { + + @Override + public void evict(Object key) { getNativeCache().remove(key); } }; @@ -176,13 +183,17 @@ public class CompoundCachePutCacheEvictIntegrationTests { @Bean GemfireCacheManager cacheManager(GemFireCache gemfireCache) { + GemfireCacheManager cacheManager = new GemfireCacheManager(); + cacheManager.setCache(gemfireCache); + return cacheManager; } @Bean GemfireRepositoryFactoryBean personRepository() { + GemfireRepositoryFactoryBean personRepository = new GemfireRepositoryFactoryBean<>(PersonRepository.class); @@ -223,6 +234,7 @@ public class CompoundCachePutCacheEvictIntegrationTests { @Bean CacheFactoryBean gemfireCache() { + CacheFactoryBean gemfireCache = new CacheFactoryBean(); gemfireCache.setClose(true); @@ -233,10 +245,10 @@ public class CompoundCachePutCacheEvictIntegrationTests { @Bean(name = "People") LocalRegionFactoryBean peopleRegion(GemFireCache gemfireCache) { - LocalRegionFactoryBean peopleRegion = new LocalRegionFactoryBean(); + + LocalRegionFactoryBean peopleRegion = new LocalRegionFactoryBean<>(); peopleRegion.setCache(gemfireCache); - peopleRegion.setClose(false); peopleRegion.setPersistent(false); return peopleRegion; @@ -244,10 +256,10 @@ public class CompoundCachePutCacheEvictIntegrationTests { @Bean(name = "DepartmentPeople") LocalRegionFactoryBean departmentPeopleRegion(GemFireCache gemfireCache) { - LocalRegionFactoryBean departmentPeopleRegion = new LocalRegionFactoryBean(); + + LocalRegionFactoryBean departmentPeopleRegion = new LocalRegionFactoryBean<>(); departmentPeopleRegion.setCache(gemfireCache); - departmentPeopleRegion.setClose(false); departmentPeopleRegion.setPersistent(false); return departmentPeopleRegion; @@ -255,10 +267,10 @@ public class CompoundCachePutCacheEvictIntegrationTests { @Bean(name = "MobilePeople") LocalRegionFactoryBean mobilePeopleRegion(GemFireCache gemfireCache) { - LocalRegionFactoryBean mobilePeopleRegion = new LocalRegionFactoryBean(); + + LocalRegionFactoryBean mobilePeopleRegion = new LocalRegionFactoryBean<>(); mobilePeopleRegion.setCache(gemfireCache); - mobilePeopleRegion.setClose(false); mobilePeopleRegion.setPersistent(false); return mobilePeopleRegion; @@ -266,6 +278,7 @@ public class CompoundCachePutCacheEvictIntegrationTests { } public enum Department { + ACCOUNTING, DESIGN, ENGINEERING, @@ -274,6 +287,7 @@ public class CompoundCachePutCacheEvictIntegrationTests { MARKETING, RESEARCH_DEVELOPMENT, SALES + } @Data @@ -336,6 +350,7 @@ public class CompoundCachePutCacheEvictIntegrationTests { this.cacheMiss.set(true); } } + public interface PersonRepository extends CrudRepository { List findByDepartment(Department department); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java index ad2419ca..e5c4e67a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java @@ -31,16 +31,25 @@ import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** + * Integration Tests for {@link MembershipAttributes}. + * * @author David Turanski * @author John Blum + * @see org.junit.Test + * @see org.apache.geode.cache.MembershipAttributes + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration(locations = "/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) -@SuppressWarnings("unused") +@SuppressWarnings({ "deprecation", "unused" }) public class MembershipAttributesIntegrationTests extends IntegrationTestsSupport { @Autowired diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepositoryIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepositoryIntegrationTests.java index 94f2ef32..4fadae9e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepositoryIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepositoryIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.repository.sample; import static org.assertj.core.api.Assertions.assertThat; @@ -26,13 +25,13 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.atomic.AtomicLong; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.RegionAttributes; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.RegionAttributes; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -43,25 +42,27 @@ import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.RegionAttributesFactoryBean; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The PersonRepositoryIntegrationTests class... + * Integration Tests for {@link PersonRepository}. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith + * @see org.apache.geode.cache.GemFireCache * @see org.springframework.data.gemfire.repository.sample.Person * @see org.springframework.data.gemfire.repository.sample.PersonRepository + * @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.4.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = PersonRepositoryIntegrationTests.GemFireConfiguration.class) +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = PersonRepositoryIntegrationTests.TestConfiguration.class) @SuppressWarnings("unused") -public class PersonRepositoryIntegrationTests { +public class PersonRepositoryIntegrationTests extends IntegrationTestsSupport { private static final String DEFAULT_GEMFIRE_LOG_LEVEL = "error"; private static final String GEMFIRE_LOG_LEVEL = System.getProperty("gemfire.log-level", DEFAULT_GEMFIRE_LOG_LEVEL); @@ -99,7 +100,7 @@ public class PersonRepositoryIntegrationTests { protected List asList(Iterable iterable) { - List list = new ArrayList(); + List list = new ArrayList<>(); for (T element : iterable) { list.add(element); @@ -202,7 +203,7 @@ public class PersonRepositoryIntegrationTests { @EnableGemfireRepositories(basePackages = "org.springframework.data.gemfire.repository.sample", includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = org.springframework.data.gemfire.repository.sample.PersonRepository.class)) - public static class GemFireConfiguration { + public static class TestConfiguration { Properties gemfireProperties() { @@ -234,23 +235,21 @@ public class PersonRepositoryIntegrationTests { } @Bean(name = "simple") - LocalRegionFactoryBean simpleRegion(Cache gemfireCache, RegionAttributes simpleRegionAttributes) { + LocalRegionFactoryBean simpleRegion(Cache gemfireCache, RegionAttributes simpleRegionAttributes) { - LocalRegionFactoryBean simpleRegion = new LocalRegionFactoryBean(); + LocalRegionFactoryBean simpleRegion = new LocalRegionFactoryBean<>(); simpleRegion.setAttributes(simpleRegionAttributes); simpleRegion.setCache(gemfireCache); - simpleRegion.setClose(false); simpleRegion.setPersistent(false); return simpleRegion; } @Bean - @SuppressWarnings("unchecked") - RegionAttributesFactoryBean simpleRegionAttributes() { + RegionAttributesFactoryBean simpleRegionAttributes() { - RegionAttributesFactoryBean simpleRegionAttributes = new RegionAttributesFactoryBean(); + RegionAttributesFactoryBean simpleRegionAttributes = new RegionAttributesFactoryBean<>(); simpleRegionAttributes.setKeyConstraint(Long.class); simpleRegionAttributes.setValueConstraint(Person.class); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/RepositoryQueriesWithJoinsIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/RepositoryQueriesWithJoinsIntegrationTest.java index 73187fec..37bc967d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/RepositoryQueriesWithJoinsIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/sample/RepositoryQueriesWithJoinsIntegrationTest.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.repository.sample; import static org.assertj.core.api.Assertions.assertThat; @@ -25,25 +24,31 @@ import java.util.concurrent.atomic.AtomicLong; 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.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The RepositoryQueriesWithJoinsTest class is a test suite of test cases testing the use of JOINS between 2 Regions - * in GemFire OQL queries (SELECT statements). + * Integration Tests for {@literal JOINS} between 2 {@link Region Regions} in OQL queries + * (i.e. {@literal SELECT} statements). * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.query.Query + * @see org.springframework.data.gemfire.repository.GemfireRepository + * @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.0.0 */ +@RunWith(SpringRunner.class) @ContextConfiguration("repositoryQueriesWithJoins.xml") -@RunWith(SpringJUnit4ClassRunner.class) @SuppressWarnings("unused") -public class RepositoryQueriesWithJoinsIntegrationTest { +public class RepositoryQueriesWithJoinsIntegrationTest extends IntegrationTestsSupport { private static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); @@ -53,20 +58,27 @@ public class RepositoryQueriesWithJoinsIntegrationTest { @Autowired private CustomerRepository customerRepo; - protected Account newAccount(Customer customer, String number) { + private Account newAccount(Customer customer, String number) { + Account account = new Account(ID_SEQUENCE.incrementAndGet(), customer); + account.setNumber(number); + return account; } - protected Customer newCustomer(String firstName, String lastName) { + private Customer newCustomer(String firstName, String lastName) { + Customer customer = new Customer(firstName, lastName); + customer.setId(ID_SEQUENCE.incrementAndGet()); + return customer; } @Test public void joinQueriesWork() { + Customer jonDoe = customerRepo.save(newCustomer("Jon", "Doe")); Customer janeDoe = customerRepo.save(newCustomer("Jane", "Doe")); Customer jackHandy = customerRepo.save(newCustomer("Jack", "Handy"));