From 6c1c7af36d3e1e11456bc9947e43e0489af14b9c Mon Sep 17 00:00:00 2001 From: John Blum Date: Tue, 7 May 2019 00:06:54 -0700 Subject: [PATCH] Adapt to API and TestContext behavior changes in Spring Framework 5.2. --- ...leClientConfigurationIntegrationTests.java | 64 ++++++++----------- 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/spring-geode/src/test/java/org/springframework/geode/config/annotation/DurableClientConfigurationIntegrationTests.java b/spring-geode/src/test/java/org/springframework/geode/config/annotation/DurableClientConfigurationIntegrationTests.java index 4e68ae92..484eb767 100644 --- a/spring-geode/src/test/java/org/springframework/geode/config/annotation/DurableClientConfigurationIntegrationTests.java +++ b/spring-geode/src/test/java/org/springframework/geode/config/annotation/DurableClientConfigurationIntegrationTests.java @@ -13,7 +13,6 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ - package org.springframework.geode.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -22,21 +21,17 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.util.Optional; -import java.util.concurrent.atomic.AtomicReference; -import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientCache; import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests for {@link EnableDurableClient} and {@link DurableClientConfiguration}. @@ -44,45 +39,41 @@ import org.springframework.test.context.junit4.SpringRunner; * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.client.ClientCache * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.geode.config.annotation.DurableClientConfiguration * @see org.springframework.geode.config.annotation.EnableDurableClient - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringRunner * @since 1.0.0 */ -@RunWith(SpringRunner.class) -@ContextConfiguration @SuppressWarnings("unused") public class DurableClientConfigurationIntegrationTests extends IntegrationTestsSupport { - private static final AtomicReference applicationContextReference = - new AtomicReference<>(null); + private static ConfigurableApplicationContext applicationContext; - private static final AtomicReference clientCacheReference = - new AtomicReference<>(null); + private static ClientCache clientCache; - @Autowired - private ConfigurableApplicationContext applicationContext; + private static ClientCacheFactoryBean clientCacheFactoryBean; - @Autowired - private GemFireCache gemfireCache; + @BeforeClass + public static void newApplicationContext() { - @Autowired - private ClientCacheFactoryBean clientCacheFactoryBean; + applicationContext = new AnnotationConfigApplicationContext(TestConfiguration.class); + + clientCache = applicationContext.getBean("gemfireCache", ClientCache.class); + + clientCacheFactoryBean = applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class); + } @AfterClass public static void closeApplicationContext() { - Optional.ofNullable(applicationContextReference.get()).ifPresent(ConfigurableApplicationContext::close); - - ClientCache clientCache = clientCacheReference.get(); + Optional.ofNullable(applicationContext) + .ifPresent(ConfigurableApplicationContext::close); assertThat(clientCache).isNotNull(); @@ -92,30 +83,25 @@ public class DurableClientConfigurationIntegrationTests extends IntegrationTests @Test public void durableClientWasConfiguredSuccessfully() { - assertThat(this.gemfireCache).isInstanceOf(ClientCache.class); - assertThat(this.gemfireCache.getDistributedSystem()).isNotNull(); - assertThat(this.gemfireCache.getDistributedSystem().getProperties()).isNotNull(); - assertThat(this.gemfireCache.getDistributedSystem().getProperties().getProperty("durable-client-id")) - .isEqualTo("abc123"); - assertThat(this.gemfireCache.getDistributedSystem().getProperties().getProperty("durable-client-timeout")) - .isEqualTo("600"); - - applicationContextReference.set(this.applicationContext); - clientCacheReference.set((ClientCache) this.gemfireCache); + assertThat(clientCache).isInstanceOf(ClientCache.class); + assertThat(clientCache.getDistributedSystem()).isNotNull(); + assertThat(clientCache.getDistributedSystem().getProperties()).isNotNull(); + assertThat(clientCache.getDistributedSystem().getProperties().getProperty("durable-client-id")).isEqualTo("abc123"); + assertThat(clientCache.getDistributedSystem().getProperties().getProperty("durable-client-timeout")).isEqualTo("600"); } @Test public void setClientCacheFactoryBeanSetsKeepAliveOnClose() { - assertThat(this.clientCacheFactoryBean).isNotNull(); - assertThat(this.clientCacheFactoryBean.isKeepAlive()).isTrue(); + assertThat(clientCacheFactoryBean).isNotNull(); + assertThat(clientCacheFactoryBean.isKeepAlive()).isTrue(); } @Test public void setClientCacheFactoryBeanSetsReadyForEventOnContextRefreshedEvent() { - assertThat(this.clientCacheFactoryBean).isNotNull(); - assertThat(this.clientCacheFactoryBean.isReadyForEvents()).isTrue(); + assertThat(clientCacheFactoryBean).isNotNull(); + assertThat(clientCacheFactoryBean.isReadyForEvents()).isTrue(); } @ClientCacheApplication