Reinstate (apply) Spring's @DirtiesContext annotation.

Additionally, declare before & after class setup/tear down proceduce to reset the ClusterAwareConfiguration.ClusterAwareCondition.
This commit is contained in:
John Blum
2021-03-24 16:03:00 -07:00
parent 579bd368de
commit f82cf51931
5 changed files with 29 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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<String, User> users;