Refactor all Unit & Integration Tests starting a Spring container with SpringRunner to extend STDG's IntegrationTestsSupport.

This commit is contained in:
John Blum
2021-03-30 11:25:08 -07:00
parent 9cdb4ca7f3
commit 0728ee1e21
10 changed files with 36 additions and 15 deletions

View File

@@ -31,7 +31,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@@ -39,6 +38,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@@ -53,7 +53,9 @@ import org.springframework.util.StringUtils;
* @see org.springframework.boot.autoconfigure.condition.AnyNestedCondition * @see org.springframework.boot.autoconfigure.condition.AnyNestedCondition
* @see org.springframework.context.annotation.Condition * @see org.springframework.context.annotation.Condition
* @see org.springframework.context.annotation.Conditional * @see org.springframework.context.annotation.Conditional
* @see org.springframework.context.annotation.ConditionContext
* @see org.springframework.context.annotation.Configuration * @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
* @since 1.2.0 * @since 1.2.0
@@ -61,7 +63,7 @@ import org.springframework.util.StringUtils;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration @ContextConfiguration
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class ComplexConditionalConfigurationIntegrationTests { public class ComplexConditionalConfigurationIntegrationTests extends IntegrationTestsSupport {
private static final AtomicBoolean importBeanDefinitionRegistrarCalled = new AtomicBoolean(false); private static final AtomicBoolean importBeanDefinitionRegistrarCalled = new AtomicBoolean(false);
@@ -121,7 +123,7 @@ public class ComplexConditionalConfigurationIntegrationTests {
} }
static final class MockConditionOne implements Condition { static final class MockConditionOne implements org.springframework.context.annotation.Condition {
@Override @Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
@@ -129,7 +131,7 @@ public class ComplexConditionalConfigurationIntegrationTests {
} }
} }
static final class MockConditionTwo implements Condition { static final class MockConditionTwo implements org.springframework.context.annotation.Condition {
@Override @Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

View File

@@ -28,6 +28,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.geode.boot.autoconfigure.DataImportExportAutoConfiguration; import org.springframework.geode.boot.autoconfigure.DataImportExportAutoConfiguration;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@@ -43,6 +44,7 @@ import example.app.golf.model.Golfer;
* @see org.springframework.boot.test.context.SpringBootTest * @see org.springframework.boot.test.context.SpringBootTest
* @see org.springframework.context.annotation.Profile * @see org.springframework.context.annotation.Profile
* @see org.springframework.data.gemfire.GemfireTemplate * @see org.springframework.data.gemfire.GemfireTemplate
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.geode.boot.autoconfigure.DataImportExportAutoConfiguration * @see org.springframework.geode.boot.autoconfigure.DataImportExportAutoConfiguration
* @see org.springframework.test.context.ActiveProfiles * @see org.springframework.test.context.ActiveProfiles
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
@@ -57,7 +59,7 @@ import example.app.golf.model.Golfer;
"spring.boot.data.gemfire.cache.data.import.active-profiles=IMPORT-LOCAL" "spring.boot.data.gemfire.cache.data.import.active-profiles=IMPORT-LOCAL"
} }
) )
public class LocalClientCacheDataImportAutoConfigurationIntegrationTests { public class LocalClientCacheDataImportAutoConfigurationIntegrationTests extends IntegrationTestsSupport {
@Autowired @Autowired
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@@ -28,6 +28,7 @@ import org.apache.geode.distributed.Locator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@@ -42,6 +43,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.client.ClientCache
* @see org.apache.geode.distributed.Locator * @see org.apache.geode.distributed.Locator
* @see org.springframework.boot.autoconfigure.SpringBootApplication * @see org.springframework.boot.autoconfigure.SpringBootApplication
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
@@ -50,7 +52,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration @ContextConfiguration
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class SpringBootLocatorApplicationIntegrationTests { public class SpringBootLocatorApplicationIntegrationTests extends IntegrationTestsSupport {
@Autowired(required = false) @Autowired(required = false)
private GemFireCache clientCache; private GemFireCache clientCache;

View File

@@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.data.gemfire.tests.support.MapBuilder; import org.springframework.data.gemfire.tests.support.MapBuilder;
import org.springframework.hamcrest.RegexMatcher; import org.springframework.hamcrest.RegexMatcher;
@@ -63,6 +64,7 @@ import lombok.ToString;
* @see org.springframework.boot.autoconfigure.SpringBootApplication * @see org.springframework.boot.autoconfigure.SpringBootApplication
* @see org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc * @see org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
* @see org.springframework.boot.test.context.SpringBootTest * @see org.springframework.boot.test.context.SpringBootTest
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
* @see org.springframework.test.web.servlet.MockMvc * @see org.springframework.test.web.servlet.MockMvc
@@ -79,7 +81,7 @@ import lombok.ToString;
) )
@AutoConfigureMockMvc @AutoConfigureMockMvc
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class MockPersistentSessionAccessSmokeTests { public class MockPersistentSessionAccessSmokeTests extends IntegrationTestsSupport {
@Autowired @Autowired
private MockMvc mvc; private MockMvc mvc;

View File

@@ -21,4 +21,6 @@ dependencies {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
} }
testImplementation('org.springframework.data:spring-data-geode-test')
} }

View File

@@ -23,6 +23,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import example.app.model.Contact; import example.app.model.Contact;
@@ -35,16 +36,14 @@ import example.app.service.ContactsService;
* @author John Blum * @author John Blum
* @see org.junit.Test * @see org.junit.Test
* @see org.springframework.boot.test.context.SpringBootTest * @see org.springframework.boot.test.context.SpringBootTest
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
* @see example.app.model.Contact
* @see example.app.repo.ContactRepository
* @see example.app.service.ContactsService
* @since 1.2.0 * @since 1.2.0
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class DatabaseWithLookAsideCachingApplicationSmokeTests { public class DatabaseWithLookAsideCachingApplicationSmokeTests extends IntegrationTestsSupport {
@Autowired @Autowired
private ContactRepository contactRepository; private ContactRepository contactRepository;

View File

@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.AbstractRefreshableApplicationContext; import org.springframework.context.support.AbstractRefreshableApplicationContext;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.geode.distributed.event.ApplicationContextMembershipListener; import org.springframework.geode.distributed.event.ApplicationContextMembershipListener;
import org.springframework.geode.distributed.event.MembershipListenerAdapter; import org.springframework.geode.distributed.event.MembershipListenerAdapter;
@@ -45,7 +46,10 @@ import org.springframework.test.context.junit4.SpringRunner;
* @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.Cache
* @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.context.ConfigurableApplicationContext
* @see org.springframework.context.support.AbstractRefreshableApplicationContext * @see org.springframework.context.support.AbstractRefreshableApplicationContext
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.geode.distributed.event.ApplicationContextMembershipListener
* @see org.springframework.geode.distributed.event.MembershipListenerAdapter
* @see org.springframework.geode.test.context.TestRefreshableApplicationContextLoader * @see org.springframework.geode.test.context.TestRefreshableApplicationContextLoader
* @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
@@ -58,7 +62,7 @@ import org.springframework.test.context.junit4.SpringRunner;
loader = TestRefreshableApplicationContextLoader.class loader = TestRefreshableApplicationContextLoader.class
) )
@SuppressWarnings({ "unused" }) @SuppressWarnings({ "unused" })
public class SpringBootApacheGeodePeerCacheApplicationUnitTests { public class SpringBootApacheGeodePeerCacheApplicationUnitTests extends IntegrationTestsSupport {
@Autowired @Autowired
private ConfigurableApplicationContext applicationContext; private ConfigurableApplicationContext applicationContext;

View File

@@ -26,6 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
@@ -37,6 +38,7 @@ import org.springframework.web.context.WebApplicationContext;
* @see org.springframework.boot.test.context.SpringBootTest * @see org.springframework.boot.test.context.SpringBootTest
* @see org.springframework.context.ApplicationContext * @see org.springframework.context.ApplicationContext
* @see org.springframework.data.gemfire.GemfireTemplate * @see org.springframework.data.gemfire.GemfireTemplate
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
* @see example.app.InitializerApplication * @see example.app.InitializerApplication
* @since 1.2.0 * @since 1.2.0
@@ -44,7 +46,7 @@ import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class InitializerApplicationSmokeTests { public class InitializerApplicationSmokeTests extends IntegrationTestsSupport {
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;

View File

@@ -40,6 +40,7 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
@@ -51,12 +52,15 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author John Blum * @author John Blum
* @see org.junit.Test * @see org.junit.Test
* @see org.mockito.Mockito * @see org.mockito.Mockito
* @see org.springframework.beans.factory.FactoryBean
* @see org.springframework.beans.factory.InitializingBean
* @see org.springframework.cache.Cache * @see org.springframework.cache.Cache
* @see org.springframework.cache.CacheManager * @see org.springframework.cache.CacheManager
* @see org.springframework.cache.annotation.Cacheable * @see org.springframework.cache.annotation.Cacheable
* @see org.springframework.cache.annotation.EnableCaching * @see org.springframework.cache.annotation.EnableCaching
* @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration * @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.stereotype.Service * @see org.springframework.stereotype.Service
* @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner * @see org.springframework.test.context.junit4.SpringRunner
@@ -65,7 +69,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration @ContextConfiguration
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class SpringCachingWithMockObjectsUnitTests { public class SpringCachingWithMockObjectsUnitTests extends IntegrationTestsSupport {
@Autowired @Autowired
private TestCacheableService testService; private TestCacheableService testService;

View File

@@ -22,6 +22,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.geode.context.annotation.RefreshableAnnotationConfigApplicationContext; import org.springframework.geode.context.annotation.RefreshableAnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@@ -31,6 +32,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* *
* @author John Blum * @author John Blum
* @see org.junit.Test * @see org.junit.Test
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.geode.context.annotation.RefreshableAnnotationConfigApplicationContext * @see org.springframework.geode.context.annotation.RefreshableAnnotationConfigApplicationContext
* @see org.springframework.geode.test.context.TestRefreshableApplicationContextLoader * @see org.springframework.geode.test.context.TestRefreshableApplicationContextLoader
* @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.ContextConfiguration
@@ -40,7 +42,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(loader = TestRefreshableApplicationContextLoader.class) @ContextConfiguration(loader = TestRefreshableApplicationContextLoader.class)
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class TestRefreshableApplicationContextLoaderIntegrationTests { public class TestRefreshableApplicationContextLoaderIntegrationTests extends IntegrationTestsSupport {
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;