Replace all uses of SpringJUnit4ClassRunner with SpringRunner.

Extends STDG's IntegrationTestsSupport abstract base class for Integration Tests.

Resolves gh-296.
This commit is contained in:
John Blum
2021-07-23 12:37:59 -07:00
parent bccec35d5c
commit 8e67fa3804
4 changed files with 81 additions and 46 deletions

View File

@@ -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 <a href="https://stackoverflow.com/questions/39830488/gemfire-entrynotfoundexception-for-cacheevict">Gemfire EntryNotFoundException on @CacheEvict</a>
* @see <a href="https://jira.spring.io/browse/SGF-539">Change GemfireCache.evict(key) to call Region.remove(key)</a>
* @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, Person, Long> personRepository() {
GemfireRepositoryFactoryBean<PersonRepository, Person, Long> 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<Long, Person> peopleRegion(GemFireCache gemfireCache) {
LocalRegionFactoryBean<Long, Person> peopleRegion = new LocalRegionFactoryBean<Long, Person>();
LocalRegionFactoryBean<Long, Person> 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<Long, Person> departmentPeopleRegion(GemFireCache gemfireCache) {
LocalRegionFactoryBean<Long, Person> departmentPeopleRegion = new LocalRegionFactoryBean<Long, Person>();
LocalRegionFactoryBean<Long, Person> 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<Long, Person> mobilePeopleRegion(GemFireCache gemfireCache) {
LocalRegionFactoryBean<Long, Person> mobilePeopleRegion = new LocalRegionFactoryBean<Long, Person>();
LocalRegionFactoryBean<Long, Person> 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<Person, Long> {
List<Person> findByDepartment(Department department);

View File

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

View File

@@ -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 <T> List<T> asList(Iterable<T> iterable) {
List<T> list = new ArrayList<T>();
List<T> 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<Long, Person> simpleRegionAttributes) {
LocalRegionFactoryBean<Long, Person> simpleRegion(Cache gemfireCache, RegionAttributes<Long, Person> simpleRegionAttributes) {
LocalRegionFactoryBean<Long, Person> simpleRegion = new LocalRegionFactoryBean<Long, Person>();
LocalRegionFactoryBean<Long, Person> simpleRegion = new LocalRegionFactoryBean<>();
simpleRegion.setAttributes(simpleRegionAttributes);
simpleRegion.setCache(gemfireCache);
simpleRegion.setClose(false);
simpleRegion.setPersistent(false);
return simpleRegion;
}
@Bean
@SuppressWarnings("unchecked")
RegionAttributesFactoryBean simpleRegionAttributes() {
RegionAttributesFactoryBean<Long, Person> simpleRegionAttributes() {
RegionAttributesFactoryBean simpleRegionAttributes = new RegionAttributesFactoryBean();
RegionAttributesFactoryBean<Long, Person> simpleRegionAttributes = new RegionAttributesFactoryBean<>();
simpleRegionAttributes.setKeyConstraint(Long.class);
simpleRegionAttributes.setValueConstraint(Person.class);

View File

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