From f82cf51931035fb2383ce9a2b609bf499f64cd5c Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 24 Mar 2021 16:03:00 -0700 Subject: [PATCH] Reinstate (apply) Spring's @DirtiesContext annotation. Additionally, declare before & after class setup/tear down proceduce to reset the ClusterAwareConfiguration.ClusterAwareCondition. --- ...ClusterAwareConfigurationIntegrationTests.java | 7 +++++++ ...urationWithAuthenticationIntegrationTests.java | 2 ++ ...rtExportAutoConfigurationIntegrationTests.java | 15 ++++++++++----- ...TemplateAutoConfigurationIntegrationTests.java | 3 +++ .../SpringBootApacheGeodeIntegrationTest.java | 7 +++++++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/aware/SecureClusterAwareConfigurationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/aware/SecureClusterAwareConfigurationIntegrationTests.java index 133cef4d..a8e13e20 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/aware/SecureClusterAwareConfigurationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/aware/SecureClusterAwareConfigurationIntegrationTests.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import javax.net.ssl.SSLContext; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -60,6 +61,7 @@ import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedReg import org.springframework.data.gemfire.config.annotation.EnableManager; import org.springframework.data.gemfire.config.support.RestTemplateConfigurer; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.geode.config.annotation.ClusterAwareConfiguration; import org.springframework.geode.config.annotation.EnableClusterAware; import org.springframework.geode.security.TestSecurityManager; import org.springframework.geode.util.GeodeConstants; @@ -121,6 +123,11 @@ public class SecureClusterAwareConfigurationIntegrationTests extends ForkingClie "-Dspring.profiles.active=cluster-aware-with-secure-server,ssl"); } + @BeforeClass @AfterClass + public static void resetClusterAwareCondition() { + ClusterAwareConfiguration.ClusterAwareCondition.reset(); + } + @Autowired @Qualifier("booksTemplate") private GemfireTemplate booksTemplate; diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/config/ClusterConfigurationWithAuthenticationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/config/ClusterConfigurationWithAuthenticationIntegrationTests.java index ddb53275..8f781234 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/config/ClusterConfigurationWithAuthenticationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/config/ClusterConfigurationWithAuthenticationIntegrationTests.java @@ -57,6 +57,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -85,6 +86,7 @@ import example.app.books.model.ISBN; * @since 1.0.0 */ @ActiveProfiles("cluster-configuration-with-auth-client") +@DirtiesContext @RunWith(SpringRunner.class) @SpringBootTest( classes = ClusterConfigurationWithAuthenticationIntegrationTests.GeodeClientConfiguration.class, diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java index d9522b51..c7b6b55b 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/data/ClientCacheDataImportExportAutoConfigurationIntegrationTests.java @@ -48,6 +48,7 @@ import org.springframework.geode.config.annotation.ClusterAwareConfiguration; import org.springframework.geode.config.annotation.EnableClusterAware; import org.springframework.geode.core.util.ObjectUtils; import org.springframework.geode.util.CacheUtils; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -72,11 +73,13 @@ import example.app.books.model.ISBN; * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport * @see org.springframework.geode.boot.autoconfigure.DataImportExportAutoConfiguration + * @see org.springframework.test.annotation.DirtiesContext * @see org.springframework.test.context.ActiveProfiles * @see org.springframework.test.context.junit4.SpringRunner * @since 1.3.0 */ @ActiveProfiles("IMPORT-CLIENT") +@DirtiesContext @RunWith(SpringRunner.class) @SpringBootTest( classes = ClientCacheDataImportExportAutoConfigurationIntegrationTests.TestGeodeClientConfiguration.class, @@ -91,16 +94,16 @@ import example.app.books.model.ISBN; public class ClientCacheDataImportExportAutoConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { - @AfterClass - public static void resetClusterAwareCondition() { - ClusterAwareConfiguration.ClusterAwareCondition.reset(); - } - @BeforeClass public static void startGeodeServer() throws IOException { startGemFireServer(TestGeodeServerConfiguration.class,"-Dspring.profiles.active=IMPORT-SERVER"); } + @BeforeClass @AfterClass + public static void resetClusterAwareCondition() { + ClusterAwareConfiguration.ClusterAwareCondition.reset(); + } + @Autowired private GemfireTemplate booksTemplate; @@ -110,6 +113,8 @@ public class ClientCacheDataImportExportAutoConfigurationIntegrationTests assertThat(this.booksTemplate).isNotNull(); assertThat(this.booksTemplate.getRegion()).isNotNull(); assertThat(this.booksTemplate.getRegion().getName()).isEqualTo("Books"); + assertThat(this.booksTemplate.getRegion().getAttributes()).isNotNull(); + assertThat(this.booksTemplate.getRegion().getAttributes().getDataPolicy()).isEqualTo(DataPolicy.EMPTY); } private void assertBook(Book book, String title, LocalDate publishedDate, ISBN isbn, Author author) { diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/template/EntityDefinedRegionTemplateAutoConfigurationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/template/EntityDefinedRegionTemplateAutoConfigurationIntegrationTests.java index b638a3e2..2b8f92bc 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/template/EntityDefinedRegionTemplateAutoConfigurationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/template/EntityDefinedRegionTemplateAutoConfigurationIntegrationTests.java @@ -39,6 +39,7 @@ import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedReg import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import example.app.books.model.Author; @@ -59,9 +60,11 @@ import example.app.books.model.ISBN; * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration + * @see org.springframework.test.annotation.DirtiesContext * @see org.springframework.test.context.junit4.SpringRunner * @since 1.0.0 */ +@DirtiesContext @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @SuppressWarnings("unused") diff --git a/spring-geode-docs/src/test/java/example/test/integration/SpringBootApacheGeodeIntegrationTest.java b/spring-geode-docs/src/test/java/example/test/integration/SpringBootApacheGeodeIntegrationTest.java index 54c82f3d..d1c508ea 100644 --- a/spring-geode-docs/src/test/java/example/test/integration/SpringBootApacheGeodeIntegrationTest.java +++ b/spring-geode-docs/src/test/java/example/test/integration/SpringBootApacheGeodeIntegrationTest.java @@ -21,6 +21,7 @@ import java.io.IOException; import javax.annotation.Resource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -40,6 +41,7 @@ import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedReg import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.repository.CrudRepository; +import org.springframework.geode.config.annotation.ClusterAwareConfiguration; import org.springframework.geode.config.annotation.EnableClusterAware; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -79,6 +81,11 @@ public class SpringBootApacheGeodeIntegrationTest extends ForkingClientServerInt startGemFireServer(TestGeodeServerConfiguration.class); } + @BeforeClass @AfterClass + public static void resetClusterAwareCondition() { + ClusterAwareConfiguration.ClusterAwareCondition.reset(); + } + @Resource(name = "Users") private org.apache.geode.cache.Region users;