From b767de02c103561048cc2807b1e2b490530133de Mon Sep 17 00:00:00 2001 From: John Blum Date: Tue, 14 Sep 2021 12:09:29 -0700 Subject: [PATCH] Refactor test classes in conjunction with reusing forked test JVMs per test class. Resolves gh-296. --- spring-data-geode/pom.xml | 1 - .../AbstractBasicCacheFactoryBean.java | 2 +- .../AbstractConfigurableCacheFactoryBean.java | 21 +- .../AbstractResolvableCacheFactoryBean.java | 30 +- .../data/gemfire/cache/GemfireCache.java | 9 +- .../config/GemfireCachingConfiguration.java | 1 - .../gemfire/config/xml/CacheServerParser.java | 33 +- .../expiration/AnnotationBasedExpiration.java | 1 - .../ContinuousQueryListenerAdapter.java | 105 +++--- .../support/AbstractFactoryBeanSupport.java | 66 +++- .../gemfire/support/ConnectionEndpoint.java | 34 +- .../support/LazyWiringDeclarableSupport.java | 41 ++- ...SpringContextBootstrappingInitializer.java | 38 ++- .../CacheAutoReconnectIntegrationTests.java | 27 +- ...eClusterConfigurationIntegrationTests.java | 72 ++-- .../gemfire/CacheFactoryBeanUnitTests.java | 16 - ...ledClientCacheRegionsIntegrationTests.java | 90 +++-- .../IndexConflictsIntegrationTests.java | 60 ++-- ...rtitionRegionMutationIntegrationTests.java | 4 +- ...ecreatingSpringApplicationContextTest.java | 21 +- .../gemfire/RegionLookupIntegrationTests.java | 130 ++++---- .../ClientCacheManagerIntegrationTests.java | 14 +- ...undCachePutCacheEvictIntegrationTests.java | 216 +++++------- .../ClientCacheIndexingIntegrationTests.java | 13 +- .../client/ClientCacheIntegrationTests.java | 14 +- .../ClientCacheSecurityIntegrationTests.java | 13 +- ...tCacheVariableServersIntegrationTests.java | 32 +- .../client/ClientRegionIntegrationTests.java | 19 +- ...actCacheConfigurationIntegrationTests.java | 57 ++-- ...curityManagerSecurityIntegrationTests.java | 2 + ...pacheShiroIniSecurityIntegrationTests.java | 2 + ...cheShiroRealmSecurityIntegrationTests.java | 2 + ...ticationConfigurationIntegrationTests.java | 4 +- ...CacheServerPropertiesIntegrationTests.java | 46 +-- ...CacheConfigCacheNamesIntegrationTests.java | 2 +- ...entCacheConfigurationIntegrationTests.java | 45 +-- ...ClientCachePropertiesIntegrationTests.java | 59 ++-- .../DiskStorePropertiesIntegrationTests.java | 48 +-- ...yLocatorConfigurationIntegrationTests.java | 40 +-- ...eClusterConfigurationIntegrationTests.java | 7 +- ...ClusterDefinedRegionsIntegrationTests.java | 7 +- ...ableCompressionConfigurationUnitTests.java | 43 +-- ...sQueriesConfigurationIntegrationTests.java | 7 +- ...ntinuousQueriesConfigurationUnitTests.java | 54 ++- ...hClusterConfigurationIntegrationTests.java | 7 +- ...nableDiskStoresConfigurationUnitTests.java | 36 +- ...eEntityDefinedRegionsIntegrationTests.java | 38 +-- .../EnableEntityDefinedRegionsUnitTests.java | 107 +++--- ...EvictionConfigurationIntegrationTests.java | 2 +- .../EnableEvictionConfigurationUnitTests.java | 49 +-- ...pirationConfigurationIntegrationTests.java | 44 +-- ...nableExpirationConfigurationUnitTests.java | 34 +- ...eceiverConfigurationIntegrationTests.java} | 135 ++++---- ...ableGemFirePropertiesIntegrationTests.java | 163 ++++----- .../EnableIndexingConfigurationUnitTests.java | 42 +-- .../EnableOffHeapConfigurationUnitTests.java | 50 +-- ...nablePdxConfigurationIntegrationTests.java | 59 ++-- ...urationDefaultContextIntegrationTests.java | 79 ++--- ...nableSslConfigurationIntegrationTests.java | 22 +- .../EnableSslConfigurationUnitTests.java | 50 +-- ...ayReceiverConfigurerIntegrationTests.java} | 105 +++--- ...ayReceiverPropertiesIntegrationTests.java} | 100 +++--- ...aySenderConfigurationIntegrationTests.java | 74 ++--- .../GatewaySenderConfigurerTests.java | 48 ++- ...tewaySenderPropertiesIntegrationTests.java | 132 +++----- .../IndexConfigurerIntegrationTests.java | 56 ++-- ...tWithCacheApplicationIntegrationTests.java | 38 +-- .../LocatorApplicationIntegrationTests.java | 7 + ...ApplicationPropertiesIntegrationTests.java | 42 +-- .../LoggingConfigurationIntegrationTests.java | 40 +-- ...nWithAddedCacheServerIntegrationTests.java | 2 +- .../PeerCachePropertiesIntegrationTests.java | 52 ++- .../PoolPropertiesIntegrationTests.java | 62 ++-- .../RegionConfigurerIntegrationTests.java | 76 ++--- ...ionOverridingDisabledIntegrationTests.java | 22 +- ...GemFireAsLastResourceIntegrationTests.java | 33 +- ...ubscriptionNamespaceIntegrationTests.java} | 46 ++- ...acheUsingPdxNamespaceIntegrationTests.java | 25 +- ...ClientRegionNamespaceIntegrationTests.java | 150 ++++----- ...DataPolicyAndShortcutIntegrationTests.java | 8 +- ...pirationRegionParsingIntegrationTests.java | 233 ------------- .../DiskStoreNamespaceIntegrationTests.java | 236 +++++++++++-- ...ctionServiceNamespaceIntegrationTests.java | 14 +- ...reV7GatewayNamespaceIntegrationTests.java} | 44 +-- ...ireV8GatewayNamespaceIntegrationTests.java | 8 +- ...onUsingBeansNamespaceIntegrationTests.java | 11 +- ...onAttributesNamespaceIntegrationTests.java | 30 +- ...ndiBindingsNamespaceIntegrationTests.java} | 17 +- ...laceholdersNamespaceIntegrationTests.java} | 22 +- .../xml/MultipleCacheIntegrationTests.java | 47 ++- ...tionedRegionNamespaceIntegrationTests.java | 83 ++--- .../xml/PoolNamespaceIntegrationTests.java | 38 +-- ...eanDefinitionHashCodeIntegrationTests.java | 23 +- .../SubRegionNamespaceIntegrationTests.java | 46 ++- ...onSubElementNamespaceIntegrationTests.java | 15 +- .../SubRegionWithInvalidDataPolicyTest.java | 13 +- ...nOrderErrorNamespaceIntegrationTests.java} | 28 +- ...tionManagerNamespaceIntegrationTests.java} | 25 +- .../AnnotationBasedExpirationUnitTests.java | 25 +- .../data/gemfire/fork/LocatorProcess.java | 5 + ...wingFunctionExecutionIntegrationTests.java | 13 +- ...tionArgumentResolverIntegrationTests.java} | 29 +- ...nExecutionClientCacheIntegrationTests.java | 41 ++- ...tionsWithClientCacheIntegrationTests.java} | 2 +- ...ResultsFromAllServersIntegrationTests.java | 23 +- .../QueryListenerAdapterUnitTests.java | 313 ++++++++++-------- ...AndEntityIdRepositoryIntegrationTests.java | 25 +- ...sitoryRegionDeleteAllIntegrationTests.java | 2 +- .../WiringInstantiatorIntegrationTests.java | 22 +- .../JSONRegionAdviceIntegrationTests.java | 26 +- ...tServiceImportExportIntegrationTests.java} | 45 ++- .../support/ConnectionEndpointUnitTests.java | 20 ++ ...ionContextInitializerIntegrationTests.java | 5 +- ...ringDeclarableSupportIntegrationTests.java | 30 +- .../LazyWiringDeclarableSupportUnitTests.java | 13 +- ...tstrappingInitializerIntegrationTests.java | 105 ++---- ...textBootstrappingInitializerUnitTests.java | 58 ++-- ...LauncherCacheProviderIntegrationTests.java | 17 +- ...gServerLauncherCacheProviderUnitTests.java | 33 +- .../support/AbstractNativeCacheTests.java | 4 +- ...xceptionTransactionalIntegrationTests.java | 6 +- ...ataAccessWithRollbackIntegrationTests.java | 7 +- ...fireCacheTransactionsIntegrationTests.java | 12 +- ...ventQueueWithListenerIntegrationTests.java | 9 +- ...rCacheProviderIntegrationTests-context.xml | 2 +- ...allowRegionBeanDefinitionOverridesTest.xml | 4 +- ...tCacheManagerIntegrationTests-context.xml} | 1 + ...UsingLocalConfigurationIntegrationTest.xml | 2 +- ...tCacheIndexingIntegrationTests-context.xml | 8 +- ...ndexingIntegrationTests-server-context.xml | 10 +- ...lientCachePoolIntegrationTests-context.xml | 7 +- ...chePoolIntegrationTests-server-context.xml | 10 +- ...ServersIntegrationTests-server-context.xml | 2 - ...tionNamespaceIntegrationTests-context.xml} | 3 +- ...gPdxNamespaceIntegrationTests-context.xml} | 2 +- ...gionNamespaceIntegrationTests-context.xml} | 0 ...cyAndShortcutIntegrationTests-context.xml} | 1 + ...toreNamespaceIntegrationTests-context.xml} | 31 +- ...viceNamespaceIntegrationTests-context.xml} | 4 +- ...ewayNamespaceIntegrationTests-context.xml} | 18 +- ...ewayNamespaceIntegrationTests-context.xml} | 2 +- ...ettingsBeansNamespaceIntegrationTests.xml} | 0 ...butesNamespaceIntegrationTests-context.xml | 2 + ...ingsNamespaceIntegrationTests-context.xml} | 2 +- ...dersNamespaceIntegrationTests-context.xml} | 2 +- ...MultipleCacheIntegrationTests-context.xml} | 2 +- ...gionNamespaceIntegrationTests-context.xml} | 2 +- ...PoolNamespaceIntegrationTests-context.xml} | 1 + ...itionHashCodeIntegrationTests-context.xml} | 0 ...gionNamespaceIntegrationTests-context.xml} | 2 +- ...mentNamespaceIntegrationTests-context.xml} | 2 +- ...rrorNamespaceIntegrationTests-context.xml} | 2 + ...agerNamespaceIntegrationTests-context.xml} | 2 +- .../gemfire/enableClientRegionLookupsTest.xml | 1 + .../data/gemfire/enableRegionLookupsTest.xml | 2 +- ...ctionExecutionIntegrationTests-context.xml | 7 +- ...ecutionIntegrationTests-server-context.xml | 15 +- ...reFunctionProxyFactoryBeanTest-context.xml | 35 -- ...onClientCacheIntegrationTests-context.xml} | 1 + ...thClientCacheIntegrationTests-context.xml} | 1 + .../data/gemfire/noClientRegionLookupTest.xml | 1 + .../gemfire/noClientSubRegionLookupTest.xml | 1 + .../noDuplicateRegionDefinitionsTest.xml | 4 +- .../data/gemfire/noLocalRegionLookupTest.xml | 2 +- .../gemfire/noPartitionRegionLookupTest.xml | 2 +- .../gemfire/noReplicateRegionLookupTest.xml | 2 +- .../data/gemfire/noSubRegionLookupTest.xml | 2 +- ...gInstantiatorIntegrationTests-context.xml} | 0 ...ONRegionAdviceIntegrationTests-context.xml | 8 +- ...eImportExportIntegrationTests-context.xml} | 4 +- ...eWithListenerIntegrationTests-context.xml} | 2 +- 171 files changed, 2516 insertions(+), 3106 deletions(-) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/{EnableGatewayReceiverConfigurationTests.java => EnableGatewayReceiverConfigurationIntegrationTests.java} (67%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/{GatewayReceiverConfigurerTests.java => GatewayReceiverConfigurerIntegrationTests.java} (69%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/{GatewayReceiverPropertiesTests.java => GatewayReceiverPropertiesIntegrationTests.java} (60%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{CacheSubscriptionTest.java => CacheSubscriptionNamespaceIntegrationTests.java} (60%) delete mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{GemfireV7GatewayNamespaceTest.java => GemfireV7GatewayNamespaceIntegrationTests.java} (84%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{JndiBindingsIntegrationTests.java => JndiBindingsNamespaceIntegrationTests.java} (78%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{JndiBindingsPropertyPlaceholderIntegrationTests.java => JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests.java} (80%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{TemplateRegionDefinitionOrderErrorNamespaceTest.java => TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests.java} (59%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/{TxManagerNamespaceIntegrationTests.java => TransactionManagerNamespaceIntegrationTests.java} (61%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/function/{PdxFunctionArgumentResolverUnitTests.java => PdxFunctionArgumentResolverIntegrationTests.java} (95%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/{FunctionsWithClientCacheTests.java => FunctionsWithClientCacheIntegrationTests.java} (95%) rename spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/{SnapshotServiceImportExportIntegrationTest.java => SnapshotServiceImportExportIntegrationTests.java} (80%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/cache/{cache-manager-client-cache.xml => ClientCacheManagerIntegrationTests-context.xml} (94%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{subscription-ns.xml => CacheSubscriptionNamespaceIntegrationTests-context.xml} (94%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{cache-using-pdx-ns.xml => CacheUsingPdxNamespaceIntegrationTests-context.xml} (93%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{client-ns.xml => ClientRegionNamespaceIntegrationTests-context.xml} (100%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{client-region-using-datapolicy-and-shortcut.xml => ClientRegionUsingDataPolicyAndShortcutIntegrationTests-context.xml} (99%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{diskstore-ns.xml => DiskStoreNamespaceIntegrationTests-context.xml} (86%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{function-service-ns.xml => FunctionServiceNamespaceIntegrationTests-context.xml} (85%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{gateway-v7-ns.xml => GemfireV7GatewayNamespaceIntegrationTests-context.xml} (86%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{gateway-v8-ns.xml => GemfireV8GatewayNamespaceIntegrationTests-context.xml} (96%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml => InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceIntegrationTests.xml} (100%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{jndi-binding-ns.xml => JndiBindingsNamespaceIntegrationTests-context.xml} (96%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{jndi-binding-with-property-placeholders-ns.xml => JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests-context.xml} (97%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{MultipleCacheTest-context.xml => MultipleCacheIntegrationTests-context.xml} (94%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{partitioned-ns.xml => PartitionedRegionNamespaceIntegrationTests-context.xml} (98%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{pool-ns.xml => PoolNamespaceIntegrationTests-context.xml} (97%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml => RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests-context.xml} (100%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{subregion-ns.xml => SubRegionNamespaceIntegrationTests-context.xml} (97%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{subregionsubelement-ns.xml => SubRegionSubElementNamespaceIntegrationTests-context.xml} (96%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{TemplateRegionDefinitionOrderErrorNamespaceTest-context.xml => TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests-context.xml} (84%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/{tx-ns.xml => TransactionManagerNamespaceIntegrationTests-context.xml} (92%) delete mode 100644 spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/GemfireFunctionProxyFactoryBeanTest-context.xml rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/{FunctionExecutionCacheClientTests-context.xml => FunctionExecutionClientCacheIntegrationTests-context.xml} (92%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/{FunctionsWithClientCacheTests-context.xml => FunctionsWithClientCacheIntegrationTests-context.xml} (94%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/{simple-config.xml => WiringInstantiatorIntegrationTests-context.xml} (100%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/{SnapshotServiceImportExportIntegrationTest-context.xml => SnapshotServiceImportExportIntegrationTests-context.xml} (91%) rename spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/{asyncEventQueueWithListener.xml => AsyncEventQueueWithListenerIntegrationTests-context.xml} (96%) diff --git a/spring-data-geode/pom.xml b/spring-data-geode/pom.xml index a76e9369..fdcdfbe5 100644 --- a/spring-data-geode/pom.xml +++ b/spring-data-geode/pom.xml @@ -272,7 +272,6 @@ true ${basedir}/src/test/resources/java-util-logging.properties - ${basedir}/src/test/resources/trusted.keystore true error apache-geode diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java index 6799423f..b0dc1a69 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractBasicCacheFactoryBean.java @@ -620,7 +620,7 @@ public abstract class AbstractBasicCacheFactoryBean extends AbstractFactoryBeanS * @see org.apache.geode.cache.GemFireCache */ protected boolean isNotClosed(@Nullable GemFireCache cache) { - return cache == null || !cache.isClosed(); + return cache != null && !cache.isClosed(); } /** diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java index 8840116e..b1f1fd8e 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractConfigurableCacheFactoryBean.java @@ -137,10 +137,7 @@ public abstract class AbstractConfigurableCacheFactoryBean extends AbstractBasic */ @SuppressWarnings("unused") protected boolean isCacheXmlPresent() { - - Resource cacheXml = getCacheXml(); - - return cacheXml != null && cacheXml.exists(); + return getOptionalCacheXml().filter(Resource::exists).isPresent(); } /** @@ -154,10 +151,7 @@ public abstract class AbstractConfigurableCacheFactoryBean extends AbstractBasic * @see java.io.File */ protected boolean isCacheXmlResolvableAsAFile() { - - Resource cacheXml = getCacheXml(); - - return cacheXml != null && cacheXml.isFile(); + return getOptionalCacheXml().filter(Resource::isFile).isPresent(); } /** @@ -234,6 +228,17 @@ public abstract class AbstractConfigurableCacheFactoryBean extends AbstractBasic } } + /** + * Determine whether to use the {@link GemfireBeanFactoryLocator}. + * + * This method really determines whether the {@link GemfireBeanFactoryLocator} is enabled and required to configure + * native Apache Geode configuration metadata ({@literal cache.xml}). + * + * @return a boolean value indicating whether to use the {@link GemfireBeanFactoryLocator}. + * @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator + * @see #getOptionalBeanFactoryLocator() + * @see #isUseBeanFactoryLocator() + */ private boolean useBeanFactoryLocator() { return isUseBeanFactoryLocator() && !getOptionalBeanFactoryLocator().isPresent(); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java index 9ce248dc..6b0948c0 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/AbstractResolvableCacheFactoryBean.java @@ -32,6 +32,7 @@ import org.springframework.lang.NonNull; * Abstract base class encapsulating logic to resolve or create a {@link GemFireCache} instance. * * @author John Blum + * @see java.util.Optional * @see java.util.Properties * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.distributed.DistributedMember @@ -85,24 +86,25 @@ public abstract class AbstractResolvableCacheFactoryBean extends AbstractConfigu @SuppressWarnings("deprecation") private void logCacheInitialization() { - getOptionalCache().ifPresent(cache -> { + getOptionalCache() + .filter(cache -> isInfoLoggingEnabled()) + .ifPresent(cache -> { - Optional.ofNullable(cache.getDistributedSystem()) - .map(DistributedSystem::getDistributedMember) - .ifPresent(member -> { + logInfo(() -> String.format("%1$s %2$s version [%3$s] Cache [%4$s]", this.cacheResolutionMessagePrefix, + apacheGeodeProductName(), apacheGeodeVersion(), cache.getName())); - String message = "Connected to Distributed System [%1$s] as Member [%2$s] in Group(s) [%3$s]" - + " with Role(s) [%4$s] on Host [%5$s] having PID [%6$d]"; + Optional.ofNullable(cache.getDistributedSystem()) + .map(DistributedSystem::getDistributedMember) + .ifPresent(member -> { - logInfo(() -> String.format(message, - cache.getDistributedSystem().getName(), member.getId(), member.getGroups(), - member.getRoles(), member.getHost(), member.getProcessId())); - }); + String message = "Connected to Distributed System [%1$s] as Member [%2$s] in Group(s) [%3$s]" + + " with Role(s) [%4$s] on Host [%5$s] having PID [%6$d]"; - logInfo(() -> String.format("%1$s %2$s version [%3$s] Cache [%4$s]", this.cacheResolutionMessagePrefix, - apacheGeodeProductName(), apacheGeodeVersion(), cache.getName())); - - }); + logInfo(() -> String.format(message, + cache.getDistributedSystem().getName(), member.getId(), member.getGroups(), + member.getRoles(), member.getHost(), member.getProcessId())); + }); + }); } /** diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java index 3cc902d1..e408b077 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/GemfireCache.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.cache; import java.util.concurrent.Callable; @@ -35,6 +34,7 @@ import org.springframework.util.Assert; * @see org.springframework.cache.Cache * @see org.apache.geode.cache.Region */ +@SuppressWarnings("rawtypes") public class GemfireCache implements Cache { private final Region region; @@ -115,9 +115,10 @@ public class GemfireCache implements Cache { * @see org.apache.geode.cache.Region#get(Object) */ public ValueWrapper get(Object key) { + Object value = getNativeCache().get(key); - return (value != null ? new SimpleValueWrapper(value) : null); + return value != null ? new SimpleValueWrapper(value) : null; } /** @@ -132,6 +133,7 @@ public class GemfireCache implements Cache { */ @SuppressWarnings("unchecked") public T get(Object key, Class type) { + Object value = getNativeCache().get(key); if (value != null && type != null && !type.isInstance(value)) { @@ -160,6 +162,7 @@ public class GemfireCache implements Cache { */ @SuppressWarnings("unchecked") public T get(Object key, Callable valueLoader) { + T value = (T) get(key, Object.class); if (value == null) { @@ -191,6 +194,7 @@ public class GemfireCache implements Cache { */ @SuppressWarnings("unchecked") public void put(Object key, Object value) { + if (value != null) { getNativeCache().put(key, value); } @@ -207,6 +211,7 @@ public class GemfireCache implements Cache { */ @SuppressWarnings("unchecked") public ValueWrapper putIfAbsent(Object key, Object value) { + Object existingValue = getNativeCache().putIfAbsent(key, value); return (existingValue != null ? new SimpleValueWrapper(existingValue) : null); diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java index 4c33afea..be8bab4b 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.cache.config; import org.apache.geode.cache.GemFireCache; diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java index a20f2b9b..90241333 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; +import java.util.concurrent.atomic.AtomicInteger; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -29,6 +27,9 @@ import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + /** * Bean definition parser for the <gfe:cache-server< SDG XML namespace (XSD) element. * @@ -40,6 +41,8 @@ import org.springframework.util.xml.DomUtils; */ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { + private final AtomicInteger cacheServerIdentifier = new AtomicInteger(0); + /** * {@inheritDoc} */ @@ -53,8 +56,10 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { */ @Override protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) { - return (super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName()) - && !"cache-ref".equals(attribute.getName())); + + return super.isEligibleAttribute(attribute, parserContext) + && !"groups".equals(attribute.getName()) + && !"cache-ref".equals(attribute.getName()); } /** @@ -62,6 +67,7 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { */ @Override protected void postProcess(BeanDefinitionBuilder builder, Element element) { + String cacheRefAttribute = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME); builder.addPropertyReference("cache", SpringUtils.defaultIfEmpty( @@ -76,11 +82,12 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { parseSubscription(element, builder); } - /* (non-Javadoc) */ private void parseSubscription(Element element, BeanDefinitionBuilder builder) { + Element subscriptionConfigElement = DomUtils.getChildElementByTagName(element, "subscription-config"); if (subscriptionConfigElement != null) { + ParsingUtils.setPropertyValue(subscriptionConfigElement, builder, "capacity", "subscriptionCapacity"); ParsingUtils.setPropertyValue(subscriptionConfigElement, builder, "disk-store", "subscriptionDiskStore"); @@ -92,14 +99,24 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { } } + /** + * {@inheritDoc} + */ + @Override + protected boolean shouldGenerateIdAsFallback() { + return true; + } + /** * {@inheritDoc} */ @Override protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) - throws BeanDefinitionStoreException { + throws BeanDefinitionStoreException { String name = super.resolveId(element, definition, parserContext); - return (StringUtils.hasText(name) ? name : "gemfireServer"); + + return StringUtils.hasText(name) ? name + : String.format("gemfireServer%d", cacheServerIdentifier.incrementAndGet()); } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java index 113327b8..b8bdf583 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpiration.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.expiration; import java.lang.annotation.Annotation; diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java index 864dde3f..ad743f88 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/listener/adapter/ContinuousQueryListenerAdapter.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.listener.adapter; import java.lang.reflect.InvocationTargetException; @@ -27,9 +26,6 @@ import org.apache.geode.cache.Operation; import org.apache.geode.cache.query.CqEvent; import org.apache.geode.cache.query.CqQuery; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.gemfire.listener.ContinuousQueryListener; @@ -38,6 +34,9 @@ import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Event listener adapter that delegates the handling of messages to target listener methods via reflection, * with flexible event type conversion. @@ -182,10 +181,13 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener { public void onEvent(CqEvent event) { try { + + Object delegate = getDelegate(); + // Determine whether the delegate is a ContinuousQueryListener implementation; // If so, this adapter will simply act as a pass-through - if (this.delegate != this && this.delegate instanceof ContinuousQueryListener) { - ((ContinuousQueryListener) this.delegate).onEvent(event); + if (delegate != this && delegate instanceof ContinuousQueryListener) { + ((ContinuousQueryListener) delegate).onEvent(event); } // Else, find the listener method handler reflectively else { @@ -224,6 +226,7 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener { * @see #getListenerMethodName */ protected void invokeListenerMethod(CqEvent event, String methodName) { + try { this.invoker.invoke(event); } @@ -233,7 +236,7 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener { } else { throw new GemfireListenerExecutionFailedException( - String.format("Listener method [%s] threw Exception...", methodName), cause.getTargetException()); + String.format("Listener method [%s] threw Exception", methodName), cause.getTargetException()); } } catch (Throwable cause) { @@ -242,7 +245,7 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener { } } - private class MethodInvoker { + private static class MethodInvoker { private final Object delegate; @@ -258,56 +261,19 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener { ReflectionUtils.doWithMethods(delegateType, method -> { ReflectionUtils.makeAccessible(method); this.methods.add(method); - }, method -> isValidEventMethodSignature(method, methodName)); + }, method -> isValidEventHandlerMethodSignature(method, methodName)); Assert.isTrue(!this.methods.isEmpty(), String.format("Cannot find a suitable method named [%1$s#%2$s];" + " Is the method public and does it have the proper arguments?", delegateType.getName(), methodName)); } - @SuppressWarnings("all") - private boolean isValidEventMethodSignature(Method method, String methodName) { - - if (isEventHandlerMethod(method, methodName)) { - - Class[] parameterTypes = method.getParameterTypes(); - - int objects = 0; - int operations = 0; - - if (parameterTypes.length > 0) { - for (Class parameterType : parameterTypes) { - if (Object.class.equals(parameterType)) { - if (++objects > 2) { - return false; - } - } - else if (Operation.class.equals(parameterType)) { - if (++operations > 2) { - return false; - } - } - else if (byte[].class.equals(parameterType)) { - } - else if (CqEvent.class.equals(parameterType)) { - } - else if (CqQuery.class.equals(parameterType)) { - } - else if (Throwable.class.equals(parameterType)) { - } - else { - return false; - } - } - - return true; - } - } - - return false; + private boolean isValidEventHandlerMethodSignature(Method method, String methodName) { + return isValidEventHandlerMethodWithName(method, methodName) + && isValidEventHandlerMethodWithSignature(method); } - private boolean isEventHandlerMethod(Method method, String methodName) { + private boolean isValidEventHandlerMethodWithName(Method method, String methodName) { return Optional.ofNullable(method) .filter(it -> Modifier.isPublic(it.getModifiers())) @@ -315,6 +281,41 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener { .isPresent(); } + @SuppressWarnings("all") + private boolean isValidEventHandlerMethodWithSignature(Method method) { + + Class[] parameterTypes = method.getParameterTypes(); + + int objects = 0; + int operations = 0; + + if (parameterTypes.length > 0) { + for (Class parameterType : parameterTypes) { + if (Object.class.equals(parameterType)) { + if (++objects > 2) { + return false; + } + } + else if (Operation.class.equals(parameterType)) { + if (++operations > 2) { + return false; + } + } + else if (byte[].class.equals(parameterType)) { } + else if (CqEvent.class.equals(parameterType)) { } + else if (CqQuery.class.equals(parameterType)) { } + else if (Throwable.class.equals(parameterType)) { } + else { + return false; + } + } + + return true; + } + + return false; + } + void invoke(CqEvent event) throws IllegalAccessException, InvocationTargetException { for (Method method : this.methods) { @@ -336,11 +337,11 @@ public class ContinuousQueryListenerAdapter implements ContinuousQueryListener { Class parameterType = parameterTypes[index]; if (Object.class.equals(parameterType)) { - args[index] = (value ? event.getNewValue() : event.getKey()); + args[index] = value ? event.getNewValue() : event.getKey(); value = true; } else if (Operation.class.equals(parameterType)) { - args[index] = (query ? event.getQueryOperation() : event.getBaseOperation()); + args[index] = query ? event.getQueryOperation() : event.getBaseOperation(); query = true; } else if (byte[].class.equals(parameterType)) { diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java index 05fcd95c..b3618e50 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/AbstractFactoryBeanSupport.java @@ -158,6 +158,64 @@ public abstract class AbstractFactoryBeanSupport return this.log; } + /** + * Returns an {@link Optional} reference to the {@link Logger} used by this {@link FactoryBean} + * to log {@link String messages}. + * + * @return an {@link Optional} reference to the {@link Logger} used by this {@link FactoryBean} + * to log {@link String messages}. + * @see java.util.Optional + * @see org.slf4j.Logger + * @see #getLog() + */ + protected Optional getOptionalLog() { + return Optional.ofNullable(getLog()); + } + + /** + * Determines whether {@literal DEBUG} logging is enabled. + * + * @return a boolean value indicating whether {@literal DEBUG} logging is enabled. + * @see org.slf4j.Logger#isDebugEnabled() + * @see #getOptionalLog() + */ + public boolean isDebugLoggingEnabled() { + return getOptionalLog().filter(Logger::isInfoEnabled).isPresent(); + } + + /** + * Determines whether {@literal INFO} logging is enabled. + * + * @return a boolean value indicating whether {@literal INFO} logging is enabled. + * @see org.slf4j.Logger#isInfoEnabled() + * @see #getOptionalLog() + */ + public boolean isInfoLoggingEnabled() { + return getOptionalLog().filter(Logger::isInfoEnabled).isPresent(); + } + + /** + * Determines whether {@literal ERROR} logging is enabled. + * + * @return a boolean value indicating whether {@literal ERROR} logging is enabled. + * @see org.slf4j.Logger#isErrorEnabled() + * @see #getOptionalLog() + */ + public boolean isErrorLoggingEnabled() { + return getOptionalLog().filter(Logger::isInfoEnabled).isPresent(); + } + + /** + * Determines whether {@literal WARN} logging is enabled. + * + * @return a boolean value indicating whether {@literal WARN} logging is enabled. + * @see org.slf4j.Logger#isWarnEnabled() + * @see #getOptionalLog() + */ + public boolean isWarnLoggingEnabled() { + return getOptionalLog().filter(Logger::isInfoEnabled).isPresent(); + } + /** * Indicates that this {@link FactoryBean} produces a single bean instance. * @@ -189,7 +247,7 @@ public abstract class AbstractFactoryBeanSupport * @see #getLog() */ protected void logDebug(Supplier message) { - Optional.ofNullable(getLog()) + getOptionalLog() .filter(Logger::isDebugEnabled) .ifPresent(log -> log.debug(message.get())); } @@ -214,7 +272,7 @@ public abstract class AbstractFactoryBeanSupport * @see #getLog() */ protected void logInfo(Supplier message) { - Optional.ofNullable(getLog()) + getOptionalLog() .filter(Logger::isInfoEnabled) .ifPresent(log -> log.info(message.get())); } @@ -239,7 +297,7 @@ public abstract class AbstractFactoryBeanSupport * @see #getLog() */ protected void logWarning(Supplier message) { - Optional.ofNullable(getLog()) + getOptionalLog() .filter(Logger::isWarnEnabled) .ifPresent(log -> log.warn(message.get())); } @@ -264,7 +322,7 @@ public abstract class AbstractFactoryBeanSupport * @see #getLog() */ protected void logError(Supplier message) { - Optional.ofNullable(getLog()) + getOptionalLog() .filter(Logger::isErrorEnabled) .ifPresent(log -> log.error(message.get())); } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java index a115e0d7..75a219ad 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpoint.java @@ -18,6 +18,7 @@ package org.springframework.data.gemfire.support; import java.net.InetSocketAddress; import org.springframework.data.gemfire.util.SpringUtils; +import org.springframework.lang.NonNull; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -45,13 +46,38 @@ public class ConnectionEndpoint implements Cloneable, Comparable { +public class SpringContextBootstrappingInitializer implements ApplicationListener, Declarable { public static final String BASE_PACKAGES_PARAMETER = "basePackages"; public static final String CONTEXT_CONFIG_LOCATIONS_PARAMETER = "contextConfigLocations"; @@ -123,6 +124,21 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic } } + /** + * Destroy the state of the {@link SpringContextBootstrappingInitializer}. + */ + public static void destroy() { + + beanClassLoaderReference.set(null); + applicationContext = null; + contextRefreshedEvent = null; + registeredAnnotatedClasses.clear(); + + synchronized (applicationEventNotifier) { + applicationEventNotifier.removeAllListeners(); + } + } + /** * Notifies any Spring ApplicationListeners of a current and existing ContextRefreshedEvent if the * ApplicationContext had been previously created, initialized and refreshed before any ApplicationListeners @@ -258,7 +274,7 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic * before using the context. * @throws IllegalArgumentException if both the basePackages and configLocation parameter arguments * are null or empty. - * @see #createApplicationContext(String[]) + * @see #newApplicationContext(String[]) * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.context.annotation.AnnotationConfigApplicationContext#scan(String...) * @see org.springframework.context.support.ClassPathXmlApplicationContext @@ -272,12 +288,12 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic Class[] annotatedClasses = registeredAnnotatedClasses.toArray(new Class[0]); - ConfigurableApplicationContext applicationContext = createApplicationContext(configLocations); + ConfigurableApplicationContext applicationContext = newApplicationContext(configLocations); return scanBasePackages(registerAnnotatedClasses(applicationContext, annotatedClasses), basePackages); } - ConfigurableApplicationContext createApplicationContext(String[] configLocations) { + ConfigurableApplicationContext newApplicationContext(String[] configLocations) { return ObjectUtils.isEmpty(configLocations) ? new AnnotationConfigApplicationContext() @@ -430,8 +446,9 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic String[] contextConfigLocationsArray = StringUtils.delimitedListToStringArray( StringUtils.trimWhitespace(contextConfigLocations), COMMA_DELIMITER, CHARS_TO_DELETE); - ConfigurableApplicationContext localApplicationContext = refreshApplicationContext( - initApplicationContext(createApplicationContext(basePackagesArray, contextConfigLocationsArray))); + ConfigurableApplicationContext localApplicationContext = + refreshApplicationContext(initApplicationContext(createApplicationContext(basePackagesArray, + contextConfigLocationsArray))); Assert.state(localApplicationContext.isRunning(), String.format( "The Spring ApplicationContext (%1$s) failed to be properly initialized with the context config files (%2$s) or base packages (%3$s)!", @@ -461,10 +478,7 @@ public class SpringContextBootstrappingInitializer implements Declarable, Applic * @see org.springframework.context.ApplicationContext#getId() */ String nullSafeGetApplicationContextId(ApplicationContext applicationContext) { - - return applicationContext != null - ? applicationContext.getId() - : null; + return applicationContext != null ? applicationContext.getId() : null; } /** diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java index 9ecab89c..5b242f5a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java @@ -16,19 +16,16 @@ package org.springframework.data.gemfire; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeNotNull; import java.io.File; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.Cache; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.gemfire.config.xml.GemfireConstants; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; /** * Integration Tests testing SDG support of Apache Geode Auto-Reconnect functionality. @@ -37,31 +34,25 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor * @see org.junit.Test * @see org.apache.geode.cache.Cache * @see org.springframework.data.gemfire.CacheFactoryBean - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @since 1.5.0 */ -public class CacheAutoReconnectIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - assumeNotNull(applicationContext); - applicationContext.close(); - } +public class CacheAutoReconnectIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { protected Cache getCache(String configLocation) { String baseConfigLocation = File.separator.concat(getClass().getPackage().getName().replace('.', File.separatorChar)); - applicationContext = new ClassPathXmlApplicationContext(baseConfigLocation.concat(File.separator).concat(configLocation)); + String resolvedConfigLocation = baseConfigLocation.concat(File.separator).concat(configLocation); - return applicationContext.getBean(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME, Cache.class); + setApplicationContext(new ClassPathXmlApplicationContext(resolvedConfigLocation)); + + return getBean(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME, Cache.class); } @Test - public void testAutoReconnectDisabled() { + public void autoReconnectIsDisabled() { Cache cache = getCache("cacheAutoReconnectDisabledIntegrationTests.xml"); @@ -73,7 +64,7 @@ public class CacheAutoReconnectIntegrationTests extends IntegrationTestsSupport } @Test - public void testAutoReconnectEnabled() { + public void autoReconnectIsEnabled() { Cache cache = getCache("cacheAutoReconnectEnabledIntegrationTests.xml"); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java index 084083f5..8302567b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheClusterConfigurationIntegrationTests.java @@ -48,13 +48,14 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.fork.LocatorProcess; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.gemfire.tests.process.ProcessWrapper; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.data.gemfire.tests.util.FileUtils; import org.springframework.data.gemfire.tests.util.ThrowableUtils; import org.springframework.data.gemfire.tests.util.ZipUtils; import org.springframework.data.gemfire.util.ArrayUtils; -import org.springframework.util.FileSystemUtils; import org.springframework.util.StringUtils; +import org.assertj.core.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,8 +75,11 @@ import org.slf4j.LoggerFactory; @SuppressWarnings("unused") public class CacheClusterConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { + private static final int ASSERTJ_MAX_STACK_TRACE_ELEMENTS = 500; + private static File locatorWorkingDirectory; + // The List of Strings represents each line of the Locator process output (System.out). private static final List locatorProcessOutput = Collections.synchronizedList(new ArrayList<>()); private static final Logger logger = LoggerFactory.getLogger(CacheClusterConfigurationIntegrationTests.class); @@ -100,7 +104,7 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ @Override protected void finished(Description description) { - if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { + if (Arrays.asList("config", "debug", "info").contains(LOG_LEVEL.toLowerCase())) { try { FileUtils.write(new File(locatorWorkingDirectory.getParent(), String.format("%s-clusterconfiglocator.log", description.getMethodName())), @@ -117,13 +121,14 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ try { String locatorProcessOutputString = StringUtils.collectionToDelimitedString(locatorProcessOutput, - FileUtils.LINE_SEPARATOR, String.format("[%1$s] - ", description.getMethodName()), ""); + FileUtils.LINE_SEPARATOR, String.format("[%s] - ", description.getMethodName()), ""); locatorProcessOutputString = StringUtils.hasText(locatorProcessOutputString) ? locatorProcessOutputString : locatorProcess.readLogFile(); return locatorProcessOutputString; + } catch (IOException cause) { throw newRuntimeException(cause, "Failed to read the contents of the Locator process log file"); @@ -132,57 +137,57 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ }; @BeforeClass - @SuppressWarnings("all") + public static void configureAssertJ() { + Assertions.setMaxStackTraceElementsDisplayed(ASSERTJ_MAX_STACK_TRACE_ELEMENTS); + } + + @BeforeClass public static void startLocator() throws IOException { - int availablePort = findAvailablePort(); + int locatorPort = findAndReserveAvailablePort(); - String locatorName = "ClusterConfigLocator"; + String locatorName = String.format("ClusterConfigLocator-%d", System.currentTimeMillis()); - locatorWorkingDirectory = - createDirectory(new File(System.getProperty("java.io.tmpdir"), locatorName.toLowerCase())); + locatorWorkingDirectory = createDirectory(new File(FileSystemUtils.WORKING_DIRECTORY, locatorName.toLowerCase())); - ZipUtils.unzip(new ClassPathResource("/cluster_config.zip"), locatorWorkingDirectory); + ZipUtils.unzip(new ClassPathResource("cluster_config.zip"), locatorWorkingDirectory); List arguments = new ArrayList<>(); - arguments.add("-Dgemfire.name=" + locatorName); - arguments.add("-Dlog4j.geode.log.level=error"); - arguments.add("-Dlogback.log.level=error"); + arguments.add(String.format("-Dgemfire.name=%s", locatorName)); + arguments.add(String.format("-Dlog4j.geode.log.level=%s", LOG_LEVEL)); + arguments.add(String.format("-Dlogback.log.level=%s", LOG_LEVEL)); arguments.add("-Dspring.data.gemfire.enable-cluster-configuration=true"); arguments.add("-Dspring.data.gemfire.load-cluster-configuration=true"); - arguments.add(String.format("-Dgemfire.log-level=%s", LOG_LEVEL)); arguments.add(String.format("-Dgemfire.log-file=%s", LOG_FILE)); - arguments.add(String.format("-Dspring.data.gemfire.locator.port=%d", availablePort)); - - locatorProcess = run(locatorWorkingDirectory, LocatorProcess.class, - arguments.toArray(new String[arguments.size()])); + arguments.add(String.format("-Dgemfire.log-level=%s", LOG_LEVEL)); + arguments.add(String.format("-Dspring.data.gemfire.locator.port=%d", locatorPort)); + locatorProcess = run(locatorWorkingDirectory, LocatorProcess.class, arguments.toArray(new String[0])); locatorProcess.register(input -> locatorProcessOutput.add(input)); - locatorProcess.registerShutdownHook(); - waitForServerToStart("localhost", availablePort); + waitForServerToStart("localhost", locatorPort); - System.setProperty("spring.data.gemfire.locator.port", String.valueOf(availablePort)); + System.setProperty("spring.data.gemfire.locator.port", String.valueOf(locatorPort)); } @AfterClass public static void stopLocator() { - locatorProcess.shutdown(); + stop(locatorProcess); System.clearProperty("spring.data.gemfire.locator.port"); - if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { - FileSystemUtils.deleteRecursively(locatorWorkingDirectory); - } - FilenameFilter logFileFilter = (directory, name) -> name.endsWith(".log"); File[] logFiles = ArrayUtils.nullSafeArray(locatorWorkingDirectory.listFiles(logFileFilter), File.class); Arrays.stream(logFiles).forEach(File::delete); + + if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) { + FileSystemUtils.deleteRecursive(locatorWorkingDirectory); + } } private Region assertRegion(Region actualRegion, String expectedRegionName) { @@ -192,8 +197,10 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ private Region assertRegion(Region actualRegion, String expectedRegionName, String expectedRegionFullPath) { - assertThat(actualRegion).as(String.format("The [%s] was not properly configured and initialized!", - expectedRegionName)).isNotNull(); + assertThat(actualRegion) + .describedAs("The [%s] was not properly configured and initialized!", expectedRegionName) + .isNotNull(); + assertThat(actualRegion.getName()).isEqualTo(expectedRegionName); assertThat(actualRegion.getFullPath()).isEqualTo(expectedRegionFullPath); @@ -254,12 +261,14 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ DataPolicy.NORMAL, Scope.LOCAL); } - @Test + @Test(expected = BeanCreationException.class) public void localConfigurationTest() { + ConfigurableApplicationContext applicationContext = null; + try { - newApplicationContext(getLocation("cacheUsingLocalConfigurationIntegrationTest.xml")); + applicationContext = newApplicationContext(getLocation("cacheUsingLocalConfigurationIntegrationTest.xml")); fail("Loading the 'cacheUsingLocalOnlyConfigurationIntegrationTest.xml' Spring ApplicationContext" + " configuration file should have resulted in an Exception due to the Region lookup on" @@ -272,6 +281,11 @@ public class CacheClusterConfigurationIntegrationTests extends ForkingClientServ assertThat(expected.getCause().getMessage() .matches("Region \\[ClusterConfigRegion\\] in Cache \\[.*\\] not found")) .as(String.format("Message was [%s]", expected.getMessage())).isTrue(); + + throw expected; + } + finally { + closeApplicationContext(applicationContext); } } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java index 8115c040..391439a3 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/CacheFactoryBeanUnitTests.java @@ -35,7 +35,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.withSettings; import java.io.InputStream; import java.util.Collections; @@ -56,8 +55,6 @@ import org.apache.geode.cache.TransactionListener; import org.apache.geode.cache.TransactionWriter; import org.apache.geode.cache.control.ResourceManager; import org.apache.geode.cache.util.GatewayConflictResolver; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.pdx.PdxSerializer; import org.springframework.beans.factory.BeanFactory; @@ -244,7 +241,6 @@ public class CacheFactoryBeanUnitTests { } @Test - @SuppressWarnings("deprecation") public void init() throws Exception { BeanFactory mockBeanFactory = mock(BeanFactory.class); @@ -253,10 +249,6 @@ public class CacheFactoryBeanUnitTests { CacheTransactionManager mockCacheTransactionManager = mock(CacheTransactionManager.class); - DistributedMember mockDistributedMember = mock(DistributedMember.class, withSettings().lenient()); - - DistributedSystem mockDistributedSystem = mock(DistributedSystem.class, withSettings().lenient()); - GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class); PdxSerializer mockPdxSerializer = mock(PdxSerializer.class); @@ -274,16 +266,8 @@ public class CacheFactoryBeanUnitTests { when(mockBeanFactory.getAliases(anyString())).thenReturn(new String[0]); when(mockCacheFactory.create()).thenReturn(mockCache); when(mockCache.getCacheTransactionManager()).thenReturn(mockCacheTransactionManager); - when(mockCache.getDistributedSystem()).thenReturn(mockDistributedSystem); when(mockCache.getResourceManager()).thenReturn(mockResourceManager); when(mockCacheXml.getInputStream()).thenReturn(mock(InputStream.class)); - when(mockDistributedSystem.getDistributedMember()).thenReturn(mockDistributedMember); - when(mockDistributedSystem.getName()).thenReturn("MockDistributedSystem"); - when(mockDistributedMember.getId()).thenReturn("MockDistributedMember"); - when(mockDistributedMember.getGroups()).thenReturn(Collections.emptyList()); - when(mockDistributedMember.getRoles()).thenReturn(Collections.emptySet()); - when(mockDistributedMember.getHost()).thenReturn("skullbox"); - when(mockDistributedMember.getProcessId()).thenReturn(12345); ClassLoader expectedThreadContextClassLoader = Thread.currentThread().getContextClassLoader(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java index ceead40b..9f3d4ef5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationTests.java @@ -38,7 +38,7 @@ import org.apache.geode.cache.client.Pool; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @@ -56,7 +56,8 @@ import org.springframework.data.gemfire.util.PropertiesBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -107,13 +108,23 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT @BeforeClass public static void runGemFireCluster() throws Exception { - serverOne = run(createDirectory("serverOne"), GemFireCacheServerOneConfiguration.class); + int locatorPort = findAndReserveAvailablePort(); + int cacheServerPortOne = findAndReserveAvailablePort(); + int cacheServerPortTwo = findAndReserveAvailablePort(); - waitForServerToStart("localhost", 41414); + serverOne = run(GemFireCacheServerOneConfiguration.class, + String.format("-Dspring.data.gemfire.cache.server.port=%d", cacheServerPortOne), + String.format("-Dspring.data.gemfire.locator.port=%d", locatorPort)); - serverTwo = run(createDirectory("serverTwo"), GemFireCacheServerTwoConfiguration.class); + waitForServerToStart("localhost", cacheServerPortOne); - waitForServerToStart("localhost", 42424); + serverTwo = run(GemFireCacheServerTwoConfiguration.class, + String.format("-Dspring.data.gemfire.cache.server.port=%d", cacheServerPortTwo), + String.format("-Dspring.data.gemfire.locator.port=%d", locatorPort)); + + waitForServerToStart("localhost", cacheServerPortTwo); + + System.setProperty("spring.data.gemfire.locator.port", String.valueOf(locatorPort)); } @AfterClass @@ -142,18 +153,20 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT assertThat(dogNames).containsAll(Arrays.asList("Spuds", "Maha")); } - @Data + @Getter + @EqualsAndHashCode @Region("Cats") @RequiredArgsConstructor(staticName = "newCat") static class Cat { - @Id @NonNull private String name; + @Id @NonNull private final String name; } - @Data + @Getter + @EqualsAndHashCode @Region("Dogs") @RequiredArgsConstructor(staticName = "newDog") static class Dog { - @Id @NonNull private String name; + @Id @NonNull private final String name; } @Configuration @@ -188,7 +201,7 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT } @Bean(name = "ServerOnePool") - PoolFactoryBean serverOnePool() { + PoolFactoryBean serverOnePool(@Value("${spring.data.gemfire.locator.port:11235}") int locatorPort) { PoolFactoryBean serverOnePool = new PoolFactoryBean(); @@ -197,13 +210,13 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT serverOnePool.setReadTimeout(Long.valueOf(TimeUnit.SECONDS.toMillis(30)).intValue()); serverOnePool.setRetryAttempts(1); serverOnePool.setServerGroup("serverOne"); - serverOnePool.setLocators(ConnectionEndpointList.from(newConnectionEndpoint("localhost", 11235))); + serverOnePool.setLocators(ConnectionEndpointList.from(ConnectionEndpoint.from("localhost", locatorPort))); return serverOnePool; } @Bean(name = "ServerTwoPool") - PoolFactoryBean serverTwoPool() { + PoolFactoryBean serverTwoPool(@Value("${spring.data.gemfire.locator.port:11235}") int locatorPort) { PoolFactoryBean serverOnePool = new PoolFactoryBean(); @@ -212,7 +225,7 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT serverOnePool.setReadTimeout(Long.valueOf(TimeUnit.SECONDS.toMillis(30)).intValue()); serverOnePool.setRetryAttempts(1); serverOnePool.setServerGroup("serverTwo"); - serverOnePool.setLocators(ConnectionEndpointList.from(newConnectionEndpoint("localhost", 11235))); + serverOnePool.setLocators(ConnectionEndpointList.from(ConnectionEndpoint.from("localhost", locatorPort))); return serverOnePool; } @@ -254,22 +267,19 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT GemfireTemplate dogsTemplate(GemFireCache gemfireCache) { return new GemfireTemplate(gemfireCache.getRegion("Dogs")); } - - ConnectionEndpoint newConnectionEndpoint(String host, int port) { - return new ConnectionEndpoint(host, port); - } } static abstract class AbstractGemFireCacheServerConfiguration { - Properties gemfireProperties() { + @Bean + Properties gemfireProperties(@Value("${spring.data.gemfire.locator.port:11235}") int locatorPort) { return PropertiesBuilder.create() .setProperty("name", applicationName()) .setProperty("log-level", logLevel()) - .setProperty("locators", "localhost[11235]") + .setProperty("locators", String.format("localhost[%d]", locatorPort)) .setProperty("groups", groups()) - .setProperty("start-locator", startLocator()) + .setProperty("start-locator", startLocator(locatorPort)) .build(); } @@ -283,36 +293,34 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT return System.getProperty("spring.data.gemfire.log.level", GEMFIRE_LOG_LEVEL); } - String startLocator() { + String startLocator(int locatorPort) { return ""; } @Bean - CacheFactoryBean gemfireCache() { + CacheFactoryBean gemfireCache(@Qualifier("gemfireProperties") Properties gemfireProperties) { CacheFactoryBean gemfireCache = new CacheFactoryBean(); gemfireCache.setClose(true); - gemfireCache.setProperties(gemfireProperties()); + gemfireCache.setProperties(gemfireProperties); return gemfireCache; } @Bean - CacheServerFactoryBean gemfireCacheServer(GemFireCache gemfireCache) { + CacheServerFactoryBean gemfireCacheServer(GemFireCache gemfireCache, + @Value("${spring.data.gemfire.cache.server.port:40404}") int cacheServerPort) { CacheServerFactoryBean gemfireCacheServer = new CacheServerFactoryBean(); gemfireCacheServer.setAutoStartup(true); gemfireCacheServer.setCache((Cache) gemfireCache); gemfireCacheServer.setMaxTimeBetweenPings(Long.valueOf(TimeUnit.SECONDS.toMillis(60)).intValue()); - gemfireCacheServer.setPort(cacheServerPort()); + gemfireCacheServer.setPort(cacheServerPort); return gemfireCacheServer; } - - abstract int cacheServerPort(); - } @Configuration @@ -320,14 +328,13 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT static class GemFireCacheServerOneConfiguration extends AbstractGemFireCacheServerConfiguration { public static void main(String[] args) { - new AnnotationConfigApplicationContext(GemFireCacheServerOneConfiguration.class) - .registerShutdownHook(); + runSpringApplication(GemFireCacheServerOneConfiguration.class, args); } @Resource(name = "Cats") private org.apache.geode.cache.Region cats; - Cat save(Cat cat) { + private Cat save(Cat cat) { cats.put(cat.getName(), cat); return cat; } @@ -341,19 +348,14 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT save(Cat.newCat("Sammy")); } - @Override - int cacheServerPort() { - return 41414; - } - @Override String groups() { return "serverOne"; } @Override - String startLocator() { - return "localhost[11235]"; + String startLocator(int locatorPort) { + return String.format("localhost[%d]", locatorPort); } @Bean(name = "Cats") @@ -373,14 +375,13 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT static class GemFireCacheServerTwoConfiguration extends AbstractGemFireCacheServerConfiguration { public static void main(String[] args) { - new AnnotationConfigApplicationContext(GemFireCacheServerTwoConfiguration.class) - .registerShutdownHook(); + runSpringApplication(GemFireCacheServerTwoConfiguration.class, args); } @Resource(name = "Dogs") private org.apache.geode.cache.Region dogs; - Dog save(Dog dog) { + private Dog save(Dog dog) { dogs.put(dog.getName(), dog); return dog; } @@ -391,11 +392,6 @@ public class GemfireTemplateQueriesOnGroupedPooledClientCacheRegionsIntegrationT save(Dog.newDog("Maha")); } - @Override - int cacheServerPort() { - return 42424; - } - @Override String groups() { return "serverTwo"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java index d7a794cf..83b34e65 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexConflictsIntegrationTests.java @@ -32,13 +32,11 @@ import org.apache.geode.cache.query.IndexNameConflictException; import org.apache.geode.cache.query.QueryService; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Import; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; /** * Integration Tests for numerous conflicting {@link Index} configurations. @@ -57,17 +55,16 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor * @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Configuration * @see org.springframework.context.annotation.Import + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see IndexFactoryBean traps IndexExistsException instead of IndexNameConflictException * @see Improve IndexFactoryBean's resilience and options for handling GemFire IndexExistsExceptions and IndexNameConflictExceptions * @since 1.6.3 */ -public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { +public class IndexConflictsIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private static final AtomicBoolean IGNORE = new AtomicBoolean(false); private static final AtomicBoolean OVERRIDE = new AtomicBoolean(false); - private ConfigurableApplicationContext applicationContext; - private void assertIndex(Index index, String expectedName, String expectedExpression, String expectedFromClause, IndexType expectedType) { @@ -82,16 +79,6 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { assertThat(getIndexCount()).isEqualTo(count); } - private boolean close(ConfigurableApplicationContext applicationContext) { - - if (applicationContext != null) { - applicationContext.close(); - return !(applicationContext.isActive() || applicationContext.isRunning()); - } - - return true; - } - private Index getIndex(String indexName) { for (Index index : nullSafeCollection(getQueryService().getIndexes())) { @@ -108,19 +95,16 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { } private QueryService getQueryService() { - return this.applicationContext.getBean("gemfireCache", GemFireCache.class).getQueryService(); + return getBean("gemfireCache", GemFireCache.class).getQueryService(); } private boolean hasIndex(String indexName) { - return (getIndex(indexName) != null); - } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); + return getIndex(indexName) != null; } @Before public void setup() { + assertThat(IGNORE.get()).isFalse(); assertThat(OVERRIDE.get()).isFalse(); } @@ -130,8 +114,6 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { OVERRIDE.set(false); IGNORE.set(false); - - assertThat(close(this.applicationContext)).isTrue(); } @Test @@ -139,10 +121,10 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { assertThat(IGNORE.compareAndSet(false, true)).isTrue(); - this.applicationContext = newApplicationContext(IndexDefinitionConflictConfiguration.class); + newApplicationContext(IndexDefinitionConflictConfiguration.class); - assertThat(this.applicationContext.containsBean("customerIdIndex")).isTrue(); - assertThat(this.applicationContext.containsBean("customerIdentifierIndex")).isTrue(); + assertThat(requireApplicationContext().containsBean("customerIdIndex")).isTrue(); + assertThat(requireApplicationContext().containsBean("customerIdentifierIndex")).isTrue(); assertIndexCount(1); assertThat(hasIndex("customerIdIndex")).isTrue(); assertThat(hasIndex("customerIdentifierIndex")).isFalse(); @@ -158,10 +140,10 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { assertThat(OVERRIDE.compareAndSet(false, true)).isTrue(); - this.applicationContext = newApplicationContext(IndexDefinitionConflictConfiguration.class); + newApplicationContext(IndexDefinitionConflictConfiguration.class); - assertThat(this.applicationContext.containsBean("customerIdIndex")).isTrue(); - assertThat(this.applicationContext.containsBean("customerIdentifierIndex")).isTrue(); + assertThat(containsBean("customerIdIndex")).isTrue(); + assertThat(containsBean("customerIdentifierIndex")).isTrue(); assertIndexCount(1); assertThat(hasIndex("customerIdIndex")).isFalse(); assertThat(hasIndex("customerIdentifierIndex")).isTrue(); @@ -176,7 +158,7 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { public void indexDefinitionConflictThrowsIndexExistsException() throws Throwable { try { - this.applicationContext = newApplicationContext(IndexDefinitionConflictConfiguration.class); + newApplicationContext(IndexDefinitionConflictConfiguration.class); } catch (BeanCreationException expected) { @@ -206,10 +188,10 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { assertThat(IGNORE.compareAndSet(false, true)).isTrue(); - this.applicationContext = newApplicationContext(IndexNameConflictConfiguration.class); + newApplicationContext(IndexNameConflictConfiguration.class); - assertThat(this.applicationContext.containsBean("customerLastNameIndex")).isTrue(); - assertThat(this.applicationContext.containsBean("customerFirstNameIndex")).isTrue(); + assertThat(containsBean("customerLastNameIndex")).isTrue(); + assertThat(containsBean("customerFirstNameIndex")).isTrue(); assertIndexCount(1); assertThat(hasIndex(IndexNameConflictConfiguration.INDEX_NAME)).isTrue(); @@ -224,11 +206,11 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { assertThat(OVERRIDE.compareAndSet(false, true)).isTrue(); - this.applicationContext = newApplicationContext(IndexNameConflictConfiguration.class); + newApplicationContext(IndexNameConflictConfiguration.class); - assertThat(this.applicationContext.getBeansOfType(Index.class)).hasSize(2); - assertThat(this.applicationContext.containsBean("customerLastNameIndex")).isTrue(); - assertThat(this.applicationContext.containsBean("customerFirstNameIndex")).isTrue(); + assertThat(getBeansOfType(Index.class)).hasSize(2); + assertThat(containsBean("customerLastNameIndex")).isTrue(); + assertThat(containsBean("customerFirstNameIndex")).isTrue(); assertIndexCount(1); assertThat(hasIndex(IndexNameConflictConfiguration.INDEX_NAME)).isTrue(); @@ -242,7 +224,7 @@ public class IndexConflictsIntegrationTests extends IntegrationTestsSupport { public void indexNameConflictThrowsIndexNameConflictException() throws Throwable { try { - this.applicationContext = newApplicationContext(IndexNameConflictConfiguration.class); + newApplicationContext(IndexNameConflictConfiguration.class); } catch (BeanCreationException expected) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java index e6cc5941..77a9a979 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/LookupPartitionRegionMutationIntegrationTests.java @@ -51,6 +51,7 @@ import org.apache.geode.cache.asyncqueue.AsyncEventListener; import org.apache.geode.cache.util.CacheListenerAdapter; import org.springframework.beans.factory.BeanNameAware; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.StringUtils; @@ -63,6 +64,7 @@ import org.springframework.util.StringUtils; * @author John Blum * @see org.junit.Test * @see org.springframework.data.gemfire.LookupRegionFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.7.0 @@ -70,7 +72,7 @@ import org.springframework.util.StringUtils; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class LookupPartitionRegionMutationIntegrationTests { +public class LookupPartitionRegionMutationIntegrationTests extends IntegrationTestsSupport { @Resource(name = "Example") private Region example; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java index 8ebbaf55..0afca550 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RecreatingSpringApplicationContextTest.java @@ -15,12 +15,14 @@ */ package org.springframework.data.gemfire; +import java.io.File; + import org.junit.After; import org.junit.Before; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; /** * Abstract base test class that creates the Spring {@link ConfigurableApplicationContext} after each method (test case). @@ -31,17 +33,18 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport */ -public abstract class RecreatingSpringApplicationContextTest extends IntegrationTestsSupport { - - protected GenericXmlApplicationContext applicationContext; +public abstract class RecreatingSpringApplicationContextTest extends SpringApplicationContextIntegrationTestsSupport { @Before public void createContext() { - applicationContext = configureContext(new GenericXmlApplicationContext()); + GenericXmlApplicationContext applicationContext = configureContext(new GenericXmlApplicationContext()); + applicationContext.load(location()); applicationContext.registerShutdownHook(); applicationContext.refresh(); + + setApplicationContext(applicationContext); } protected abstract String location(); @@ -51,8 +54,12 @@ public abstract class RecreatingSpringApplicationContextTest extends Integration } @After - public void closeContext() { - closeApplicationContext(this.applicationContext); + public void cleanupAfterTests() { + destroyAllGemFireMockObjects(); + + for (String name : new File(".").list((file, filename) -> filename.startsWith("BACKUP"))) { + new File(name).delete(); + } } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java index e5bba639..623c7740 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionLookupIntegrationTests.java @@ -18,8 +18,7 @@ package org.springframework.data.gemfire; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import java.util.Optional; - +import org.junit.After; import org.junit.Test; import org.apache.geode.cache.DataPolicy; @@ -44,7 +43,6 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor * @since 1.4.0 * @link https://jira.spring.io/browse/SGF-204 */ -// TODO: slow test; can this test use mocks? public class RegionLookupIntegrationTests extends IntegrationTestsSupport { private void assertNoRegionLookup(String configLocation) { @@ -52,36 +50,41 @@ public class RegionLookupIntegrationTests extends IntegrationTestsSupport { ConfigurableApplicationContext applicationContext = null; try { - applicationContext = createApplicationContext(configLocation); + applicationContext = newApplicationContext(configLocation); fail("Spring ApplicationContext should have thrown a BeanCreationException caused by a RegionExistsException!"); } catch (BeanCreationException expected) { - assertThat(expected.getCause() instanceof RegionExistsException).as(expected.getMessage()).isTrue(); + assertThat(expected.getCause() instanceof RegionExistsException) + .describedAs(expected.getMessage()) + .isTrue(); throw (RegionExistsException) expected.getCause(); + } finally { closeApplicationContext(applicationContext); } } - private ConfigurableApplicationContext createApplicationContext(String configLocation) { + private ConfigurableApplicationContext newApplicationContext(String configLocation) { return new ClassPathXmlApplicationContext(configLocation); } - private void closeApplicationContext(ConfigurableApplicationContext applicationContext) { - Optional.ofNullable(applicationContext).ifPresent(ConfigurableApplicationContext::close); + @After + public void cleanupAfterTests() { + destroyAllGemFireMockObjects(); } @Test - public void testAllowRegionBeanDefinitionOverrides() { + public void allowRegionBeanDefinitionOverrides() { ConfigurableApplicationContext applicationContext = null; try { - applicationContext = createApplicationContext( - "/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml"); + + applicationContext = + newApplicationContext("/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml"); assertThat(applicationContext).isNotNull(); assertThat(applicationContext.containsBean("regionOne")).isTrue(); @@ -108,47 +111,88 @@ public class RegionLookupIntegrationTests extends IntegrationTestsSupport { } @Test(expected = RegionExistsException.class) - public void testNoDuplicateRegionDefinitions() { - assertNoRegionLookup("/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml"); - } - - @Test(expected = RegionExistsException.class) - public void testNoClientRegionLookups() { + public void noClientRegionLookups() { assertNoRegionLookup("/org/springframework/data/gemfire/noClientRegionLookupTest.xml"); } @Test(expected = RegionExistsException.class) - public void testNoClientSubRegionLookups() { + public void noClientSubRegionLookups() { assertNoRegionLookup("/org/springframework/data/gemfire/noClientSubRegionLookupTest.xml"); } @Test(expected = RegionExistsException.class) - public void testNoLocalRegionLookups() { + public void noDuplicateRegionDefinitions() { + assertNoRegionLookup("/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml"); + } + + @Test(expected = RegionExistsException.class) + public void noLocalRegionLookups() { assertNoRegionLookup("/org/springframework/data/gemfire/noLocalRegionLookupTest.xml"); } @Test(expected = RegionExistsException.class) - public void testNoPartitionRegionLookups() { + public void noPartitionRegionLookups() { assertNoRegionLookup("/org/springframework/data/gemfire/noPartitionRegionLookupTest.xml"); } @Test(expected = RegionExistsException.class) - public void testNoReplicateRegionLookups() { + public void noReplicateRegionLookups() { assertNoRegionLookup("/org/springframework/data/gemfire/noReplicateRegionLookupTest.xml"); } @Test(expected = RegionExistsException.class) - public void testNoSubRegionLookups() { + public void noSubRegionLookups() { assertNoRegionLookup("/org/springframework/data/gemfire/noSubRegionLookupTest.xml"); } @Test - public void testEnableRegionLookups() { + public void withEnableClientRegionLookups() { ConfigurableApplicationContext applicationContext = null; try { - applicationContext = createApplicationContext("/org/springframework/data/gemfire/enableRegionLookupsTest.xml"); + + applicationContext = + newApplicationContext("/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml"); + + assertThat(applicationContext).isNotNull(); + assertThat(applicationContext.containsBean("NativeClientRegion")).isTrue(); + assertThat(applicationContext.containsBean("NativeClientParentRegion")).isTrue(); + assertThat(applicationContext.containsBean("/NativeClientParentRegion/NativeClientChildRegion")).isTrue(); + + Region nativeClientRegion = applicationContext.getBean("NativeClientRegion", Region.class); + + assertThat(nativeClientRegion).isNotNull(); + assertThat(nativeClientRegion.getName()).isEqualTo("NativeClientRegion"); + assertThat(nativeClientRegion.getFullPath()).isEqualTo("/NativeClientRegion"); + assertThat(nativeClientRegion.getAttributes()).isNotNull(); + assertThat(nativeClientRegion.getAttributes().getCloningEnabled()).isFalse(); + assertThat(nativeClientRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL); + + Region nativeClientChildRegion = + applicationContext.getBean("/NativeClientParentRegion/NativeClientChildRegion", Region.class); + + assertThat(nativeClientChildRegion).isNotNull(); + assertThat(nativeClientChildRegion.getName()).isEqualTo("NativeClientChildRegion"); + assertThat(nativeClientChildRegion.getFullPath()) + .isEqualTo("/NativeClientParentRegion/NativeClientChildRegion"); + assertThat(nativeClientChildRegion.getAttributes()).isNotNull(); + assertThat(nativeClientChildRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL); + } + finally { + closeApplicationContext(applicationContext); + } + } + + @Test + public void withEnableRegionLookups() { + + ConfigurableApplicationContext applicationContext = null; + + try { + + applicationContext = + newApplicationContext("/org/springframework/data/gemfire/enableRegionLookupsTest.xml"); assertThat(applicationContext).isNotNull(); assertThat(applicationContext.containsBean("NativeLocalRegion")).isTrue(); @@ -228,42 +272,4 @@ public class RegionLookupIntegrationTests extends IntegrationTestsSupport { closeApplicationContext(applicationContext); } } - - @Test - public void testEnableClientRegionLookups() { - - ConfigurableApplicationContext applicationContext = null; - - try { - - applicationContext = createApplicationContext("/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml"); - - assertThat(applicationContext).isNotNull(); - assertThat(applicationContext.containsBean("NativeClientRegion")).isTrue(); - assertThat(applicationContext.containsBean("NativeClientParentRegion")).isTrue(); - assertThat(applicationContext.containsBean("/NativeClientParentRegion/NativeClientChildRegion")).isTrue(); - - Region nativeClientRegion = applicationContext.getBean("NativeClientRegion", Region.class); - - assertThat(nativeClientRegion).isNotNull(); - assertThat(nativeClientRegion.getName()).isEqualTo("NativeClientRegion"); - assertThat(nativeClientRegion.getFullPath()).isEqualTo("/NativeClientRegion"); - assertThat(nativeClientRegion.getAttributes()).isNotNull(); - assertThat(nativeClientRegion.getAttributes().getCloningEnabled()).isFalse(); - assertThat(nativeClientRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL); - - Region nativeClientChildRegion = - applicationContext.getBean("/NativeClientParentRegion/NativeClientChildRegion", Region.class); - - assertThat(nativeClientChildRegion).isNotNull(); - assertThat(nativeClientChildRegion.getName()).isEqualTo("NativeClientChildRegion"); - assertThat(nativeClientChildRegion.getFullPath()) - .isEqualTo("/NativeClientParentRegion/NativeClientChildRegion"); - assertThat(nativeClientChildRegion.getAttributes()).isNotNull(); - assertThat(nativeClientChildRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL); - } - finally { - closeApplicationContext(applicationContext); - } - } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java index 01d4e450..9572807b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/ClientCacheManagerIntegrationTests.java @@ -23,8 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -35,19 +34,22 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.junit.Test * @see org.springframework.data.gemfire.cache.GemfireCacheManager * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(value = "/org/springframework/data/gemfire/cache/cache-manager-client-cache.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest +@SuppressWarnings("unused") public class ClientCacheManagerIntegrationTests extends IntegrationTestsSupport { @Autowired - GemfireCacheManager cacheManager; + private GemfireCacheManager cacheManager; @Test public void cacheManagerUsesConfiguredGemFireRegionAsCache() { - assertThat(cacheManager.getCache("Example")).isNotNull(); + + assertThat(this.cacheManager).isNotNull(); + assertThat(this.cacheManager.getCache("Example")).isNotNull(); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java index ef27db77..76f17fcb 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CompoundCachePutCacheEvictIntegrationTests.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.Serializable; import java.util.List; -import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Resource; @@ -30,6 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -41,8 +41,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; -import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.LocalRegionFactoryBean; +import org.springframework.data.gemfire.cache.config.EnableGemfireCaching; +import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; +import org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions; +import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; import org.springframework.data.gemfire.mapping.GemfireMappingContext; import org.springframework.data.gemfire.mapping.annotation.Region; import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean; @@ -77,79 +79,89 @@ import lombok.RequiredArgsConstructor; * @since 1.9.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = CompoundCachePutCacheEvictIntegrationTests.ApplicationTestConfiguration.class) +@ContextConfiguration(classes = CompoundCachePutCacheEvictIntegrationTests.TestConfiguration.class) @SuppressWarnings("unused") public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTestsSupport { - private Person janeDoe; - private Person jonDoe; + private Employee janeDoe; + private Employee jonDoe; @Autowired - private PeopleService peopleService; + private EmployeeRepository employeeRepository; - @Resource(name = "People") - private org.apache.geode.cache.Region peopleRegion; + @Autowired + private EmployeeService employeeService; - protected void assertNoPeopleInDepartment(Department department) { + @Resource(name = "Employees") + private org.apache.geode.cache.Region employeesRegion; + + private void assertNoEmployeeInDepartment(Department department) { assertPeopleInDepartment(department); } - protected void assertPeopleInDepartment(Department department, Person... people) { - List peopleInDepartment = peopleService.findByDepartment(department); + private void assertPeopleInDepartment(Department department, Employee... people) { + + List peopleInDepartment = employeeService.findByDepartment(department); assertThat(peopleInDepartment).isNotNull(); assertThat(peopleInDepartment.size()).isEqualTo(people.length); assertThat(peopleInDepartment).contains(people); } - protected Person newPerson(String name, String mobile, Department department) { - return newPerson(IdentifierSequence.nextId(), name, mobile, department); + private Employee newEmployee(String name, String mobile, Department department) { + return newEmployee(IdentifierSequence.nextId(), name, mobile, department); } - protected Person newPerson(Long id, String name, String mobile, Department department) { - Person person = Person.newPerson(department, mobile, name); - person.setId(id); - return person; - } - - protected Person save(Person person) { - peopleRegion.put(person.getId(), person); - return person; + private Employee newEmployee(Long id, String name, String mobile, Department department) { + Employee employee = Employee.newEmployee(department, mobile, name); + employee.setId(id); + return employee; } @Before public void setup() { - janeDoe = save(newPerson("Jane Doe", "541-555-1234", Department.MARKETING)); - jonDoe = save(newPerson("Jon Doe", "972-555-1248", Department.ENGINEERING)); - assertThat(peopleRegion.containsValue(janeDoe)).isTrue(); - assertThat(peopleRegion.containsValue(janeDoe)).isTrue(); + janeDoe = employeeRepository.save(newEmployee("Jane Doe", "541-555-1234", Department.MARKETING)); + jonDoe = employeeRepository.save(newEmployee("Jon Doe", "972-555-1248", Department.ENGINEERING)); + + assertThat(employeesRegion).containsValue(janeDoe); + assertThat(employeesRegion).containsValue(jonDoe); } @Test public void janeDoeUpdateSuccessful() { - assertNoPeopleInDepartment(Department.DESIGN); - assertThat(peopleService.isCacheMiss()).isTrue(); + + assertNoEmployeeInDepartment(Department.DESIGN); + assertThat(employeeService.isCacheMiss()).isTrue(); janeDoe.setDepartment(Department.DESIGN); - peopleService.update(janeDoe); + employeeService.update(janeDoe); + assertThat(employeesRegion).containsValue(janeDoe); assertPeopleInDepartment(Department.DESIGN, janeDoe); - assertThat(peopleService.isCacheMiss()).isTrue(); + assertThat(employeeService.isCacheMiss()).isTrue(); + + assertThat(employeesRegion).containsValue(janeDoe); + assertPeopleInDepartment(Department.DESIGN, janeDoe); + assertThat(employeeService.isCacheMiss()).isFalse(); } @Test public void jonDoeUpdateSuccessful() { + jonDoe.setDepartment(Department.RESEARCH_DEVELOPMENT); - peopleService.update(jonDoe); + employeeService.update(jonDoe); assertPeopleInDepartment(Department.RESEARCH_DEVELOPMENT, jonDoe); - assertThat(peopleService.isCacheMiss()).isTrue(); + assertThat(employeeService.isCacheMiss()).isTrue(); + + assertPeopleInDepartment(Department.RESEARCH_DEVELOPMENT, jonDoe); + assertThat(employeeService.isCacheMiss()).isFalse(); } @Configuration @EnableCaching - @Import(ApplicationTestConfiguration.class) + @Import(TestConfiguration.class) static class Sgf539WorkaroundConfiguration { @Bean @@ -177,25 +189,14 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests } @Configuration - @EnableCaching @Import(GemFireConfiguration.class) - static class ApplicationTestConfiguration { + static class TestConfiguration { @Bean - GemfireCacheManager cacheManager(GemFireCache gemfireCache) { + GemfireRepositoryFactoryBean personRepository() { - GemfireCacheManager cacheManager = new GemfireCacheManager(); - - cacheManager.setCache(gemfireCache); - - return cacheManager; - } - - @Bean - GemfireRepositoryFactoryBean personRepository() { - - GemfireRepositoryFactoryBean personRepository = - new GemfireRepositoryFactoryBean<>(PersonRepository.class); + GemfireRepositoryFactoryBean personRepository = + new GemfireRepositoryFactoryBean<>(EmployeeRepository.class); personRepository.setGemfireMappingContext(new GemfireMappingContext()); @@ -203,79 +204,16 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests } @Bean - PeopleService peopleService(PersonRepository personRepository) { - return new PeopleService(personRepository); + EmployeeService peopleService(EmployeeRepository personRepository) { + return new EmployeeService(personRepository); } } - @Configuration - static class GemFireConfiguration { - - static final String DEFAULT_GEMFIRE_LOG_LEVEL = "error"; - - Properties gemfireProperties() { - - Properties gemfireProperties = new Properties(); - - gemfireProperties.setProperty("name", applicationName()); - gemfireProperties.setProperty("locators", ""); - gemfireProperties.setProperty("log-level", logLevel()); - - return gemfireProperties; - } - - String applicationName() { - return CompoundCachePutCacheEvictIntegrationTests.class.getName(); - } - - String logLevel() { - return System.getProperty("spring.data.gemfire.log.level", DEFAULT_GEMFIRE_LOG_LEVEL); - } - - @Bean - CacheFactoryBean gemfireCache() { - - CacheFactoryBean gemfireCache = new CacheFactoryBean(); - - gemfireCache.setClose(true); - gemfireCache.setProperties(gemfireProperties()); - - return gemfireCache; - } - - @Bean(name = "People") - LocalRegionFactoryBean peopleRegion(GemFireCache gemfireCache) { - - LocalRegionFactoryBean peopleRegion = new LocalRegionFactoryBean<>(); - - peopleRegion.setCache(gemfireCache); - peopleRegion.setPersistent(false); - - return peopleRegion; - } - - @Bean(name = "DepartmentPeople") - LocalRegionFactoryBean departmentPeopleRegion(GemFireCache gemfireCache) { - - LocalRegionFactoryBean departmentPeopleRegion = new LocalRegionFactoryBean<>(); - - departmentPeopleRegion.setCache(gemfireCache); - departmentPeopleRegion.setPersistent(false); - - return departmentPeopleRegion; - } - - @Bean(name = "MobilePeople") - LocalRegionFactoryBean mobilePeopleRegion(GemFireCache gemfireCache) { - - LocalRegionFactoryBean mobilePeopleRegion = new LocalRegionFactoryBean<>(); - - mobilePeopleRegion.setCache(gemfireCache); - mobilePeopleRegion.setPersistent(false); - - return mobilePeopleRegion; - } - } + @ClientCacheApplication + @EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL) + @EnableEntityDefinedRegions(basePackageClasses = Employee.class, clientRegionShortcut = ClientRegionShortcut.LOCAL) + @EnableGemfireCaching + static class GemFireConfiguration { } public enum Department { @@ -291,9 +229,9 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests } @Data - @Region("People") - @RequiredArgsConstructor(staticName = "newPerson") - public static class Person implements Serializable { + @Region("Employees") + @RequiredArgsConstructor(staticName = "newEmployee") + public static class Employee implements Serializable { @Id private Long id; @@ -305,32 +243,32 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests } @Service - public static class PeopleService extends CacheableService { + public static class EmployeeService extends CacheableService { - private final PersonRepository personRepository; + private final EmployeeRepository employeeRepository; - public PeopleService(PersonRepository personRepository) { - this.personRepository = personRepository; + public EmployeeService(EmployeeRepository employeeRepository) { + this.employeeRepository = employeeRepository; } - @Cacheable("DepartmentPeople") - public List findByDepartment(Department department) { + @Cacheable("DepartmentEmployees") + public List findByDepartment(Department department) { setCacheMiss(); - return personRepository.findByDepartment(department); + return employeeRepository.findByDepartment(department); } - @Cacheable("MobilePeople") - public Person findByMobile(String mobile) { + @Cacheable("MobileEmployees") + public Employee findByMobile(String mobile) { setCacheMiss(); - return personRepository.findByMobile(mobile); + return employeeRepository.findByMobile(mobile); } @Caching( - evict = @CacheEvict(value = "DepartmentPeople", key = "#p0.department"), - put = @CachePut(value = "MobilePeople", key="#p0.mobile") + evict = @CacheEvict(value = "DepartmentEmployees", key = "#p0.department"), + put = @CachePut(value = "MobileEmployees", key="#p0.mobile") ) - public Person update(Person person) { - return personRepository.save(person); + public Employee update(Employee employee) { + return employeeRepository.save(employee); } } @@ -351,11 +289,11 @@ public class CompoundCachePutCacheEvictIntegrationTests extends IntegrationTests } } - public interface PersonRepository extends CrudRepository { + public interface EmployeeRepository extends CrudRepository { - List findByDepartment(Department department); + List findByDepartment(Department department); - Person findByMobile(String mobile); + Employee findByMobile(String mobile); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java index 46102086..7843a902 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests.java @@ -18,8 +18,6 @@ package org.springframework.data.gemfire.client; import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.junit.BeforeClass; import org.junit.Test; @@ -64,15 +62,8 @@ public class ClientCacheIndexingIntegrationTests extends ForkingClientServerInte @BeforeClass public static void startGeodeServer() throws IOException { - - List arguments = new ArrayList<>(); - - arguments.add(String.format("-Dgemfire.name=%s", - ClientCacheIndexingIntegrationTests.class.getSimpleName().contains("Server"))); - - arguments.add(getServerContextXmlFileLocation(ClientCacheIndexingIntegrationTests.class)); - - startGemFireServer(ServerProcess.class, arguments.toArray(new String[0])); + startGemFireServer(ServerProcess.class, + getServerContextXmlFileLocation(ClientCacheIndexingIntegrationTests.class)); } private Index getIndex(GemFireCache gemfireCache, String indexName) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java index 48275f13..04ba5c41 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheIntegrationTests.java @@ -25,12 +25,10 @@ import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; -import org.springframework.data.gemfire.tests.util.IOUtils; /** * Integration Tests for {@link org.apache.geode.cache.client.ClientCache}. @@ -45,15 +43,11 @@ import org.springframework.data.gemfire.tests.util.IOUtils; * @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Configuration * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects */ @SuppressWarnings("unused") -public class ClientCacheIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); - } +public class ClientCacheIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private boolean testClientCacheClose(Class clientCacheConfiguration) { @@ -71,7 +65,7 @@ public class ClientCacheIntegrationTests extends IntegrationTestsSupport { return clientCache.isClosed(); } finally { - IOUtils.close(applicationContext); + closeApplicationContext(applicationContext); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java index 52bcf18e..08c9efd0 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheSecurityIntegrationTests.java @@ -32,6 +32,7 @@ import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.LoaderHelper; import org.apache.geode.cache.Region; +import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.fork.ServerProcess; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; @@ -57,14 +58,20 @@ public class ClientCacheSecurityIntegrationTests extends ForkingClientServerInte List arguments = new ArrayList(); - arguments.add(String.format("-Dgemfire.name=%1$s", - ClientCacheSecurityIntegrationTests.class.getSimpleName().concat("Server"))); + org.springframework.core.io.Resource trustedKeystore = new ClassPathResource("trusted.keystore"); - arguments.add(String.format("-Djavax.net.ssl.keyStore=%1$s", System.getProperty("javax.net.ssl.keyStore"))); + //System.err.printf("trusted.keystore file is located at [%s]%n", trustedKeystore.getFile().getAbsolutePath()); + + arguments.add(String.format("-Dgemfire.name=%s", + asApplicationName(ClientCacheSecurityIntegrationTests.class).concat("Server"))); + + arguments.add(String.format("-Djavax.net.ssl.keyStore=%s", trustedKeystore.getFile().getAbsolutePath())); arguments.add(getServerContextXmlFileLocation(ClientCacheSecurityIntegrationTests.class)); startGemFireServer(ServerProcess.class, arguments.toArray(new String[arguments.size()])); + + System.setProperty("javax.net.ssl.keyStore", trustedKeystore.getFile().getAbsolutePath()); } @Resource(name = "Example") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java index a813497a..8cc948cd 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -36,9 +37,9 @@ import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.LoaderHelper; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.Pool; -import org.apache.geode.cache.client.PoolManager; import org.apache.geode.cache.server.CacheServer; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; @@ -52,8 +53,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Integration Tests testing the use of variable {@literal servers} attribute on <gfe:pool/< in SDG XML Namespace - * configuration metadata when connecting a client and server. + * Integration Tests for the use of the variable {@literal servers} attribute on <gfe:pool/< element + * in SDG XML Namespace configuration metadata when connecting a client and server. * * @author John Blum * @see org.junit.Test @@ -91,26 +92,25 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer @AfterClass public static void cleanup() { - System.clearProperty("test.cache.server.port.one"); - System.clearProperty("test.cache.server.port.two"); + Arrays.asList("test.cache.server.port.one", "test.cache.server.port.two").forEach(System::clearProperty); } + @Autowired + private Pool serverPool; + @Resource(name = "Example") private Region example; @Before public void setup() { + assertThat(this.serverPool).isNotNull(); + assertThat(this.serverPool.getName()).isEqualTo("serverPool"); + assertThat(this.serverPool.getServers()).hasSize(3); assertThat(this.example).isNotNull(); assertThat(this.example.getName()).isEqualTo("Example"); assertThat(this.example.getAttributes()).isNotNull(); assertThat(this.example.getAttributes().getPoolName()).isEqualTo("serverPool"); - - Pool pool = PoolManager.find("serverPool"); - - assertThat(pool).isNotNull(); - assertThat(pool.getName()).isEqualTo("serverPool"); - assertThat(pool.getServers()).hasSize(3); } @Test @@ -126,7 +126,7 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer private static final AtomicInteger cacheMissCounter = new AtomicInteger(0); @Override - public Integer load(final LoaderHelper helper) throws CacheLoaderException { + public Integer load(LoaderHelper helper) throws CacheLoaderException { return cacheMissCounter.incrementAndGet(); } @@ -147,10 +147,10 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer Map cacheServers = CollectionUtils.nullSafeMap(applicationContext.getBeansOfType(CacheServer.class)); - for (CacheServer cacheServer : cacheServers.values()) { - logger.info("CacheServer host:port [{}:{}]%n", - cacheServer.getBindAddress(), cacheServer.getPort()); - } + assertThat(cacheServers).hasSize(3); + + cacheServers.values().forEach(cacheServer -> logger.info("CacheServer host:port [{}:{}]%n", + cacheServer.getBindAddress(), cacheServer.getPort())); } } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java index 5ed217fe..84572e33 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionIntegrationTests.java @@ -22,15 +22,16 @@ import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.context.annotation.Bean; +import org.springframework.data.gemfire.GemfireUtils; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -42,13 +43,13 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration +@GemFireUnitTest @SuppressWarnings("unused") public class ClientRegionIntegrationTests extends IntegrationTestsSupport { @@ -57,11 +58,19 @@ public class ClientRegionIntegrationTests extends IntegrationTestsSupport { @Test public void clientRegionUsesDefaultPoolWhenUnspecified() { + + assertThat(this.example).isNotNull(); + assertThat(this.example.getName()).isEqualTo(GemfireUtils.toRegionName("Example")); + assertThat(this.example.getFullPath()).isEqualTo(GemfireUtils.toRegionPath("Example")); + assertThat(this.example.getAttributes()).isNotNull(); + assertThat(this.example.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL); assertThat(this.example.getAttributes().getPoolName()).isNull(); + + // NOTE: A null Pool name implies the use of the Apache Geode DEFAULT Pool. + } @ClientCacheApplication - @EnableGemFireMockObjects static class ClientRegionConfiguration { @Bean("Example") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java index f1fe5f52..3901bcb5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractCacheConfigurationIntegrationTests.java @@ -18,8 +18,8 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.Cache; @@ -27,9 +27,9 @@ import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientCache; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -41,18 +41,14 @@ import org.springframework.mock.env.MockPropertySource; * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.client.ClientCache + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.2 */ -public class AbstractCacheConfigurationIntegrationTests { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class AbstractCacheConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private void assertName(GemFireCache gemfireCache, String name) { @@ -62,35 +58,36 @@ public class AbstractCacheConfigurationIntegrationTests { assertThat(gemfireCache.getDistributedSystem().getProperties().getProperty("name")).isEqualTo(name); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return newApplicationContext(null, annotatedClasses); + @Override + protected ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { + return newApplicationContext((PropertySource) null, annotatedClasses); } private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = + testPropertySource != null ? applicationContext -> { + Optional.ofNullable(testPropertySource).ifPresent(it -> { - Optional.ofNullable(testPropertySource).ifPresent(it -> { + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + propertySources.addFirst(testPropertySource); + }); - propertySources.addFirst(testPropertySource); - }); + return applicationContext; + } + : Function.identity(); - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); - - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test public void clientCacheNameUsesAnnotationNameAttributeDefaultValue() { - this.applicationContext = newApplicationContext(TestClientCacheConfiguration.class); + newApplicationContext(TestClientCacheConfiguration.class); - GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", ClientCache.class); + GemFireCache peerCache = getBean("gemfireCache", ClientCache.class); assertName(peerCache, ClientCacheConfiguration.DEFAULT_NAME); } @@ -101,9 +98,9 @@ public class AbstractCacheConfigurationIntegrationTests { MockPropertySource testPropertySource = new MockPropertySource() .withProperty("spring.data.gemfire.name", "TestClient"); - this.applicationContext = newApplicationContext(testPropertySource, TestClientCacheConfiguration.class); + newApplicationContext(testPropertySource, TestClientCacheConfiguration.class); - GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", ClientCache.class); + GemFireCache peerCache = getBean("gemfireCache", ClientCache.class); assertName(peerCache, "TestClient"); } @@ -111,9 +108,9 @@ public class AbstractCacheConfigurationIntegrationTests { @Test public void peerCacheNameUsesAnnotationNameAttributeConfiguredValue() { - this.applicationContext = newApplicationContext(TestPeerCacheConfiguration.class); + newApplicationContext(TestPeerCacheConfiguration.class); - GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", Cache.class); + GemFireCache peerCache = getBean("gemfireCache", Cache.class); assertName(peerCache, "TestPeerCacheApp"); } @@ -124,9 +121,9 @@ public class AbstractCacheConfigurationIntegrationTests { MockPropertySource testPropertySource = new MockPropertySource() .withProperty("spring.data.gemfire.cache.name", "TestPeer"); - this.applicationContext = newApplicationContext(testPropertySource, TestPeerCacheConfiguration.class); + newApplicationContext(testPropertySource, TestPeerCacheConfiguration.class); - GemFireCache peerCache = this.applicationContext.getBean("gemfireCache", Cache.class); + GemFireCache peerCache = getBean("gemfireCache", Cache.class); assertName(peerCache, "TestPeer"); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java index d0c421cd..7d5d7136 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheGeodeSecurityManagerSecurityIntegrationTests.java @@ -33,6 +33,7 @@ import org.apache.geode.security.ResourcePermission; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -54,6 +55,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ActiveProfiles("apache-geode-client") @ContextConfiguration(classes = AbstractGeodeSecurityIntegrationTests.GeodeClientConfiguration.class) +@DirtiesContext public class ApacheGeodeSecurityManagerSecurityIntegrationTests extends AbstractGeodeSecurityIntegrationTests { protected static final String GEODE_SECURITY_MANAGER_PROPERTY_CONFIGURATION_PROFILE = diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java index a4581ad1..5b042502 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroIniSecurityIntegrationTests.java @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -41,6 +42,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ActiveProfiles("apache-geode-client") @ContextConfiguration(classes = AbstractGeodeSecurityIntegrationTests.GeodeClientConfiguration.class) +@DirtiesContext public class ApacheShiroIniSecurityIntegrationTests extends AbstractGeodeSecurityIntegrationTests { protected static final String SHIRO_INI_CONFIGURATION_PROFILE = "shiro-ini-configuration"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java index 5a3851d8..2ef6261a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ApacheShiroRealmSecurityIntegrationTests.java @@ -28,6 +28,7 @@ import org.apache.shiro.realm.text.PropertiesRealm; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -47,6 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ActiveProfiles("apache-geode-client") @ContextConfiguration(classes = AbstractGeodeSecurityIntegrationTests.GeodeClientConfiguration.class) +@DirtiesContext public class ApacheShiroRealmSecurityIntegrationTests extends AbstractGeodeSecurityIntegrationTests { protected static final String SHIRO_REALM_CONFIGURATION_PROFILE = "shiro-realm-configuration"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java index 9ba72c52..ccf60f27 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AutoConfiguredAuthenticationConfigurationIntegrationTests.java @@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.data.gemfire.config.annotation.TestSecurityManager.SECURITY_PASSWORD; import static org.springframework.data.gemfire.config.annotation.TestSecurityManager.SECURITY_USERNAME; -import java.util.Optional; - import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; @@ -65,7 +63,7 @@ public class AutoConfiguredAuthenticationConfigurationIntegrationTests @After public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); + closeApplicationContext(this.applicationContext); } private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java index 0c463038..f22d39aa 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java @@ -17,21 +17,19 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Optional; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.server.CacheServer; import org.apache.geode.cache.server.ClientSubscriptionConfig; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -44,34 +42,26 @@ import org.springframework.mock.env.MockPropertySource; * @see org.apache.geode.cache.server.ClientSubscriptionConfig * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ -public class CacheServerPropertiesIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class CacheServerPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } private void assertCacheServer(CacheServer cacheServer, String bindAddress, String hostnameForClients, @@ -113,12 +103,11 @@ public class CacheServerPropertiesIntegrationTests extends IntegrationTestsSuppo .withProperty("spring.data.gemfire.cache.server.port", "${gemfire.cache.server.port:12345}") .withProperty("spring.data.gemfire.cache.server.TestCacheServer.subscription-eviction-policy", "MEM"); - this.applicationContext = newApplicationContext(testPropertySource, TestCacheServerConfiguration.class); + newApplicationContext(testPropertySource, TestCacheServerConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("TestCacheServer")).isTrue(); + assertThat(containsBean("TestCacheServer")).isTrue(); - CacheServer testCacheServer = this.applicationContext.getBean("TestCacheServer", CacheServer.class); + CacheServer testCacheServer = getBean("TestCacheServer", CacheServer.class); assertThat(testCacheServer).isNotNull(); assertThat(testCacheServer.getBindAddress()).isEqualTo("10.120.12.1"); @@ -173,19 +162,18 @@ public class CacheServerPropertiesIntegrationTests extends IntegrationTestsSuppo .withProperty("spring.data.gemfire.cache.server.TestCacheServer.subscription-eviction-policy", "ENTRY") .withProperty("spring.data.gemfire.cache.server.TestCacheServer.tcp-no-delay", true); - this.applicationContext = newApplicationContext(testPropertySource, TestCacheServersConfiguration.class); + newApplicationContext(testPropertySource, TestCacheServersConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("TestCacheServer")).isTrue(); + assertThat(containsBean("TestCacheServer")).isTrue(); - CacheServer gemfirCacheServer = this.applicationContext.getBean("gemfireCacheServer", CacheServer.class); + CacheServer gemfirCacheServer = getBean("gemfireCacheServer", CacheServer.class); assertCacheServer(gemfirCacheServer, "192.168.0.2", "skullbox", 10000L, 500, 451000, 8, 30000, 60, 41414, 16384, 21, "TestDiskStore", SubscriptionEvictionPolicy.MEM, false); - CacheServer testCacheServer = this.applicationContext.getBean("TestCacheServer", CacheServer.class); + CacheServer testCacheServer = getBean("TestCacheServer", CacheServer.class); assertCacheServer(testCacheServer, "10.121.12.1", "jambox", 15000L, 200, 651000, 16, 15000, diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java index e4c1d615..8525a8b5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests.java @@ -58,7 +58,7 @@ public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void tearDown() { + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java index 9954bd52..baeaaf86 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCacheConfigurationIntegrationTests.java @@ -18,19 +18,14 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import java.util.Optional; - -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.Pool; import org.apache.geode.cache.client.SocketFactory; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** @@ -42,46 +37,25 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * @see org.junit.Test * @see org.mockito.Mockito * @see org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.4.0 */ @SuppressWarnings("unused") -public class ClientCacheConfigurationIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); - - return applicationContext; - } +public class ClientCacheConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { @Test public void clientCacheDefaultPoolWithCustomSocketFactory() { - this.applicationContext = - newApplicationContext(ClientCacheDefaultPoolWithCustomSocketFactoryConfiguration.class); + newApplicationContext(ClientCacheDefaultPoolWithCustomSocketFactoryConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - - ClientCache clientCache = this.applicationContext.getBean(ClientCache.class); + ClientCache clientCache = getBean(ClientCache.class); assertThat(clientCache).isNotNull(); Pool defaultPool = clientCache.getDefaultPool(); - SocketFactory mockSocketFactory = this.applicationContext.getBean("mockSocketFactory", SocketFactory.class); + SocketFactory mockSocketFactory = getBean("mockSocketFactory", SocketFactory.class); assertThat(defaultPool).isNotNull(); assertThat(defaultPool.getName()).isEqualTo("DEFAULT"); @@ -93,12 +67,9 @@ public class ClientCacheConfigurationIntegrationTests extends IntegrationTestsSu @Test public void clientCacheDefaultPoolWithDefaultSocketFactory() { - this.applicationContext = - newApplicationContext(ClientCacheDefaultPoolWithDefaultSocketFactoryConfiguration.class); + newApplicationContext(ClientCacheDefaultPoolWithDefaultSocketFactoryConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - - ClientCache clientCache = this.applicationContext.getBean(ClientCache.class); + ClientCache clientCache = getBean(ClientCache.class); assertThat(clientCache).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java index 0c900b58..983359c6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java @@ -18,10 +18,9 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import java.util.Optional; import java.util.Properties; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.client.ClientCache; @@ -32,12 +31,11 @@ import org.apache.geode.cache.control.ResourceManager; import org.apache.geode.pdx.PdxSerializer; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -51,34 +49,26 @@ import org.springframework.mock.env.MockPropertySource; * @see org.springframework.core.env.PropertySource * @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.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ -public class ClientCachePropertiesIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class ClientCachePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test @@ -101,23 +91,22 @@ public class ClientCachePropertiesIntegrationTests extends IntegrationTestsSuppo .withProperty("spring.data.gemfire.pool.server-group", "TestGroup") .withProperty("spring.data.gemfire.pool.default.subscription-redundancy", 2); - this.applicationContext = newApplicationContext(testPropertySource, TestClientCacheConfiguration.class); + newApplicationContext(testPropertySource, TestClientCacheConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("mockPdxSerializer")).isTrue(); ClientCacheFactoryBean testClientCacheFactoryBean = - this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class); + getBean("&gemfireCache", ClientCacheFactoryBean.class); assertThat(testClientCacheFactoryBean).isNotNull(); assertThat(testClientCacheFactoryBean.isUseBeanFactoryLocator()).isFalse(); - ClientCache testClientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class); + ClientCache testClientCache = getBean("gemfireCache", ClientCache.class); assertThat(testClientCache).isNotNull(); - PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class); + PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class); assertThat(mockPdxSerializer).isNotNull(); assertThat(testClientCache).isNotNull(); @@ -202,24 +191,22 @@ public class ClientCachePropertiesIntegrationTests extends IntegrationTestsSuppo .withProperty("spring.data.gemfire.pdx.persistent", true) .withProperty("spring.data.gemfire.pdx.read-serialized", true); - this.applicationContext = newApplicationContext(testPropertySource, TestDynamicClientCacheConfiguration.class); + newApplicationContext(testPropertySource, TestDynamicClientCacheConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("mockPdxSerializer")).isTrue(); - ClientCacheFactoryBean clientCacheFactoryBean = - this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class); + ClientCacheFactoryBean clientCacheFactoryBean = getBean("&gemfireCache", ClientCacheFactoryBean.class); assertThat(clientCacheFactoryBean).isNotNull(); - ClientCache clientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class); + ClientCache clientCache = getBean("gemfireCache", ClientCache.class); assertThat(clientCache).isNotNull(); - PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class); + PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class); - SocketFactory mockSocketFactory = this.applicationContext.getBean("mockSocketFactory", SocketFactory.class); + SocketFactory mockSocketFactory = getBean("mockSocketFactory", SocketFactory.class); assertThat(mockPdxSerializer).isNotNull(); assertThat(mockSocketFactory).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java index 189daa35..fa49feb0 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java @@ -17,20 +17,18 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Optional; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.DiskStore; import org.apache.geode.cache.DiskStoreFactory; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -43,34 +41,26 @@ import org.springframework.mock.env.MockPropertySource; * @see org.apache.geode.cache.DiskStoreFactory * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.config.annotation.EnableDiskStore - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ -public class DiskStorePropertiesIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class DiskStorePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @SuppressWarnings("all") @@ -102,12 +92,11 @@ public class DiskStorePropertiesIntegrationTests extends IntegrationTestsSupport .withProperty("spring.data.gemfire.disk.store.time-interval", 500L) .withProperty("spring.data.gemfire.disk.store.NonExistingDiskStore.time-interval", 30000L); - this.applicationContext = newApplicationContext(testPropertySource, TestDiskStoreConfiguration.class); + newApplicationContext(testPropertySource, TestDiskStoreConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("TestDiskStore")).isTrue(); + assertThat(containsBean("TestDiskStore")).isTrue(); - DiskStore testDiskStore = this.applicationContext.getBean("TestDiskStore", DiskStore.class); + DiskStore testDiskStore = getBean("TestDiskStore", DiskStore.class); assertThat(testDiskStore).isNotNull(); assertThat(testDiskStore.getName()).isEqualTo("TestDiskStore"); @@ -145,19 +134,18 @@ public class DiskStorePropertiesIntegrationTests extends IntegrationTestsSupport .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.time-interval", 250L) .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.write-buffer-size", 65535); - this.applicationContext = newApplicationContext(testPropertySource, TestDiskStoresConfiguration.class); + newApplicationContext(testPropertySource, TestDiskStoresConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("TestDiskStoreOne")).isTrue(); - assertThat(this.applicationContext.containsBean("TestDiskStoreTwo")).isTrue(); + assertThat(containsBean("TestDiskStoreOne")).isTrue(); + assertThat(containsBean("TestDiskStoreTwo")).isTrue(); - DiskStore testDiskStoreOne = this.applicationContext.getBean("TestDiskStoreOne", DiskStore.class); + DiskStore testDiskStoreOne = getBean("TestDiskStoreOne", DiskStore.class); assertDiskStore(testDiskStoreOne, "TestDiskStoreOne", true, false, 60, 90.0f, 75.0f, 512L, 1024, 500L, 16384); - DiskStore testDiskStoreTwo = this.applicationContext.getBean("TestDiskStoreTwo", DiskStore.class); + DiskStore testDiskStoreTwo = getBean("TestDiskStoreTwo", DiskStore.class); assertDiskStore(testDiskStoreTwo, "TestDiskStoreTwo", true, false, 75, 95.0f, 80.0f, 2048L, diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java index 1c656df3..0fd138d1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableBeanFactoryLocatorConfigurationIntegrationTests.java @@ -17,16 +17,11 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Optional; - import org.junit.After; import org.junit.Test; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** @@ -34,46 +29,29 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * * @author John Blum * @see org.junit.Test - * @see org.springframework.context.ConfigurableApplicationContext - * @see org.springframework.context.annotation.AnnotationConfigApplicationContext + * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.BeanFactoryLocatorConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableBeanFactoryLocator - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.0 */ -public class EnableBeanFactoryLocatorConfigurationIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class EnableBeanFactoryLocatorConfigurationIntegrationTests + extends SpringApplicationContextIntegrationTestsSupport { @After public void tearDown() { - - Optional.ofNullable(this.applicationContext). - ifPresent(ConfigurableApplicationContext::close); - - GemfireBeanFactoryLocator.clear(); - } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - ConfigurableApplicationContext applicationContext = - new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; + closeAllBeanFactoryLocators(); } private void testGemFireCacheBeanFactoryLocator(Class configuration, Class cacheFactoryBeanType, boolean beanFactoryLocatorEnabled) { - this.applicationContext = newApplicationContext(configuration); + newApplicationContext(configuration); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache).isInstanceOf(cacheFactoryBeanType); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java index 05522b5a..e9b8e15c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java @@ -31,7 +31,6 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @@ -179,11 +178,7 @@ public class EnableClusterConfigurationIntegrationTests extends ForkingClientSer static class GeodeServerTestConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(GeodeServerTestConfiguration.class, args); } @Bean diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java index 3c14d88e..6a98f34a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterDefinedRegionsIntegrationTests.java @@ -34,7 +34,6 @@ import org.apache.geode.cache.client.ClientCache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.data.gemfire.LocalRegionFactoryBean; @@ -135,11 +134,7 @@ public class EnableClusterDefinedRegionsIntegrationTests extends ForkingClientSe static class GeodeServerTestConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(GeodeServerTestConfiguration.class, args); } @Bean("LocalRegion") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java index bd093f01..29f75733 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableCompressionConfigurationUnitTests.java @@ -30,8 +30,6 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.compression.Compressor; import org.apache.geode.compression.SnappyCompressor; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.LocalRegionFactoryBean; @@ -39,7 +37,7 @@ import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.test.model.Person; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** @@ -51,24 +49,17 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.CompressionConfiguration * @see org.springframework.data.gemfire.config.annotation.EnableCompression - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.0 */ -public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class EnableCompressionConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void tearDown() { - closeApplicationContext(this.applicationContext); + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); - } - private void assertRegionCompressor(Region region, String regionName, Compressor compressor) { assertThat(region).isNotNull(); @@ -81,40 +72,36 @@ public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSup @Test public void enableCompressionForAllRegions() { - this.applicationContext = newApplicationContext(EnableCompressionForAllRegionsConfiguration.class); + newApplicationContext(EnableCompressionForAllRegionsConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("ExampleClientRegion")).isFalse(); + assertThat(containsBean("ExampleClientRegion")).isFalse(); - Compressor compressor = this.applicationContext.getBean(Compressor.class); + Compressor compressor = getBean(Compressor.class); assertThat(compressor).isInstanceOf(SnappyCompressor.class); Arrays.asList("People", "ExampleLocalRegion", "ExamplePartitionRegion", "ExampleReplicateRegion") .forEach(regionName -> { - assertThat(this.applicationContext.containsBean(regionName)).isTrue(); - assertRegionCompressor(this.applicationContext.getBean(regionName, Region.class), - regionName, compressor); + assertThat(containsBean(regionName)).isTrue(); + assertRegionCompressor(getBean(regionName, Region.class), regionName, compressor); }); } @Test public void enableCompressionForSelectRegions() { - this.applicationContext = newApplicationContext(EnableCompressionForSelectRegionsConfiguration.class); + newApplicationContext(EnableCompressionForSelectRegionsConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - - Compressor compressor = this.applicationContext.getBean("MockCompressor", Compressor.class); + Compressor compressor = getBean("MockCompressor", Compressor.class); assertThat(compressor).isNotNull(); assertThat(compressor).isNotInstanceOf(SnappyCompressor.class); - assertThat(this.applicationContext.containsBean(SNAPPY_COMPRESSOR_BEAN_NAME)).isTrue(); + assertThat(containsBean(SNAPPY_COMPRESSOR_BEAN_NAME)).isTrue(); Arrays.asList("People", "ExampleClientRegion").forEach(regionName -> { - assertThat(this.applicationContext.containsBean(regionName)).isTrue(); - assertRegionCompressor(this.applicationContext.getBean(regionName, Region.class), - regionName, "People".equals(regionName) ? compressor : null); + assertThat(containsBean(regionName)).isTrue(); + assertRegionCompressor(getBean(regionName, Region.class), regionName, + "People".equals(regionName) ? compressor : null); }); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java index 61ce6cb2..4c64d29b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationIntegrationTests.java @@ -42,7 +42,6 @@ import org.apache.geode.cache.query.CqEvent; import org.apache.geode.cache.util.CacheListenerAdapter; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -179,11 +178,7 @@ public class EnableContinuousQueriesConfigurationIntegrationTests extends Forkin static class GeodeServerTestConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(GeodeServerTestConfiguration.class, args); } @Bean(name = "TemperatureReadings") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java index 8e296a24..cea32556 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesConfigurationUnitTests.java @@ -27,6 +27,7 @@ import static org.springframework.data.gemfire.util.ArrayUtils.asArray; import java.lang.reflect.Proxy; import java.util.concurrent.Executor; +import org.junit.After; import org.junit.Test; import org.apache.geode.cache.GemFireCache; @@ -45,7 +46,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -60,10 +60,9 @@ import org.springframework.data.gemfire.repository.config.EnableGemfireRepositor import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactoryBean; import org.springframework.data.gemfire.test.model.Person; import org.springframework.data.gemfire.test.repo.PersonRepository; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; -import org.springframework.data.gemfire.tests.util.IOUtils; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Component; import org.springframework.util.ErrorHandler; @@ -93,45 +92,37 @@ import lombok.Data; * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.1 */ -public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTestsSupport { +public class EnableContinuousQueriesConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); + @After + public void tearDown() { + destroyAllGemFireMockObjects(); } @Test public void continuousQueryListenerContainerConfigurationIsCorrect() { - ConfigurableApplicationContext applicationContext = - newApplicationContext(TestContinuousQueryListenerContainerConfiguration.class); + newApplicationContext(TestContinuousQueryListenerContainerConfiguration.class); - try { + ErrorHandler mockErrorHandler = getBean("mockErrorHandler", ErrorHandler.class); - ErrorHandler mockErrorHandler = applicationContext.getBean("mockErrorHandler", ErrorHandler.class); + Executor mockTaskExecutor = getBean("mockTaskExecutor", Executor.class); - Executor mockTaskExecutor = applicationContext.getBean("mockTaskExecutor", Executor.class); + Pool mockPool = getBean("mockPool", Pool.class); - Pool mockPool = applicationContext.getBean("mockPool", Pool.class); + QueryService mockQueryService = getBean("mockQueryService", QueryService.class); - QueryService mockQueryService = applicationContext.getBean("mockQueryService", QueryService.class); + assertThat(containsBean("continuousQueryListenerContainer")).isTrue(); - assertThat(applicationContext.containsBean("continuousQueryListenerContainer")).isTrue(); + ContinuousQueryListenerContainer container = + getBean("continuousQueryListenerContainer", ContinuousQueryListenerContainer.class); - ContinuousQueryListenerContainer container = - applicationContext.getBean("continuousQueryListenerContainer", - ContinuousQueryListenerContainer.class); - - assertThat(container).isNotNull(); - assertThat(container.getErrorHandler().orElse(null)).isEqualTo(mockErrorHandler); - assertThat(container.getPhase()).isEqualTo(1); - assertThat(container.getPoolName()).isEqualTo(mockPool.getName()); - assertThat(container.getQueryService()).isEqualTo(mockQueryService); - assertThat(container.getTaskExecutor()).isEqualTo(mockTaskExecutor); - } - finally { - IOUtils.close(applicationContext); - GemFireMockObjectsSupport.destroy(); - } + assertThat(container).isNotNull(); + assertThat(container.getErrorHandler().orElse(null)).isEqualTo(mockErrorHandler); + assertThat(container.getPhase()).isEqualTo(1); + assertThat(container.getPoolName()).isEqualTo(mockPool.getName()); + assertThat(container.getQueryService()).isEqualTo(mockQueryService); + assertThat(container.getTaskExecutor()).isEqualTo(mockTaskExecutor); } private void testRegisterAndExecuteContinuousQuery(Class... annotatedClasses) throws Exception { @@ -139,6 +130,7 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe ConfigurableApplicationContext applicationContext = newApplicationContext(annotatedClasses); try { + assertThat(applicationContext).isNotNull(); assertThat(applicationContext.containsBean("DEFAULT")).isTrue(); @@ -164,8 +156,8 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe verify(mockCqQuery, times(1)).execute(); } finally { - IOUtils.close(applicationContext); - GemFireMockObjectsSupport.destroy(); + closeApplicationContext(applicationContext); + destroyAllGemFireMockObjects(); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java index 0e5ae4f8..27db1adc 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableContinuousQueriesWithClusterConfigurationIntegrationTests.java @@ -31,7 +31,6 @@ import org.apache.geode.cache.query.CqEvent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -129,11 +128,7 @@ public class EnableContinuousQueriesWithClusterConfigurationIntegrationTests static class GemFireServerConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(GemFireServerConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(GemFireServerConfiguration.class, args); } } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java index 5fbe2b96..24611256 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableDiskStoresConfigurationUnitTests.java @@ -19,19 +19,15 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import java.io.File; -import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.junit.After; import org.junit.Test; import org.mockito.stubbing.Answer; import org.apache.geode.cache.DiskStore; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** @@ -45,22 +41,15 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * @see org.springframework.data.gemfire.config.annotation.EnableDiskStores * @see org.springframework.data.gemfire.config.annotation.DiskStoreConfiguration * @see org.springframework.data.gemfire.config.annotation.DiskStoresConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ @SuppressWarnings("unused") -public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupport { +public class EnableDiskStoresConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { private static final AtomicInteger MOCK_ID = new AtomicInteger(0); - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } - private void assertDiskStore(DiskStore diskStore, String name, boolean allowForceCompaction, boolean autoCompact, int compactionThreshold, float diskUsageCriticalPercentage, float diskUsageWarningPercentage, long maxOplogSize, int queueSize, long timeInterval, int writeBufferSize) { @@ -110,15 +99,6 @@ public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupp } } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; - } - private File newFile(String location) { return new File(location); } @@ -126,9 +106,9 @@ public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupp @Test public void enableSingleDiskStore() { - this.applicationContext = newApplicationContext(SingleDiskStoreConfiguration.class); + newApplicationContext(SingleDiskStoreConfiguration.class); - DiskStore testDiskStore = this.applicationContext.getBean("TestDiskStore", DiskStore.class); + DiskStore testDiskStore = getBean("TestDiskStore", DiskStore.class); assertDiskStore(testDiskStore, "TestDiskStore", true, true, 75, 95.0f, 75.0f, 8192L, 100, 2000L, 65536); assertDiskStoreDirectoryLocations(testDiskStore, newFile("/absolute/path/to/gemfire/disk/directory"), @@ -139,13 +119,13 @@ public class EnableDiskStoresConfigurationUnitTests extends IntegrationTestsSupp @Test public void enableMultipleDiskStores() { - this.applicationContext = newApplicationContext(MultipleDiskStoresConfiguration.class); + newApplicationContext(MultipleDiskStoresConfiguration.class); - DiskStore testDiskStoreOne = this.applicationContext.getBean("TestDiskStoreOne", DiskStore.class); + DiskStore testDiskStoreOne = getBean("TestDiskStoreOne", DiskStore.class); assertDiskStore(testDiskStoreOne, "TestDiskStoreOne", false, true, 75, 99.0f, 90.0f, 2048L, 100, 1000L, 32768); - DiskStore testDiskStoreTwo = this.applicationContext.getBean("TestDiskStoreTwo", DiskStore.class); + DiskStore testDiskStoreTwo = getBean("TestDiskStoreTwo", DiskStore.class); assertDiskStore(testDiskStoreTwo, "TestDiskStoreTwo", true, true, 85, 99.0f, 90.0f, 4096L, 0, 1000L, 32768); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java index ccb9cc0f..2fc76793 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsIntegrationTests.java @@ -17,21 +17,19 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Optional; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Region; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.test.model.Person; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -45,33 +43,25 @@ import org.springframework.mock.env.MockPropertySource; * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions * @see org.springframework.data.gemfire.config.annotation.EntityDefinedRegionsConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.2 */ -public class EnableEntityDefinedRegionsIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class EnableEntityDefinedRegionsIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test @@ -81,11 +71,9 @@ public class EnableEntityDefinedRegionsIntegrationTests extends IntegrationTests MockPropertySource testPropertySource = new MockPropertySource() .withProperty("spring.data.gemfire.entities.base-packages", Person.class.getPackage().getName()); - this.applicationContext = newApplicationContext(testPropertySource, TestConfiguration.class); + newApplicationContext(testPropertySource, TestConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - - Region people = this.applicationContext.getBean("People", Region.class); + Region people = getBean("People", Region.class); assertThat(people).isNotNull(); assertThat(people.getName()).isEqualTo("People"); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java index ca9bc700..b4cbdd92 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEntityDefinedRegionsUnitTests.java @@ -25,7 +25,6 @@ import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeList import static org.springframework.data.gemfire.util.RegionUtils.toRegionPath; import java.util.List; -import java.util.Optional; import org.junit.After; import org.junit.Test; @@ -45,8 +44,6 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.cache.client.Pool; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; @@ -64,7 +61,7 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.mapping.annotation.LocalRegion; import org.springframework.data.gemfire.mapping.annotation.PartitionRegion; import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.MockObjectsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; @@ -86,21 +83,15 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * @see org.springframework.data.gemfire.mapping.annotation.ReplicateRegion * @see org.springframework.data.gemfire.mapping.annotation.ReplicateRegion * @see org.springframework.data.gemfire.tests.mock.MockObjectsSupport - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ @SuppressWarnings({ "unchecked", "unused" }) -public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class EnableEntityDefinedRegionsUnitTests extends SpringApplicationContextIntegrationTestsSupport { @After public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - destroyAllGemFireMockObjects(); } @@ -171,9 +162,9 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport private void assertUndefinedRegions(String... regionBeanNames) { stream(nullSafeArray(regionBeanNames, String.class)).forEach(regionBeanName -> - assertThat(this.applicationContext.containsBean(regionBeanName)).isFalse()); + assertThat(containsBean(regionBeanName)).isFalse()); - assertThat(this.applicationContext.getBeansOfType(Region.class)).hasSize(11 - length(regionBeanNames)); + assertThat(getBeansOfType(Region.class)).hasSize(11 - length(regionBeanNames)); } private FixedPartitionAttributes findFixedPartitionAttributes(PartitionAttributes partitionAttributes, @@ -193,28 +184,18 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport return null; } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; - } - @Test public void entityClientRegionsDefined() { - this.applicationContext = newApplicationContext(ClientPersistentEntitiesConfiguration.class); + newApplicationContext(ClientPersistentEntitiesConfiguration.class); - Region sessions = this.applicationContext.getBean("Sessions", Region.class); + Region sessions = getBean("Sessions", Region.class); assertRegion(sessions, "Sessions", String.class, ClientRegionEntity.class); assertRegionAttributes(sessions.getAttributes(), DataPolicy.NORMAL, null, true, false, null, null); - Region genericRegionEntity = - this.applicationContext.getBean("GenericRegionEntity", Region.class); + Region genericRegionEntity = getBean("GenericRegionEntity", Region.class); assertRegion(genericRegionEntity, "GenericRegionEntity", Long.class, GenericRegionEntity.class); assertRegionAttributes(genericRegionEntity.getAttributes(), DataPolicy.EMPTY, @@ -228,15 +209,14 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport @Test public void entityClientRegionsDefinedWithCustomConfiguration() { - this.applicationContext = newApplicationContext(ClientPersistentEntitiesWithCustomConfiguration.class); + newApplicationContext(ClientPersistentEntitiesWithCustomConfiguration.class); - Region sessions = this.applicationContext.getBean("Sessions", Region.class); + Region sessions = getBean("Sessions", Region.class); assertRegionWithAttributes(sessions, "Sessions", DataPolicy.NORMAL, null, true, false, null, null); - Region genericRegionEntity = - this.applicationContext.getBean("GenericRegionEntity", Region.class); + Region genericRegionEntity = getBean("GenericRegionEntity", Region.class); assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.NORMAL, null, true, false, "TestPool", null); @@ -249,38 +229,33 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport @Test public void entityClientRegionsDefinedWithServerRegionMappingAnnotations() { - this.applicationContext = - newApplicationContext(ClientPersistentEntitiesWithServerRegionMappingAnnotationsConfiguration.class); + newApplicationContext(ClientPersistentEntitiesWithServerRegionMappingAnnotationsConfiguration.class); - Region sessions = this.applicationContext.getBean("Sessions", Region.class); + Region sessions = getBean("Sessions", Region.class); assertRegion(sessions, "Sessions", String.class, ClientRegionEntity.class); assertRegionAttributes(sessions.getAttributes(), DataPolicy.NORMAL, null, true, false, null, null); - Region genericRegionEntity = - this.applicationContext.getBean("GenericRegionEntity", Region.class); + Region genericRegionEntity = getBean("GenericRegionEntity", Region.class); assertRegion(genericRegionEntity, "GenericRegionEntity", Long.class, GenericRegionEntity.class); assertRegionAttributes(genericRegionEntity.getAttributes(), DataPolicy.EMPTY, null, true, false, null, null); - Region localRegionEntity = - this.applicationContext.getBean("LocalRegionEntity", Region.class); + Region localRegionEntity = getBean("LocalRegionEntity", Region.class); assertRegion(localRegionEntity, "LocalRegionEntity", String.class, LocalRegionEntity.class); assertRegionAttributes(localRegionEntity.getAttributes(), DataPolicy.EMPTY, null, true, false, null, null); - Region customers = - this.applicationContext.getBean("Customers", Region.class); + Region customers = getBean("Customers", Region.class); assertRegion(customers, "Customers", Long.class, PartitionRegionEntity.class); assertRegionAttributes(customers.getAttributes(), DataPolicy.EMPTY, null, true, false, null, null); - Region accounts = - this.applicationContext.getBean("Accounts", Region.class); + Region accounts = getBean("Accounts", Region.class); assertRegion(accounts, "Accounts", Object.class, ReplicateRegionEntity.class); assertRegionAttributes(accounts.getAttributes(), DataPolicy.EMPTY, @@ -293,9 +268,9 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport @Test public void entityPeerPartitionRegionsDefined() { - this.applicationContext = newApplicationContext(PeerPartitionRegionPersistentEntitiesConfiguration.class); + newApplicationContext(PeerPartitionRegionPersistentEntitiesConfiguration.class); - Region customers = this.applicationContext.getBean("Customers", Region.class); + Region customers = getBean("Customers", Region.class); assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); @@ -306,12 +281,12 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport assertFixedPartitionAttributes(findFixedPartitionAttributes(customers.getAttributes().getPartitionAttributes(), "two"), "two", false, 21); - Region contactEvents = this.applicationContext.getBean("ContactEvents", Region.class); + Region contactEvents = getBean("ContactEvents", Region.class); assertRegionWithAttributes(contactEvents, "ContactEvents", DataPolicy.PERSISTENT_PARTITION, "mockDiskStore", false, true, null, Scope.DISTRIBUTED_NO_ACK); assertPartitionAttributes(contactEvents.getAttributes().getPartitionAttributes(), "Customers", - this.applicationContext.getBean("mockPartitionResolver", PartitionResolver.class), 2); + getBean("mockPartitionResolver", PartitionResolver.class), 2); assertUndefinedRegions("ClientRegionEntity", "Sessions", "CollocatedPartitionRegionEntity", "GenericRegionEntity", "LocalRegionEntity", "NonEntity", "PartitionRegionEntity", "ReplicateRegionEntity", @@ -322,7 +297,7 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport public void entityPartitionRegionAlreadyDefinedThrowsRegionExistsException() { try { - this.applicationContext = newApplicationContext(ExistingPartitionRegionPersistentEntitiesConfiguration.class); + newApplicationContext(ExistingPartitionRegionPersistentEntitiesConfiguration.class); } catch (BeanCreationException expected) { @@ -336,9 +311,9 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport @Test public void entityReplicateRegionAlreadyDefinedIgnoresEntityDefinedRegionDefinition() { - this.applicationContext = newApplicationContext(ExistingReplicateRegionPersistentEntitiesConfiguration.class); + newApplicationContext(ExistingReplicateRegionPersistentEntitiesConfiguration.class); - Region accounts = this.applicationContext.getBean("Accounts", Region.class); + Region accounts = getBean("Accounts", Region.class); assertRegionWithAttributes(accounts, "Accounts", DataPolicy.REPLICATE, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); @@ -347,27 +322,26 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport @Test public void entityServerRegionsDefined() { - this.applicationContext = newApplicationContext(ServerPersistentEntitiesConfiguration.class); + newApplicationContext(ServerPersistentEntitiesConfiguration.class); - Region accounts = this.applicationContext.getBean("Accounts", Region.class); + Region accounts = getBean("Accounts", Region.class); assertRegionWithAttributes(accounts, "Accounts", DataPolicy.REPLICATE, null, true, false, null, Scope.DISTRIBUTED_ACK); - Region customers = this.applicationContext.getBean("Customers", Region.class); + Region customers = getBean("Customers", Region.class); assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); assertPartitionAttributes(customers.getAttributes().getPartitionAttributes(), null, null, 1); - Region localRegionEntity = this.applicationContext.getBean("LocalRegionEntity", Region.class); + Region localRegionEntity = getBean("LocalRegionEntity", Region.class); assertRegionWithAttributes(localRegionEntity, "LocalRegionEntity", DataPolicy.NORMAL, null, true, false, null, Scope.LOCAL); - Region genericRegionEntity = - this.applicationContext.getBean("GenericRegionEntity", Region.class); + Region genericRegionEntity = getBean("GenericRegionEntity", Region.class); assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.PARTITION, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); @@ -379,26 +353,24 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport @Test public void entityServerRegionsDefinedWithCustomConfiguration() { - this.applicationContext = newApplicationContext(ServerPersistentEntitiesWithCustomConfiguration.class); + newApplicationContext(ServerPersistentEntitiesWithCustomConfiguration.class); - Region accounts = this.applicationContext.getBean("Sessions", Region.class); + Region accounts = getBean("Sessions", Region.class); assertRegionWithAttributes(accounts, "Sessions", DataPolicy.REPLICATE, null, true, false, null, Scope.DISTRIBUTED_ACK); - Region genericRegionEntity = - this.applicationContext.getBean("GenericRegionEntity", Region.class); + Region genericRegionEntity = getBean("GenericRegionEntity", Region.class); assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.REPLICATE, null, true, false, null, Scope.DISTRIBUTED_ACK); - Region localRegionEntity = - this.applicationContext.getBean("LocalRegionEntity", Region.class); + Region localRegionEntity = getBean("LocalRegionEntity", Region.class); assertRegionWithAttributes(localRegionEntity, "LocalRegionEntity", DataPolicy.NORMAL, null, true, false, null, Scope.LOCAL); - Region customers = this.applicationContext.getBean("Customers", Region.class); + Region customers = getBean("Customers", Region.class); assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); @@ -410,22 +382,19 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport @Test public void entityServerRegionsDefinedWithClientRegionMappingAnnotations() { - this.applicationContext = - newApplicationContext(ServerPersistentEntitiesWithClientRegionMappingAnnotationsConfiguration.class); + newApplicationContext(ServerPersistentEntitiesWithClientRegionMappingAnnotationsConfiguration.class); - Region sessions = this.applicationContext.getBean("Sessions", Region.class); + Region sessions = getBean("Sessions", Region.class); assertRegionWithAttributes(sessions, "Sessions", DataPolicy.PARTITION, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); - Region genericRegionEntity = - this.applicationContext.getBean("GenericRegionEntity", Region.class); + Region genericRegionEntity = getBean("GenericRegionEntity", Region.class); assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.PARTITION, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); - Region customers = - this.applicationContext.getBean("Customers", Region.class); + Region customers = getBean("Customers", Region.class); assertRegionWithAttributes(customers, "Customers", DataPolicy.PERSISTENT_PARTITION, null, true, false, null, Scope.DISTRIBUTED_NO_ACK); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java index 8904c65a..6e5f360c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationIntegrationTests.java @@ -52,7 +52,7 @@ public class EnableEvictionConfigurationIntegrationTests extends SpringApplicati private static final String GEMFIRE_LOG_LEVEL = "error"; @After - public void tearDown() { + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java index 8227aa90..0fff8dc4 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableEvictionConfigurationUnitTests.java @@ -28,15 +28,13 @@ import org.apache.geode.cache.EvictionAttributes; import org.apache.geode.cache.Region; import org.apache.geode.cache.util.ObjectSizer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.eviction.EvictionActionType; import org.springframework.data.gemfire.eviction.EvictionAttributesFactoryBean; import org.springframework.data.gemfire.eviction.EvictionPolicyType; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; @@ -55,13 +53,10 @@ import org.springframework.data.gemfire.util.ArrayUtils; * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ -public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class EnableEvictionConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void tearDown() { - closeApplicationContext(this.applicationContext); + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } @@ -88,11 +83,7 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor @SuppressWarnings("unchecked") protected Region getRegion(String beanName) { - return applicationContext.getBean(beanName, Region.class); - } - - private AnnotationConfigApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); + return getBean(beanName, Region.class); } private EvictionAttributes newEvictionAttributes(Integer maximum, EvictionPolicyType type, EvictionActionType action, @@ -112,35 +103,35 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor @Test public void usesDefaultEvictionPolicyConfiguration() { - applicationContext = newApplicationContext(DefaultEvictionPolicyConfiguration.class); + newApplicationContext(DefaultEvictionPolicyConfiguration.class); EvictionAttributes defaultEvictionAttributes = EvictionAttributes.createLRUEntryAttributes(); - assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class), defaultEvictionAttributes); - assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class), defaultEvictionAttributes); + assertEvictionAttributes(getBean("PartitionRegion", Region.class), defaultEvictionAttributes); + assertEvictionAttributes(getBean("ReplicateRegion", Region.class), defaultEvictionAttributes); } @Test public void usesCustomEvictionPolicyConfiguration() { - applicationContext = newApplicationContext(CustomEvictionPolicyConfiguration.class); + newApplicationContext(CustomEvictionPolicyConfiguration.class); - ObjectSizer mockObjectSizer = applicationContext.getBean("mockObjectSizer", ObjectSizer.class); + ObjectSizer mockObjectSizer = getBean("mockObjectSizer", ObjectSizer.class); EvictionAttributes customEvictionAttributes = newEvictionAttributes(65536, EvictionPolicyType.MEMORY_SIZE, EvictionActionType.OVERFLOW_TO_DISK, mockObjectSizer); - assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class), customEvictionAttributes); - assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class), customEvictionAttributes); + assertEvictionAttributes(getBean("PartitionRegion", Region.class), customEvictionAttributes); + assertEvictionAttributes(getBean("ReplicateRegion", Region.class), customEvictionAttributes); } @Test public void usesRegionSpecificEvictionPolicyConfiguration() { - applicationContext = newApplicationContext(RegionSpecificEvictionPolicyConfiguration.class); + newApplicationContext(RegionSpecificEvictionPolicyConfiguration.class); - ObjectSizer mockObjectSizer = applicationContext.getBean("mockObjectSizer", ObjectSizer.class); + ObjectSizer mockObjectSizer = getBean("mockObjectSizer", ObjectSizer.class); EvictionAttributes partitionRegionEvictionAttributes = newEvictionAttributes(null, EvictionPolicyType.HEAP_PERCENTAGE, EvictionActionType.OVERFLOW_TO_DISK, @@ -149,26 +140,22 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor EvictionAttributes replicateRegionEvictionAttributes = newEvictionAttributes(10000, EvictionPolicyType.ENTRY_COUNT, EvictionActionType.LOCAL_DESTROY); - assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class), - partitionRegionEvictionAttributes); + assertEvictionAttributes(getBean("PartitionRegion", Region.class), partitionRegionEvictionAttributes); - assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class), - replicateRegionEvictionAttributes); + assertEvictionAttributes(getBean("ReplicateRegion", Region.class), replicateRegionEvictionAttributes); } @Test public void usesLastMatchingEvictionPolicyConfiguration() { - applicationContext = newApplicationContext(LastMatchingWinsEvictionPolicyConfiguration.class); + newApplicationContext(LastMatchingWinsEvictionPolicyConfiguration.class); EvictionAttributes lastMatchingEvictionAttributes = newEvictionAttributes(99, EvictionPolicyType.ENTRY_COUNT, EvictionActionType.OVERFLOW_TO_DISK); - assertEvictionAttributes(applicationContext.getBean("PartitionRegion", Region.class), - lastMatchingEvictionAttributes); + assertEvictionAttributes(getBean("PartitionRegion", Region.class), lastMatchingEvictionAttributes); - assertEvictionAttributes(applicationContext.getBean("ReplicateRegion", Region.class), - lastMatchingEvictionAttributes); + assertEvictionAttributes(getBean("ReplicateRegion", Region.class), lastMatchingEvictionAttributes); } @PeerCacheApplication diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java index 912db7e9..3cd705f7 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationIntegrationTests.java @@ -17,9 +17,6 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Optional; - -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.DataPolicy; @@ -29,11 +26,10 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.expiration.AnnotationBasedExpiration; import org.springframework.data.gemfire.test.model.Person; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.stereotype.Service; @@ -48,35 +44,12 @@ import org.springframework.stereotype.Service; * @see org.springframework.data.gemfire.config.annotation.EnableExpiration * @see org.springframework.data.gemfire.config.annotation.ExpirationConfiguration * @see org.springframework.data.gemfire.expiration.AnnotationBasedExpiration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ @SuppressWarnings("unused") -public class EnableExpirationConfigurationIntegrationTests extends IntegrationTestsSupport { - - private static final String GEMFIRE_LOG_LEVEL = "error"; - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - - destroyAllGemFireMockObjects(); - } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - this.applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - return this.applicationContext; - } - - @SuppressWarnings("unchecked") - private Region getRegion(ConfigurableApplicationContext applicationContext, String beanName) { - return applicationContext.getBean(beanName, Region.class); - } +public class EnableExpirationConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private void assertRegionExpirationConfiguration(ConfigurableApplicationContext applicationContext, String regionBeanName) { @@ -94,6 +67,11 @@ public class EnableExpirationConfigurationIntegrationTests extends IntegrationTe .isInstanceOf(AnnotationBasedExpiration.class); } + @SuppressWarnings("unchecked") + private Region getRegion(ConfigurableApplicationContext applicationContext, String beanName) { + return applicationContext.getBean(beanName, Region.class); + } + @Test public void assertApplicationCachingDefinedRegionsExpirationPoliciesAreCorrect() { @@ -116,7 +94,7 @@ public class EnableExpirationConfigurationIntegrationTests extends IntegrationTe "People"); } - @ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL) + @ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests") @EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL) @EnableExpiration @EnableGemFireMockObjects @@ -142,13 +120,13 @@ public class EnableExpirationConfigurationIntegrationTests extends IntegrationTe } } - @ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL) + @ClientCacheApplication(name = "EnableExpirationConfigurationIntegrationTests") @EnableEntityDefinedRegions(basePackageClasses = Person.class, clientRegionShortcut = ClientRegionShortcut.LOCAL) @EnableExpiration @EnableGemFireMockObjects static class ClientCacheRegionExpirationConfiguration { } - @PeerCacheApplication(name = "EnableExpirationConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL) + @PeerCacheApplication(name = "EnableExpirationConfigurationIntegrationTests") @EnableEntityDefinedRegions(basePackageClasses = Person.class, serverRegionShortcut = RegionShortcut.LOCAL) @EnableExpiration @EnableGemFireMockObjects diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java index 872fb3db..66cefb64 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableExpirationConfigurationUnitTests.java @@ -22,8 +22,6 @@ import static org.mockito.Mockito.when; import static org.springframework.data.gemfire.config.annotation.EnableExpiration.ExpirationPolicy; import static org.springframework.data.gemfire.config.annotation.EnableExpiration.ExpirationType; -import java.util.Optional; - import org.junit.After; import org.junit.Test; @@ -33,12 +31,10 @@ import org.apache.geode.cache.ExpirationAttributes; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.expiration.ExpirationActionType; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; @@ -56,20 +52,14 @@ import org.springframework.data.gemfire.util.ArrayUtils; * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.data.gemfire.config.annotation.EnableExpiration * @see org.springframework.data.gemfire.config.annotation.ExpirationConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ -public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class EnableExpirationConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } @@ -122,11 +112,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp @SuppressWarnings("unchecked") private Region getRegion(String beanName) { - return this.applicationContext.getBean(beanName, Region.class); - } - - private AnnotationConfigApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); + return getBean(beanName, Region.class); } private ExpirationAttributes newExpirationAttributes(int timeout, ExpirationActionType action) { @@ -141,7 +127,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesDefaultExpirationPolicyConfiguration() { - this.applicationContext = newApplicationContext(DefaultExpirationPolicyConfiguration.class); + newApplicationContext(DefaultExpirationPolicyConfiguration.class); ExpirationAttributes expectedExpiration = newExpirationAttributes(0, ExpirationActionType.INVALIDATE); @@ -158,7 +144,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesCustomIdleTimeoutExpirationPolicyConfiguration() { - this.applicationContext = newApplicationContext(CustomIdleTimeoutExpirationPolicyConfiguration.class); + newApplicationContext(CustomIdleTimeoutExpirationPolicyConfiguration.class); ExpirationAttributes expectedExpiration = newExpirationAttributes(300, ExpirationActionType.LOCAL_DESTROY); @@ -176,7 +162,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesCustomTimeToLiveExpirationPolicyConfiguration() { - this.applicationContext = newApplicationContext(CustomTimeToLiveTimeoutExpirationPolicyConfiguration.class); + newApplicationContext(CustomTimeToLiveTimeoutExpirationPolicyConfiguration.class); ExpirationAttributes expectedExpiration = newExpirationAttributes(900, ExpirationActionType.LOCAL_INVALIDATE); @@ -194,7 +180,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesRegionSpecificExpirationPolicyConfiguration() { - this.applicationContext = newApplicationContext(RegionSpecificExpirationPolicyConfiguration.class); + newApplicationContext(RegionSpecificExpirationPolicyConfiguration.class); ExpirationAttributes expectedIdleTimeout = newExpirationAttributes(180, ExpirationActionType.INVALIDATE); ExpirationAttributes expectedTimeToLive = newExpirationAttributes(360, ExpirationActionType.DESTROY); @@ -213,7 +199,7 @@ public class EnableExpirationConfigurationUnitTests extends IntegrationTestsSupp @SuppressWarnings({ "rawtypes", "unchecked" }) public void usesMixedExpirationPolicyConfiguration() { - this.applicationContext = newApplicationContext(MixedExpirationPolicyConfiguration.class); + newApplicationContext(MixedExpirationPolicyConfiguration.class); ExpirationAttributes expectedIdleTimeout = newExpirationAttributes(60, ExpirationActionType.LOCAL_INVALIDATE); ExpirationAttributes expectedTimeToLive = newExpirationAttributes(600, ExpirationActionType.DESTROY); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationIntegrationTests.java similarity index 67% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationIntegrationTests.java index 63efccbf..08db5f2a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGatewayReceiverConfigurationIntegrationTests.java @@ -23,50 +23,86 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Optional; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewayTransportFilter; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; /** * Tests for {@link EnableGatewayReceiver}. * * @author Udo Kohlmeyer + * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.apache.geode.cache.server.CacheServer - * @see org.springframework.context.annotation.Configuration + * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean + * @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfiguration + * @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner - * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean - * @see GatewayReceiverConfigurer - * @see GatewayReceiverConfiguration * @since 2.2.0 */ -public class EnableGatewayReceiverConfigurationTests { +public class EnableGatewayReceiverConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { - private ConfigurableApplicationContext applicationContext; + @Test + public void annotationConfiguredGatewayTransportFiltersOrdered() { - @After - public void shutdown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); + newApplicationContext(TestConfigurationFromAnnotation.class); + + TestGatewayReceiverConfigurer gatewayReceiverConfigurer = + (TestGatewayReceiverConfigurer) getBean(GatewayReceiverConfigurer.class); + + GatewayReceiver gatewayReceiver = getBean("GatewayReceiver",GatewayReceiver.class); + + assertThat(gatewayReceiver.getStartPort()).isEqualTo(12000); + assertThat(gatewayReceiver.getEndPort()).isEqualTo(13000); + assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost"); + assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost"); + assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(5000); + assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(32768); + assertThat(gatewayReceiver.isManualStart()).isEqualTo(false); + assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2); + assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1"); + assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2"); + assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"}); + } + + @Test + public void beanConfiguredGatewayTransportFiltersOrdered() { + + newApplicationContext(TestConfigurationWithOrder.class); + + TestGatewayReceiverConfigurer gatewayReceiverConfigurer = + (TestGatewayReceiverConfigurer) getBean(GatewayReceiverConfigurer.class); + + GatewayReceiver gatewayReceiver = getBean("GatewayReceiver",GatewayReceiver.class); + + assertThat(gatewayReceiver.getStartPort()).isEqualTo(10000); + assertThat(gatewayReceiver.getEndPort()).isEqualTo(11000); + assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost"); + assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost"); + assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(1000); + assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(16384); + assertThat(gatewayReceiver.isManualStart()).isEqualTo(false); + assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2); + assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1"); + assertThat(((EnableGatewayReceiverConfigurationIntegrationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2"); + assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"}); } - @Configuration @CacheServerApplication @EnableGatewayReceiver(manualStart = false, startPort = 10000, endPort = 11000, maximumTimeBetweenPings = 1000, - socketBufferSize = 16384, bindAddress = "localhost",transportFilters = {"transportBean1", "transportBean2"}, - hostnameForSenders = "hostnameLocalhost") + socketBufferSize = 16384, bindAddress = "localhost",transportFilters = {"transportBean1", "transportBean2"}, + hostnameForSenders = "hostnameLocalhost") + @SuppressWarnings("unused") static class TestConfigurationWithOrder { @Bean("transportBean1") @@ -87,11 +123,11 @@ public class EnableGatewayReceiverConfigurationTests { } } - @Configuration @CacheServerApplication @EnableGatewayReceiver(manualStart = false, startPort = 12000, endPort = 13000, maximumTimeBetweenPings = 5000, - socketBufferSize = 32768, transportFilters = {"transportBean1", "transportBean2"}, bindAddress = "localhost", - hostnameForSenders = "hostnameLocalhost") + socketBufferSize = 32768, transportFilters = {"transportBean1", "transportBean2"}, bindAddress = "localhost", + hostnameForSenders = "hostnameLocalhost") + @SuppressWarnings("unused") static class TestConfigurationFromAnnotation { @Bean("transportBean1") @@ -110,52 +146,6 @@ public class EnableGatewayReceiverConfigurationTests { } } - @Test - public void annotationConfiguredGatewayTransportFiltersOrdered() { - - this.applicationContext = newApplicationContext(TestConfigurationFromAnnotation.class); - - TestGatewayReceiverConfigurer gatewayReceiverConfigurer = - (TestGatewayReceiverConfigurer) this.applicationContext.getBean(GatewayReceiverConfigurer.class); - - GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class); - - assertThat(gatewayReceiver.getStartPort()).isEqualTo(12000); - assertThat(gatewayReceiver.getEndPort()).isEqualTo(13000); - assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost"); - assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost"); - assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(5000); - assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(32768); - assertThat(gatewayReceiver.isManualStart()).isEqualTo(false); - assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2); - assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1"); - assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2"); - assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"}); - } - - @Test - public void beanConfiguredGatewayTransportFiltersOrdered() { - - this.applicationContext = newApplicationContext(TestConfigurationWithOrder.class); - - TestGatewayReceiverConfigurer gatewayReceiverConfigurer = - (TestGatewayReceiverConfigurer) this.applicationContext.getBean(GatewayReceiverConfigurer.class); - - GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class); - - assertThat(gatewayReceiver.getStartPort()).isEqualTo(10000); - assertThat(gatewayReceiver.getEndPort()).isEqualTo(11000); - assertThat(gatewayReceiver.getBindAddress()).isEqualTo("localhost"); - assertThat(gatewayReceiver.getHostnameForSenders()).isEqualTo("hostnameLocalhost"); - assertThat(gatewayReceiver.getMaximumTimeBetweenPings()).isEqualTo(1000); - assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(16384); - assertThat(gatewayReceiver.isManualStart()).isEqualTo(false); - assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2); - assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1"); - assertThat(((EnableGatewayReceiverConfigurationTests.TestGatewayTransportFilter)gatewayReceiver.getGatewayTransportFilters().get(1)).name).isEqualTo("transportBean2"); - assertThat(gatewayReceiverConfigurer.beanNames.toArray()).isEqualTo(new String[]{"transportBean1", "transportBean2"}); - } - private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable { private final List beanNames = new ArrayList<>(); @@ -173,7 +163,7 @@ public class EnableGatewayReceiverConfigurationTests { private static class TestGatewayTransportFilter implements GatewayTransportFilter { - private String name; + private final String name; public TestGatewayTransportFilter(String name) { this.name = name; @@ -189,13 +179,4 @@ public class EnableGatewayReceiverConfigurationTests { return null; } } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; - } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java index 2ec360d3..4074fa17 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java @@ -20,20 +20,19 @@ import static org.mockito.Mockito.mock; import java.util.Optional; import java.util.Properties; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.GemFireCache; import org.apache.geode.pdx.PdxSerializer; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.mock.env.MockPropertySource; @@ -52,41 +51,35 @@ import org.springframework.util.StringUtils; * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.core.env.PropertySource - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.0 */ @SuppressWarnings("rawtypes") -public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSupport { +public class EnableGemFirePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return newApplicationContext(null, annotatedClasses); + @Override + protected ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { + return newApplicationContext((PropertySource) null, annotatedClasses); } private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = + testPropertySource != null ? applicationContext -> { + Optional.ofNullable(testPropertySource).ifPresent(it -> { - Optional.ofNullable(testPropertySource).ifPresent(it -> { + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + propertySources.addFirst(testPropertySource); + }); - propertySources.addFirst(testPropertySource); - }); + return applicationContext; + } + : Function.identity(); - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); - - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test @@ -105,13 +98,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.security.log.level", "info") .withProperty("spring.data.gemfire.security.properties-file", "/path/to/security.properties"); - this.applicationContext = - newApplicationContext(testPropertySource, TestAuthGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestAuthGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -141,13 +132,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.service.http.ssl-require-authentication", "true") .withProperty("spring.data.gemfire.service.http.dev-rest-api.start", "true"); - this.applicationContext = - newApplicationContext(testPropertySource, TestHttpGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestHttpGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -168,13 +157,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.locator.host", "10.64.32.16") .withProperty("spring.data.gemfire.locator.port", "11235"); - this.applicationContext = - newApplicationContext(testPropertySource, TestLocatorGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestLocatorGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -194,13 +181,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.logging.log-file-size-limit", "10") .withProperty("spring.data.gemfire.logging.level", "info"); - this.applicationContext = - newApplicationContext(testPropertySource, TestLoggingGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestLoggingGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -226,13 +211,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.manager.start", "true") .withProperty("spring.data.gemfire.manager.update-rate", "1000"); - this.applicationContext = - newApplicationContext(testPropertySource, TestManagerGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestManagerGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -257,13 +240,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.service.memcached.port", "2468") .withProperty("spring.data.gemfire.service.memcached.protocol", "BINARY"); - this.applicationContext = - newApplicationContext(testPropertySource, TestMemcachedServerGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestMemcachedServerGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -278,16 +259,14 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup @Test public void nameAndGroupsAnnotationBasedGemFirePropertiesConfiguration() { - this.applicationContext = - newApplicationContext(TestNameAndGroupsAnnotationBasedGemFirePropertiesConfiguration.class); + newApplicationContext(TestNameAndGroupsAnnotationBasedGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("gemfireProperties")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireProperties")).isTrue(); //Properties gemfireProperties = this.applicationContext.getBean("gemfireProperties", Properties.class); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -307,13 +286,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup PropertySource testPropertySource = new MockPropertySource("TestPropertySource") .withProperty("spring.data.gemfire.cache.off-heap.memory-size", "1024g"); - this.applicationContext = - newApplicationContext(testPropertySource, TestOffHeapGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestOffHeapGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -334,14 +311,12 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.pdx.read-serialized", "true") .withProperty("spring.data.gemfire.pdx.serializer-bean-name", "mockPdxSerializer"); - this.applicationContext = - newApplicationContext(testPropertySource, TestPdxGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestPdxGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("mockPdxSerializer")).isTrue(); - CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getPdxDiskStoreName()).isEqualTo("TestDiskStore"); @@ -349,7 +324,7 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup assertThat(gemfireCache.getPdxPersistent()).isTrue(); assertThat(gemfireCache.getPdxReadSerialized()).isTrue(); - PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class); + PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class); assertThat(mockPdxSerializer).isNotNull(); assertThat(gemfireCache.getPdxSerializer()).isEqualTo(mockPdxSerializer); @@ -362,13 +337,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.service.redis.bind-address", "10.16.8.4") .withProperty("spring.data.gemfire.service.redis.port", "13579"); - this.applicationContext = - newApplicationContext(testPropertySource, TestRedisServerGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestRedisServerGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -390,13 +363,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.security.postprocessor.class-name", "example.security.PostProcessor") .withProperty("spring.data.gemfire.security.shiro.ini-resource-path", "/path/to/shiro.ini"); - this.applicationContext = - newApplicationContext(testPropertySource, TestSecurityGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestSecurityGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -414,13 +385,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup @Test public void serializableObjectFilterAndValidateSerializableObjectsGemFirePropertiesConfiguration() { - this.applicationContext = - newApplicationContext(TestSerializableObjectFilterAndValidateSerializableObjectsGemFirePropertiesConfiguration.class); + newApplicationContext(TestSerializableObjectFilterAndValidateSerializableObjectsGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireProperties")).isTrue(); + assertThat(containsBean("gemfireProperties")).isTrue(); - Properties gemfireProperties = this.applicationContext.getBean("gemfireProperties", Properties.class); + Properties gemfireProperties = getBean("gemfireProperties", Properties.class); assertThat(gemfireProperties).isNotNull(); assertThat(gemfireProperties.containsKey("serializable-object-filter")).isTrue(); @@ -446,14 +415,12 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.security.ssl.truststore.type", "PKCS11") .withProperty("spring.data.gemfire.security.ssl.web-require-authentication", "true"); - this.applicationContext = - newApplicationContext(testPropertySource, TestSslGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestSslGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("gemfireProperties")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireProperties")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -490,13 +457,11 @@ public class EnableGemFirePropertiesIntegrationTests extends IntegrationTestsSup .withProperty("spring.data.gemfire.stats.enable-time-statistics", "true") .withProperty("spring.data.gemfire.stats.sample-rate", "100"); - this.applicationContext = - newApplicationContext(testPropertySource, TestStatisticsGemFirePropertiesConfiguration.class); + newApplicationContext(testPropertySource, TestStatisticsGemFirePropertiesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableIndexingConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableIndexingConfigurationUnitTests.java index 0c135199..9072b23c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableIndexingConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableIndexingConfigurationUnitTests.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.After; @@ -55,7 +54,6 @@ import org.apache.geode.cache.query.QueryService; import org.apache.lucene.analysis.Analyzer; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -68,6 +66,7 @@ import org.springframework.data.gemfire.config.annotation.test.entities.GenericR import org.springframework.data.gemfire.config.annotation.test.entities.LocalRegionEntity; import org.springframework.data.gemfire.config.annotation.test.entities.NonEntity; import org.springframework.data.gemfire.config.annotation.test.entities.ReplicateRegionEntity; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; @@ -90,10 +89,11 @@ import org.springframework.lang.Nullable; * @see org.springframework.data.gemfire.config.annotation.IndexConfiguration * @see org.springframework.data.gemfire.mapping.annotation.Indexed * @see org.springframework.data.gemfire.mapping.annotation.LuceneIndexed + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @since 1.9.0 */ @SuppressWarnings({ "rawtypes", "unused" }) -public class EnableIndexingConfigurationUnitTests { +public class EnableIndexingConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { private static final Set indexes = Collections.synchronizedSet(new HashSet<>()); @@ -125,14 +125,8 @@ public class EnableIndexingConfigurationUnitTests { return null; } - private ConfigurableApplicationContext applicationContext; - @After public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - indexes.clear(); } @@ -154,22 +148,13 @@ public class EnableIndexingConfigurationUnitTests { assertThat(index.getType()).isEqualTo(indexType.getGemfireIndexType()); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; - } - @Test public void persistentEntityIndexesAreCreated() { - this.applicationContext = newApplicationContext(IndexingEnabledWithIndexedPersistentEntityConfiguration.class); + newApplicationContext(IndexingEnabledWithIndexedPersistentEntityConfiguration.class); - assertLuceneIndexes(this.applicationContext); - assertOqlIndexes(this.applicationContext); + assertLuceneIndexes(requireApplicationContext()); + assertOqlIndexes(requireApplicationContext()); } private void assertLuceneIndexes(ConfigurableApplicationContext applicationContext) { @@ -198,10 +183,9 @@ public class EnableIndexingConfigurationUnitTests { @Test public void persistentEntityIndexesAreNotCreated() { - this.applicationContext = - newApplicationContext(IndexingNotEnabledWithIndexedPersistentEntityConfiguration.class); + newApplicationContext(IndexingNotEnabledWithIndexedPersistentEntityConfiguration.class); - Map indexes = this.applicationContext.getBeansOfType(Index.class); + Map indexes = getBeansOfType(Index.class); assertThat(indexes).isNotNull(); assertThat(indexes).isEmpty(); @@ -210,10 +194,9 @@ public class EnableIndexingConfigurationUnitTests { @Test public void indexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameDefinition() { - this.applicationContext = - newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameDefinitionConfiguration.class); + newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameDefinitionConfiguration.class); - Index firstNameIndex = this.applicationContext.getBean("LoyalCustomersFirstNameFunctionalIdx", Index.class); + Index firstNameIndex = getBean("LoyalCustomersFirstNameFunctionalIdx", Index.class); assertOqlIndex(firstNameIndex, "LoyalCustomersFirstNameFunctionalIdx", "first_name", "/LoyalCustomers", IndexType.FUNCTIONAL); @@ -224,10 +207,9 @@ public class EnableIndexingConfigurationUnitTests { @Test public void indexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameName() { - this.applicationContext = - newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameNameConfiguration.class); + newApplicationContext(IndexAnnotatedEntityPropertyIsIgnoredWithExistingIndexHavingSameNameConfiguration.class); - Index lastNameIndex = this.applicationContext.getBean("LastNameIdx", Index.class); + Index lastNameIndex = getBean("LastNameIdx", Index.class); assertOqlIndex(lastNameIndex, "LastNameIdx", "last_name", "/People", IndexType.HASH); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java index 927606ca..d2509b6b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableOffHeapConfigurationUnitTests.java @@ -18,7 +18,6 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; -import java.util.Optional; import org.junit.After; import org.junit.Test; @@ -27,8 +26,6 @@ import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; import org.apache.geode.cache.control.ResourceManager; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -37,7 +34,7 @@ import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.test.model.Person; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** @@ -49,27 +46,17 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.EnableOffHeap * @see org.springframework.data.gemfire.config.annotation.OffHeapConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.2 */ -public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class EnableOffHeapConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); - } - private void assertRegionOffHeap(Region region, String regionName, boolean offHeapEnabled) { assertThat(region).isNotNull(); @@ -82,11 +69,9 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport @Test public void offHeapCriticalAndEvictionMemoryPercentagesConfiguredProperly() { - this.applicationContext = newApplicationContext(OffHeapCriticalAndEvictionMemoryPercentagesConfiguration.class); + newApplicationContext(OffHeapCriticalAndEvictionMemoryPercentagesConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -106,11 +91,9 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport @Test public void offHeapConfiguredForAllRegions() { - this.applicationContext = newApplicationContext(EnableOffHeapForAllRegionsConfiguration.class); + newApplicationContext(EnableOffHeapForAllRegionsConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -120,20 +103,17 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport Arrays.asList("People", "ExampleLocalRegion", "ExamplePartitionRegion", "ExampleReplicateRegion") .forEach(regionName -> { - assertThat(this.applicationContext.containsBean(regionName)).isTrue(); - assertRegionOffHeap(this.applicationContext.getBean(regionName, Region.class), - regionName, true); + assertThat(containsBean(regionName)).isTrue(); + assertRegionOffHeap(getBean(regionName, Region.class), regionName, true); }); } @Test public void offHeapConfiguredForSelectRegions() { - this.applicationContext = newApplicationContext(EnableOffHeapForSelectRegionsConfiguration.class); + newApplicationContext(EnableOffHeapForSelectRegionsConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - - GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); @@ -143,9 +123,9 @@ public class EnableOffHeapConfigurationUnitTests extends IntegrationTestsSupport Arrays.asList("People", "ExampleLocalRegion", "ExamplePartitionRegion", "ExampleReplicateRegion") .forEach(regionName -> { - assertThat(this.applicationContext.containsBean(regionName)).isTrue(); - assertRegionOffHeap(this.applicationContext.getBean(regionName, Region.class), - regionName, Arrays.asList("People", "ExamplePartitionRegion").contains(regionName)); + assertThat(containsBean(regionName)).isTrue(); + assertRegionOffHeap(getBean(regionName, Region.class), regionName, + Arrays.asList("People", "ExamplePartitionRegion").contains(regionName)); }); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java index 1179b046..12c8746e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnablePdxConfigurationIntegrationTests.java @@ -18,8 +18,6 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import java.util.Optional; - import org.junit.After; import org.junit.Test; @@ -27,17 +25,14 @@ import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.pdx.PdxSerializer; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.DiskStoreFactoryBean; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.mapping.MappingPdxSerializer; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** @@ -49,53 +44,40 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * @see org.apache.geode.pdx.PdxSerializer * @see org.springframework.data.gemfire.config.annotation.EnablePdx * @see org.springframework.data.gemfire.config.annotation.PdxConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ -public class EnablePdxConfigurationIntegrationTests extends IntegrationTestsSupport { - - @Autowired - private ConfigurableApplicationContext applicationContext; +public class EnablePdxConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - return new AnnotationConfigApplicationContext(annotatedClasses); - } - @Test public void regionBeanDefinitionDependsOnPdxDiskStoreBean() { - this.applicationContext = newApplicationContext(TestEnablePdxWithDiskStoreConfiguration.class); + newApplicationContext(TestEnablePdxWithDiskStoreConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("MockPdxSerializer")).isTrue(); - assertThat(this.applicationContext.containsBean("TestDiskStore")).isTrue(); - assertThat(this.applicationContext.containsBean("TestRegion")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("MockPdxSerializer")).isTrue(); + assertThat(containsBean("TestDiskStore")).isTrue(); + assertThat(containsBean("TestRegion")).isTrue(); - CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class); assertThat(gemfireCache).isNotNull(); - assertThat(gemfireCache.getPdxSerializer()) - .isEqualTo(this.applicationContext.getBean("MockPdxSerializer", PdxSerializer.class)); + assertThat(gemfireCache.getPdxSerializer()).isEqualTo(getBean("MockPdxSerializer", PdxSerializer.class)); BeanDefinition testDiskStoreBeanDefinition = - this.applicationContext.getBeanFactory().getBeanDefinition("TestDiskStore"); + requireApplicationContext().getBeanFactory().getBeanDefinition("TestDiskStore"); assertThat(testDiskStoreBeanDefinition).isNotNull(); assertThat(testDiskStoreBeanDefinition.getDependsOn()).isNullOrEmpty(); BeanDefinition testRegionBeanDefinition = - this.applicationContext.getBeanFactory().getBeanDefinition("TestRegion"); + requireApplicationContext().getBeanFactory().getBeanDefinition("TestRegion"); assertThat(testRegionBeanDefinition).isNotNull(); assertThat(testRegionBeanDefinition.getDependsOn()).containsExactly("TestDiskStore"); @@ -104,26 +86,25 @@ public class EnablePdxConfigurationIntegrationTests extends IntegrationTestsSupp @Test public void regionBeanDefinitionHasNoDependencies() { - this.applicationContext = newApplicationContext(TestEnablePdxConfigurationWithNoDiskStoreConfiguration.class); + newApplicationContext(TestEnablePdxConfigurationWithNoDiskStoreConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("TestDiskStore")).isTrue(); - assertThat(this.applicationContext.containsBean("TestRegion")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("TestDiskStore")).isTrue(); + assertThat(containsBean("TestRegion")).isTrue(); - CacheFactoryBean gemfireCache = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + CacheFactoryBean gemfireCache = getBean("&gemfireCache", CacheFactoryBean.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getPdxSerializer()).isInstanceOf(MappingPdxSerializer.class); BeanDefinition testDiskStoreBeanDefinition = - this.applicationContext.getBeanFactory().getBeanDefinition("TestDiskStore"); + requireApplicationContext().getBeanFactory().getBeanDefinition("TestDiskStore"); assertThat(testDiskStoreBeanDefinition).isNotNull(); assertThat(testDiskStoreBeanDefinition.getDependsOn()).isNullOrEmpty(); BeanDefinition testRegionBeanDefinition = - this.applicationContext.getBeanFactory().getBeanDefinition("TestRegion"); + requireApplicationContext().getBeanFactory().getBeanDefinition("TestRegion"); assertThat(testRegionBeanDefinition).isNotNull(); assertThat(testRegionBeanDefinition.getDependsOn()).isNullOrEmpty(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationDefaultContextIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationDefaultContextIntegrationTests.java index 36c85cbb..687a7c76 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationDefaultContextIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationDefaultContextIntegrationTests.java @@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; import java.util.Properties; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.Cache; @@ -28,10 +28,9 @@ import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.client.ClientCache; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.mock.env.MockPropertySource; import org.springframework.util.StringUtils; @@ -53,22 +52,15 @@ import org.springframework.util.StringUtils; * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.config.annotation.EnableSsl * @see org.springframework.data.gemfire.config.annotation.SslConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @since 2.2.0 */ -public class EnableSslConfigurationDefaultContextIntegrationTests extends IntegrationTestsSupport { +@SuppressWarnings("rawtypes") +public class EnableSslConfigurationDefaultContextIntegrationTests + extends SpringApplicationContextIntegrationTestsSupport { private static final String GEMFIRE_LOG_LEVEL = "error"; - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - } - private void assertGemFirePropertiesCorrectlySet(Properties gemfireProperties) { assertThat(gemfireProperties).isNotNull(); @@ -90,19 +82,18 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr } private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } private PropertySource setSpringDataGemFireProperties() { @@ -129,15 +120,13 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr @Test public void sslAnnotationBasedClientConfigurationIsCorrect() { - this.applicationContext = newApplicationContext(new MockPropertySource("TestPropertySource"), + newApplicationContext(new MockPropertySource("TestPropertySource"), SslAnnotationBasedClientConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")); - assertThat(this.applicationContext.containsBean("gemfireProperties")); + assertThat(containsBean("gemfireCache")); + assertThat(containsBean("gemfireProperties")); - GemFireCache clientCache = - this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache clientCache = getBean("gemfireCache", GemFireCache.class); //Get Properties from GemFire Properties gemfireProperties = clientCache.getDistributedSystem().getProperties(); @@ -152,14 +141,12 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr PropertySource testPropertySource = setSpringDataGemFireProperties(); - this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedClientConfiguration.class); + newApplicationContext(testPropertySource, SslPropertyBasedClientConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")); - assertThat(this.applicationContext.containsBean("gemfireProperties")); + assertThat(containsBean("gemfireCache")); + assertThat(containsBean("gemfireProperties")); - GemFireCache clientCache = - this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache clientCache = getBean("gemfireCache", GemFireCache.class); assertThat(clientCache).isNotNull(); @@ -193,16 +180,14 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr @Test public void sslAnnotationBasedPeerConfigurationIsCorrect(){ - this.applicationContext = - newApplicationContext(new MockPropertySource("TestPropertySource"), - SslAnnotationBasedPeerConfiguration.class); + newApplicationContext(new MockPropertySource("TestPropertySource"), + SslAnnotationBasedPeerConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")); - assertThat(this.applicationContext.containsBean("gemfireProperties")); + assertThat(containsBean("gemfireCache")); + assertThat(containsBean("gemfireProperties")); + + GemFireCache peerCache = getBean("gemfireCache", GemFireCache.class); - GemFireCache peerCache = - this.applicationContext.getBean("gemfireCache", GemFireCache.class); assertThat(peerCache).isNotNull(); Properties gemfireProperties = peerCache.getDistributedSystem().getProperties(); @@ -215,14 +200,12 @@ public class EnableSslConfigurationDefaultContextIntegrationTests extends Integr PropertySource testPropertySource = setSpringDataGemFireProperties(); - this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedPeerConfiguration.class); + newApplicationContext(testPropertySource, SslPropertyBasedPeerConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")); - assertThat(this.applicationContext.containsBean("gemfireProperties")); + assertThat(containsBean("gemfireCache")); + assertThat(containsBean("gemfireProperties")); - GemFireCache peerCache = - this.applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache peerCache = getBean("gemfireCache", GemFireCache.class); assertThat(peerCache).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java index 11bc83f7..deb25eb1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationIntegrationTests.java @@ -31,8 +31,8 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; @@ -69,9 +69,14 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI @BeforeClass public static void startGeodeServer() throws Exception { + + org.springframework.core.io.Resource trustedKeystore = new ClassPathResource("trusted.keystore"); + startGemFireServer(GeodeServerTestConfiguration.class, - String.format("-Dgemfire.name=%s", asApplicationName(EnableSslConfigurationIntegrationTests.class)), - String.format("-Djavax.net.ssl.keyStore=%s", System.getProperty("javax.net.ssl.keyStore"))); + String.format("-Dgemfire.name=%s", asApplicationName(EnableSslConfigurationIntegrationTests.class).concat("Server")), + String.format("-Djavax.net.ssl.keyStore=%s", trustedKeystore.getFile().getAbsolutePath())); + + System.setProperty("javax.net.ssl.keyStore", trustedKeystore.getFile().getAbsolutePath()); } @Test @@ -111,11 +116,7 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI static class GeodeServerTestConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(GeodeServerTestConfiguration.class, args); } @Bean @@ -135,7 +136,6 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI echoRegion.setCache(gemfireCache); echoRegion.setCacheLoader(echoCacheLoader()); - echoRegion.setClose(false); echoRegion.setPersistent(false); return echoRegion; @@ -152,8 +152,8 @@ public class EnableSslConfigurationIntegrationTests extends ForkingClientServerI } @Override - public void close() { - } + public void close() { } + }; } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java index 38d9ae3a..dee8bb44 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableSslConfigurationUnitTests.java @@ -19,16 +19,15 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; import java.util.Properties; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.mock.env.MockPropertySource; @@ -43,47 +42,36 @@ import org.springframework.util.StringUtils; * @see org.apache.geode.cache.GemFireCache * @see org.springframework.data.gemfire.config.annotation.EnableSsl * @see org.springframework.data.gemfire.config.annotation.SslConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.1.0 */ -public class EnableSslConfigurationUnitTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class EnableSslConfigurationUnitTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test public void sslAnnotationBasedConfigurationIsCorrect() { - this.applicationContext = newApplicationContext(new MockPropertySource("TestPropertySource"), - SslAnnotationBasedConfiguration.class); + newApplicationContext(new MockPropertySource("TestPropertySource"), SslAnnotationBasedConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")); - assertThat(this.applicationContext.containsBean("gemfireProperties")); + assertThat(containsBean("gemfireCache")); + assertThat(containsBean("gemfireProperties")); - ClientCacheFactoryBean clientCache = - this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class); + ClientCacheFactoryBean clientCache = getBean("&gemfireCache", ClientCacheFactoryBean.class); assertThat(clientCache).isNotNull(); @@ -128,14 +116,12 @@ public class EnableSslConfigurationUnitTests extends IntegrationTestsSupport { .withProperty("spring.data.gemfire.security.ssl.use-default-context", "true") .withProperty("spring.data.gemfire.security.ssl.web-require-authentication", "true"); - this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedConfiguration.class); + newApplicationContext(testPropertySource, SslPropertyBasedConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")); - assertThat(this.applicationContext.containsBean("gemfireProperties")); + assertThat(containsBean("gemfireCache")); + assertThat(containsBean("gemfireProperties")); - ClientCacheFactoryBean clientCache = - this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class); + ClientCacheFactoryBean clientCache = getBean("&gemfireCache", ClientCacheFactoryBean.class); assertThat(clientCache).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerIntegrationTests.java similarity index 69% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerIntegrationTests.java index 8682637a..e6bc167e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverConfigurerIntegrationTests.java @@ -19,62 +19,57 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.InputStream; import java.io.OutputStream; -import java.util.Arrays; -import java.util.Optional; +import java.util.Collections; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewayTransportFilter; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; import org.springframework.mock.env.MockPropertySource; /** - * Tests for {@link EnableGatewayReceiver}. + * Integration Tests for {@link EnableGatewayReceiver}. * * @author Udo Kohlmeyer + * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.apache.geode.cache.server.CacheServer + * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.apache.geode.cache.wan.GatewayTransportFilter + * @see org.springframework.context.annotation.Bean * @see org.springframework.context.annotation.Configuration + * @see org.springframework.core.env.PropertySources + * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean + * @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfiguration + * @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner - * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean - * @see GatewayReceiverConfigurer - * @see GatewayReceiverConfiguration * @since 2.2.0 */ -public class GatewayReceiverConfigurerTests { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class GatewayReceiverConfigurerIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test @@ -82,12 +77,12 @@ public class GatewayReceiverConfigurerTests { MockPropertySource testPropertySource = new MockPropertySource(); - this.applicationContext = newApplicationContext(testPropertySource, - GatewayReceiverConfigurerTests.TestConfigurationWithProperties.class); + newApplicationContext(testPropertySource, + GatewayReceiverConfigurerIntegrationTests.TestConfigurationWithProperties.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue(); - GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver", GatewayReceiver.class); + assertThat(containsBean("GatewayReceiver")).isTrue(); + + GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class); assertThat(gatewayReceiver.getStartPort()).isEqualTo(23000); assertThat(gatewayReceiver.getEndPort()).isEqualTo(25000); @@ -97,8 +92,7 @@ public class GatewayReceiverConfigurerTests { assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(987654); assertThat(gatewayReceiver.isManualStart()).isEqualTo(false); assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(1); - assertThat( - ((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name) + assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name) .isEqualTo("transportBean1"); } @@ -116,12 +110,12 @@ public class GatewayReceiverConfigurerTests { .withProperty("spring.data.gemfire.gateway.receiver.manual-start", true) .withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean1,transportBean2"); - this.applicationContext = newApplicationContext(testPropertySource, - GatewayReceiverConfigurerTests.TestConfigurationWithProperties.class); + newApplicationContext(testPropertySource, + GatewayReceiverConfigurerIntegrationTests.TestConfigurationWithProperties.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue(); - GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver", GatewayReceiver.class); + assertThat(containsBean("GatewayReceiver")).isTrue(); + + GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class); assertThat(gatewayReceiver.getStartPort()).isEqualTo(23000); assertThat(gatewayReceiver.getEndPort()).isEqualTo(25000); @@ -131,8 +125,7 @@ public class GatewayReceiverConfigurerTests { assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(987654); assertThat(gatewayReceiver.isManualStart()).isEqualTo(false); assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(1); - assertThat( - ((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name) + assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name) .isEqualTo("transportBean1"); } @@ -147,12 +140,12 @@ public class GatewayReceiverConfigurerTests { .withProperty("spring.data.gemfire.gateway.receiver.manual-start", true) .withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1"); - this.applicationContext = newApplicationContext(testPropertySource, - GatewayReceiverConfigurerTests.TestConfiguration.class); + newApplicationContext(testPropertySource, + GatewayReceiverConfigurerIntegrationTests.TestConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue(); - GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver", GatewayReceiver.class); + assertThat(containsBean("GatewayReceiver")).isTrue(); + + GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class); assertThat(gatewayReceiver.getStartPort()).isEqualTo(10000); assertThat(gatewayReceiver.getEndPort()).isEqualTo(11000); @@ -162,28 +155,26 @@ public class GatewayReceiverConfigurerTests { assertThat(gatewayReceiver.getSocketBufferSize()).isEqualTo(32768); assertThat(gatewayReceiver.isManualStart()).isEqualTo(true); assertThat(gatewayReceiver.getGatewayTransportFilters().size()).isEqualTo(2); - assertThat( - ((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name) + assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(0)).name) .isEqualTo("transportBean2"); - assertThat( - ((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(1)).name) + assertThat(((TestGatewayTransportFilter) gatewayReceiver.getGatewayTransportFilters().get(1)).name) .isEqualTo("transportBean1"); } - @Configuration @CacheServerApplication @EnableGatewayReceiver + @SuppressWarnings("unused") static class TestConfigurationWithProperties { @Bean("transportBean1") GatewayTransportFilter createGatewayTransportBean1() { - return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1"); + return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean1"); } @Bean("transportBean2") GatewayTransportFilter createGatewayTransportBean2() { - return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2"); + return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean2"); } @Bean("gatewayConfigurer") @@ -196,26 +187,26 @@ public class GatewayReceiverConfigurerTests { bean.setManualStart(false); bean.setMaximumTimeBetweenPings(1234567); bean.setSocketBufferSize(987654); - bean.setTransportFilters(Arrays.asList(createGatewayTransportBean1())); + bean.setTransportFilters(Collections.singletonList(createGatewayTransportBean1())); }; } } - @Configuration @CacheServerApplication @EnableGatewayReceiver(manualStart = false, startPort = 10000, endPort = 11000, maximumTimeBetweenPings = 1000, socketBufferSize = 16384, bindAddress = "localhost",transportFilters = {"transportBean1", "transportBean2"}, hostnameForSenders = "hostnameLocalhost") + @SuppressWarnings("unused") static class TestConfiguration { @Bean("transportBean1") GatewayTransportFilter createGatewayTransportBean1() { - return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean1"); + return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean1"); } @Bean("transportBean2") GatewayTransportFilter createGatewayTransportBean2() { - return new GatewayReceiverConfigurerTests.TestGatewayTransportFilter("transportBean2"); + return new GatewayReceiverConfigurerIntegrationTests.TestGatewayTransportFilter("transportBean2"); } @Bean("gatewayConfigurer") @@ -230,7 +221,7 @@ public class GatewayReceiverConfigurerTests { private static class TestGatewayTransportFilter implements GatewayTransportFilter { - private String name; + private final String name; public TestGatewayTransportFilter(String name) { this.name = name; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesIntegrationTests.java similarity index 60% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesIntegrationTests.java index 8002c060..e026224f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewayReceiverPropertiesIntegrationTests.java @@ -23,83 +23,67 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Optional; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.wan.GatewayReceiver; import org.apache.geode.cache.wan.GatewayTransportFilter; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; -import org.springframework.core.env.PropertySource; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; import org.springframework.mock.env.MockPropertySource; /** - * Tests for {@link EnableGatewayReceiver}. + * Integration Tests for {@link EnableGatewayReceiver}, {@link GatewayReceiverConfiguration} + * and {@link GatewayReceiverConfigurer}. * * @author Udo Kohlmeyer + * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.apache.geode.cache.server.CacheServer - * @see org.springframework.context.annotation.Configuration + * @see org.apache.geode.cache.wan.GatewayReceiver + * @see org.springframework.context.annotation.Bean * @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfigurer * @see org.springframework.data.gemfire.config.annotation.GatewayReceiverConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 */ -public class GatewayReceiverPropertiesTests extends IntegrationTestsSupport { +public class GatewayReceiverPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { - private ConfigurableApplicationContext applicationContext; + @Override + protected ConfigurableApplicationContext processBeforeRefresh(ConfigurableApplicationContext applicationContext) { - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } - - private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { - - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + MockPropertySource testPropertySource = new MockPropertySource() + .withProperty("spring.data.gemfire.gateway.receiver.bind-address", "123.123.123.123") + .withProperty("spring.data.gemfire.gateway.receiver.hostname-for-senders", "testHostName") + .withProperty("spring.data.gemfire.gateway.receiver.start-port", 16000) + .withProperty("spring.data.gemfire.gateway.receiver.end-port", 17000) + .withProperty("spring.data.gemfire.gateway.receiver.maximum-time-between-pings", 30000) + .withProperty("spring.data.gemfire.gateway.receiver.socket-buffer-size", 32768) + .withProperty("spring.data.gemfire.gateway.receiver.manual-start", true) + .withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1"); MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); propertySources.addFirst(testPropertySource); - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); - return applicationContext; } @Test public void gatewayReceiverPropertiesConfiguration() { - MockPropertySource testPropertySource = new MockPropertySource() - .withProperty("spring.data.gemfire.gateway.receiver.bind-address", "123.123.123.123") - .withProperty("spring.data.gemfire.gateway.receiver.hostname-for-senders", "testHostName") - .withProperty("spring.data.gemfire.gateway.receiver.start-port", 16000) - .withProperty("spring.data.gemfire.gateway.receiver.end-port", 17000) - .withProperty("spring.data.gemfire.gateway.receiver.maximum-time-between-pings", 30000) - .withProperty("spring.data.gemfire.gateway.receiver.socket-buffer-size", 32768) - .withProperty("spring.data.gemfire.gateway.receiver.manual-start", true) - .withProperty("spring.data.gemfire.gateway.receiver.transport-filters", "transportBean2,transportBean1"); + newApplicationContext(GatewayReceiverPropertiesIntegrationTests.TestConfigurationWithProperties.class); - this.applicationContext = newApplicationContext(testPropertySource, - GatewayReceiverPropertiesTests.TestConfigurationWithProperties.class); + assertThat(requireApplicationContext().containsBean("GatewayReceiver")).isTrue(); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("GatewayReceiver")).isTrue(); - GatewayReceiver gatewayReceiver = this.applicationContext.getBean("GatewayReceiver",GatewayReceiver.class); + GatewayReceiver gatewayReceiver = getBean("GatewayReceiver", GatewayReceiver.class); assertThat(gatewayReceiver.getStartPort()).isEqualTo(16000); assertThat(gatewayReceiver.getEndPort()).isEqualTo(17000); @@ -116,27 +100,44 @@ public class GatewayReceiverPropertiesTests extends IntegrationTestsSupport { @CacheServerApplication @EnableGatewayReceiver + @SuppressWarnings("unused") static class TestConfigurationWithProperties{ @Bean("transportBean1") GatewayTransportFilter createGatewayTransportBean1() { - return new GatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean1"); + return new GatewayReceiverPropertiesIntegrationTests.TestGatewayTransportFilter("transportBean1"); } @Bean("transportBean2") GatewayTransportFilter createGatewayTransportBean2() { - return new GatewayReceiverPropertiesTests.TestGatewayTransportFilter("transportBean2"); + return new GatewayReceiverPropertiesIntegrationTests.TestGatewayTransportFilter("transportBean2"); } @Bean("gatewayConfigurer") GatewayReceiverConfigurer gatewayReceiverConfigurer() { - return new GatewayReceiverPropertiesTests.TestGatewayReceiverConfigurer(); + return new GatewayReceiverPropertiesIntegrationTests.TestGatewayReceiverConfigurer(); + } + } + + private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable { + + private final List beanNames = new ArrayList<>(); + + @Override + public Iterator iterator() { + return Collections.unmodifiableList(this.beanNames).iterator(); + } + + @Override + public void configure(String beanName, GatewayReceiverFactoryBean bean) { + bean.getTransportFilters().stream().forEach(transportFilter -> + this.beanNames.add(((GatewayReceiverPropertiesIntegrationTests.TestGatewayTransportFilter) transportFilter).name)); } } private static class TestGatewayTransportFilter implements GatewayTransportFilter { - private String name; + private final String name; public TestGatewayTransportFilter(String name) { this.name = name; @@ -152,19 +153,4 @@ public class GatewayReceiverPropertiesTests extends IntegrationTestsSupport { return null; } } - - private static class TestGatewayReceiverConfigurer implements GatewayReceiverConfigurer, Iterable { - - private final List beanNames = new ArrayList<>(); - - @Override - public Iterator iterator() { - return Collections.unmodifiableList(this.beanNames).iterator(); - } - - @Override - public void configure(String beanName, GatewayReceiverFactoryBean bean) { - bean.getTransportFilters().stream().forEach(o -> beanNames.add(((GatewayReceiverPropertiesTests.TestGatewayTransportFilter) o).name)); - } - } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationIntegrationTests.java index 3eba7a04..9226f348 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurationIntegrationTests.java @@ -21,7 +21,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.TreeMap; import java.util.stream.Collectors; @@ -37,11 +36,9 @@ import org.apache.geode.cache.wan.GatewayQueueEvent; import org.apache.geode.cache.wan.GatewaySender; import org.apache.geode.cache.wan.GatewayTransportFilter; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; import org.springframework.data.gemfire.wan.OrderPolicyType; @@ -61,7 +58,7 @@ import org.springframework.data.gemfire.wan.OrderPolicyType; * @see org.springframework.data.gemfire.config.annotation.EnableGatewaySenders * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean * @see org.springframework.test.context.ContextConfiguration @@ -69,29 +66,22 @@ import org.springframework.data.gemfire.wan.OrderPolicyType; * @since 2.2.0 */ @SuppressWarnings("unused") -public class GatewaySenderConfigurationIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class GatewaySenderConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void shutdown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } @Test public void annotationConfigurationOfMultipleGatewaySendersWithDefaultsFromParent() { - this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class, + newApplicationContext(BaseGatewaySenderTestConfiguration.class, TestConfigurationOfMultipleGatewaySenderAnnotationsButWithDefaultsFromParent.class); - TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean(TestGatewaySenderConfigurer.class); + TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class); - Map beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class); + Map beansOfType = getBeansOfType(GatewaySender.class); String[] senders = new String[] { "TestGatewaySender", "TestGatewaySender2" }; @@ -100,7 +90,7 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests for (String sender : senders) { - GatewaySender gatewaySender = this.applicationContext.getBean(sender, GatewaySender.class); + GatewaySender gatewaySender = getBean(sender, GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(true); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -127,8 +117,8 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); assertThat(region1.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2"); @@ -140,10 +130,10 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests @Test public void annotationConfiguredMultipleGatewaySenders() { - this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class, + newApplicationContext(BaseGatewaySenderTestConfiguration.class, TestConfigurationWithMultipleGatewaySenderAnnotations.class); - Map beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class); + Map beansOfType = getBeansOfType(GatewaySender.class); assertThat(beansOfType.keySet().toArray()).containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2"); } @@ -151,13 +141,11 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests @Test public void annotationConfiguredGatewaySender() { - this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class, - TestConfigurationWithAnnotations.class); + newApplicationContext(BaseGatewaySenderTestConfiguration.class, TestConfigurationWithAnnotations.class); - TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean(TestGatewaySenderConfigurer.class); + TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class); - GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); + GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(true); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -169,7 +157,7 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests assertThat(gatewaySender.getDiskStoreName()).isEqualTo("someDiskStore"); assertThat(gatewaySender.getOrderPolicy()).isEqualTo(GatewaySender.OrderPolicy.PARTITION); assertThat(gatewaySender.getGatewayEventFilters()) - .containsExactlyInAnyOrder(this.applicationContext.getBean("SomeEventFilter", GatewayEventFilter.class)); + .containsExactlyInAnyOrder(getBean("SomeEventFilter", GatewayEventFilter.class)); assertThat(((TestGatewayEventSubstitutionFilter) gatewaySender.getGatewayEventSubstitutionFilter()).name) .isEqualTo("SomeEventSubstitutionFilter"); assertThat(gatewaySender.getAlertThreshold()).isEqualTo(1234); @@ -183,8 +171,8 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); @@ -193,13 +181,13 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests @Test public void annotationConfigurationOfMultipleGatewaySendersWithOverrides() { - this.applicationContext = newApplicationContext(BaseGatewaySenderTestConfiguration.class, + newApplicationContext(BaseGatewaySenderTestConfiguration.class, TestConfigurationOfMultipleGatewaySenderAnnotationsWithOverrides.class); TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean("gatewayConfigurer", TestGatewaySenderConfigurer.class); + getBean("gatewayConfigurer", TestGatewaySenderConfigurer.class); - Map beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class); + Map beansOfType = getBeansOfType(GatewaySender.class); String[] senders = new String[] { "TestGatewaySender", "TestGatewaySender2" }; @@ -208,7 +196,7 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests for (String sender : senders) { - GatewaySender gatewaySender = this.applicationContext.getBean(sender, GatewaySender.class); + GatewaySender gatewaySender = getBean(sender, GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(true); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -228,36 +216,26 @@ public class GatewaySenderConfigurationIntegrationTests extends IntegrationTests assertThat(gatewaySender.getSocketBufferSize()).isEqualTo(16384); } - GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); + GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(1); assertThat(((GatewaySenderConfigurationIntegrationTests.TestGatewayTransportFilter) gatewaySender .getGatewayTransportFilters().get(0)).name).isEqualTo("transportBean1"); - gatewaySender = this.applicationContext.getBean("TestGatewaySender2", GatewaySender.class); + gatewaySender = getBean("TestGatewaySender2", GatewaySender.class); assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(2); assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender2"); assertThat(region2.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2"); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; - } - @EnableGatewaySenders(gatewaySenders = { @EnableGatewaySender(name = "TestGatewaySender", manualStart = true, remoteDistributedSystemId = 2, diskSynchronous = true, batchConflationEnabled = true, parallel = true, persistent = false, diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java index 55762c59..5aed38d5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderConfigurerTests.java @@ -20,9 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.InputStream; import java.io.OutputStream; import java.util.Map; -import java.util.Optional; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.EntryEvent; @@ -35,13 +34,12 @@ import org.apache.geode.cache.wan.GatewaySender; import org.apache.geode.cache.wan.GatewayTransportFilter; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -49,45 +47,40 @@ import org.springframework.mock.env.MockPropertySource; * Tests for {@link EnableGatewaySenders} and {@link EnableGatewaySender}. * * @author Udo Kohlmeyer + * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.wan.GatewaySender * @see org.springframework.context.annotation.Configuration + * @see org.springframework.data.gemfire.config.annotation.EnableGatewaySender + * @see org.springframework.data.gemfire.config.annotation.EnableGatewaySenders * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration + * @see org.springframework.data.gemfire.config.annotation.GatewaySendersConfiguration * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 */ @SuppressWarnings("unused") -public class GatewaySenderConfigurerTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void shutdown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class GatewaySenderConfigurerTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = + applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test @@ -104,11 +97,10 @@ public class GatewaySenderConfigurerTests extends IntegrationTestsSupport { testPropertySource.setProperty("spring.data.gemfire.gateway.sender.TestGatewaySender2.socket-read-timeout", 4000); testPropertySource.setProperty("spring.data.gemfire.gateway.sender.socket-buffer-size", 16384); - this.applicationContext = newApplicationContext(testPropertySource, - BaseGatewaySenderTestConfiguration.class, + newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, TestTwoGatewaySenderConfigurersBasic.class); - Map beansOfType = this.applicationContext.getBeansOfType(GatewaySender.class); + Map beansOfType = getBeansOfType(GatewaySender.class); String[] senders = new String[] { "TestGatewaySender", "TestGatewaySender2" }; @@ -117,7 +109,7 @@ public class GatewaySenderConfigurerTests extends IntegrationTestsSupport { for (String sender : senders) { - GatewaySender gatewaySender = this.applicationContext.getBean(sender, GatewaySender.class); + GatewaySender gatewaySender = getBean(sender, GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(false); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -137,8 +129,8 @@ public class GatewaySenderConfigurerTests extends IntegrationTestsSupport { assertThat(gatewaySender.getGatewayTransportFilters().size()).isEqualTo(0); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); assertThat(region1.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2"); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesIntegrationTests.java index 1fa36b91..8d65e309 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/GatewaySenderPropertiesIntegrationTests.java @@ -21,8 +21,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.TreeMap; +import java.util.function.Function; import java.util.stream.Collectors; import org.junit.After; @@ -39,12 +39,11 @@ import org.apache.geode.cache.wan.GatewaySender; import org.apache.geode.cache.wan.GatewayTransportFilter; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; import org.springframework.data.gemfire.wan.OrderPolicyType; @@ -62,23 +61,33 @@ import org.springframework.mock.env.MockPropertySource; * @see org.springframework.context.annotation.Configuration * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfiguration * @see org.springframework.data.gemfire.config.annotation.GatewaySenderConfigurer - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.2.0 */ -public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSupport { +public class GatewaySenderPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { - private ConfigurableApplicationContext applicationContext; + private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, + Class... annotatedClasses) { + + Function applicationContextInitializer = + applicationContext -> { + + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + + propertySources.addFirst(testPropertySource); + + return applicationContext; + }; + + return newApplicationContext(applicationContextInitializer, annotatedClasses); + } @After - public void shutdown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } @@ -129,13 +138,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup "transportBean1") .withProperty("spring.data.gemfire.gateway.sender.TestGatewaySender2.regions", "Region1"); - this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, + newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, TestConfigurationWithPropertiesMultipleGatewaySenders.class); - TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean(TestGatewaySenderConfigurer.class); + TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class); - GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); + GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(true); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -159,7 +167,7 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - gatewaySender = this.applicationContext.getBean("TestGatewaySender2", GatewaySender.class); + gatewaySender = getBean("TestGatewaySender2", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(false); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(3); @@ -183,14 +191,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); assertThat(region1.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2"); - assertThat(region2.getAttributes().getGatewaySenderIds()) - .containsExactlyInAnyOrder("TestGatewaySender"); - + assertThat(region2.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender"); } @Test @@ -240,13 +246,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup "transportBean1") .withProperty("spring.data.gemfire.gateway.sender.TestGatewaySender2.regions", ""); - this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, + newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, TestConfigurationWithMultipleGatewaySenderAnnotations.class); - TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean(TestGatewaySenderConfigurer.class); + TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class); - GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); + GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(true); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -270,7 +275,7 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - gatewaySender = this.applicationContext.getBean("TestGatewaySender2", GatewaySender.class); + gatewaySender = getBean("TestGatewaySender2", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(false); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(3); @@ -294,14 +299,13 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); assertThat(region1.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2"); assertThat(region2.getAttributes().getGatewaySenderIds()) .containsExactlyInAnyOrder("TestGatewaySender", "TestGatewaySender2"); - } @Test @@ -330,13 +334,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup "transportBean2, transportBean1") .withProperty("spring.data.gemfire.gateway.sender.TestGatewaySender.regions", "Region1,Region2"); - this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, + newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, TestConfigurationWithProperties.class); - TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean(TestGatewaySenderConfigurer.class); + TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class); - GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); + GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(true); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -360,14 +363,11 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); - - assertThat(region1.getAttributes().getGatewaySenderIds()) - .containsExactlyInAnyOrder("TestGatewaySender"); - assertThat(region2.getAttributes().getGatewaySenderIds()) - .containsExactlyInAnyOrder("TestGatewaySender"); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); + assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); + assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); } @Test @@ -396,13 +396,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup "transportBean2, transportBean1") .withProperty("spring.data.gemfire.gateway.sender.regions", "Region1,Region2"); - this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, + newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, TestConfigurationWithProperties.class); - TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean(TestGatewaySenderConfigurer.class); + TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class); - GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); + GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(true); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -426,14 +425,11 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); - - assertThat(region1.getAttributes().getGatewaySenderIds()) - .containsExactlyInAnyOrder("TestGatewaySender"); - assertThat(region2.getAttributes().getGatewaySenderIds()) - .containsExactlyInAnyOrder("TestGatewaySender"); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); + assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); + assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); } @Test @@ -463,13 +459,12 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup "transportBean2, transportBean1") .withProperty("spring.data.gemfire.gateway.sender.regions", "Region1,Region2"); - this.applicationContext = newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, + newApplicationContext(testPropertySource, BaseGatewaySenderTestConfiguration.class, TestConfigurationWithProperties.class); - TestGatewaySenderConfigurer gatewaySenderConfigurer = - this.applicationContext.getBean(TestGatewaySenderConfigurer.class); + TestGatewaySenderConfigurer gatewaySenderConfigurer = getBean(TestGatewaySenderConfigurer.class); - GatewaySender gatewaySender = this.applicationContext.getBean("TestGatewaySender", GatewaySender.class); + GatewaySender gatewaySender = getBean("TestGatewaySender", GatewaySender.class); assertThat(gatewaySender.isManualStart()).isEqualTo(false); assertThat(gatewaySender.getRemoteDSId()).isEqualTo(2); @@ -493,30 +488,11 @@ public class GatewaySenderPropertiesIntegrationTests extends IntegrationTestsSup assertThat(gatewaySenderConfigurer.beanNames.get(gatewaySender.getId()).toArray()) .isEqualTo(new String[] { "transportBean2", "transportBean1" }); - Region region1 = this.applicationContext.getBean("Region1", Region.class); - Region region2 = this.applicationContext.getBean("Region2", Region.class); + Region region1 = getBean("Region1", Region.class); + Region region2 = getBean("Region2", Region.class); - assertThat(region1.getAttributes().getGatewaySenderIds()) - .containsExactlyInAnyOrder("TestGatewaySender"); - assertThat(region2.getAttributes().getGatewaySenderIds()) - .containsExactlyInAnyOrder("TestGatewaySender"); - - } - - private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { - - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - - propertySources.addFirst(testPropertySource); - - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); - - return applicationContext; + assertThat(region1.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); + assertThat(region2.getAttributes().getGatewaySenderIds()).containsExactlyInAnyOrder("TestGatewaySender"); } @EnableGatewaySenders(gatewaySenders = { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java index 83d5adeb..14ead739 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/IndexConfigurerIntegrationTests.java @@ -21,21 +21,20 @@ import static org.mockito.Mockito.mock; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; -import java.util.Optional; import java.util.Set; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.lucene.LuceneIndex; import org.apache.geode.cache.lucene.LuceneService; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; @@ -47,7 +46,10 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.mapping.annotation.LocalRegion; import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion; import org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean; -import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; +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 IndexConfigurer}. @@ -57,21 +59,26 @@ import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireM * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.lucene.LuceneIndex * @see org.apache.geode.cache.query.Index + * @see org.springframework.context.ApplicationContext * @see org.springframework.data.gemfire.IndexFactoryBean * @see org.springframework.data.gemfire.config.annotation.IndexConfigurer * @see org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean - * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 */ @SuppressWarnings("unused") -public class IndexConfigurerIntegrationTests { +@RunWith(SpringRunner.class) +@ContextConfiguration +public class IndexConfigurerIntegrationTests extends IntegrationTestsSupport { - private static ConfigurableApplicationContext applicationContext; + @Autowired + private ApplicationContext applicationContext; - @BeforeClass - public static void setup() { - - applicationContext = newApplicationContext(TestConfiguration.class); + @Before + public void setup() { assertThat(applicationContext).isNotNull(); assertThat(applicationContext.containsBean("CustomersFirstNameFunctionalIdx")).isTrue(); @@ -83,20 +90,8 @@ public class IndexConfigurerIntegrationTests { assertThat(applicationContext.containsBean("TitleLuceneIdx")).isTrue(); } - @AfterClass - public static void tearDown() { - Optional.ofNullable(applicationContext).ifPresent(ConfigurableApplicationContext::close); - } - - /* (non-Javadoc) */ - private static ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - applicationContext.registerShutdownHook(); - return applicationContext; - } - - /* (non-Javadoc) */ private void assertIndexConfigurerInvocations(TestIndexConfigurer indexConfigurer, String... indexBeanNames) { + assertThat(indexConfigurer).isNotNull(); assertThat(indexConfigurer).contains(indexBeanNames); assertThat(indexConfigurer).hasSize(indexBeanNames.length); @@ -121,7 +116,6 @@ public class IndexConfigurerIntegrationTests { } @PeerCacheApplication - @EnableIndexing @EnableEntityDefinedRegions(basePackageClasses = NonEntity.class, excludeFilters = { @ComponentScan.Filter(type = FilterType.ANNOTATION, @@ -130,6 +124,8 @@ public class IndexConfigurerIntegrationTests { classes = CollocatedPartitionRegionEntity.class) } ) + @EnableIndexing + @EnableGemFireMockObjects static class TestConfiguration { @Bean("LoyalCustomers") @@ -144,11 +140,6 @@ public class IndexConfigurerIntegrationTests { return localRegion; } - @Bean - GemFireMockObjectsBeanPostProcessor testBeanPostProcessor() { - return new GemFireMockObjectsBeanPostProcessor(); - } - @Bean BeanPostProcessor indexFactoryBeanReplacingBeanPostProcessor() { @@ -158,6 +149,7 @@ public class IndexConfigurerIntegrationTests { public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof LuceneIndexFactoryBean) { + LuceneIndexFactoryBean luceneIndexFactoryBean = (LuceneIndexFactoryBean) bean; LuceneService mockLuceneService = mock(LuceneService.class); LuceneIndex mockLuceneIndex = mock(LuceneIndex.class); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java index 688b1fac..1703f076 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests.java @@ -19,9 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Fail.fail; import static org.mockito.Mockito.mock; -import java.util.Optional; - -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.GemFireCache; @@ -29,10 +26,8 @@ import org.apache.geode.cache.client.ClientCache; import org.apache.geode.distributed.Locator; import org.springframework.beans.factory.BeanDefinitionStoreException; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; /** @@ -50,43 +45,26 @@ import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockO * @see org.springframework.data.gemfire.config.annotation.LocatorApplicationConfiguration * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.context.annotation.AnnotationConfigApplicationContext + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.2.0 */ @SuppressWarnings("unused") -public class LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests extends IntegrationTestsSupport { +public class LocatorApplicationCannotCoexistWithCacheApplicationIntegrationTests + extends SpringApplicationContextIntegrationTestsSupport { private static final String GEMFIRE_LOG_LEVEL = "error"; - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); - - return applicationContext; - } - private void testCacheAndLocatorApplication(Class testConfiguration) { try { - this.applicationContext = newApplicationContext(testConfiguration); - this.applicationContext.getBean(GemFireCache.class); - this.applicationContext.getBean(Locator.class); + newApplicationContext(testConfiguration); + getBean(GemFireCache.class); + getBean(Locator.class); fail("Caches and Locators cannot coexist!"); + } catch (BeanDefinitionStoreException expected) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationIntegrationTests.java index 72a781f7..8ff941af 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationIntegrationTests.java @@ -31,6 +31,7 @@ import org.apache.geode.distributed.Locator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** @@ -52,6 +53,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @since 2.2.0 */ @RunWith(SpringRunner.class) +@ContextConfiguration @SuppressWarnings("unused") public class LocatorApplicationIntegrationTests extends IntegrationTestsSupport { @@ -76,6 +78,10 @@ public class LocatorApplicationIntegrationTests extends IntegrationTestsSupport Cache peerCache = null; + assertThat(distributedSystemProperties.getProperty("locators")) + .describedAs("Locators was [%s]", distributedSystemProperties.getProperty("locators")) + .isNotEmpty(); + try { peerCache = new CacheFactory() .set("name", LocatorApplicationIntegrationTests.class.getSimpleName()) @@ -83,6 +89,7 @@ public class LocatorApplicationIntegrationTests extends IntegrationTestsSupport .set("cache-xml-file", distributedSystemProperties.getProperty("cache-xml-file")) .set("jmx-manager", distributedSystemProperties.getProperty("jmx-manager")) .set("locators", distributedSystemProperties.getProperty("locators")) + //.set("locators", "localhost[0]") // This locators configuration setting causes the test to fail .set("log-file", distributedSystemProperties.getProperty("log-file")) .set("log-level", distributedSystemProperties.getProperty("log-level")) .create(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java index 44f80b93..61074c71 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationPropertiesIntegrationTests.java @@ -19,10 +19,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.spy; -import java.util.Optional; import java.util.Properties; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.distributed.Locator; @@ -30,12 +29,11 @@ import org.apache.geode.distributed.Locator; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.LocatorFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.lang.Nullable; import org.springframework.mock.env.MockPropertySource; @@ -48,39 +46,31 @@ import org.springframework.mock.env.MockPropertySource; * @see java.util.Properties * @see org.junit.Test * @see org.apache.geode.distributed.Locator -\ * @see org.springframework.core.env.PropertySource + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.LocatorFactoryBean - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource * @since 2.2.0 */ @SuppressWarnings("unused") -public class LocatorApplicationPropertiesIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - } +public class LocatorApplicationPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = + applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test @@ -94,9 +84,9 @@ public class LocatorApplicationPropertiesIntegrationTests extends IntegrationTes .withProperty("spring.data.gemfire.locator.port", 54321) .withProperty("spring.data.gemfire.locators", "host1[1234],host2[6789]"); - this.applicationContext = newApplicationContext(testPropertySource, TestConfiguration.class); + newApplicationContext(testPropertySource, TestConfiguration.class); - LocatorFactoryBean locatorFactoryBean = this.applicationContext.getBean(LocatorFactoryBean.class); + LocatorFactoryBean locatorFactoryBean = getBean(LocatorFactoryBean.class); assertThat(locatorFactoryBean).isNotNull(); assertThat(locatorFactoryBean.getBindAddress().orElse(null)).isEqualTo("10.120.240.32"); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LoggingConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LoggingConfigurationIntegrationTests.java index 7a09301b..df601197 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LoggingConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LoggingConfigurationIntegrationTests.java @@ -31,10 +31,9 @@ import org.junit.Test; import org.apache.geode.cache.GemFireCache; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.PropertiesPropertySource; import org.springframework.data.gemfire.GemFireProperties; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.data.gemfire.util.PropertiesBuilder; import org.springframework.util.StringUtils; @@ -51,36 +50,23 @@ import org.springframework.util.StringUtils; * @see org.springframework.core.env.PropertiesPropertySource * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication * @see org.springframework.data.gemfire.config.annotation.EnableLogging - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.util.PropertiesBuilder * @since 1.9.0 */ -public class LoggingConfigurationIntegrationTests extends IntegrationTestsSupport { +public class LoggingConfigurationIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private final AtomicReference propertiesReference = new AtomicReference<>(null); - private ConfigurableApplicationContext applicationContext; - - @Before - public void setup() { - + @Before @After + public void setupAndTearDown() { this.propertiesReference.set(null); - - deleteLogFiles(); - } - - @After - public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - deleteLogFiles(); } private void assertGemFireCacheLogLevelAndLogFile(String logLevel, String logFile) { - GemFireCache gemfireCache = this.applicationContext.getBean(GemFireCache.class); + GemFireCache gemfireCache = getBean(GemFireCache.class); logFile = StringUtils.hasText(logFile) ? logFile : ""; @@ -104,23 +90,15 @@ public class LoggingConfigurationIntegrationTests extends IntegrationTestsSuppor Arrays.stream(ArrayUtils.nullSafeArray(files, File.class)).forEach(File::delete); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); + @Override + protected ConfigurableApplicationContext processBeforeRefresh(ConfigurableApplicationContext applicationContext) { Optional.ofNullable(this.propertiesReference.get()) .ifPresent(properties -> applicationContext.getEnvironment() .getPropertySources() .addFirst(new PropertiesPropertySource("Test Properties", properties))); - applicationContext.refresh(); - - this.applicationContext = applicationContext; - - return applicationContext; + return super.processBeforeRefresh(applicationContext); } private void with(Properties properties) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java index afc6b7e6..1899497a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java @@ -117,7 +117,7 @@ public class PeerCacheApplicationWithAddedCacheServerIntegrationTests static class TestLocatorConfiguration { public static void main(String[] args) { - runSpringApplication(TestLocatorConfiguration.class); + runSpringApplication(TestLocatorConfiguration.class, args); block(); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java index 00045f99..4f96861d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java @@ -18,10 +18,9 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import java.util.Optional; import java.util.Properties; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.Cache; @@ -29,12 +28,11 @@ import org.apache.geode.cache.control.ResourceManager; import org.apache.geode.pdx.PdxSerializer; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.data.gemfire.CacheFactoryBean; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -49,35 +47,27 @@ import org.springframework.mock.env.MockPropertySource; * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ @SuppressWarnings("unused") -public class PeerCachePropertiesIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } +public class PeerCachePropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } @Test @@ -95,15 +85,14 @@ public class PeerCachePropertiesIntegrationTests extends IntegrationTestsSupport .withProperty("spring.data.gemfire.pdx.ignore-unread-fields", false) .withProperty("spring.data.gemfire.pdx.persistent", true); - this.applicationContext = newApplicationContext(testPropertySource, TestPeerCacheConfiguration.class); + newApplicationContext(testPropertySource, TestPeerCacheConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("mockPdxSerializer")).isTrue(); - Cache testPeerCache = this.applicationContext.getBean("gemfireCache", Cache.class); + Cache testPeerCache = getBean("gemfireCache", Cache.class); - PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class); + PdxSerializer mockPdxSerializer = getBean("mockPdxSerializer", PdxSerializer.class); assertThat(testPeerCache).isNotNull(); assertThat(mockPdxSerializer).isNotNull(); @@ -143,14 +132,13 @@ public class PeerCachePropertiesIntegrationTests extends IntegrationTestsSupport .withProperty("spring.data.gemfire.cache.peer.search-timeout", 120) .withProperty("spring.data.gemfire.cache.peer.use-cluster-configuration", true); - this.applicationContext = newApplicationContext(testPropertySource, TestDynamicPeerCacheConfiguration.class); + newApplicationContext(testPropertySource, TestDynamicPeerCacheConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); - CacheFactoryBean cacheFactoryBean = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + CacheFactoryBean cacheFactoryBean = getBean("&gemfireCache", CacheFactoryBean.class); - Cache cache = this.applicationContext.getBean("gemfireCache", Cache.class); + Cache cache = getBean("gemfireCache", Cache.class); assertThat(cacheFactoryBean).isNotNull(); assertThat(cacheFactoryBean.isUseBeanFactoryLocator()).isTrue(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java index 31bb79c4..c92bd7f2 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PoolPropertiesIntegrationTests.java @@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import java.net.InetSocketAddress; +import java.util.function.Function; -import org.junit.After; import org.junit.Test; import org.apache.geode.cache.client.ClientCache; @@ -29,11 +29,10 @@ import org.apache.geode.cache.client.PoolFactory; import org.apache.geode.cache.client.SocketFactory; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.mock.env.MockPropertySource; @@ -50,34 +49,27 @@ import org.springframework.mock.env.MockPropertySource; * @see org.springframework.data.gemfire.config.annotation.AddPoolsConfiguration * @see org.springframework.data.gemfire.config.annotation.EnablePool * @see org.springframework.data.gemfire.config.annotation.EnablePools - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.0 */ @SuppressWarnings("unused") -public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; - - @After - public void tearDown() { - closeApplicationContext(this.applicationContext); - } +public class PoolPropertiesIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + Function applicationContextInitializer = + applicationContext -> { - MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); + MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources(); - propertySources.addFirst(testPropertySource); + propertySources.addFirst(testPropertySource); - applicationContext.registerShutdownHook(); - applicationContext.register(annotatedClasses); - applicationContext.refresh(); + return applicationContext; + }; - return applicationContext; + return newApplicationContext(applicationContextInitializer, annotatedClasses); } private void assertPool(Pool pool, int freeConnectionTimeout, long idleTimeout, int loadConditioningInterval, @@ -130,15 +122,14 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport { .withProperty("spring.data.gemfire.pool.subscription-enabled", true) .withProperty("spring.data.gemfire.pool.TestPool.subscription-redundancy", 2); - this.applicationContext = newApplicationContext(testPropertySource, TestPoolConfiguration.class); + newApplicationContext(testPropertySource, TestPoolConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("TestPool")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("TestPool")).isTrue(); - Pool testPool = this.applicationContext.getBean("TestPool", Pool.class); + Pool testPool = getBean("TestPool", Pool.class); - SocketFactory mockSocketFactory = this.applicationContext.getBean("mockSocketFactory", SocketFactory.class); + SocketFactory mockSocketFactory = getBean("mockSocketFactory", SocketFactory.class); assertThat(testPool).isNotNull(); assertThat(mockSocketFactory).isNotNull(); @@ -236,21 +227,20 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport { .withProperty("spring.data.gemfire.pool.TestPoolTwo.subscription-redundancy", 4) .withProperty("spring.data.gemfire.pool.TestPoolTwo.thread-local-connections", true); - this.applicationContext = newApplicationContext(testPropertySource, TestPoolsConfiguration.class); + newApplicationContext(testPropertySource, TestPoolsConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); - assertThat(this.applicationContext.containsBean("TestPoolOne")).isTrue(); - assertThat(this.applicationContext.containsBean("TestPoolTwo")).isTrue(); + assertThat(containsBean("gemfireCache")).isTrue(); + assertThat(containsBean("TestPoolOne")).isTrue(); + assertThat(containsBean("TestPoolTwo")).isTrue(); - ClientCache gemfireCache = this.applicationContext.getBean(ClientCache.class); + ClientCache gemfireCache = getBean(ClientCache.class); assertThat(gemfireCache).isNotNull(); Pool defaultPool = gemfireCache.getDefaultPool(); - SocketFactory mockSocketFactoryOne = this.applicationContext.getBean("mockSocketFactoryOne", SocketFactory.class); - SocketFactory mockSocketFactoryTwo = this.applicationContext.getBean("mockSocketFactoryTwo", SocketFactory.class); + SocketFactory mockSocketFactoryOne = getBean("mockSocketFactoryOne", SocketFactory.class); + SocketFactory mockSocketFactoryTwo = getBean("mockSocketFactoryTwo", SocketFactory.class); assertThat(mockSocketFactoryOne).isNotNull(); assertThat(mockSocketFactoryTwo).isNotNull(); @@ -263,7 +253,7 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport { true, 300000, 3, true); - Pool testPoolOne = this.applicationContext.getBean("TestPoolOne", Pool.class); + Pool testPoolOne = getBean("TestPoolOne", Pool.class); assertPool(testPoolOne, 30000, 300000L, 120000, 500, 50, true, "TestPoolOne", 5000L, @@ -272,7 +262,7 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport { true, 180000, 2, true); - Pool testPoolTwo = this.applicationContext.getBean("TestPoolTwo", Pool.class); + Pool testPoolTwo = getBean("TestPoolTwo", Pool.class); assertPool(testPoolTwo, 20000, 15000L, 60000, 1000, 100, true, "TestPoolTwo", 20000L, diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java index b1e23e10..e90f9e72 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java @@ -28,8 +28,6 @@ import org.junit.Test; import org.apache.geode.cache.GemFireCache; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; @@ -42,7 +40,7 @@ import org.springframework.data.gemfire.mapping.annotation.ClientRegion; import org.springframework.data.gemfire.mapping.annotation.LocalRegion; import org.springframework.data.gemfire.mapping.annotation.PartitionRegion; import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.util.ReflectionUtils; @@ -56,17 +54,14 @@ import org.springframework.util.ReflectionUtils; * @see org.springframework.data.gemfire.PeerRegionFactoryBean * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean * @see org.springframework.data.gemfire.config.annotation.RegionConfigurer - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.1.0 */ -public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class RegionConfigurerIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { @After - public void tearDown() { - closeApplicationContext(this.applicationContext); + public void cleanupAfterTests() { destroyAllGemFireMockObjects(); } @@ -84,15 +79,6 @@ public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport { .orElseGet(Collections::emptySet); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - - applicationContext.registerShutdownHook(); - - return applicationContext; - } - private void assertRegionConfigurerInvocations(Iterable actualRegionBeanNames, String... expectedRegionBeanNames) { @@ -104,53 +90,45 @@ public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport { @Test public void clientRegionConfigurersCalledSuccessfully() { - this.applicationContext = newApplicationContext(ClientTestConfiguration.class); + newApplicationContext(ClientTestConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("Test")).isTrue(); - assertThat(this.applicationContext.containsBean("Sessions")).isTrue(); - assertThat(this.applicationContext.containsBean("GenericRegionEntity")).isTrue(); - assertThat(this.applicationContext.containsBean("testRegionConfigurerOne")).isTrue(); - assertThat(this.applicationContext.containsBean("testRegionConfigurerTwo")).isTrue(); - assertThat(this.applicationContext.containsBean("testRegionConfigurerThree")).isTrue(); + assertThat(containsBean("Test")).isTrue(); + assertThat(containsBean("Sessions")).isTrue(); + assertThat(containsBean("GenericRegionEntity")).isTrue(); + assertThat(containsBean("testRegionConfigurerOne")).isTrue(); + assertThat(containsBean("testRegionConfigurerTwo")).isTrue(); + assertThat(containsBean("testRegionConfigurerThree")).isTrue(); - assertRegionConfigurerInvocations( - this.applicationContext.getBean("testRegionConfigurerOne", TestRegionConfigurer.class), + assertRegionConfigurerInvocations(getBean("testRegionConfigurerOne", TestRegionConfigurer.class), "GenericRegionEntity", "Sessions"); - assertRegionConfigurerInvocations( - this.applicationContext.getBean("testRegionConfigurerTwo", TestRegionConfigurer.class), + assertRegionConfigurerInvocations(getBean("testRegionConfigurerTwo", TestRegionConfigurer.class), "GenericRegionEntity", "Sessions"); - assertRegionConfigurerInvocations( - resolveBeanNames(this.applicationContext.getBean("testRegionConfigurerThree", RegionConfigurer.class)), - "GenericRegionEntity", "Sessions"); + assertRegionConfigurerInvocations(resolveBeanNames(getBean("testRegionConfigurerThree", + RegionConfigurer.class)), "GenericRegionEntity", "Sessions"); } @Test public void peerRegionConfigurersCalledSuccessfully() { - this.applicationContext = newApplicationContext(PeerTestConfiguration.class); + newApplicationContext(PeerTestConfiguration.class); - assertThat(this.applicationContext).isNotNull(); - assertThat(this.applicationContext.containsBean("Test")).isTrue(); - assertThat(this.applicationContext.containsBean("GenericRegionEntity")).isTrue(); - assertThat(this.applicationContext.containsBean("Customers")).isTrue(); - assertThat(this.applicationContext.containsBean("testRegionConfigurerOne")).isTrue(); - assertThat(this.applicationContext.containsBean("testRegionConfigurerTwo")).isTrue(); - assertThat(this.applicationContext.containsBean("testRegionConfigurerThree")).isTrue(); + assertThat(containsBean("Test")).isTrue(); + assertThat(containsBean("GenericRegionEntity")).isTrue(); + assertThat(containsBean("Customers")).isTrue(); + assertThat(containsBean("testRegionConfigurerOne")).isTrue(); + assertThat(containsBean("testRegionConfigurerTwo")).isTrue(); + assertThat(containsBean("testRegionConfigurerThree")).isTrue(); - assertRegionConfigurerInvocations( - this.applicationContext.getBean("testRegionConfigurerOne", TestRegionConfigurer.class), + assertRegionConfigurerInvocations(getBean("testRegionConfigurerOne", TestRegionConfigurer.class), "Customers", "GenericRegionEntity"); - assertRegionConfigurerInvocations( - this.applicationContext.getBean("testRegionConfigurerTwo", TestRegionConfigurer.class), + assertRegionConfigurerInvocations(getBean("testRegionConfigurerTwo", TestRegionConfigurer.class), "Customers", "GenericRegionEntity"); - assertRegionConfigurerInvocations( - resolveBeanNames(this.applicationContext.getBean("testRegionConfigurerThree", RegionConfigurer.class)), - "Customers", "GenericRegionEntity"); + assertRegionConfigurerInvocations(resolveBeanNames(getBean("testRegionConfigurerThree", + RegionConfigurer.class)),"Customers", "GenericRegionEntity"); } @SuppressWarnings("unused") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.java index 3c8cc530..60adf0bd 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.java @@ -37,7 +37,8 @@ import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Profile; import org.springframework.data.gemfire.GemFireProperties; import org.springframework.data.gemfire.support.DisableBeanDefinitionOverridingApplicationContextInitializer; -import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects; +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; @@ -57,7 +58,8 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.context.annotation.Import * @see org.springframework.context.annotation.Profile * @see org.springframework.data.gemfire.GemFireProperties - * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @see Error - Bean Definition Overriding - ClientGemFirePropertiesConfigurer @@ -67,10 +69,7 @@ import org.springframework.test.context.junit4.SpringRunner; //@ActiveProfiles("incorrect-test-configuration") @ContextConfiguration(initializers = DisableBeanDefinitionOverridingApplicationContextInitializer.class) @SuppressWarnings("unused") -public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests { - - @Autowired - private ConfigurableApplicationContext applicationContext; +public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests extends IntegrationTestsSupport { @Autowired private GemFireCache cache; @@ -78,9 +77,9 @@ public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegratio @Before public void assertApplicationContextBeanDefinitionOverridingIsDisabled() { - assertThat(this.applicationContext).isNotNull(); + ConfigurableApplicationContext applicationContext = requireApplicationContext(); - ConfigurableListableBeanFactory beanFactory = this.applicationContext.getBeanFactory(); + ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); assertThat(beanFactory).isInstanceOf(DefaultListableBeanFactory.class); @@ -90,14 +89,15 @@ public class UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegratio .map(beanName -> applicationContext.getBeanFactory().getBeanDefinition(beanName)) .map(BeanDefinition::getBeanClassName) .filter(beanClassName -> String.valueOf(beanClassName).contains("ClientGemFirePropertiesConfigurer")) - .count()).isEqualTo(2); } + .count()).isEqualTo(2); + } @Test public void gemfireCacheSecurityAndSslConfigurationIsCorrect() { assertThat(this.cache).isNotNull(); - //assertThat(this.cache.getName()) - // .isEqualTo(UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.class.getSimpleName()); + assertThat(this.cache.getName()) + .isEqualTo(UsingAnnotationConfigWithBeanDefinitionOverridingDisabledIntegrationTests.class.getSimpleName()); DistributedSystem distributedSystem = this.cache.getDistributedSystem(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java index fcd0a09f..e628a732 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/support/EnableGemFireAsLastResourceIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation.support; import static org.assertj.core.api.Assertions.assertThat; @@ -38,12 +37,12 @@ import org.apache.geode.ra.GFConnectionFactory; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.gemfire.config.annotation.EnableGemFireAsLastResource; import org.springframework.data.gemfire.config.annotation.GemFireAsLastResourceConfiguration; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.stereotype.Service; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; @@ -62,47 +61,39 @@ import org.springframework.transaction.annotation.Transactional; * @see org.apache.geode.ra.GFConnectionFactory * @see org.springframework.data.gemfire.config.annotation.EnableGemFireAsLastResource * @see org.springframework.data.gemfire.config.annotation.GemFireAsLastResourceConfiguration + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.transaction.PlatformTransactionManager * @see org.springframework.transaction.annotation.EnableTransactionManagement * @see org.springframework.transaction.annotation.Transactional * @since 2.0.0 */ -public class EnableGemFireAsLastResourceIntegrationTests { +public class EnableGemFireAsLastResourceIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { - private static List transactionEvents = new ArrayList<>(); + private static final List transactionEvents = new ArrayList<>(); @Before public void setup() { transactionEvents.clear(); } - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - applicationContext.registerShutdownHook(); - return applicationContext; - } - @Test public void configurationIsCorrect() { - ConfigurableApplicationContext applicationContext = - newApplicationContext(TestGemFireAsLastResourceConfiguration.class); + newApplicationContext(TestGemFireAsLastResourceConfiguration.class); - assertThat(applicationContext).isNotNull(); - - GemFireCache gemfireCache = applicationContext.getBean("gemfireCache", GemFireCache.class); + GemFireCache gemfireCache = getBean("gemfireCache", GemFireCache.class); assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getCopyOnRead()).isTrue(); GemFireAsLastResourceConnectionAcquiringAspect connectionAcquiringAspect = - applicationContext.getBean(GemFireAsLastResourceConnectionAcquiringAspect.class); + getBean(GemFireAsLastResourceConnectionAcquiringAspect.class); assertThat(connectionAcquiringAspect).isNotNull(); assertThat(connectionAcquiringAspect.getOrder()).isEqualTo(3); GemFireAsLastResourceConnectionClosingAspect connectionClosingAspect = - applicationContext.getBean(GemFireAsLastResourceConnectionClosingAspect.class); + getBean(GemFireAsLastResourceConnectionClosingAspect.class); assertThat(connectionClosingAspect).isNotNull(); assertThat(connectionClosingAspect.getOrder()).isEqualTo(1); @@ -219,6 +210,7 @@ public class EnableGemFireAsLastResourceIntegrationTests { @Configuration @EnableGemFireAsLastResource @EnableTransactionManagement(order = 2) + @SuppressWarnings("unused") static class TestGemFireAsLastResourceConfiguration { @Bean("gemfireCache") @@ -282,12 +274,12 @@ public class EnableGemFireAsLastResourceIntegrationTests { @Configuration @EnableGemFireAsLastResource - static class TestMissingEnableTransactionManagementAnnotationConfiguration { - } + static class TestMissingEnableTransactionManagementAnnotationConfiguration { } @Configuration @EnableGemFireAsLastResource @EnableTransactionManagement + @SuppressWarnings("unused") static class TestMissingEnableTransactionManagementOrderAttributeConfiguration { @Bean("transactionManager") @@ -298,6 +290,7 @@ public class EnableGemFireAsLastResourceIntegrationTests { @Configuration @Import(TestGemFireAsLastResourceConfiguration.class) + @SuppressWarnings("unused") static class TestSpringApplicationConfiguration { @Bean("TestTransactionalServiceClass") @@ -330,8 +323,8 @@ public class EnableGemFireAsLastResourceIntegrationTests { } - @Service("TestTransactionalServiceClass") @Transactional + @Service("TestTransactionalServiceClass") static class TestTransactionalServiceClass implements TestTransactionalService { public void doInTransactionCommits() { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionNamespaceIntegrationTests.java similarity index 60% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionNamespaceIntegrationTests.java index 69e6771f..50835218 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionNamespaceIntegrationTests.java @@ -25,13 +25,9 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.SubscriptionAttributes; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.PeerRegionFactoryBean; -import org.springframework.data.gemfire.TestUtils; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -44,27 +40,25 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.SubscriptionAttributes * @see org.springframework.data.gemfire.SubscriptionAttributesFactoryBean * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.3.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "subscription-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings({ "rawtypes", "unused" }) -public class CacheSubscriptionTest extends IntegrationTestsSupport { - - @Autowired - private ApplicationContext applicationContext; +public class CacheSubscriptionNamespaceIntegrationTests extends IntegrationTestsSupport { @Test - public void testReplicatedRegionSubscriptionAllPolicy() throws Exception { + public void replicateRegionSubscriptionAllPolicy() { - assertThat(applicationContext.containsBean("replicALL")).isTrue(); + assertThat(requireApplicationContext().containsBean("replicALL")).isTrue(); - PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&replicALL", PeerRegionFactoryBean.class); - RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean); + PeerRegionFactoryBean regionFactoryBean = + requireApplicationContext().getBean("&replicALL", PeerRegionFactoryBean.class); + + RegionAttributes regionAttributes = regionFactoryBean.getAttributes(); assertThat(regionAttributes).isNotNull(); @@ -75,12 +69,14 @@ public class CacheSubscriptionTest extends IntegrationTestsSupport { } @Test - public void testPartitionRegionSubscriptionCacheContentPolicy() throws Exception { + public void partitionRegionSubscriptionCacheContentPolicy() { - assertThat(applicationContext.containsBean("partCACHE_CONTENT")).isTrue(); + assertThat(requireApplicationContext().containsBean("partCACHE_CONTENT")).isTrue(); - PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&partCACHE_CONTENT", PeerRegionFactoryBean.class); - RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean); + PeerRegionFactoryBean regionFactoryBean = + requireApplicationContext().getBean("&partCACHE_CONTENT", PeerRegionFactoryBean.class); + + RegionAttributes regionAttributes = regionFactoryBean.getAttributes(); assertThat(regionAttributes).isNotNull(); @@ -91,12 +87,14 @@ public class CacheSubscriptionTest extends IntegrationTestsSupport { } @Test - public void testPartitionRegionSubscriptionDefaultPolicy() throws Exception { + public void partitionRegionSubscriptionDefaultPolicy() { - assertThat(applicationContext.containsBean("partDEFAULT")).isTrue(); + assertThat(requireApplicationContext().containsBean("partDEFAULT")).isTrue(); - PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&partDEFAULT", PeerRegionFactoryBean.class); - RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean); + PeerRegionFactoryBean regionFactoryBean = + requireApplicationContext().getBean("&partDEFAULT", PeerRegionFactoryBean.class); + + RegionAttributes regionAttributes = regionFactoryBean.getAttributes(); assertThat(regionAttributes).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java index 543db67f..9dcea766 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests.java @@ -22,43 +22,36 @@ import org.junit.runner.RunWith; import org.apache.geode.pdx.PdxSerializer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration Tests with test case testing the SDG XML namespace configuration metadata when PDX is configured - * in Apache Geode. + * Integration Tests testing SDG XML namespace configuration metadata when PDX is configured in Apache Geode. * * @author John Blum * @see org.junit.Test * @see org.apache.geode.pdx.PdxSerializer + * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.3.3 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "cache-using-pdx-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class CacheUsingPdxNamespaceIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; - @Test public void testApplicationContextHasPdxDiskStoreAwareBeanFactoryPostProcessor() { PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor = - applicationContext.getBean(PdxDiskStoreAwareBeanFactoryPostProcessor.class); + requireApplicationContext().getBean(PdxDiskStoreAwareBeanFactoryPostProcessor.class); // NOTE the postProcessor reference will not be null as the ApplicationContext.getBean(:Class) method (getting // a bean by Class type) will throw a NoSuchBeanDefinitionException if no bean of type @@ -71,14 +64,16 @@ public class CacheUsingPdxNamespaceIntegrationTests extends IntegrationTestsSupp @Test public void testCachePdxConfiguration() { - CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + CacheFactoryBean cacheFactoryBean = + requireApplicationContext().getBean("&gemfireCache", CacheFactoryBean.class); assertThat(cacheFactoryBean).isNotNull(); assertThat(cacheFactoryBean.getPdxDiskStoreName()).isEqualTo("pdxStore"); assertThat(Boolean.TRUE.equals(cacheFactoryBean.getPdxPersistent())).isTrue(); assertThat(Boolean.TRUE.equals(cacheFactoryBean.getPdxReadSerialized())).isTrue(); - PdxSerializer autoSerializer = applicationContext.getBean("autoSerializer", PdxSerializer.class); + PdxSerializer autoSerializer = + requireApplicationContext().getBean("autoSerializer", PdxSerializer.class); assertThat(autoSerializer).isNotNull(); assertThat(cacheFactoryBean.getPdxSerializer()).isSameAs(autoSerializer); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceIntegrationTests.java index 3cffb91c..39711d5a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceIntegrationTests.java @@ -15,17 +15,12 @@ */ package org.springframework.data.gemfire.config.xml; -import static java.util.Arrays.stream; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; -import java.io.File; - -import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,16 +40,13 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.apache.geode.cache.util.CacheWriterAdapter; import org.apache.geode.compression.Compressor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.SimpleCacheListener; import org.springframework.data.gemfire.SimpleObjectSizer; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.Interest; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; @@ -69,41 +61,53 @@ import org.springframework.util.ObjectUtils; * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean * @see org.springframework.data.gemfire.config.xml.ClientRegionParser * @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.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "client-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; + private void assertInterest(boolean expectedDurable, boolean expectedReceiveValues, - @AfterClass - public static void tearDown() { - stream(nullSafeArray(new File(".").list((dir, name) -> name.startsWith("BACKUP")), String.class)) - .forEach(fileName -> new File(fileName).delete()); + InterestResultPolicy expectedPolicy, Interest actualInterest) { + + assertThat(actualInterest).isNotNull(); + assertThat(actualInterest.isDurable()).isEqualTo(expectedDurable); + assertThat(actualInterest.isReceiveValues()).isEqualTo(expectedReceiveValues); + assertThat(actualInterest.getPolicy()).isEqualTo(expectedPolicy); + } + + @SuppressWarnings("rawtypes") + private Interest getInterestWithKey(String key, Interest... interests) { + + for (Interest interest : interests) { + if (interest.getKey().equals(key)) { + return interest; + } + } + + return null; } @Test - public void testBeanNames() { + public void beanNamesAreCorrect() { - assertThat(applicationContext.containsBean("SimpleRegion")).isTrue(); - assertThat(applicationContext.containsBean("Publisher")).isTrue(); - assertThat(applicationContext.containsBean("ComplexRegion")).isTrue(); - assertThat(applicationContext.containsBean("PersistentRegion")).isTrue(); - assertThat(applicationContext.containsBean("OverflowRegion")).isTrue(); - assertThat(applicationContext.containsBean("Compressed")).isTrue(); + assertThat(requireApplicationContext().containsBean("SimpleRegion")).isTrue(); + assertThat(requireApplicationContext().containsBean("Publisher")).isTrue(); + assertThat(requireApplicationContext().containsBean("ComplexRegion")).isTrue(); + assertThat(requireApplicationContext().containsBean("PersistentRegion")).isTrue(); + assertThat(requireApplicationContext().containsBean("OverflowRegion")).isTrue(); + assertThat(requireApplicationContext().containsBean("Compressed")).isTrue(); } @Test - public void testSimpleClientRegion() { + public void simpleClientRegionConfigurationIsCorrect() { - assertThat(applicationContext.containsBean("simple")).isTrue(); + assertThat(requireApplicationContext().containsBean("simple")).isTrue(); - Region simple = applicationContext.getBean("simple", Region.class); + Region simple = requireApplicationContext().getBean("simple", Region.class); assertThat(simple).as("The 'SimpleRegion' Client Region was not properly configured and initialized!") .isNotNull(); @@ -115,12 +119,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo @Test @SuppressWarnings("rawtypes") - public void testPublishingClientRegion() throws Exception { + public void publishingClientRegionConfigurationIsCorrect() throws Exception { - assertThat(applicationContext.containsBean("empty")).isTrue(); + assertThat(requireApplicationContext().containsBean("empty")).isTrue(); - ClientRegionFactoryBean emptyClientRegionFactoryBean = applicationContext - .getBean("&empty", ClientRegionFactoryBean.class); + ClientRegionFactoryBean emptyClientRegionFactoryBean = + requireApplicationContext().getBean("&empty", ClientRegionFactoryBean.class); assertThat(emptyClientRegionFactoryBean).isNotNull(); assertThat(TestUtils.readField("dataPolicy", emptyClientRegionFactoryBean)).isEqualTo(DataPolicy.EMPTY); @@ -131,12 +135,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo @Test @SuppressWarnings("rawtypes") - public void testComplexClientRegion() throws Exception { + public void complexClientRegionConfigurationIsCorrect() throws Exception { - assertThat(applicationContext.containsBean("complex")).isTrue(); + assertThat(requireApplicationContext().containsBean("complex")).isTrue(); - ClientRegionFactoryBean complexClientRegionFactoryBean = applicationContext - .getBean("&complex", ClientRegionFactoryBean.class); + ClientRegionFactoryBean complexClientRegionFactoryBean = + requireApplicationContext().getBean("&complex", ClientRegionFactoryBean.class); assertThat(complexClientRegionFactoryBean).isNotNull(); @@ -144,7 +148,7 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo assertThat(ObjectUtils.isEmpty(cacheListeners)).isFalse(); assertThat(cacheListeners.length).isEqualTo(2); - assertThat(applicationContext.getBean("c-listener")).isSameAs(cacheListeners[0]); + assertThat(requireApplicationContext().getBean("c-listener")).isSameAs(cacheListeners[0]); assertThat(cacheListeners[1] instanceof SimpleCacheListener).isTrue(); assertThat(cacheListeners[1]).isNotSameAs(cacheListeners[0]); @@ -160,11 +164,11 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo @Test @SuppressWarnings("rawtypes") - public void testPersistentClientRegion() { + public void persistentClientRegionConfigurationIsCorrect() { - assertThat(applicationContext.containsBean("persistent")).isTrue(); + assertThat(requireApplicationContext().containsBean("persistent")).isTrue(); - Region persistent = applicationContext.getBean("persistent", Region.class); + Region persistent = requireApplicationContext().getBean("persistent", Region.class); assertThat(persistent) .describedAs("The 'PersistentRegion' Region was not properly configured and initialized!") @@ -182,12 +186,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo @Test @SuppressWarnings("rawtypes") - public void testOverflowClientRegion() throws Exception { + public void overflowClientRegionConfigurationIsCorrect() throws Exception { - assertThat(applicationContext.containsBean("overflow")).isTrue(); + assertThat(requireApplicationContext().containsBean("overflow")).isTrue(); - ClientRegionFactoryBean overflowClientRegionFactoryBean = applicationContext - .getBean("&overflow", ClientRegionFactoryBean.class); + ClientRegionFactoryBean overflowClientRegionFactoryBean = + requireApplicationContext().getBean("&overflow", ClientRegionFactoryBean.class); assertThat(overflowClientRegionFactoryBean).isNotNull(); assertThat(TestUtils.readField("diskStoreName", overflowClientRegionFactoryBean)).isEqualTo("diskStore"); @@ -209,12 +213,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo } @Test - public void testClientRegionWithCacheLoaderAndCacheWriter() throws Exception { + public void clientRegionWithCacheLoaderAndCacheWriterConfigurationIsCorrect() throws Exception { - assertThat(applicationContext.containsBean("loadWithWrite")).isTrue(); + assertThat(requireApplicationContext().containsBean("loadWithWrite")).isTrue(); ClientRegionFactoryBean factory = - applicationContext.getBean("&loadWithWrite", ClientRegionFactoryBean.class); + requireApplicationContext().getBean("&loadWithWrite", ClientRegionFactoryBean.class); assertThat(factory).isNotNull(); assertThat(TestUtils.readField("name", factory)).isEqualTo("LoadedFullOfWrites"); @@ -224,11 +228,11 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo } @Test - public void testCompressedReplicateRegion() { + public void compressedReplicateRegionConfigurationIsCorrect() { - assertThat(applicationContext.containsBean("Compressed")).isTrue(); + assertThat(requireApplicationContext().containsBean("Compressed")).isTrue(); - Region compressed = applicationContext.getBean("Compressed", Region.class); + Region compressed = requireApplicationContext().getBean("Compressed", Region.class); assertThat(compressed).as("The 'Compressed' Client Region was not properly configured and initialized!") .isNotNull(); @@ -238,21 +242,25 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo assertThat(compressed.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.EMPTY); assertThat(compressed.getAttributes().getPoolName()).isEqualTo("gemfire-pool"); assertThat(compressed.getAttributes().getCompressor() instanceof TestCompressor) - .as(String.format("Expected 'TestCompressor'; but was '%1$s'!", - ObjectUtils.nullSafeClassName(compressed.getAttributes().getCompressor()))).isTrue(); + .describedAs(String.format("Expected 'TestCompressor'; but was '%s'!", + ObjectUtils.nullSafeClassName(compressed.getAttributes().getCompressor()))) + .isTrue(); assertThat(compressed.getAttributes().getCompressor().toString()).isEqualTo("STD"); } @Test @SuppressWarnings("unchecked") - public void testClientRegionWithAttributes() { + public void clientRegionWithAttributesConfigurationIsCorrect() { - assertThat(applicationContext.containsBean("client-with-attributes")).isTrue(); + assertThat(requireApplicationContext().containsBean("client-with-attributes")).isTrue(); - Region clientRegion = applicationContext.getBean("client-with-attributes", Region.class); + Region clientRegion = + requireApplicationContext().getBean("client-with-attributes", Region.class); assertThat(clientRegion) - .as("The 'client-with-attributes' Client Region was not properly configured and initialized!").isNotNull(); + .describedAs("The 'client-with-attributes' Client Region was not properly configured and initialized!") + .isNotNull(); + assertThat(clientRegion.getName()).isEqualTo("client-with-attributes"); assertThat(clientRegion.getFullPath()).isEqualTo(Region.SEPARATOR + "client-with-attributes"); assertThat(clientRegion.getAttributes()).isNotNull(); @@ -270,12 +278,12 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo @Test @SuppressWarnings("unchecked") - public void testClientRegionWithRegisteredInterests() throws Exception { + public void clientRegionWithRegisteredInterestsConfigurationIsCorrect() throws Exception { - assertThat(applicationContext.containsBean("client-with-interests")).isTrue(); + assertThat(requireApplicationContext().containsBean("client-with-interests")).isTrue(); ClientRegionFactoryBean factoryBean = - applicationContext.getBean("&client-with-interests", ClientRegionFactoryBean.class); + requireApplicationContext().getBean("&client-with-interests", ClientRegionFactoryBean.class); assertThat(factoryBean).isNotNull(); @@ -287,7 +295,8 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo assertInterest(true, false, InterestResultPolicy.KEYS, getInterestWithKey(".*", interests)); assertInterest(true, false, InterestResultPolicy.KEYS_VALUES, getInterestWithKey("keyPrefix.*", interests)); - Region mockClientRegion = applicationContext.getBean("client-with-interests", Region.class); + Region mockClientRegion = + requireApplicationContext().getBean("client-with-interests", Region.class); assertThat(mockClientRegion).isNotNull(); @@ -298,27 +307,6 @@ public class ClientRegionNamespaceIntegrationTests extends IntegrationTestsSuppo eq(InterestResultPolicy.KEYS_VALUES), eq(true), eq(false)); } - private void assertInterest(boolean expectedDurable, boolean expectedReceiveValues, - InterestResultPolicy expectedPolicy, Interest actualInterest) { - - assertThat(actualInterest).isNotNull(); - assertThat(actualInterest.isDurable()).isEqualTo(expectedDurable); - assertThat(actualInterest.isReceiveValues()).isEqualTo(expectedReceiveValues); - assertThat(actualInterest.getPolicy()).isEqualTo(expectedPolicy); - } - - @SuppressWarnings("rawtypes") - private Interest getInterestWithKey(String key, Interest... interests) { - - for (Interest interest : interests) { - if (interest.getKey().equals(key)) { - return interest; - } - } - - return null; - } - public static final class TestCacheLoader implements CacheLoader { @Override diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutIntegrationTests.java index 84b2e27f..ab9e453d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutIntegrationTests.java @@ -25,6 +25,7 @@ import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; /** * Integration Tests for client {@link Region} bean definition with both {@literal data-policy}(i.e. {@link DataPolicy}) @@ -36,16 +37,17 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.client.ClientRegionShortcut * @see org.springframework.context.support.ClassPathXmlApplicationContext + * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @since 1.3.3 */ -public class ClientRegionUsingDataPolicyAndShortcutIntegrationTests { +public class ClientRegionUsingDataPolicyAndShortcutIntegrationTests extends IntegrationTestsSupport { @Test(expected = BeanDefinitionParsingException.class) public void testClientRegionBeanDefinitionWithDataPolicyAndShortcut() { try { - new ClassPathXmlApplicationContext( - "/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml"); + new ClassPathXmlApplicationContext(getContextXmlFileLocation(ClientRegionUsingDataPolicyAndShortcutIntegrationTests.class)); } catch (BeanDefinitionParsingException expected) { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java deleted file mode 100644 index dd3e3302..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreEvictionAndExpirationRegionParsingIntegrationTests.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright 2010-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.gemfire.config.xml; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; - -import java.io.File; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CustomExpiry; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.DiskStore; -import org.apache.geode.cache.DiskStoreFactory; -import org.apache.geode.cache.EvictionAction; -import org.apache.geode.cache.EvictionAlgorithm; -import org.apache.geode.cache.EvictionAttributes; -import org.apache.geode.cache.ExpirationAction; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.Region.Entry; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.Scope; -import org.apache.geode.cache.util.ObjectSizer; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.PartitionedRegionFactoryBean; -import org.springframework.data.gemfire.PeerRegionFactoryBean; -import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; -import org.springframework.data.gemfire.SimpleObjectSizer; -import org.springframework.data.gemfire.TestUtils; -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.SpringRunner; -import org.springframework.util.FileSystemUtils; - -/** - * Integration Tests for {@link Region}, {@link EvictionAttributes} and {@link DiskStore} SDG XML namespace - * configuration metadata parsing. - * - * @author Costin Leau - * @author David Turanski - * @author John Blum - * @see org.junit.Test - * @see org.apache.geode.cache.DiskStore - * @see org.apache.geode.cache.ExpirationAttributes - * @see org.apache.geode.cache.EvictionAttributes - * @see org.apache.geode.cache.Region - * @see org.apache.geode.cache.RegionAttributes - * @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(SpringRunner.class) -@ContextConfiguration(locations = "diskstore-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) -@SuppressWarnings("unused") -// TODO: Move test cases into a DiskStoreIntegrationTests class -public class DiskStoreEvictionAndExpirationRegionParsingIntegrationTests extends IntegrationTestsSupport { - - private static File diskStoreDirectory; - - @Autowired - private ApplicationContext applicationContext; - - @Autowired - @Qualifier("diskStore1") - private DiskStore diskStore; - - @BeforeClass - public static void setUp() { - diskStoreDirectory = new File("./tmp"); - assertThat(diskStoreDirectory.isDirectory() || diskStoreDirectory.mkdirs()).isTrue(); - } - - @AfterClass - public static void tearDown() { - - FileSystemUtils.deleteRecursively(diskStoreDirectory); - - for (String name : nullSafeArray(new File(".") - .list((dir, name) -> name.startsWith("BACKUP")), String.class)) { - - new File(name).delete(); - } - } - - @Test - public void testDiskStore() { - - assertThat(applicationContext.getBean("ds2")).isNotNull(); - applicationContext.getBean("diskStore1"); - assertThat(diskStore).isNotNull(); - assertThat(diskStore.getName()).isEqualTo("diskStore1"); - assertThat(diskStore.getQueueSize()).isEqualTo(50); - assertThat(diskStore.getAutoCompact()).isTrue(); - assertThat(diskStore.getCompactionThreshold()).isEqualTo(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD); - assertThat(diskStore.getTimeInterval()).isEqualTo(9999); - assertThat(diskStore.getMaxOplogSize()).isEqualTo(1); - assertThat(diskStore.getDiskDirs()[0]).isEqualTo(diskStoreDirectory); - Cache cache = applicationContext.getBean("gemfireCache", Cache.class); - assertThat(cache.findDiskStore("diskStore1")).isSameAs(diskStore); - } - - @Test - @SuppressWarnings("rawtypes") - public void testReplicatedDataRegionAttributes() throws Exception { - - assertThat(applicationContext.containsBean("replicated-data")).isTrue(); - - PeerRegionFactoryBean replicatedDataRegionFactoryBean = applicationContext.getBean("&replicated-data", PeerRegionFactoryBean.class); - - assertThat(replicatedDataRegionFactoryBean instanceof ReplicatedRegionFactoryBean).isTrue(); - assertThat(replicatedDataRegionFactoryBean.getDataPolicy()).isEqualTo(DataPolicy.REPLICATE); - assertThat(replicatedDataRegionFactoryBean.getDataPolicy().withPersistence()).isFalse(); - assertThat(TestUtils.readField("diskStoreName", replicatedDataRegionFactoryBean)).isEqualTo("diskStore1"); - assertThat(TestUtils.readField("scope", replicatedDataRegionFactoryBean)).isNull(); - - Region replicatedDataRegion = applicationContext.getBean("replicated-data", Region.class); - - RegionAttributes replicatedDataRegionAttributes = TestUtils.readField("attributes", replicatedDataRegionFactoryBean); - - assertThat(replicatedDataRegionAttributes).isNotNull(); - assertThat(replicatedDataRegionAttributes.getScope()).isEqualTo(Scope.DISTRIBUTED_NO_ACK); - - EvictionAttributes replicatedDataEvictionAttributes = replicatedDataRegionAttributes.getEvictionAttributes(); - - assertThat(replicatedDataEvictionAttributes).isNotNull(); - assertThat(replicatedDataEvictionAttributes.getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); - assertThat(replicatedDataEvictionAttributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_ENTRY); - assertThat(replicatedDataEvictionAttributes.getMaximum()).isEqualTo(50); - assertThat(replicatedDataEvictionAttributes.getObjectSizer()).isNull(); - } - - @Test - @SuppressWarnings("rawtypes") - public void testPartitionDataOptions() throws Exception { - - assertThat(applicationContext.containsBean("partition-data")).isTrue(); - - PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("&partition-data", PeerRegionFactoryBean.class); - - assertThat(regionFactoryBean instanceof PartitionedRegionFactoryBean).isTrue(); - assertThat(TestUtils.readField("persistent", regionFactoryBean)).isTrue(); - RegionAttributes attrs = TestUtils.readField("attributes", regionFactoryBean); - - EvictionAttributes evicAttr = attrs.getEvictionAttributes(); - - assertThat(evicAttr.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY); - assertThat(evicAttr.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_MEMORY); - - ObjectSizer sizer = evicAttr.getObjectSizer(); - - assertThat(sizer.getClass()).isEqualTo(SimpleObjectSizer.class); - } - - @Test - @SuppressWarnings("rawtypes") - public void testEntryTtl() throws Exception { - - assertThat(applicationContext.containsBean("replicated-data")).isTrue(); - - PeerRegionFactoryBean fb = applicationContext.getBean("&replicated-data", PeerRegionFactoryBean.class); - RegionAttributes attrs = TestUtils.readField("attributes", fb); - - ExpirationAttributes entryTTL = attrs.getEntryTimeToLive(); - assertThat(entryTTL.getTimeout()).isEqualTo(100); - assertThat(entryTTL.getAction()).isEqualTo(ExpirationAction.DESTROY); - - ExpirationAttributes entryTTI = attrs.getEntryIdleTimeout(); - assertThat(entryTTI.getTimeout()).isEqualTo(200); - assertThat(entryTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE); - - ExpirationAttributes regionTTL = attrs.getRegionTimeToLive(); - assertThat(regionTTL.getTimeout()).isEqualTo(300); - assertThat(regionTTL.getAction()).isEqualTo(ExpirationAction.DESTROY); - - ExpirationAttributes regionTTI = attrs.getRegionIdleTimeout(); - assertThat(regionTTI.getTimeout()).isEqualTo(400); - assertThat(regionTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE); - } - - - @Test - @SuppressWarnings("rawtypes") - public void testCustomExpiry() throws Exception { - - assertThat(applicationContext.containsBean("replicated-data-custom-expiry")).isTrue(); - - PeerRegionFactoryBean fb = applicationContext.getBean("&replicated-data-custom-expiry", PeerRegionFactoryBean.class); - RegionAttributes attrs = TestUtils.readField("attributes", fb); - - assertThat(attrs.getCustomEntryIdleTimeout()).isNotNull(); - assertThat(attrs.getCustomEntryTimeToLive()).isNotNull(); - - assertThat(attrs.getCustomEntryIdleTimeout() instanceof TestCustomExpiry).isTrue(); - assertThat(attrs.getCustomEntryTimeToLive() instanceof TestCustomExpiry).isTrue(); - } - - public static class TestCustomExpiry implements CustomExpiry { - - @Override - public ExpirationAttributes getExpiry(Entry entry) { - return null; - } - - @Override - public void close() { } - - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java index 5d369f74..d3654bf1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceIntegrationTests.java @@ -20,16 +20,37 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.util.Properties; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.CustomExpiry; +import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.DiskStore; +import org.apache.geode.cache.DiskStoreFactory; +import org.apache.geode.cache.EvictionAction; +import org.apache.geode.cache.EvictionAlgorithm; +import org.apache.geode.cache.EvictionAttributes; +import org.apache.geode.cache.ExpirationAction; +import org.apache.geode.cache.ExpirationAttributes; +import org.apache.geode.cache.GemFireCache; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionAttributes; +import org.apache.geode.cache.Scope; +import org.apache.geode.cache.util.ObjectSizer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.gemfire.PartitionedRegionFactoryBean; +import org.springframework.data.gemfire.PeerRegionFactoryBean; +import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; +import org.springframework.data.gemfire.SimpleObjectSizer; +import org.springframework.data.gemfire.TestUtils; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; +import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.test.context.junit4.SpringRunner; /** @@ -39,43 +60,210 @@ import org.springframework.test.context.junit4.SpringRunner; * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.DiskStore + * @see org.springframework.data.gemfire.DiskStoreFactoryBean * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.0.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "diskstore-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class DiskStoreNamespaceIntegrationTests extends IntegrationTestsSupport { + private static File diskStoreDirectory; + + @Autowired + private GemFireCache cache; + + @Autowired + @Qualifier("diskStore1") + private DiskStore diskStoreOne; + + @Autowired + @Qualifier("ds2") + private DiskStore diskStoreTwo; + @Autowired @Qualifier("fullyConfiguredDiskStore") - private DiskStore diskStore; + private DiskStore fullyConfiguredDiskStore; @Autowired - @Qualifier("props") - private Properties props; + @Qualifier("diskStoreProperties") + private Properties diskStoreProperties; + + @BeforeClass + public static void createDiskStoreDirectory() { + createDirectory(diskStoreDirectory = new File("./tmp")); + diskStoreDirectory.deleteOnExit(); + } + + @AfterClass + public static void deleteDiskStoreDirectory() { + + FileSystemUtils.deleteRecursive(diskStoreDirectory); + + for (String name : ArrayUtils.nullSafeArray(FileSystemUtils.WORKING_DIRECTORY + .list((dir, name) -> name.startsWith("BACKUP")), String.class)) { + new File(name).delete(); + } + } @Test - public void testDiskStoreConfiguration() { + public void diskStoreOneIsAccessibleFromTheCache() { + assertThat(this.cache.findDiskStore("diskStore1")).isSameAs(this.diskStoreOne); + } + + @Test + public void diskStoreTwoConfigurationIsCorrect() { + + assertThat(diskStoreTwo).isNotNull(); + assertThat(diskStoreTwo.getName()).isEqualTo("ds2"); + assertThat(diskStoreTwo.getQueueSize()).isEqualTo(50); + assertThat(diskStoreTwo.getAutoCompact()).isTrue(); + assertThat(diskStoreTwo.getCompactionThreshold()).isEqualTo(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD); + assertThat(diskStoreTwo.getTimeInterval()).isEqualTo(9999); + assertThat(diskStoreTwo.getMaxOplogSize()).isEqualTo(1); + assertThat(diskStoreTwo.getDiskDirs()[0]).isEqualTo(diskStoreDirectory.getParentFile()); + } + + @Test + public void fullyConfiguredDiskStoreConfigurationIsCorrect() { + + assertThat(fullyConfiguredDiskStore) + .describedAs("The 'fullyConfiguredDiskStore' was not properly configured and initialized") + .isNotNull(); + + assertThat(fullyConfiguredDiskStore.getName()).isEqualTo("fullyConfiguredDiskStore"); + assertThat(fullyConfiguredDiskStore.getAllowForceCompaction()).isEqualTo(Boolean.valueOf(diskStoreProperties.getProperty("allowForceCompaction"))); + assertThat(fullyConfiguredDiskStore.getAutoCompact()).isEqualTo(Boolean.valueOf(diskStoreProperties.getProperty("autoCompact"))); + assertThat(Long.valueOf(fullyConfiguredDiskStore.getCompactionThreshold())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("compactionThreshold"))); + assertThat(Double.valueOf(fullyConfiguredDiskStore.getDiskUsageCriticalPercentage())).isEqualTo(Double.valueOf(diskStoreProperties.getProperty("diskUsageCriticalPercentage"))); + assertThat(Double.valueOf(fullyConfiguredDiskStore.getDiskUsageWarningPercentage())).isEqualTo(Double.valueOf(diskStoreProperties.getProperty("diskUsageWarningPercentage"))); + assertThat(Long.valueOf(fullyConfiguredDiskStore.getMaxOplogSize())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("maxOplogSize"))); + assertThat(Long.valueOf(fullyConfiguredDiskStore.getQueueSize())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("queueSize"))); + assertThat(Long.valueOf(fullyConfiguredDiskStore.getTimeInterval())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("timeInterval"))); + assertThat(Long.valueOf(fullyConfiguredDiskStore.getWriteBufferSize())).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("writeBufferSize"))); + assertThat(fullyConfiguredDiskStore.getDiskDirs()).isNotNull(); + assertThat(fullyConfiguredDiskStore.getDiskDirs().length).isEqualTo(1); + assertThat(fullyConfiguredDiskStore.getDiskDirs()[0]).isEqualTo(new File(diskStoreProperties.getProperty("location"))); + assertThat(Long.valueOf(fullyConfiguredDiskStore.getDiskDirSizes()[0])).isEqualTo(Long.valueOf(diskStoreProperties.getProperty("maxSize"))); + } + + @Test + @SuppressWarnings("rawtypes") + public void replicatedDataRegionAttributesIsConfiguredCorrectly() throws Exception { + + assertThat(requireApplicationContext().containsBean("replicated-data")).isTrue(); + + PeerRegionFactoryBean replicatedDataRegionFactoryBean = + requireApplicationContext().getBean("&replicated-data", PeerRegionFactoryBean.class); + + assertThat(replicatedDataRegionFactoryBean instanceof ReplicatedRegionFactoryBean).isTrue(); + assertThat(replicatedDataRegionFactoryBean.getDataPolicy()).isEqualTo(DataPolicy.REPLICATE); + assertThat(replicatedDataRegionFactoryBean.getDataPolicy().withPersistence()).isFalse(); + assertThat(TestUtils.readField("diskStoreName", replicatedDataRegionFactoryBean)).isEqualTo("diskStore1"); + assertThat(TestUtils.readField("scope", replicatedDataRegionFactoryBean)).isNull(); + + Region replicatedDataRegion = requireApplicationContext().getBean("replicated-data", Region.class); + + RegionAttributes replicatedDataRegionAttributes = TestUtils.readField("attributes", replicatedDataRegionFactoryBean); + + assertThat(replicatedDataRegionAttributes).isNotNull(); + assertThat(replicatedDataRegionAttributes.getScope()).isEqualTo(Scope.DISTRIBUTED_NO_ACK); + + EvictionAttributes replicatedDataEvictionAttributes = replicatedDataRegionAttributes.getEvictionAttributes(); + + assertThat(replicatedDataEvictionAttributes).isNotNull(); + assertThat(replicatedDataEvictionAttributes.getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); + assertThat(replicatedDataEvictionAttributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_ENTRY); + assertThat(replicatedDataEvictionAttributes.getMaximum()).isEqualTo(50); + assertThat(replicatedDataEvictionAttributes.getObjectSizer()).isNull(); + } + + @Test + @SuppressWarnings("rawtypes") + public void partitionDataOptionsAreCorrect() throws Exception { + + assertThat(requireApplicationContext().containsBean("partition-data")).isTrue(); + + PeerRegionFactoryBean regionFactoryBean = + requireApplicationContext().getBean("&partition-data", PeerRegionFactoryBean.class); + + assertThat(regionFactoryBean).isInstanceOf(PartitionedRegionFactoryBean.class); + assertThat(TestUtils.readField("persistent", regionFactoryBean)).isTrue(); + + RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean); + + assertThat(regionAttributes).isNotNull(); + + EvictionAttributes evictionAttributes = regionAttributes.getEvictionAttributes(); + + assertThat(evictionAttributes.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY); + assertThat(evictionAttributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_MEMORY); + + ObjectSizer sizer = evictionAttributes.getObjectSizer(); + + assertThat(sizer.getClass()).isEqualTo(SimpleObjectSizer.class); + } + + @Test + @SuppressWarnings("rawtypes") + public void entryTtlConfigurationIsCorrect() throws Exception { + + assertThat(requireApplicationContext().containsBean("replicated-data")).isTrue(); + + PeerRegionFactoryBean regionFactoryBean = + requireApplicationContext().getBean("&replicated-data", PeerRegionFactoryBean.class); + + RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean); + + ExpirationAttributes entryTTL = regionAttributes.getEntryTimeToLive(); + + assertThat(entryTTL.getTimeout()).isEqualTo(100); + assertThat(entryTTL.getAction()).isEqualTo(ExpirationAction.DESTROY); + + ExpirationAttributes entryTTI = regionAttributes.getEntryIdleTimeout(); + + assertThat(entryTTI.getTimeout()).isEqualTo(200); + assertThat(entryTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE); + + ExpirationAttributes regionTTL = regionAttributes.getRegionTimeToLive(); + + assertThat(regionTTL.getTimeout()).isEqualTo(300); + assertThat(regionTTL.getAction()).isEqualTo(ExpirationAction.DESTROY); + + ExpirationAttributes regionTTI = regionAttributes.getRegionIdleTimeout(); + + assertThat(regionTTI.getTimeout()).isEqualTo(400); + assertThat(regionTTI.getAction()).isEqualTo(ExpirationAction.INVALIDATE); + } + + @Test + @SuppressWarnings("rawtypes") + public void testCustomExpiry() throws Exception { + + assertThat(requireApplicationContext().containsBean("replicated-data-with-custom-expiry")).isTrue(); + + PeerRegionFactoryBean regionFactoryBean = + requireApplicationContext().getBean("&replicated-data-with-custom-expiry", PeerRegionFactoryBean.class); + + RegionAttributes regionAttributes = TestUtils.readField("attributes", regionFactoryBean); + + assertThat(regionAttributes.getCustomEntryIdleTimeout()).isInstanceOf(TestCustomExpiry.class); + assertThat(regionAttributes.getCustomEntryTimeToLive()).isInstanceOf(TestCustomExpiry.class); + } + + public static class TestCustomExpiry implements CustomExpiry { + + @Override + public ExpirationAttributes getExpiry(Region.Entry entry) { + return null; + } + + @Override + public void close() { } - assertThat(diskStore).as("The 'fullyConfiguredDiskStore' was not properly configured and initialized").isNotNull(); - assertThat(diskStore.getName()).isEqualTo("fullyConfiguredDiskStore"); - assertThat(diskStore.getAllowForceCompaction()).isEqualTo(Boolean.valueOf(props.getProperty("allowForceCompaction"))); - assertThat(diskStore.getAutoCompact()).isEqualTo(Boolean.valueOf(props.getProperty("autoCompact"))); - assertThat(Long.valueOf(diskStore.getCompactionThreshold())).isEqualTo(Long.valueOf(props.getProperty("compactionThreshold"))); - assertThat(Double.valueOf(diskStore.getDiskUsageCriticalPercentage())).isEqualTo(Double.valueOf(props.getProperty("diskUsageCriticalPercentage"))); - assertThat(Double.valueOf(diskStore.getDiskUsageWarningPercentage())).isEqualTo(Double.valueOf(props.getProperty("diskUsageWarningPercentage"))); - assertThat(Long.valueOf(diskStore.getMaxOplogSize())).isEqualTo(Long.valueOf(props.getProperty("maxOplogSize"))); - assertThat(Long.valueOf(diskStore.getQueueSize())).isEqualTo(Long.valueOf(props.getProperty("queueSize"))); - assertThat(Long.valueOf(diskStore.getTimeInterval())).isEqualTo(Long.valueOf(props.getProperty("timeInterval"))); - assertThat(Long.valueOf(diskStore.getWriteBufferSize())).isEqualTo(Long.valueOf(props.getProperty("writeBufferSize"))); - assertThat(diskStore.getDiskDirs()).isNotNull(); - assertThat(diskStore.getDiskDirs().length).isEqualTo(1); - assertThat(diskStore.getDiskDirs()[0]).isEqualTo(new File(props.getProperty("location"))); - assertThat(Long.valueOf(diskStore.getDiskDirSizes()[0])).isEqualTo(Long.valueOf(props.getProperty("maxSize"))); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests.java index 79172a98..89df51f9 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests.java @@ -25,8 +25,7 @@ import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.cache.execute.FunctionService; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -41,25 +40,24 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.execute.FunctionContext * @see org.apache.geode.cache.execute.FunctionService * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations="function-service-ns.xml", - initializers= GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class FunctionServiceNamespaceIntegrationTests extends IntegrationTestsSupport { @Test - public void testFunctionsRegistered() { + public void functionsAreRegistered() { assertThat(FunctionService.getRegisteredFunctions().size()).isEqualTo(2); assertThat(FunctionService.getFunction("function1")).isNotNull(); assertThat(FunctionService.getFunction("function2")).isNotNull(); } - public static class Function1 implements Function { + public static class FunctionOne implements Function { @Override public void execute(FunctionContext functionContext) { } @@ -70,7 +68,7 @@ public class FunctionServiceNamespaceIntegrationTests extends IntegrationTestsSu } } - public static class Function2 implements Function { + public static class FunctionTwo implements Function { @Override public void execute(FunctionContext functionContext) { } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceIntegrationTests.java similarity index 84% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceIntegrationTests.java index a574c3a3..5c632bfc 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceIntegrationTests.java @@ -17,12 +17,10 @@ package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.InputStream; import java.io.OutputStream; import java.util.List; -import org.junit.AfterClass; import org.junit.Test; import org.apache.geode.cache.Region; @@ -40,7 +38,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; +import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; /** @@ -53,34 +51,28 @@ import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; * @see org.apache.geode.cache.wan.GatewayReceiver * @see org.apache.geode.cache.wan.GatewaySender * @see org.springframework.data.gemfire.RecreatingSpringApplicationContextTest + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean + * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean */ @SuppressWarnings("unused") -public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationContextTest { - - @AfterClass - public static void tearDown() { - - for (String name : new File(".").list((file, filename) -> filename.startsWith("BACKUP"))) { - new File(name).delete(); - } - } +public class GemfireV7GatewayNamespaceIntegrationTests extends RecreatingSpringApplicationContextTest { @Override protected T configureContext(T context) { - context.getBeanFactory().addBeanPostProcessor(new GemFireMockObjectsBeanPostProcessor()); + new GemFireMockObjectsApplicationContextInitializer().initialize(context); return context; } @Override protected String location() { - return "/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml"; + return getContextXmlFileLocation(GemfireV7GatewayNamespaceIntegrationTests.class); } @Test public void asyncEventQueueConfigurationIsCorrect() { - AsyncEventQueue asyncEventQueue = - this.applicationContext.getBean("async-event-queue", AsyncEventQueue.class); + AsyncEventQueue asyncEventQueue = getBean("async-event-queue", AsyncEventQueue.class); assertThat(asyncEventQueue).isNotNull(); assertThat(asyncEventQueue.isBatchConflationEnabled()).isTrue(); @@ -98,7 +90,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo public void gatewaySenderFactoryBeanConfigurationIsCorrect() throws Exception { GatewaySenderFactoryBean gatewaySenderFactoryBean = - this.applicationContext.getBean("&gateway-sender", GatewaySenderFactoryBean.class); + getBean("&gateway-sender", GatewaySenderFactoryBean.class); assertThat(gatewaySenderFactoryBean).isNotNull(); assertThat(gatewaySenderFactoryBean.getCache()).isNotNull(); @@ -127,14 +119,15 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo @SuppressWarnings("rawtypes") public void nestedGatewaySenderConfigurationIsCorrect() throws Exception { - Region region = this.applicationContext.getBean("region-with-nested-gateway-sender", Region.class); + Region region = getBean("region-with-nested-gateway-sender", Region.class); assertThat(region).isNotNull(); assertThat(region.getAttributes()).isNotNull(); assertThat(region.getAttributes().getGatewaySenderIds()).isNotNull(); assertThat(region.getAttributes().getGatewaySenderIds()).hasSize(2); - PeerRegionFactoryBean regionFactoryBean = applicationContext.getBean("®ion-with-nested-gateway-sender", PeerRegionFactoryBean.class); + PeerRegionFactoryBean regionFactoryBean = + getBean("®ion-with-nested-gateway-sender", PeerRegionFactoryBean.class); List gatewaySenders = TestUtils.readField("gatewaySenders", regionFactoryBean); @@ -178,8 +171,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo public void gatewaySenderWithEventTransportFilterRefsConfigurationIsCorrect() throws Exception { GatewaySenderFactoryBean gatewaySenderFactoryBean = - this.applicationContext.getBean("&gateway-sender-with-event-transport-filter-refs", - GatewaySenderFactoryBean.class); + getBean("&gateway-sender-with-event-transport-filter-refs", GatewaySenderFactoryBean.class); assertThat(gatewaySenderFactoryBean).isNotNull(); assertThat(gatewaySenderFactoryBean.getCache()).isNotNull(); @@ -189,12 +181,13 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo assertThat(gatewaySenderFactoryBean.getDispatcherThreads()).isEqualTo(10); assertThat(gatewaySenderFactoryBean.isManualStart()).isTrue(); - List eventFilters = TestUtils.readField("eventFilters", gatewaySenderFactoryBean); + List eventFilters = + TestUtils.readField("eventFilters", gatewaySenderFactoryBean); assertThat(eventFilters).isNotNull(); assertThat(eventFilters).hasSize(1); assertThat(eventFilters.get(0)).isInstanceOf(TestEventFilter.class); - assertThat(eventFilters.get(0)).isSameAs(applicationContext.getBean("event-filter")); + assertThat(eventFilters.get(0)).isSameAs(getBean("event-filter", GatewayEventFilter.class)); List transportFilters = TestUtils.readField("transportFilters", gatewaySenderFactoryBean); @@ -202,14 +195,13 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo assertThat(transportFilters).isNotNull(); assertThat(transportFilters).hasSize(1); assertThat(transportFilters.get(0)).isInstanceOf(TestTransportFilter.class); - assertThat(transportFilters.get(0)).isSameAs(applicationContext.getBean("transport-filter")); + assertThat(transportFilters.get(0)).isSameAs(getBean("transport-filter", GatewayTransportFilter.class)); } @Test public void gatewayReceiverConfigurationIsCorrect() { - GatewayReceiver gatewayReceiver = - this.applicationContext.getBean("gateway-receiver", GatewayReceiver.class); + GatewayReceiver gatewayReceiver = getBean("gateway-receiver", GatewayReceiver.class); assertThat(gatewayReceiver).isNotNull(); assertThat(gatewayReceiver.getBindAddress()).isEqualTo("192.168.0.1"); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java index 26865afb..e3706309 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests.java @@ -28,8 +28,7 @@ import org.apache.geode.cache.wan.GatewaySender; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -41,7 +40,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.wan.GatewayReceiver * @see org.apache.geode.cache.wan.GatewaySender * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean * @see org.springframework.test.context.ContextConfiguration @@ -49,8 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @since 2.0.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "gateway-v8-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class GemfireV8GatewayNamespaceIntegrationTests extends IntegrationTestsSupport { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests.java index d829050b..a3f1d9c5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests.java @@ -23,6 +23,7 @@ import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Region; import org.springframework.beans.factory.BeanCreationException; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.RegionAttributesFactoryBean; @@ -38,6 +39,7 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor * * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.PeerRegionFactoryBean * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport @@ -46,13 +48,15 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor public class InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests extends IntegrationTestsSupport { private static final String CONFIG_LOCATION = - "org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml"; + "org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceIntegrationTests.xml"; @Test(expected = IllegalArgumentException.class) public void testInvalidDataPolicyPersistentAttributeSettings() { + ConfigurableApplicationContext applicationContext = null; + try { - new ClassPathXmlApplicationContext(CONFIG_LOCATION); + applicationContext = new ClassPathXmlApplicationContext(CONFIG_LOCATION); } catch (BeanCreationException expected) { @@ -62,6 +66,9 @@ public class InvalidRegionDefinitionUsingBeansNamespaceIntegrationTests extends throw (IllegalArgumentException) expected.getCause(); } + finally { + closeApplicationContext(applicationContext); + } } @SuppressWarnings("unused") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests.java index c2427619..14b8f26f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests.java @@ -24,8 +24,7 @@ import org.apache.geode.cache.Region; import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; -import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.xml.sax.SAXParseException; @@ -38,40 +37,31 @@ import org.xml.sax.SAXParseException; * @see org.apache.geode.cache.Region * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.context.support.GenericXmlApplicationContext - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireMockObjectsBeanPostProcessor * @since 1.5.0 */ -public class InvalidRegionExpirationAttributesNamespaceIntegrationTests extends IntegrationTestsSupport { - - private String contextConfigLocation() { - return getClass().getName().replaceAll("\\.", "/").concat("-context.xml"); - } +public class InvalidRegionExpirationAttributesNamespaceIntegrationTests + extends SpringApplicationContextIntegrationTestsSupport { private ConfigurableApplicationContext createApplicationContext() { - return new GenericXmlApplicationContext(); - } - private ConfigurableApplicationContext configureContext(ConfigurableApplicationContext applicationContext) { - applicationContext.getBeanFactory().addBeanPostProcessor(new GemFireMockObjectsBeanPostProcessor()); - return applicationContext; - } + GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(); - private ConfigurableApplicationContext initializeApplicationContext(ConfigurableApplicationContext applicationContext) { - - assertThat(applicationContext).isInstanceOf(GenericXmlApplicationContext.class); - ((GenericXmlApplicationContext) applicationContext).load(contextConfigLocation()); + applicationContext.load(getContextXmlFileLocation(InvalidRegionExpirationAttributesNamespaceIntegrationTests.class)); applicationContext.registerShutdownHook(); applicationContext.refresh(); + setApplicationContext(applicationContext); + return applicationContext; } @Test(expected = XmlBeanDefinitionStoreException.class) - public void testInvalidXmlSyntax() { + public void invalidXmlSyntaxThrowsException() { try { - initializeApplicationContext(configureContext(createApplicationContext())); + createApplicationContext(); } catch (XmlBeanDefinitionStoreException expected) { assertThat(expected).hasCauseInstanceOf(SAXParseException.class); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsNamespaceIntegrationTests.java similarity index 78% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsIntegrationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsNamespaceIntegrationTests.java index 5ab22083..5d99972b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsNamespaceIntegrationTests.java @@ -17,6 +17,9 @@ package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; + +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,6 +28,7 @@ import org.apache.geode.internal.datasource.GemFireBasicDataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -36,14 +40,21 @@ import org.springframework.test.context.junit4.SpringRunner; * @author David Turanski * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.Cache * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration("jndi-binding-ns.xml") +@ContextConfiguration @SuppressWarnings("unused") -public class JndiBindingsIntegrationTests extends IntegrationTestsSupport { +public class JndiBindingsNamespaceIntegrationTests extends IntegrationTestsSupport { + + @AfterClass + public static void cleanupAfterTests() { + FileSystemUtils.deleteRecursive(new File(FileSystemUtils.WORKING_DIRECTORY, "newDB")); + FileSystemUtils.newFile(FileSystemUtils.WORKING_DIRECTORY, "derby.log").delete(); + } @Autowired private Cache cache; @@ -53,7 +64,7 @@ public class JndiBindingsIntegrationTests extends IntegrationTestsSupport { Object dataSourceObject = cache.getJNDIContext().lookup("java:/SimpleDataSource"); - assertThat(dataSourceObject instanceof GemFireBasicDataSource).isTrue(); + assertThat(dataSourceObject).isInstanceOf(GemFireBasicDataSource.class); GemFireBasicDataSource dataSource = (GemFireBasicDataSource) dataSourceObject; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsPropertyPlaceholderIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests.java similarity index 80% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsPropertyPlaceholderIntegrationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests.java index d93ac4f4..d4dbe53d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsPropertyPlaceholderIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests.java @@ -26,12 +26,9 @@ import org.junit.runner.RunWith; import org.apache.geode.internal.datasource.ConfigProperty; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.CacheFactoryBean; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -41,21 +38,16 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.junit.Test * @see org.springframework.context.ApplicationContext * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.4.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "jndi-binding-with-property-placeholders-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) -public class JndiBindingsPropertyPlaceholderIntegrationTests extends IntegrationTestsSupport { +@GemFireUnitTest +public class JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests extends IntegrationTestsSupport { - @Autowired - @SuppressWarnings("unused") - private ApplicationContext applicationContext; - - protected void assertPropertyValueExists(String expectedPropertyName, String expectedPropertyValue, + private void assertPropertyValueExists(String expectedPropertyName, String expectedPropertyValue, List properties) { for (ConfigProperty property : properties) { @@ -70,9 +62,9 @@ public class JndiBindingsPropertyPlaceholderIntegrationTests extends Integration } @Test - public void testCacheJndiDataSourceConfiguration() { + public void cacheJndiContextDataSourceConfigurationIsCorrect() { - CacheFactoryBean factory = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + CacheFactoryBean factory = requireApplicationContext().getBean("&gemfireCache", CacheFactoryBean.class); List jndiDataSources = factory.getJndiDataSources(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MultipleCacheIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MultipleCacheIntegrationTests.java index bc0d84fb..b925e474 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MultipleCacheIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MultipleCacheIntegrationTests.java @@ -23,6 +23,7 @@ import org.apache.geode.cache.Region; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.util.SpringUtils; /** * Integration Tests for multiple Apache Geode {@link GemFireCache caches}. @@ -43,28 +44,42 @@ public class MultipleCacheIntegrationTests extends IntegrationTestsSupport { @Test public void testMultipleCaches() { - String configLocation = "/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml"; + String configLocation = getContextXmlFileLocation(MultipleCacheIntegrationTests.class); - ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext(configLocation); - ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext(configLocation); + ConfigurableApplicationContext applicationContextOne = null; + ConfigurableApplicationContext applicationContextTwo = null; - Cache cache1 = context1.getBean(Cache.class); - Cache cache2 = context2.getBean(Cache.class); + try { - assertThat(cache1).isNotNull(); - assertThat(cache2).isSameAs(cache1); + applicationContextOne = new ClassPathXmlApplicationContext(configLocation); + applicationContextTwo = new ClassPathXmlApplicationContext(configLocation); - Region region1 = context1.getBean(Region.class); - Region region2 = context2.getBean(Region.class); + Cache cacheOne = applicationContextOne.getBean(Cache.class); + Cache cacheTwo = applicationContextTwo.getBean(Cache.class); - assertThat(region1).isNotNull(); - assertThat(region2).isSameAs(region1); - assertThat(cache1.isClosed()).isFalse(); - assertThat(region1.isDestroyed()).isFalse(); + assertThat(cacheOne).isNotNull(); + assertThat(cacheTwo).isSameAs(cacheOne); - context1.close(); + Region regionOne = applicationContextOne.getBean(Region.class); + Region regionTwo = applicationContextTwo.getBean(Region.class); - assertThat(cache1.isClosed()).isFalse(); - assertThat(region1.isDestroyed()).as("region was destroyed").isFalse(); + assertThat(regionOne).isNotNull(); + assertThat(regionTwo).isSameAs(regionOne); + assertThat(cacheOne.isClosed()).isFalse(); + assertThat(regionOne.isDestroyed()).isFalse(); + + applicationContextOne.close(); + + assertThat(cacheOne.isClosed()).isFalse(); + assertThat(regionOne.isDestroyed()).describedAs("Region was destroyed").isFalse(); + } + finally { + + final ConfigurableApplicationContext applicationContextOneRef = applicationContextOne; + final ConfigurableApplicationContext applicationContextTwoRef = applicationContextTwo; + + SpringUtils.safeDoOperation(() -> closeApplicationContext(applicationContextOneRef)); + SpringUtils.safeDoOperation(() -> closeApplicationContext(applicationContextTwoRef)); + } } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests.java index 8e666dc6..183f873b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests.java @@ -33,49 +33,43 @@ import org.apache.geode.cache.partition.PartitionListener; import org.apache.geode.cache.partition.PartitionListenerAdapter; import org.apache.geode.compression.Compressor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.PeerRegionFactoryBean; import org.springframework.data.gemfire.SimpleCacheListener; import org.springframework.data.gemfire.SimplePartitionResolver; import org.springframework.data.gemfire.TestUtils; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; /** - * Integration Tests for the Partitioned Region XML namespace configuration metadata. + * Integration Tests for {@link DataPolicy#PARTITION} {@link Region} SDG XML namespace configuration metadata. * * @author Costin Leau * @author David Turanski * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.DataPolicy#PARTITION * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean * @see org.springframework.data.gemfire.config.xml.PartitionedRegionParser * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "partitioned-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; - @Test public void testSimplePartitionRegion() { - assertThat(applicationContext.containsBean("simple")).isTrue(); + assertThat(requireApplicationContext().containsBean("simple")).isTrue(); - Region simple = applicationContext.getBean("simple", Region.class); + Region simple = requireApplicationContext().getBean("simple", Region.class); assertThat(simple).isNotNull(); assertThat(simple.getName()).isEqualTo("simple"); @@ -88,19 +82,20 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests @SuppressWarnings("rawtypes") public void testOptionsPartitionRegion() throws Exception { - assertThat(applicationContext.containsBean("options")).isTrue(); - assertThat(applicationContext.containsBean("redundant")).isTrue(); + assertThat(requireApplicationContext().containsBean("options")).isTrue(); + assertThat(requireApplicationContext().containsBean("redundant")).isTrue(); - Region options = applicationContext.getBean("options", Region.class); + Region options = requireApplicationContext().getBean("options", Region.class); assertThat(options).isNotNull(); - assertThat(options.getAttributes()).isNotNull(); assertThat(options.getName()).isEqualTo("redundant"); + assertThat(options.getAttributes()).isNotNull(); assertThat(options.getAttributes().getOffHeap()).isTrue(); - PeerRegionFactoryBean optionsRegionFactoryBean = applicationContext.getBean("&options", PeerRegionFactoryBean.class); + PeerRegionFactoryBean optionsRegionFactoryBean = + requireApplicationContext().getBean("&options", PeerRegionFactoryBean.class); - assertThat(optionsRegionFactoryBean instanceof PartitionedRegionFactoryBean).isTrue(); + assertThat(optionsRegionFactoryBean).isInstanceOf(PartitionedRegionFactoryBean.class); assertThat(TestUtils.readField("scope", optionsRegionFactoryBean)).isNull(); assertThat(TestUtils.readField("name", optionsRegionFactoryBean)).isEqualTo("redundant"); assertThat(TestUtils.readField("scope", optionsRegionFactoryBean)).isNull(); @@ -123,21 +118,22 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests @SuppressWarnings("rawtypes") public void testComplexPartitionRegion() throws Exception { - assertThat(applicationContext.containsBean("complex")).isTrue(); + assertThat(requireApplicationContext().containsBean("complex")).isTrue(); - PeerRegionFactoryBean complexRegionFactoryBean = applicationContext.getBean("&complex", PeerRegionFactoryBean.class); + PeerRegionFactoryBean complexRegionFactoryBean = + requireApplicationContext().getBean("&complex", PeerRegionFactoryBean.class); CacheListener[] cacheListeners = TestUtils.readField("cacheListeners", complexRegionFactoryBean); assertThat(ObjectUtils.isEmpty(cacheListeners)).isFalse(); assertThat(cacheListeners.length).isEqualTo(2); - assertThat(applicationContext.getBean("c-listener")).isSameAs(cacheListeners[0]); - assertThat(cacheListeners[1] instanceof SimpleCacheListener).isTrue(); + assertThat(requireApplicationContext().getBean("c-listener")).isSameAs(cacheListeners[0]); + assertThat(cacheListeners[1]).isInstanceOf(SimpleCacheListener.class); assertThat(TestUtils.readField("cacheLoader", complexRegionFactoryBean)) - .isSameAs(applicationContext.getBean("c-loader")); + .isSameAs(requireApplicationContext().getBean("c-loader")); assertThat(TestUtils.readField("cacheWriter", complexRegionFactoryBean)) - .isSameAs(applicationContext.getBean("c-writer")); + .isSameAs(requireApplicationContext().getBean("c-writer")); RegionAttributes complexRegionAttributes = TestUtils.readField("attributes", complexRegionFactoryBean); @@ -156,17 +152,19 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests @Test public void testCompressedPartitionRegion() { - assertThat(applicationContext.containsBean("compressed")).isTrue(); + assertThat(requireApplicationContext().containsBean("compressed")).isTrue(); - Region compressed = applicationContext.getBean("compressed", Region.class); + Region compressed = requireApplicationContext().getBean("compressed", Region.class); - assertThat(compressed).as("The 'compressed' PARTITION Region was not properly configured and initialized!") + assertThat(compressed) + .describedAs("The 'compressed' PARTITION Region was not properly configured and initialized!") .isNotNull(); + assertThat(compressed.getName()).isEqualTo("compressed"); assertThat(compressed.getFullPath()).isEqualTo(Region.SEPARATOR + "compressed"); assertThat(compressed.getAttributes()).isNotNull(); assertThat(compressed.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PARTITION); - assertThat(compressed.getAttributes().getCompressor() instanceof TestCompressor).isTrue(); + assertThat(compressed.getAttributes().getCompressor()).isInstanceOf(TestCompressor.class); assertThat(compressed.getAttributes().getCompressor().toString()).isEqualTo("testCompressor"); } @@ -174,7 +172,8 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests @SuppressWarnings("rawtypes") public void testFixedPartitionRegion() throws Exception { - PeerRegionFactoryBean fixedRegionFactoryBean = applicationContext.getBean("&fixed", PeerRegionFactoryBean.class); + PeerRegionFactoryBean fixedRegionFactoryBean = + requireApplicationContext().getBean("&fixed", PeerRegionFactoryBean.class); assertThat(fixedRegionFactoryBean).isNotNull(); @@ -199,12 +198,14 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests @Test public void testMultiplePartitionListeners() { - assertThat(applicationContext.containsBean("listeners")).isTrue(); + assertThat(requireApplicationContext().containsBean("listeners")).isTrue(); - Region listeners = applicationContext.getBean("listeners", Region.class); + Region listeners = requireApplicationContext().getBean("listeners", Region.class); - assertThat(listeners).as("The 'listeners' PARTITION Region was not properly configured and initialized!") + assertThat(listeners) + .describedAs("The 'listeners' PARTITION Region was not properly configured and initialized!") .isNotNull(); + assertThat(listeners.getName()).isEqualTo("listeners"); assertThat(listeners.getFullPath()).isEqualTo(Region.SEPARATOR + "listeners"); assertThat(listeners.getAttributes()).isNotNull(); @@ -219,7 +220,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests List expectedNames = Arrays.asList("X", "Y", "Z", "ABC"); for (PartitionListener listener : listenersPartitionAttributes.getPartitionListeners()) { - assertThat(listener instanceof TestPartitionListener).isTrue(); + assertThat(listener).isInstanceOf(TestPartitionListener.class); assertThat(expectedNames.contains(listener.toString())).isTrue(); } } @@ -227,12 +228,14 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests @Test public void testSinglePartitionListeners() { - assertThat(applicationContext.containsBean("listenerRef")).isTrue(); + assertThat(requireApplicationContext().containsBean("listenerRef")).isTrue(); - Region listeners = applicationContext.getBean("listenerRef", Region.class); + Region listeners = requireApplicationContext().getBean("listenerRef", Region.class); - assertThat(listeners).as("The 'listenerRef' PARTITION Region was not properly configured and initialized!") + assertThat(listeners) + .describedAs("The 'listenerRef' PARTITION Region was not properly configured and initialized!") .isNotNull(); + assertThat(listeners.getName()).isEqualTo("listenerRef"); assertThat(listeners.getFullPath()).isEqualTo(Region.SEPARATOR + "listenerRef"); assertThat(listeners.getAttributes()).isNotNull(); @@ -243,7 +246,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests assertThat(listenersPartitionAttributes).isNotNull(); assertThat(listenersPartitionAttributes.getPartitionListeners()).isNotNull(); assertThat(listenersPartitionAttributes.getPartitionListeners().length).isEqualTo(1); - assertThat(listenersPartitionAttributes.getPartitionListeners()[0] instanceof TestPartitionListener).isTrue(); + assertThat(listenersPartitionAttributes.getPartitionListeners()[0]).isInstanceOf(TestPartitionListener.class); assertThat(listenersPartitionAttributes.getPartitionListeners()[0].toString()).isEqualTo("ABC"); } @@ -251,7 +254,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests private String name; - public void setName(final String name) { + public void setName(String name) { this.name = name; } @@ -275,7 +278,7 @@ public class PartitionedRegionNamespaceIntegrationTests extends IntegrationTests private String name; - public void setName(final String name) { + public void setName(String name) { this.name = name; } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests.java index fc49b2ed..d779dafc 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests.java @@ -24,16 +24,13 @@ import org.junit.runner.RunWith; import org.apache.geode.cache.client.Pool; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.PoolAdapter; import org.springframework.data.gemfire.client.PoolFactoryBean; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpointList; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -47,18 +44,15 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.client.PoolFactoryBean * @see org.springframework.data.gemfire.config.xml.PoolParser * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "pool-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; - private void assertConnectionEndpoint(ConnectionEndpointList connectionEndpoints, String expectedHost, int expectedPort) { @@ -83,10 +77,10 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { @Test public void gemfirePoolIsConfiguredProperly() throws Exception { - assertThat(applicationContext.containsBean("gemfirePool")).isTrue(); - assertThat(applicationContext.containsBean("gemfire-pool")).isTrue(); + assertThat(requireApplicationContext().containsBean("gemfirePool")).isTrue(); + assertThat(requireApplicationContext().containsBean("gemfire-pool")).isTrue(); - PoolFactoryBean poolFactoryBean = applicationContext.getBean("&gemfirePool", PoolFactoryBean.class); + PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&gemfirePool", PoolFactoryBean.class); ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean); @@ -96,9 +90,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { @Test public void simplePoolIsConfiguredProperly() throws Exception { - assertThat(applicationContext.containsBean("simple")).isTrue(); + assertThat(requireApplicationContext().containsBean("simple")).isTrue(); - PoolFactoryBean poolFactoryBean = applicationContext.getBean("&simple", PoolFactoryBean.class); + PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&simple", PoolFactoryBean.class); ConnectionEndpointList servers = TestUtils.readField("servers", poolFactoryBean); @@ -112,9 +106,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { @Test public void locatorPoolIsConfiguredProperly() throws Exception { - assertThat(applicationContext.containsBean("locator")).isTrue(); + assertThat(requireApplicationContext().containsBean("locator")).isTrue(); - PoolFactoryBean poolFactoryBean = applicationContext.getBean("&locator", PoolFactoryBean.class); + PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&locator", PoolFactoryBean.class); ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean); @@ -134,9 +128,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { @Test public void serverPoolIsConfiguredProperly() throws Exception { - assertThat(applicationContext.containsBean("server")).isTrue(); + assertThat(requireApplicationContext().containsBean("server")).isTrue(); - PoolFactoryBean poolFactoryBean = applicationContext.getBean("&server", PoolFactoryBean.class); + PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&server", PoolFactoryBean.class); Pool pool = poolFactoryBean.getPool(); assertThat(pool).isInstanceOf(PoolAdapter.class); @@ -175,9 +169,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { @Test public void locatorsPoolIsConfiguredProperly() throws Exception { - assertThat(applicationContext.containsBean("locators")).isTrue(); + assertThat(requireApplicationContext().containsBean("locators")).isTrue(); - PoolFactoryBean poolFactoryBean = applicationContext.getBean("&locators", PoolFactoryBean.class); + PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&locators", PoolFactoryBean.class); ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean); @@ -195,9 +189,9 @@ public class PoolNamespaceIntegrationTests extends IntegrationTestsSupport { @Test public void serversPoolIsConfiguredProperly() throws Exception { - assertThat(applicationContext.containsBean("servers")).isTrue(); + assertThat(requireApplicationContext().containsBean("servers")).isTrue(); - PoolFactoryBean poolFactoryBean = applicationContext.getBean("&servers", PoolFactoryBean.class); + PoolFactoryBean poolFactoryBean = requireApplicationContext().getBean("&servers", PoolFactoryBean.class); ConnectionEndpointList servers = TestUtils.readField("servers", poolFactoryBean); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java index 37471e69..ef8e5c46 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests.java @@ -20,12 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.support.AbstractApplicationContext; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -75,26 +72,22 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.junit.Test * @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.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @link https://jira.springsource.org/browse/SGF-178 * @since 1.3.3 */ @RunWith(SpringRunner.class) -@ContextConfiguration( - locations = "/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests extends IntegrationTestsSupport { - @Autowired - private AbstractApplicationContext applicationContext; - @Test public void testNonParentRegionBeanDefinitionHashCode() { - BeanDefinition nonParentRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("NON_PARENT"); + BeanDefinition nonParentRegionBeanDefinition = + requireApplicationContext().getBeanFactory().getBeanDefinition("NON_PARENT"); assertThat(nonParentRegionBeanDefinition).isNotNull(); assertThat(nonParentRegionBeanDefinition.hashCode() != 0).isTrue(); @@ -103,7 +96,8 @@ public class RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests extends I @Test public void testParentRegionBeanDefinitionHashCode() { - BeanDefinition parentRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("PARENT"); + BeanDefinition parentRegionBeanDefinition = + requireApplicationContext().getBeanFactory().getBeanDefinition("PARENT"); assertThat(parentRegionBeanDefinition).isNotNull(); assertThat(parentRegionBeanDefinition.hashCode() != 0).isTrue(); @@ -112,7 +106,8 @@ public class RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests extends I @Test public void testChildRegionBeanDefinitionHashCode() { - BeanDefinition childRegionBeanDefinition = applicationContext.getBeanFactory().getBeanDefinition("/PARENT/CHILD"); + BeanDefinition childRegionBeanDefinition = + requireApplicationContext().getBeanFactory().getBeanDefinition("/PARENT/CHILD"); assertThat(childRegionBeanDefinition).isNotNull(); assertThat(childRegionBeanDefinition.hashCode() != 0).isTrue(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java index e33d9f37..0c35953b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests.java @@ -24,13 +24,10 @@ import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.Region; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.TestUtils; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -42,23 +39,19 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.Cache * @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.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "subregion-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings({ "rawtypes", "unused" }) public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; - @Test public void testNestedRegionsCreated() { - Cache cache = applicationContext.getBean(Cache.class); + Cache cache = requireApplicationContext().getBean(Cache.class); assertThat(cache.getRegion("parent")).isNotNull(); assertThat(cache.getRegion("/parent/child")).isNotNull(); @@ -69,9 +62,9 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport @SuppressWarnings("unchecked") public void testNestedReplicatedRegions() { - Region parent = applicationContext.getBean("parent", Region.class); - Region child = applicationContext.getBean("/parent/child", Region.class); - Region grandchild = applicationContext.getBean("/parent/child/grandchild", Region.class); + Region parent = requireApplicationContext().getBean("parent", Region.class); + Region child = requireApplicationContext().getBean("/parent/child", Region.class); + Region grandchild = requireApplicationContext().getBean("/parent/child/grandchild", Region.class); assertThat(child).isNotNull(); assertThat(child.getName()).isEqualTo("child"); @@ -87,9 +80,9 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport @SuppressWarnings("unchecked") public void testMixedNestedRegions() { - Region parent = applicationContext.getBean("replicatedParent", Region.class); - Region child = applicationContext.getBean("/replicatedParent/replicatedChild", Region.class); - Region grandchild = applicationContext.getBean("/replicatedParent/replicatedChild/partitionedGrandchild", Region.class); + Region parent = requireApplicationContext().getBean("replicatedParent", Region.class); + Region child = requireApplicationContext().getBean("/replicatedParent/replicatedChild", Region.class); + Region grandchild = requireApplicationContext().getBean("/replicatedParent/replicatedChild/partitionedGrandchild", Region.class); assertThat(child).isNotNull(); assertThat(child.getFullPath()).isEqualTo("/replicatedParent/replicatedChild"); @@ -103,18 +96,18 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport @SuppressWarnings("unchecked") public void testNestedRegionsWithSiblings() { - Region parent = applicationContext.getBean("parentWithSiblings", Region.class); - Region child1 = applicationContext.getBean("/parentWithSiblings/child1", Region.class); + Region parent = requireApplicationContext().getBean("parentWithSiblings", Region.class); + Region child1 = requireApplicationContext().getBean("/parentWithSiblings/child1", Region.class); assertThat(child1.getFullPath()).isEqualTo("/parentWithSiblings/child1"); - Region child2 = applicationContext.getBean("/parentWithSiblings/child2", Region.class); + Region child2 = requireApplicationContext().getBean("/parentWithSiblings/child2", Region.class); assertThat(child2.getFullPath()).isEqualTo("/parentWithSiblings/child2"); assertThat(parent.getSubregion("child1")).isSameAs(child1); assertThat(parent.getSubregion("child2")).isSameAs(child2); - Region grandchild1 = applicationContext.getBean("/parentWithSiblings/child1/grandChild11", Region.class); + Region grandchild1 = requireApplicationContext().getBean("/parentWithSiblings/child1/grandChild11", Region.class); assertThat(grandchild1.getFullPath()).isEqualTo("/parentWithSiblings/child1/grandChild11"); } @@ -123,13 +116,14 @@ public class SubRegionNamespaceIntegrationTests extends IntegrationTestsSupport @SuppressWarnings("unused" ) public void testComplexNestedRegions() throws Exception { - Region parent = applicationContext.getBean("complexNested", Region.class); - Region child1 = applicationContext.getBean("/complexNested/child1", Region.class); - Region child2 = applicationContext.getBean("/complexNested/child2", Region.class); - Region grandchild11 = applicationContext.getBean("/complexNested/child1/grandChild11", Region.class); + Region parent = requireApplicationContext().getBean("complexNested", Region.class); + Region child1 = requireApplicationContext().getBean("/complexNested/child1", Region.class); + Region child2 = requireApplicationContext().getBean("/complexNested/child2", Region.class); + Region grandchild11 = requireApplicationContext().getBean("/complexNested/child1/grandChild11", Region.class); ReplicatedRegionFactoryBean grandchild11FactoryBean = - applicationContext.getBean("&/complexNested/child1/grandChild11", ReplicatedRegionFactoryBean.class); + requireApplicationContext().getBean("&/complexNested/child1/grandChild11", + ReplicatedRegionFactoryBean.class); assertThat(grandchild11FactoryBean).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests.java index f7b5b641..a69e9534 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests.java @@ -30,11 +30,8 @@ import org.apache.geode.cache.asyncqueue.AsyncEvent; import org.apache.geode.cache.asyncqueue.AsyncEventListener; import org.apache.geode.cache.util.CacheListenerAdapter; -import org.springframework.beans.factory.annotation.Autowired; -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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; /** @@ -47,20 +44,16 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.junit.Test * @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.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.3.3 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "subregionsubelement-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class SubRegionSubElementNamespaceIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; - @Resource(name = "/Customers/Accounts") private Region customersAccountsRegion; @@ -88,7 +81,7 @@ public class SubRegionSubElementNamespaceIntegrationTests extends IntegrationTes @Test public void testOrderItemsSubRegionGatewaySender() { - Region orderItemsRegion = applicationContext.getBean("/Orders/Items", Region.class); + Region orderItemsRegion = requireApplicationContext().getBean("/Orders/Items", Region.class); assertThat(orderItemsRegion).isNotNull(); assertThat(orderItemsRegion.getAttributes()).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionWithInvalidDataPolicyTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionWithInvalidDataPolicyTest.java index 141941b1..990729bd 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionWithInvalidDataPolicyTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionWithInvalidDataPolicyTest.java @@ -44,7 +44,7 @@ import org.xml.sax.SAXParseException; public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport { @Test(expected = XmlBeanDefinitionStoreException.class) - public void testSubRegionBeanDefinitionWithInconsistentDataPolicy() { + public void subRegionBeanDefinitionWithInconsistentDataPolicyThrowsException() { try { new ClassPathXmlApplicationContext( @@ -52,7 +52,7 @@ public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport } catch (XmlBeanDefinitionStoreException expected) { - assertThat(expected.getCause() instanceof SAXParseException).isTrue(); + assertThat(expected.getCause()).isInstanceOf(SAXParseException.class); assertThat(expected.getCause().getMessage().contains("PERSISTENT_PARTITION")).isTrue(); throw expected; @@ -60,7 +60,7 @@ public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport } @Test(expected = BeanCreationException.class) - public void testSubRegionBeanDefinitionWithInvalidDataPolicyPersistentSettings() { + public void subRegionBeanDefinitionWithInvalidDataPolicyAndPersistentSettingsThrowsException() { try { new ClassPathXmlApplicationContext( @@ -68,10 +68,9 @@ public class SubRegionWithInvalidDataPolicyTest extends IntegrationTestsSupport } catch (BeanCreationException expected) { - assertThat(expected.getMessage().contains("Error creating bean with name '/Parent/Child'")).isTrue(); - assertThat(expected.getCause() instanceof IllegalArgumentException).isTrue(); - assertThat(expected.getCause().getMessage()) - .isEqualTo("Data Policy [REPLICATE] is not valid when persistent is true"); + assertThat(expected).hasMessageContaining("Error creating bean with name '/Parent/Child'"); + assertThat(expected).hasCauseInstanceOf(IllegalArgumentException.class); + assertThat(expected.getCause()).hasMessage("Data Policy [REPLICATE] is not valid when persistent is true"); throw expected; } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests.java similarity index 59% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests.java index 89b8e742..d4c56154 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests.java @@ -13,45 +13,45 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; +import org.apache.geode.cache.Region; + import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; /** - * The TemplateRegionDefinitionOrderErrorNamespaceTest class is a test suite of test cases testing the contract - * and functionality of Region Templates, and specifically the correct order definition of Region Templates before - * the Region bean definitions and concrete types that use those templates. + * Integration Tests testing the incorrect order of Template {@link Region} bean definitions + * and regular {@link Region} bean definitions referring to the templates. * * @author John Blum * @see org.junit.Test * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.5.0 */ -public class TemplateRegionDefinitionOrderErrorNamespaceTest { - - private String getConfigLocation() { - return getClass().getName().replace(".", "/").concat("-context.xml"); - } +public class TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests extends IntegrationTestsSupport { @Test(expected = BeanDefinitionParsingException.class) - public void testIncorrectTemplateRegionDefinitionOrder() throws Exception { + public void incorrectTemplateRegionBeanDefinitionOrderThrowsParseException() { try { - new ClassPathXmlApplicationContext(getConfigLocation()); + new ClassPathXmlApplicationContext(getContextXmlFileLocation( + TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests.class)); } catch (BeanDefinitionParsingException expected) { - assertThat(expected) - .hasMessageContaining("The Region template [RegionTemplate] must be defined before the Region [TemplateBasedPartitionRegion] referring to the template"); + assertThat(expected).hasMessageContaining("The Region template [RegionTemplate] must be defined before" + + " the Region [TemplateBasedPartitionRegion] referring to the template"); + assertThat(expected).hasNoCause(); throw expected; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TransactionManagerNamespaceIntegrationTests.java similarity index 61% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceIntegrationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TransactionManagerNamespaceIntegrationTests.java index 3dfe829c..c3cf74a0 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TransactionManagerNamespaceIntegrationTests.java @@ -20,12 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.data.gemfire.transaction.GemfireTransactionManager; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** @@ -34,28 +31,26 @@ import org.springframework.test.context.junit4.SpringRunner; * @author Costin Leau * @author John Blum * @see org.junit.Test + * @see org.springframework.data.gemfire.CacheFactoryBean + * @see org.springframework.data.gemfire.transaction.GemfireTransactionManager * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "/org/springframework/data/gemfire/config/xml/tx-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") -public class TxManagerNamespaceIntegrationTests extends IntegrationTestsSupport { - - @Autowired - private ApplicationContext applicationContext; +public class TransactionManagerNamespaceIntegrationTests extends IntegrationTestsSupport { @Test - public void testBasicCache() { + public void basicCacheWithTransactionsIsConfiguredCorrectly() { - assertThat(applicationContext.containsBean("gemfireTransactionManager")).isTrue(); - assertThat(applicationContext.containsBean("gemfire-transaction-manager")).isTrue(); + assertThat(requireApplicationContext().containsBean("gemfireTransactionManager")).isTrue(); + assertThat(requireApplicationContext().containsBean("gemfire-transaction-manager")).isTrue(); GemfireTransactionManager transactionManager = - applicationContext.getBean("gemfireTransactionManager", GemfireTransactionManager.class); + requireApplicationContext().getBean("gemfireTransactionManager", GemfireTransactionManager.class); assertThat(transactionManager.isCopyOnRead()).isFalse(); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationUnitTests.java index b5c61219..a80955a2 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationUnitTests.java @@ -20,12 +20,16 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.springframework.data.gemfire.expiration.AnnotationBasedExpiration.ExpirationMetaData; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.stubbing.Answer; @@ -48,16 +52,24 @@ import org.springframework.expression.spel.support.StandardEvaluationContext; * * @author John Blum * @see org.junit.Test + * @see org.mockito.Mock * @see org.mockito.Mockito + * @see org.mockito.Spy * @see org.springframework.data.gemfire.expiration.AnnotationBasedExpiration * @since 1.7.0 */ @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) public class AnnotationBasedExpirationUnitTests { + @BeforeClass @AfterClass + public static void testSetupAndTearDown() { + AnnotationBasedExpiration.BEAN_FACTORY_REFERENCE.set(null); + AnnotationBasedExpiration.EVALUATION_CONTEXT_REFERENCE.set(null); + } + private final AnnotationBasedExpiration noDefaultExpiration = new AnnotationBasedExpiration(); - protected void assertExpiration(ExpirationAttributes expirationAttributes, int expectedTimeout, + private void assertExpiration(ExpirationAttributes expirationAttributes, int expectedTimeout, ExpirationAction expectedAction) { assertThat(expirationAttributes).isNotNull(); @@ -65,7 +77,7 @@ public class AnnotationBasedExpirationUnitTests { assertThat(expirationAttributes.getAction()).isEqualTo(expectedAction); } - protected void assertExpiration(ExpirationMetaData expirationMetaData, int expectedTimeout, + private void assertExpiration(ExpirationMetaData expirationMetaData, int expectedTimeout, ExpirationActionType expectedExpirationAction) { assertThat(expirationMetaData).isNotNull(); @@ -178,15 +190,12 @@ public class AnnotationBasedExpirationUnitTests { assertThat(TestUtils.readField("beanFactory", beanResolver)).isEqualTo(mockBeanFactory); return null; + }).when(mockEvaluationContext).setBeanResolver(any(BeanResolver.class)); - AnnotationBasedExpiration annotationBasedExpiration = new AnnotationBasedExpiration() { + AnnotationBasedExpiration annotationBasedExpiration = spy(new AnnotationBasedExpiration<>()); - @Override - StandardEvaluationContext newEvaluationContext() { - return mockEvaluationContext; - } - }; + doReturn(mockEvaluationContext).when(annotationBasedExpiration).newEvaluationContext(); annotationBasedExpiration.setBeanFactory(mockBeanFactory); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java index 07394e91..30092a35 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/LocatorProcess.java @@ -17,6 +17,7 @@ package org.springframework.data.gemfire.fork; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.Properties; import java.util.concurrent.TimeUnit; @@ -29,6 +30,7 @@ import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.tests.process.ProcessUtils; import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.data.gemfire.tests.util.ThreadUtils; +import org.springframework.data.gemfire.util.ArrayUtils; /** * The {@link LocatorProcess} class is a main Java class that is used fork and launch an Apache Geode {@link Locator} @@ -149,6 +151,9 @@ public class LocatorProcess { if (locator != null) { locator.stop(); } + + Arrays.stream(ArrayUtils.nullSafeArray(FileSystemUtils.WORKING_DIRECTORY.listFiles((dir, name) -> name.startsWith("vf.gf") && name.endsWith(".pid")), File.class)) + .forEach(File::delete); })); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests.java index cd9a2998..0e880e96 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests.java @@ -18,8 +18,6 @@ package org.springframework.data.gemfire.function; import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.junit.BeforeClass; import org.junit.Test; @@ -66,15 +64,8 @@ public class ExceptionThrowingFunctionExecutionIntegrationTests extends ForkingC @BeforeClass public static void startGeodeServer() throws IOException { - - List arguments = new ArrayList<>(); - - arguments.add(String.format("-Dgemfire.name=%s", - ExceptionThrowingFunctionExecutionIntegrationTests.class.getSimpleName().concat("Server"))); - - arguments.add(getServerContextXmlFileLocation(ExceptionThrowingFunctionExecutionIntegrationTests.class)); - - startGemFireServer(ServerProcess.class, arguments.toArray(new String[0])); + startGemFireServer(ServerProcess.class, + getServerContextXmlFileLocation(ExceptionThrowingFunctionExecutionIntegrationTests.class)); } @Test(expected = FunctionException.class) diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/PdxFunctionArgumentResolverUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/PdxFunctionArgumentResolverIntegrationTests.java similarity index 95% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/function/PdxFunctionArgumentResolverUnitTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/function/PdxFunctionArgumentResolverIntegrationTests.java index c30e5859..55cd76be 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/PdxFunctionArgumentResolverUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/PdxFunctionArgumentResolverIntegrationTests.java @@ -40,6 +40,7 @@ import org.apache.geode.pdx.PdxWriter; import org.apache.geode.pdx.internal.PdxInstanceEnum; import org.apache.geode.pdx.internal.PdxInstanceFactoryImpl; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -52,13 +53,15 @@ import org.springframework.util.ObjectUtils; * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.execute.FunctionContext * @see org.apache.geode.pdx.PdxInstance + * @see org.apache.geode.pdx.PdxInstanceFactory * @see org.apache.geode.pdx.PdxSerializer * @see org.apache.geode.pdx.internal.PdxInstanceEnum * @see org.springframework.data.gemfire.function.PdxFunctionArgumentResolver + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @since 1.5.2 */ @SuppressWarnings("rawtypes") -public class PdxFunctionArgumentResolverUnitTests { +public class PdxFunctionArgumentResolverIntegrationTests extends IntegrationTestsSupport { private static Cache gemfireCache; @@ -70,7 +73,7 @@ public class PdxFunctionArgumentResolverUnitTests { gemfireCache = new CacheFactory() .setPdxSerializer(new PersonPdxSerializer()) .setPdxReadSerialized(true) - .set("name", PdxFunctionArgumentResolverUnitTests.class.getSimpleName()) + .set("name", PdxFunctionArgumentResolverIntegrationTests.class.getSimpleName()) .set("log-level", "error") .create(); } @@ -309,11 +312,11 @@ public class PdxFunctionArgumentResolverUnitTests { private final String firstName; private final String lastName; - public Person(final String firstName, final String lastName, final Gender gender) { + public Person(String firstName, String lastName, Gender gender) { - Assert.hasText(firstName, "The person's first name must be specified!"); - Assert.hasText(lastName, "The person's last name must be specified!"); - Assert.notNull(gender, "The person's gender must be specified!"); + Assert.hasText(firstName, "The person's first name must be specified"); + Assert.hasText(lastName, "The person's last name must be specified"); + Assert.notNull(gender, "The person's gender must be specified"); this.firstName = firstName; this.lastName = lastName; @@ -321,21 +324,21 @@ public class PdxFunctionArgumentResolverUnitTests { } public String getFirstName() { - return firstName; + return this.firstName; } public String getLastName() { - return lastName; + return this.lastName; } public Gender getGender() { - return gender; + return this.gender; } @Override public boolean equals(Object obj) { - if (obj == this) { + if (this == obj) { return true; } @@ -352,10 +355,13 @@ public class PdxFunctionArgumentResolverUnitTests { @Override public int hashCode() { + int hashValue = 17; + hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getFirstName()); hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getLastName()); hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getGender()); + return hashValue; } @@ -371,10 +377,13 @@ public class PdxFunctionArgumentResolverUnitTests { public boolean toData(final Object obj, final PdxWriter out) { if (obj instanceof Person) { + Person person = (Person) obj; + out.writeString("firstName", person.getFirstName()); out.writeString("lastName", person.getLastName()); out.writeObject("gender", person.getGender()); + return true; } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests.java index 29ef0bf2..1599e538 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests.java @@ -28,8 +28,6 @@ import org.apache.geode.cache.execute.FunctionException; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @@ -47,23 +45,20 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.execute.Execution * @see org.apache.geode.cache.execute.Function - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = ClientCacheTestConfiguration.class) +@ContextConfiguration(classes = FunctionExecutionClientCacheIntegrationTests.ClientCacheTestConfiguration.class) public class FunctionExecutionClientCacheIntegrationTests extends IntegrationTestsSupport { - @Autowired - ApplicationContext applicationContext; - @Test public void contextCreated() { - ClientCache cache = this.applicationContext.getBean("gemfireCache", ClientCache.class); + ClientCache cache = requireApplicationContext().getBean("gemfireCache", ClientCache.class); - Pool pool = this.applicationContext.getBean("gemfirePool", Pool.class); + Pool pool = requireApplicationContext().getBean("gemfirePool", Pool.class); assertThat(pool.getName()).isEqualTo("gemfirePool"); assertThat(cache.getDefaultPool().getLocators().isEmpty()).isTrue(); @@ -72,29 +67,31 @@ public class FunctionExecutionClientCacheIntegrationTests extends IntegrationTes assertThat(pool.getServers().size()).isEqualTo(1); assertThat(cache.getDefaultPool().getServers().get(0)).isEqualTo(pool.getServers().get(0)); - Region region = this.applicationContext.getBean("r1", Region.class); + Region region = requireApplicationContext().getBean("r1", Region.class); assertThat(region.getName()).isEqualTo("r1"); assertThat(region.getAttributes()).isNotNull(); assertThat(region.getAttributes().getPoolName()).isNull(); - GemfireOnServerFunctionTemplate template = this.applicationContext.getBean(GemfireOnServerFunctionTemplate.class); + GemfireOnServerFunctionTemplate template = requireApplicationContext().getBean(GemfireOnServerFunctionTemplate.class); - assertThat(template.getResultCollector() instanceof MyResultCollector).isTrue(); + assertThat(template.getResultCollector()).isInstanceOf(MyResultCollector.class); + } + + @Configuration + @ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests-context.xml") + @EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.three") + @SuppressWarnings("unused") + static class ClientCacheTestConfiguration { + + @Bean + MyResultCollector myResultCollector() { + return new MyResultCollector(); + } } } -@Configuration -@ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionCacheClientTests-context.xml") -@EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.three") -@SuppressWarnings("unused") -class ClientCacheTestConfiguration { - @Bean - MyResultCollector myResultCollector() { - return new MyResultCollector(); - } -} @SuppressWarnings("rawtypes") class MyResultCollector implements ResultCollector { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheIntegrationTests.java similarity index 95% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheIntegrationTests.java index a1084aae..4bbce10d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheIntegrationTests.java @@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner; */ @RunWith(SpringRunner.class) @GemFireUnitTest -public class FunctionsWithClientCacheTests extends IntegrationTestsSupport { +public class FunctionsWithClientCacheIntegrationTests extends IntegrationTestsSupport { @Test public void doNothing() { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java index 6c7364d2..c60f13a9 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/onservers/FunctionsReturnResultsFromAllServersIntegrationTests.java @@ -26,8 +26,9 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.apache.geode.cache.execute.Function; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.gemfire.config.annotation.CacheServerApplication; import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; import org.springframework.data.gemfire.function.annotation.GemfireFunction; @@ -40,16 +41,20 @@ import org.springframework.data.gemfire.tests.integration.ForkingClientServerInt import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.EnableTransactionManagement; /** + * Integration Tests testing the return values from {@link Function} executions. + * * @author Patrick Johnson * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.execute.Function * @see org.springframework.data.gemfire.function.annotation.GemfireFunction * @see org.springframework.data.gemfire.function.config.EnableGemfireFunctionExecutions * @see org.springframework.data.gemfire.function.config.EnableGemfireFunctions * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ @SuppressWarnings("unused") @RunWith(SpringRunner.class) @@ -70,21 +75,22 @@ public class FunctionsReturnResultsFromAllServersIntegrationTests extends Forkin @BeforeClass public static void startGemFireServer() throws Exception { - final int port1 = findAvailablePort(); + final int port1 = findAndReserveAvailablePort(); gemfireServer1 = run(MetricsFunctionServerConfiguration.class, String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, port1)); waitForServerToStart(DEFAULT_HOSTNAME, port1); - final int port2 = findAvailablePort(); + final int port2 = findAndReserveAvailablePort(); gemfireServer2 = run(MetricsFunctionServerConfiguration.class, String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, port2)); waitForServerToStart(DEFAULT_HOSTNAME, port2); - System.setProperty(GEMFIRE_POOL_SERVERS_PROPERTY, String.format("%s[%d],%s[%d]", DEFAULT_HOSTNAME, port1, DEFAULT_HOSTNAME, port2)); + System.setProperty(GEMFIRE_POOL_SERVERS_PROPERTY, + String.format("%s[%d],%s[%d]", DEFAULT_HOSTNAME, port1, DEFAULT_HOSTNAME, port2)); } @AfterClass @@ -113,7 +119,6 @@ public class FunctionsReturnResultsFromAllServersIntegrationTests extends Forkin @ClientCacheApplication @EnableGemfireFunctionExecutions(basePackageClasses = AllServersAdminFunctions.class) - @EnableTransactionManagement static class TestConfiguration { } @CacheServerApplication @@ -121,11 +126,7 @@ public class FunctionsReturnResultsFromAllServersIntegrationTests extends Forkin public static class MetricsFunctionServerConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(MetricsFunctionServerConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(MetricsFunctionServerConfiguration.class, args); } @GemfireFunction(id = "GetAllMetricsFunction", hasResult = true) diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/QueryListenerAdapterUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/QueryListenerAdapterUnitTests.java index e9ef81bc..c482cc0f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/QueryListenerAdapterUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/QueryListenerAdapterUnitTests.java @@ -16,10 +16,15 @@ package org.springframework.data.gemfire.listener.adapter; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.same; -import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import org.junit.Before; @@ -44,20 +49,50 @@ public class QueryListenerAdapterUnitTests { private ContinuousQueryListenerAdapter adapter; - @Before - public void setUp() { - this.adapter = new ContinuousQueryListenerAdapter(); + @SuppressWarnings("unused") + interface Delegate { + + void handleEvent(CqEvent event); + + void handleQuery(CqQuery query); + + void handleOperation(Operation op); + + void handleArray(byte[] ba); + + void handleKey(Object key); + + void handleKeyValue(Object key, Object value); + + void handleError(Throwable th); + + void handleOperations(Operation base, Operation query); + + void handleAll(CqEvent event, CqQuery query, byte[] data, Object key, Operation op, Throwable error, Operation queryOp, Object value); + + void handleInvalid(Object o1, Object o2, Object o3); + } - CqEvent event() { + static class SampleListener implements ContinuousQueryListener { + + int count; + + @Override + public void onEvent(CqEvent event) { + count++; + } + } + + static CqEvent event() { return new CqEvent() { - final CqQuery cq = mock(CqQuery.class); final byte[] deltaValue = new byte[0]; + final CqQuery cq = mock(CqQuery.class); + final Exception exception = new Exception(); final Object key = new Object(); final Object value = new Object(); - final Exception exception = new Exception(); public Operation getBaseOperation() { return Operation.CACHE_CLOSE; @@ -89,29 +124,9 @@ public class QueryListenerAdapterUnitTests { }; } - @SuppressWarnings("unused") - interface Delegate { - - void handleEvent(CqEvent event); - - void handleQuery(CqQuery query); - - void handleOperation(Operation op); - - void handleArray(byte[] ba); - - void handleKey(Object key); - - void handleKV(Object k, Object v); - - void handleEx(Throwable th); - - void handleOps(Operation base, Operation query); - - void handleAll(CqEvent event, CqQuery query, byte[] ba, Object key, Operation op, Throwable th, Operation qOp, Object v); - - void handleInvalid(Object o1, Object o2, Object o3); - + @Before + public void setUp() { + this.adapter = new ContinuousQueryListenerAdapter(); } @Test @@ -126,7 +141,7 @@ public class QueryListenerAdapterUnitTests { } @Test - public void testAdapterWithListenerAndDefaultMessage() { + public void adapterWithListenerAndDefaultMessageOnEventIsCorrect() { ContinuousQueryListener mockCqListener = mock(ContinuousQueryListener.class); @@ -136,100 +151,11 @@ public class QueryListenerAdapterUnitTests { cqListenerAdapter.onEvent(event); - verify(mockCqListener).onEvent(same(event)); + verify(mockCqListener, times(1)).onEvent(same(event)); } @Test - public void testHandleEvent() { - - Delegate mockDelegate = mock(Delegate.class); - - ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); - - CqEvent event = event(); - - cqListenerAdapter.onEvent(event); - - verify(mockDelegate).handleEvent(same(event)); - } - - @Test - public void testHandleArray() { - - Delegate mockDelegate = mock(Delegate.class); - - ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); - - CqEvent event = event(); - - cqListenerAdapter.setDefaultListenerMethod("handleArray"); - cqListenerAdapter.onEvent(event); - - verify(mockDelegate).handleArray(eq(event.getDeltaValue())); - } - - @Test - public void testHandleKey() { - - Delegate mockDelegate = mock(Delegate.class); - - ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); - - CqEvent event = event(); - - cqListenerAdapter.setDefaultListenerMethod("handleKey"); - cqListenerAdapter.onEvent(event); - - verify(mockDelegate).handleKey(eq(event.getKey())); - } - - @Test - public void testHandleKV() { - - Delegate mockDelegate = mock(Delegate.class); - - ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); - - CqEvent event = event(); - - cqListenerAdapter.setDefaultListenerMethod("handleKV"); - cqListenerAdapter.onEvent(event); - - verify(mockDelegate).handleKV(eq(event.getKey()), eq(event.getNewValue())); - } - - @Test - public void testHandleEx() { - - Delegate mockDelegate = mock(Delegate.class); - - ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); - - CqEvent event = event(); - - cqListenerAdapter.setDefaultListenerMethod("handleEx"); - cqListenerAdapter.onEvent(event); - - verify(mockDelegate).handleEx(eq(event.getThrowable())); - } - - @Test - public void testHandleOps() { - - Delegate mockDelegate = mock(Delegate.class); - - ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); - - CqEvent event = event(); - - cqListenerAdapter.setDefaultListenerMethod("handleOps"); - cqListenerAdapter.onEvent(event); - - verify(mockDelegate).handleOps(eq(event.getBaseOperation()), eq(event.getQueryOperation())); - } - - @Test - public void testHandleAll() { + public void handlesAll() { Delegate mockDelegate = mock(Delegate.class); @@ -240,22 +166,134 @@ public class QueryListenerAdapterUnitTests { cqListenerAdapter.setDefaultListenerMethod("handleAll"); cqListenerAdapter.onEvent(event); - verify(mockDelegate).handleAll(eq(event), eq(event.getCq()), eq(event.getDeltaValue()), eq(event.getKey()), - eq(event.getBaseOperation()), eq(event.getThrowable()), eq(event.getQueryOperation()), + verify(mockDelegate, times(1)) + .handleAll(eq(event), eq(event.getCq()), eq(event.getDeltaValue()), eq(event.getKey()), + eq(event.getBaseOperation()), eq(event.getThrowable()), eq(event.getQueryOperation()), eq(event.getNewValue())); } @Test - public void testInvalid() { + public void handlesArray() { Delegate mockDelegate = mock(Delegate.class); ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); - cqListenerAdapter.setDefaultListenerMethod("handleInvalid"); - cqListenerAdapter.onEvent(event()); + CqEvent event = event(); - doThrow(new IllegalArgumentException()).when(mockDelegate); + cqListenerAdapter.setDefaultListenerMethod("handleArray"); + cqListenerAdapter.onEvent(event); + + verify(mockDelegate, times(1)).handleArray(eq(event.getDeltaValue())); + } + + @Test + public void handlesCqEvent() { + + Delegate mockDelegate = mock(Delegate.class); + + ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); + + CqEvent event = event(); + + cqListenerAdapter.onEvent(event); + + verify(mockDelegate, times(1)).handleEvent(same(event)); + } + + @Test + public void handlesCqQuery() { + + Delegate mockDelegate = mock(Delegate.class); + + ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); + + cqListenerAdapter.setDefaultListenerMethod("handleQuery"); + + CqEvent event = event(); + + cqListenerAdapter.onEvent(event); + + verify(mockDelegate, times(1)).handleQuery(same(event.getCq())); + } + + @Test + public void handlesError() { + + Delegate mockDelegate = mock(Delegate.class); + + ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); + + CqEvent event = event(); + + cqListenerAdapter.setDefaultListenerMethod("handleError"); + cqListenerAdapter.onEvent(event); + + verify(mockDelegate, times(1)).handleError(eq(event.getThrowable())); + } + + @Test + public void handlesKey() { + + Delegate mockDelegate = mock(Delegate.class); + + ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); + + CqEvent event = event(); + + cqListenerAdapter.setDefaultListenerMethod("handleKey"); + cqListenerAdapter.onEvent(event); + + verify(mockDelegate, times(1)).handleKey(eq(event.getKey())); + } + + @Test + public void handlesKeyValue() { + + Delegate mockDelegate = mock(Delegate.class); + + ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); + + CqEvent event = event(); + + cqListenerAdapter.setDefaultListenerMethod("handleKeyValue"); + cqListenerAdapter.onEvent(event); + + verify(mockDelegate, times(1)) + .handleKeyValue(eq(event.getKey()), eq(event.getNewValue())); + } + + @Test + public void handlesOperations() { + + Delegate mockDelegate = mock(Delegate.class); + + ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); + + CqEvent event = event(); + + cqListenerAdapter.setDefaultListenerMethod("handleOperations"); + cqListenerAdapter.onEvent(event); + + verify(mockDelegate, times(1)) + .handleOperations(eq(event.getBaseOperation()), eq(event.getQueryOperation())); + } + + @Test + public void handlesInvalid() { + + Delegate mockDelegate = mock(Delegate.class); + + try { + + ContinuousQueryListenerAdapter cqListenerAdapter = new ContinuousQueryListenerAdapter(mockDelegate); + + cqListenerAdapter.setDefaultListenerMethod("handleInvalid"); + cqListenerAdapter.onEvent(event()); + } + finally { + verify(mockDelegate, never()).handleInvalid(any(), any(), any()); + } } /** @@ -266,23 +304,12 @@ public class QueryListenerAdapterUnitTests { SampleListener listener = new SampleListener(); - ContinuousQueryListener listenerAdapter = new ContinuousQueryListenerAdapter(listener) { - protected void handleListenerException(Throwable cause) { - throw new RuntimeException(cause); - } - }; + ContinuousQueryListenerAdapter listenerAdapter = spy(new ContinuousQueryListenerAdapter(listener)); + + doAnswer(invocation -> { throw new RuntimeException(invocation.getArgument(0)); }) + .when(listenerAdapter).handleListenerException(isA(Throwable.class)); listenerAdapter.onEvent(event()); assertThat(listener.count).isEqualTo(1); } - - static class SampleListener implements ContinuousQueryListener { - - int count; - - @Override - public void onEvent(CqEvent event) { - count++; - } - } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java index d709e3f5..c3582341 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/config/IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests.java @@ -27,8 +27,6 @@ import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.client.ClientRegionShortcut; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; @@ -38,7 +36,7 @@ import org.springframework.data.gemfire.repository.sample.Animal; import org.springframework.data.gemfire.repository.sample.Plant; import org.springframework.data.gemfire.repository.sample.PlantRepository; import org.springframework.data.gemfire.repository.sample.RabbitRepository; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.repository.Repository; @@ -56,28 +54,23 @@ import org.springframework.data.repository.Repository; * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.context.annotation.Bean * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @see org.springframework.data.repository.Repository * @see PR-55 * @since 1.4.0 */ @SuppressWarnings("unused") -public class IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests extends IntegrationTestsSupport { - - private static ConfigurableApplicationContext newApplicationContext(Class testConfiguration) { - return new AnnotationConfigApplicationContext(testConfiguration); - } +public class IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTests + extends SpringApplicationContextIntegrationTestsSupport { @SuppressWarnings("rawtypes") - private void withTestConfigurationExpectIllegalArgumentExceptionWithMessage(Class testConfiguration, + private void usingTestConfigurationExpectIllegalArgumentExceptionWithMessage(Class testConfiguration, Class repositoryType, Supplier exceptionMessage) { try { - - ConfigurableApplicationContext applicationContext = newApplicationContext(testConfiguration); - - assertThat(applicationContext.getBean(repositoryType)).isNotNull(); + newApplicationContext(testConfiguration); + assertThat(getBean(repositoryType)).isNotNull(); } catch (BeanCreationException expected) { @@ -91,7 +84,7 @@ public class IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTe @Test(expected = IllegalArgumentException.class) public void withRegionUsingStringKeyAndRepositoryUsingLongId() { - withTestConfigurationExpectIllegalArgumentExceptionWithMessage( + usingTestConfigurationExpectIllegalArgumentExceptionWithMessage( TestIncompatibleRegionKeyRepositoryIdTypeConfiguration.class, RabbitRepository.class, () -> String.format("Region [/Rabbits] requires keys of type [%1$s], but Repository [%2$s] declared an id of type [%3$s]", @@ -101,7 +94,7 @@ public class IncompatibleRegionKeyRepositoryIdAndEntityIdRepositoryIntegrationTe @Test(expected = IllegalArgumentException.class) public void withRepositoryUsingStringIdAndEntityUsingLongId() { - withTestConfigurationExpectIllegalArgumentExceptionWithMessage( + usingTestConfigurationExpectIllegalArgumentExceptionWithMessage( TestIncompatibleRepositoryIdEntityIdTypeConfiguration.class, PlantRepository.class, () -> String.format("Repository [%1$s] declared an id of type [%2$s], but entity [%3$s] has an id of type [%4$s]", diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java index 4681fb87..c50953ca 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryRegionDeleteAllIntegrationTests.java @@ -130,7 +130,7 @@ public class SimpleGemfireRepositoryRegionDeleteAllIntegrationTests extends Fork static class GeodeServerTestConfiguration { public static void main(String[] args) { - runSpringApplication(GeodeServerTestConfiguration.class); + runSpringApplication(GeodeServerTestConfiguration.class, args); } @Bean("Users") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/WiringInstantiatorIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/WiringInstantiatorIntegrationTests.java index 93d2f642..6a539748 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/WiringInstantiatorIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/WiringInstantiatorIntegrationTests.java @@ -31,7 +31,6 @@ import org.apache.geode.DataSerializable; import org.apache.geode.Instantiator; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -49,17 +48,13 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration("simple-config.xml") +@ContextConfiguration @SuppressWarnings("unused") public class WiringInstantiatorIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; - @Autowired private WiringInstantiator instantiator; - public static class AnnotatedBean implements DataSerializable { @Autowired @@ -121,8 +116,8 @@ public class WiringInstantiatorIntegrationTests extends IntegrationTestsSupport assertThat(bean.point).isNotNull(); assertThat(bean.shape).isNotNull(); - assertThat(applicationContext.getBean("point")).isSameAs(bean.point); - assertThat(applicationContext.getBean("area")).isSameAs(bean.shape); + assertThat(requireApplicationContext().getBean("point")).isSameAs(bean.point); + assertThat(requireApplicationContext().getBean("area")).isSameAs(bean.shape); } @Test @@ -131,7 +126,7 @@ public class WiringInstantiatorIntegrationTests extends IntegrationTestsSupport WiringInstantiator instantiator2 = new WiringInstantiator(new AsmInstantiatorGenerator().getInstantiator(TemplateWiringBean.class, 99)); - instantiator2.setBeanFactory(applicationContext.getAutowireCapableBeanFactory()); + instantiator2.setBeanFactory(requireApplicationContext().getAutowireCapableBeanFactory()); instantiator2.afterPropertiesSet(); Object instance = instantiator2.newInstance(); @@ -142,12 +137,15 @@ public class WiringInstantiatorIntegrationTests extends IntegrationTestsSupport assertThat(bean.point).isNull(); assertThat(bean.beans).isNotNull(); - assertThat(applicationContext.getBean("beans")).isSameAs(bean.beans); + assertThat(requireApplicationContext().getBean("beans")).isSameAs(bean.beans); } + @SuppressWarnings("unchecked") public void testInstantiatorFactoryBean() { - @SuppressWarnings("unchecked") - List list = (List) applicationContext.getBean("instantiator-factory"); + + List list = + (List) requireApplicationContext().getBean("instantiator-factory", List.class); + assertThat(list).isNotNull(); assertThat(list.size()).isEqualTo(2); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests.java index 98842f67..a7d19720 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests.java @@ -51,6 +51,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.GemfireOperations * @see org.springframework.data.gemfire.serialization.json.JSONRegionAdvice + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @see com.fasterxml.jackson.databind.ObjectMapper @@ -60,9 +61,16 @@ import org.springframework.test.context.junit4.SpringRunner; @SuppressWarnings("unused") public class JSONRegionAdviceIntegrationTests extends IntegrationTestsSupport { - // TODO figure out why auto-proxying the Region for JSON support prevents the GemfireTemplate from being "auto-wired", - // as a GemfireTemplate rather than GemfireOperations, resulting in a NoSuchBeanDefinitionException thrown by the - // Spring container? + private static String toJson(Object bean) { + + try { + return new ObjectMapper().writeValueAsString(bean); + } + catch (JsonProcessingException cause) { + throw newIllegalArgumentException(cause, "Failed to convert object [%s] into JSON", bean); + } + } + @Autowired private GemfireOperations template; @@ -71,17 +79,7 @@ public class JSONRegionAdviceIntegrationTests extends IntegrationTestsSupport { @Before public void setup() { - jsonRegion.clear(); - } - - private static String toJson(Object bean) { - - try { - return new ObjectMapper().writeValueAsString(bean); - } - catch (JsonProcessingException cause) { - throw newIllegalArgumentException(cause, "Failed to convert object (%1$s) into JSON", bean); - } + this.jsonRegion.clear(); } @Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTests.java similarity index 80% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTests.java index c7c1bf5f..3b52cb92 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTests.java @@ -32,7 +32,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.data.gemfire.repository.sample.Person; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport; import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.data.gemfire.tests.util.ThreadUtils; import org.springframework.util.FileCopyUtils; @@ -45,11 +45,11 @@ import org.springframework.util.FileCopyUtils; * @see org.junit.Test * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean - * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.integration.SpringApplicationContextIntegrationTestsSupport * @since 1.7.0 */ @SuppressWarnings("unused") -public class SnapshotServiceImportExportIntegrationTest extends IntegrationTestsSupport { +public class SnapshotServiceImportExportIntegrationTests extends SpringApplicationContextIntegrationTestsSupport { private static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); @@ -93,33 +93,32 @@ public class SnapshotServiceImportExportIntegrationTest extends IntegrationTests File exportDirectory = new File(snapshotsDirectory, "export"); File importDirectory = new File(snapshotsDirectory, "import"); - assertThat(exportDirectory.isDirectory() || exportDirectory.mkdirs()).isTrue(); - assertThat(importDirectory.isDirectory() || importDirectory.mkdirs()).isTrue(); + createDirectory(exportDirectory); + createDirectory(importDirectory); importPeopleSnapshot = new File(importDirectory, "people-snapshot.gfd"); FileCopyUtils.copy(new ClassPathResource("/people.snapshot").getFile(), importPeopleSnapshot); - assertThat(importPeopleSnapshot.isFile()).isTrue(); - assertThat(importPeopleSnapshot.length() > 0).isTrue(); + assertThat(importPeopleSnapshot).isFile(); + assertThat(importPeopleSnapshot).isNotEmpty(); - applicationContext = new ClassPathXmlApplicationContext( - SnapshotServiceImportExportIntegrationTest.class.getName().replace(".", "/").concat("-context.xml")); + String configLocation = getContextXmlFileLocation(SnapshotServiceImportExportIntegrationTests.class); + applicationContext = new ClassPathXmlApplicationContext(configLocation); applicationContext.registerShutdownHook(); - people = applicationContext.getBean("People", Region.class); } @AfterClass public static void tearDownAfterClass() { - applicationContext.close(); + closeApplicationContext(applicationContext); File exportPeopleSnapshot = new File(new File(snapshotsDirectory, "export"), "people-snapshot.gfd"); - assertThat(exportPeopleSnapshot.isFile()).isTrue(); - assertThat(exportPeopleSnapshot.length()).isEqualTo(importPeopleSnapshot.length()); + assertThat(exportPeopleSnapshot).isFile(); + assertThat(exportPeopleSnapshot).hasSize(importPeopleSnapshot.length()); FileSystemUtils.deleteRecursive(snapshotsDirectory.getParentFile()); } @@ -132,18 +131,18 @@ public class SnapshotServiceImportExportIntegrationTest extends IntegrationTests private void setupPeople() { - put(newPerson("Jon", "Doe")); - put(newPerson("Jane", "Doe")); - put(newPerson("Cookie", "Doe")); - put(newPerson("Fro", "Doe")); - put(newPerson("Joe", "Doe")); - put(newPerson("Lan", "Doe")); - put(newPerson("Pie", "Doe")); - put(newPerson("Play", "Doe")); - put(newPerson("Sour", "Doe")); + save(newPerson("Jon", "Doe")); + save(newPerson("Jane", "Doe")); + save(newPerson("Cookie", "Doe")); + save(newPerson("Fro", "Doe")); + save(newPerson("Joe", "Doe")); + save(newPerson("Lan", "Doe")); + save(newPerson("Pie", "Doe")); + save(newPerson("Play", "Doe")); + save(newPerson("Sour", "Doe")); } - private Person put(Person person) { + private Person save(Person person) { people.putIfAbsent(person.getId(), person); return person; } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/ConnectionEndpointUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/ConnectionEndpointUnitTests.java index 2af0e469..2bb11962 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/ConnectionEndpointUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/ConnectionEndpointUnitTests.java @@ -34,6 +34,26 @@ import org.junit.Test; */ public class ConnectionEndpointUnitTests { + @Test + public void fromHostAndPort() { + + ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.from("testhost", 1234); + + assertThat(connectionEndpoint).isNotNull(); + assertThat(connectionEndpoint.getHost()).isEqualTo("testhost"); + assertThat(connectionEndpoint.getPort()).isEqualTo(1234); + } + + @Test + public void fromPort() { + + ConnectionEndpoint connectionEndpoint = ConnectionEndpoint.from(4321); + + assertThat(connectionEndpoint).isNotNull(); + assertThat(connectionEndpoint.getHost()).isEqualTo(ConnectionEndpoint.DEFAULT_HOST); + assertThat(connectionEndpoint.getPort()).isEqualTo(4321); + } + @Test public void fromInetSocketAddress() { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DisableBeanDefinitionOverridingApplicationContextInitializerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DisableBeanDefinitionOverridingApplicationContextInitializerIntegrationTests.java index fa12e3d8..3c5abee8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DisableBeanDefinitionOverridingApplicationContextInitializerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DisableBeanDefinitionOverridingApplicationContextInitializerIntegrationTests.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -37,6 +38,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.context.ApplicationContextInitializer * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.support.DisableBeanDefinitionOverridingApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 2.6.0 @@ -44,7 +46,8 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(initializers = DisableBeanDefinitionOverridingApplicationContextInitializer.class) @SuppressWarnings("unused") -public class DisableBeanDefinitionOverridingApplicationContextInitializerIntegrationTests { +public class DisableBeanDefinitionOverridingApplicationContextInitializerIntegrationTests + extends IntegrationTestsSupport { @Autowired private ConfigurableApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java index e7fa94af..5ab35453 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportIntegrationTests.java @@ -23,6 +23,7 @@ import java.util.Properties; import javax.sql.DataSource; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,6 +33,7 @@ import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.data.gemfire.repository.sample.User; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.support.DataSourceAdapter; +import org.springframework.data.gemfire.util.PropertiesBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; @@ -52,15 +54,18 @@ import org.springframework.util.Assert; @SuppressWarnings("unused") public class LazyWiringDeclarableSupportIntegrationTests extends IntegrationTestsSupport { + private static Properties createParameters(String parameter, String value) { + return PropertiesBuilder.create().setProperty(parameter, value).build(); + } + + @AfterClass + public static void tearDown() { + SpringContextBootstrappingInitializer.destroy(); + } + @Autowired private ApplicationContext applicationContext; - private static Properties createParameters(String parameter, String value) { - Properties parameters = new Properties(); - parameters.setProperty(parameter, value); - return parameters; - } - @Test public void autoWiringSuccessful() { @@ -93,6 +98,7 @@ public class LazyWiringDeclarableSupportIntegrationTests extends IntegrationTest public void autoWiringWithNonExistingBeanTemplateThrowsIllegalArgumentException() { try { + TestDeclarable declarable = new TestDeclarable(); declarable.init(createParameters(TEMPLATE_BEAN_NAME_PROPERTY, "nonExistingBeanTemplate")); @@ -116,17 +122,17 @@ public class LazyWiringDeclarableSupportIntegrationTests extends IntegrationTest @Autowired private User user; - public final void setDataSource(DataSource dataSource) { + public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } - DataSource getDataSource() { - return dataSource; + public DataSource getDataSource() { + return this.dataSource; } - protected User getUser() { - Assert.state(user != null, "A reference to the User was not properly configured"); - return user; + User getUser() { + Assert.state(this.user != null, "A reference to the User was not properly configured"); + return this.user; } } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportUnitTests.java index 951ede6a..736acd13 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupportUnitTests.java @@ -28,6 +28,7 @@ import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; @@ -35,6 +36,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.data.gemfire.util.PropertiesBuilder; /** * Unit Tests for {@link LazyWiringDeclarableSupport}. @@ -58,12 +60,12 @@ public class LazyWiringDeclarableSupportUnitTests { } private static Properties createParameters(String parameter, String value) { + return PropertiesBuilder.create().setProperty(parameter, value).build(); + } - Properties parameters = new Properties(); - - parameters.setProperty(parameter, value); - - return parameters; + @After + public void tearDown() { + SpringContextBootstrappingInitializer.destroy(); } @Test @@ -445,6 +447,7 @@ public class LazyWiringDeclarableSupportUnitTests { @Override void doInit(BeanFactory beanFactory, Properties parameters) { + this.actualBeanFactory = beanFactory; this.actualParameters = parameters; this.initialized = true; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTests.java index 9213a3a3..d666cb73 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTests.java @@ -16,24 +16,22 @@ package org.springframework.data.gemfire.support; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; import java.time.Instant; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import javax.sql.DataSource; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheLoaderException; @@ -71,77 +69,27 @@ import org.springframework.util.Assert; @SuppressWarnings("unused") public class SpringContextBootstrappingInitializerIntegrationTests extends IntegrationTestsSupport { - private static final long CACHE_CLOSE_TIMEOUT = TimeUnit.SECONDS.toMillis(15); - - private static final Object MUTEX_LOCK = new Object(); - - protected static final String GEMFIRE_LOCATORS = "localhost[11235]"; protected static final String GEMFIRE_LOG_LEVEL = "error"; protected static final String GEMFIRE_JMX_MANAGER = "true"; protected static final String GEMFIRE_JMX_MANAGER_PORT = "1199"; protected static final String GEMFIRE_JMX_MANAGER_START = "true"; - protected static final String GEMFIRE_MCAST_PORT = "0"; protected static final String GEMFIRE_NAME = SpringContextBootstrappingInitializerIntegrationTests.class.getSimpleName(); protected static final String GEMFIRE_START_LOCATORS = "localhost[11235]"; - @Before - public void setup() { - - try { - - long timeout = System.currentTimeMillis() + CACHE_CLOSE_TIMEOUT; - - while (CacheFactory.getAnyInstance() != null && System.currentTimeMillis() < timeout) { - synchronized (MUTEX_LOCK) { - try { - MUTEX_LOCK.wait(500L); - } - catch (InterruptedException ignore) { } - } - } - - fail(String.format("The Cache instance was not properly closed in the allotted timeout of %d seconds%n", - TimeUnit.MILLISECONDS.toSeconds(CACHE_CLOSE_TIMEOUT))); - } - catch (CacheClosedException ignore) { } + @AfterClass + public static void cleanupAfterTests() { + SpringContextBootstrappingInitializer.destroy(); } - @After - public void tearDown() { + @Before @After + public void testSetupAndTearDown() { + + SpringUtils.safeDoOperation(() -> + closeApplicationContext(SpringContextBootstrappingInitializer.getApplicationContext())); - SpringContextBootstrappingInitializer.getApplicationContext().close(); UserDataStoreCacheLoader.INSTANCE.set(null); - tearDownCache(); - } - private void tearDownCache() { - - try { - - Cache cache = CacheFactory.getAnyInstance(); - - if (cache != null) { - - cache.close(); - - // Now, wait for the Apache Geode or Pivotal GemFire Hog to shutdown, OIY! - synchronized (MUTEX_LOCK) { - - SpringUtils.safeRunOperation(() -> { - while (!cache.isClosed()) { - MUTEX_LOCK.wait(500L); - } - }); - - MUTEX_LOCK.notifyAll(); - } - } - } - catch (CacheClosedException ignore) { - // CacheClosedExceptions happen when the Cache reference returned by GemFireCacheImpl.getInstance() - // inside the CacheFactory.getAnyInstance() is null, or the Cache is already closed with calling - // Cache.close(); - } + closeAnyGemFireCache(); } @SuppressWarnings("all") @@ -151,14 +99,19 @@ public class SpringContextBootstrappingInitializerIntegrationTests extends Integ .set("name", GEMFIRE_NAME) .set("log-level", GEMFIRE_LOG_LEVEL) .set("cache-xml-file", cacheXmlFile) - //.set("start-locator", GEMFIRE_LOCATORS) + //.set("start-locator", GEMFIRE_START_LOCATORS) //.set("jmx-manager", GEMFIRE_JMX_MANAGER) //.set("jmx-manager-port", GEMFIRE_JMX_MANAGER_PORT) //.set("jmx-manager-start", GEMFIRE_JMX_MANAGER_START) .create(); - assertThat(gemfireCache).as("The GemFire Cache was not properly created and initialized!").isNotNull(); - assertThat(gemfireCache.isClosed()).as("The GemFire Cache is closed!").isFalse(); + assertThat(gemfireCache) + .describedAs("GemFireCache was not properly created and initialized") + .isNotNull(); + + assertThat(gemfireCache.isClosed()) + .describedAs("GemFireCache is closed") + .isFalse(); Set> rootRegions = gemfireCache.rootRegions(); @@ -205,7 +158,7 @@ public class SpringContextBootstrappingInitializerIntegrationTests extends Integ } @Test - public void testSpringContextBootstrappingInitializerUsingAnnotatedClasses() { + public void springContextBootstrappingInitializerUsingAnnotatedClassesIsCorrect() { SpringContextBootstrappingInitializer.register(TestAppConfig.class); @@ -221,13 +174,13 @@ public class SpringContextBootstrappingInitializerIntegrationTests extends Integ } @Test - public void testSpringContextBootstrappingInitializerUsingBasePackages() { + public void springContextBootstrappingInitializerUsingXmlWithBasePackages() { doSpringContextBootstrappingInitializationTest( "cache-with-spring-context-bootstrap-initializer-using-base-packages.xml"); } @Test - public void testSpringContextBootstrappingInitializerUsingContextConfigLocations() { + public void springContextBootstrappingInitializerUsingXmlWithContextConfigLocations() { doSpringContextBootstrappingInitializationTest( "cache-with-spring-context-bootstrap-initializer.xml"); } @@ -264,19 +217,19 @@ public class SpringContextBootstrappingInitializerIntegrationTests extends Integ @Autowired private DataSource userDataSource; - protected static User createUser(String username) { + static User createUser(String username) { return createUser(username, true, Instant.now(), String.format("%1$s@xcompay.com", username)); } - protected static User createUser(String username, Boolean active) { + static User createUser(String username, Boolean active) { return createUser(username, active, Instant.now(), String.format("%1$s@xcompay.com", username)); } - protected static User createUser(String username, Boolean active, Instant since) { + static User createUser(String username, Boolean active, Instant since) { return createUser(username, active, since, String.format("%1$s@xcompay.com", username)); } - protected static User createUser(String username, Boolean active, Instant since, String email) { + static User createUser(String username, Boolean active, Instant since, String email) { User user = new User(username); @@ -306,7 +259,7 @@ public class SpringContextBootstrappingInitializerIntegrationTests extends Integ getClass().getName())); } - protected DataSource getDataSource() { + DataSource getDataSource() { return this.userDataSource; } @@ -315,6 +268,12 @@ public class SpringContextBootstrappingInitializerIntegrationTests extends Integ this.userDataSource = null; } + @Override + public void destroy() throws Exception { + super.destroy(); + INSTANCE.set(null); + } + @Override public User load(LoaderHelper helper) throws CacheLoaderException { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerUnitTests.java index bb19cef8..e62f8cd6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerUnitTests.java @@ -88,12 +88,7 @@ public class SpringContextBootstrappingInitializerUnitTests { @After public void tearDown() { - - SpringContextBootstrappingInitializer.applicationContext = null; - SpringContextBootstrappingInitializer.contextRefreshedEvent = null; - SpringContextBootstrappingInitializer.setBeanClassLoader(null); - SpringContextBootstrappingInitializer.unregister(TestAppConfigOne.class); - SpringContextBootstrappingInitializer.unregister(TestAppConfigTwo.class); + SpringContextBootstrappingInitializer.destroy(); } @Test @@ -205,7 +200,7 @@ public class SpringContextBootstrappingInitializerUnitTests { SpringContextBootstrappingInitializer initializer = spy(new SpringContextBootstrappingInitializer() { @Override - ConfigurableApplicationContext createApplicationContext(String[] configLocations) { + ConfigurableApplicationContext newApplicationContext(String[] configLocations) { return ObjectUtils.isEmpty(configLocations) ? mockAnnotationApplicationContext @@ -241,7 +236,7 @@ public class SpringContextBootstrappingInitializerUnitTests { SpringContextBootstrappingInitializer initializer = spy(new SpringContextBootstrappingInitializer() { @Override - ConfigurableApplicationContext createApplicationContext(String[] configLocations) { + ConfigurableApplicationContext newApplicationContext(String[] configLocations) { return ObjectUtils.isEmpty(configLocations) ? mockAnnotationApplicationContext @@ -273,7 +268,7 @@ public class SpringContextBootstrappingInitializerUnitTests { SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer() { @Override - ConfigurableApplicationContext createApplicationContext(final String[] configLocations) { + ConfigurableApplicationContext newApplicationContext(final String[] configLocations) { return ObjectUtils.isEmpty(configLocations) ? mockAnnotationApplicationContext @@ -532,7 +527,7 @@ public class SpringContextBootstrappingInitializerUnitTests { SpringContextBootstrappingInitializer initializer = spy(new SpringContextBootstrappingInitializer() { @Override - protected ConfigurableApplicationContext createApplicationContext(String[] configLocations) { + protected ConfigurableApplicationContext newApplicationContext(String[] configLocations) { return mockApplicationContext; } }); @@ -813,8 +808,8 @@ public class SpringContextBootstrappingInitializerUnitTests { assertThat(SpringContextBootstrappingInitializer.contextRefreshedEvent).isNull(); assertUnnotified(testApplicationListener); - ContextRefreshedEvent mockContextRefreshedEvent = mock(ContextRefreshedEvent.class, - "MockContextRefreshedEvent"); + ContextRefreshedEvent mockContextRefreshedEvent = + mock(ContextRefreshedEvent.class, "MockContextRefreshedEvent"); new SpringContextBootstrappingInitializer().onApplicationEvent(mockContextRefreshedEvent); @@ -897,8 +892,8 @@ public class SpringContextBootstrappingInitializerUnitTests { assertUnnotified(testApplicationListenerTwo); assertUnnotified(testApplicationListenerThree); - ContextRefreshedEvent mockContextRefreshedEvent = mock(ContextRefreshedEvent.class, - "MockContextRefreshedEvent"); + ContextRefreshedEvent mockContextRefreshedEvent = + mock(ContextRefreshedEvent.class,"MockContextRefreshedEvent"); new SpringContextBootstrappingInitializer().onApplicationEvent(mockContextRefreshedEvent); @@ -920,13 +915,15 @@ public class SpringContextBootstrappingInitializerUnitTests { TestApplicationListener testApplicationListener = new TestApplicationListener("TestApplicationListener"); try { - testApplicationListener = SpringContextBootstrappingInitializer.unregister( - SpringContextBootstrappingInitializer.register(testApplicationListener)); + + testApplicationListener = SpringContextBootstrappingInitializer. + unregister(SpringContextBootstrappingInitializer.register(testApplicationListener)); assertUnnotified(testApplicationListener); - new SpringContextBootstrappingInitializer().onApplicationEvent(mock(ContextRefreshedEvent.class, - "MockContextRefreshedEvent")); + ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class,"MockContextRefreshedEvent"); + + new SpringContextBootstrappingInitializer().onApplicationEvent(mockEvent); assertUnnotified(testApplicationListener); } @@ -940,8 +937,8 @@ public class SpringContextBootstrappingInitializerUnitTests { assertThat(SpringContextBootstrappingInitializer.contextRefreshedEvent).isNull(); - TestApplicationListener testApplicationListener = new TestApplicationListener( - "testNotifyOnExistingContextRefreshedEventBeforeApplicationContextExists"); + TestApplicationListener testApplicationListener = + new TestApplicationListener("testNotifyOnExistingContextRefreshedEventBeforeApplicationContextExists"); try { testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener); @@ -959,8 +956,8 @@ public class SpringContextBootstrappingInitializerUnitTests { new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent); - TestApplicationListener testApplicationListener = new TestApplicationListener( - "testNotifyOnExistingContextRefreshedEventAfterContextRefreshed"); + TestApplicationListener testApplicationListener = + new TestApplicationListener("testNotifyOnExistingContextRefreshedEventAfterContextRefreshed"); try { testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener); @@ -979,16 +976,17 @@ public class SpringContextBootstrappingInitializerUnitTests { SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer(); - TestApplicationListener testApplicationListenerOne = new TestApplicationListener( - "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.1"); + TestApplicationListener testApplicationListenerOne = + new TestApplicationListener("testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.1"); - TestApplicationListener testApplicationListenerTwo = new TestApplicationListener( - "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.2"); + TestApplicationListener testApplicationListenerTwo = + new TestApplicationListener("testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.2"); - TestApplicationListener testApplicationListenerThree = new TestApplicationListener( - "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.3"); + TestApplicationListener testApplicationListenerThree = + new TestApplicationListener("testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.3"); try { + testApplicationListenerOne = SpringContextBootstrappingInitializer.register(testApplicationListenerOne); assertUnnotified(testApplicationListenerOne); @@ -1061,7 +1059,7 @@ public class SpringContextBootstrappingInitializerUnitTests { private final String name; - public TestApplicationListener(final String name) { + public TestApplicationListener(String name) { this.name = name; } @@ -1078,7 +1076,7 @@ public class SpringContextBootstrappingInitializerUnitTests { } @Override - public void onApplicationEvent(final ContextRefreshedEvent event) { + public void onApplicationEvent(ContextRefreshedEvent event) { this.actualEvent = event; this.notified = true; } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderIntegrationTests.java index 3f00fb57..91a67e1f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderIntegrationTests.java @@ -26,7 +26,8 @@ import org.apache.geode.distributed.ServerLauncher; import org.apache.geode.distributed.ServerLauncher.ServerState; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.data.gemfire.GemfireUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.util.SpringUtils; /** * Integration Tests {@link SpringServerLauncherCacheProvider} class. @@ -44,18 +45,15 @@ import org.springframework.data.gemfire.GemfireUtils; * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.support.SpringServerLauncherCacheProvider */ -public class SpringServerLauncherCacheProviderIntegrationTests { +public class SpringServerLauncherCacheProviderIntegrationTests extends IntegrationTestsSupport { @After public void tearDown() { - System.clearProperty(gemfireName()); - SpringContextBootstrappingInitializer.getApplicationContext().close(); - GemfireUtils.closeClientCache(); - } + SpringUtils.safeDoOperation(() -> + closeApplicationContext(SpringContextBootstrappingInitializer.getApplicationContext())); - private String gemfireName() { - return GemfireUtils.GEMFIRE_PREFIX + GemfireUtils.NAME_PROPERTY_NAME; + SpringContextBootstrappingInitializer.destroy(); } @Test @@ -66,7 +64,7 @@ public class SpringServerLauncherCacheProviderIntegrationTests { ServerLauncher.Builder builder = new ServerLauncher.Builder(); builder.setSpringXmlLocation(springXmlLocation); - builder.setMemberName("membername"); + builder.setMemberName("TestMemberName"); builder.setDisableDefaultServer(true); ServerLauncher launcher = builder.build(); @@ -81,6 +79,7 @@ public class SpringServerLauncherCacheProviderIntegrationTests { Cache cache = applicationContext.getBean(Cache.class); assertThat(cache).isNotNull(); + assertThat(cache.getName()).isEqualTo("TestMemberName"); assertThat(cache.getResourceManager().getCriticalHeapPercentage()).isEqualTo(55.0f); state = launcher.stop(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderUnitTests.java index a35511aa..618455d1 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/SpringServerLauncherCacheProviderUnitTests.java @@ -17,7 +17,9 @@ package org.springframework.data.gemfire.support; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -32,7 +34,8 @@ import org.apache.geode.distributed.ServerLauncher; import org.apache.geode.distributed.ServerLauncherCacheProvider; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.data.gemfire.GemfireUtils; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.util.PropertiesBuilder; /** * Unit Tests testing the contract and functionality of the {@link SpringServerLauncherCacheProvider} class. @@ -43,7 +46,9 @@ import org.springframework.data.gemfire.GemfireUtils; * @author Dan Smith * @author John Blum * @see org.junit.Test + * @see org.mockito.Mock * @see org.mockito.Mockito + * @see org.mockito.Spy * @see org.apache.geode.cache.Cache * @see org.apache.geode.distributed.ServerLauncher * @see org.apache.geode.distributed.ServerLauncherCacheProvider @@ -51,22 +56,15 @@ import org.springframework.data.gemfire.GemfireUtils; * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.support.SpringServerLauncherCacheProvider */ -public class SpringServerLauncherCacheProviderUnitTests { - - private String gemfireName() { - return (GemfireUtils.GEMFIRE_PREFIX + GemfireUtils.NAME_PROPERTY_NAME); - } +public class SpringServerLauncherCacheProviderUnitTests extends IntegrationTestsSupport { private Properties singletonProperties(String propertyName, String propertyValue) { - Properties properties = new Properties(); - properties.setProperty(propertyName, propertyValue); - return properties; + return PropertiesBuilder.create().setProperty(propertyName, propertyValue).build(); } @After public void tearDown() { - System.clearProperty(gemfireName()); - SpringContextBootstrappingInitializer.applicationContext = null; + SpringContextBootstrappingInitializer.destroy(); } @Test @@ -85,16 +83,13 @@ public class SpringServerLauncherCacheProviderUnitTests { final SpringContextBootstrappingInitializer initializer = mock(SpringContextBootstrappingInitializer.class); - SpringServerLauncherCacheProvider provider = new SpringServerLauncherCacheProvider() { + SpringServerLauncherCacheProvider provider = spy(new SpringServerLauncherCacheProvider()); - @Override - public SpringContextBootstrappingInitializer newSpringContextBootstrappingInitializer() { - return initializer; - } - }; + doReturn(initializer).when(provider).newSpringContextBootstrappingInitializer(); - Properties expectedParameters = singletonProperties( - SpringContextBootstrappingInitializer.CONTEXT_CONFIG_LOCATIONS_PARAMETER, "test-context.xml"); + Properties expectedParameters = + singletonProperties(SpringContextBootstrappingInitializer.CONTEXT_CONFIG_LOCATIONS_PARAMETER, + "test-context.xml"); assertThat(provider.createCache(null, mockServerLauncher)).isEqualTo(mockCache); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java index 2af2dfd6..102d2c34 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java @@ -22,6 +22,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.cache.Cache; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; /** * Abstract base test class for native cache implementations. @@ -30,8 +31,9 @@ import org.springframework.cache.Cache; * @author John Blum * @see org.junit.Test * @see org.springframework.cache.Cache + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport */ -public abstract class AbstractNativeCacheTests { +public abstract class AbstractNativeCacheTests extends IntegrationTestsSupport { protected static final String CACHE_NAME = "Example"; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/CommitConflictExceptionTransactionalIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/CommitConflictExceptionTransactionalIntegrationTests.java index 8a8649dc..8ce6f2ff 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/CommitConflictExceptionTransactionalIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/CommitConflictExceptionTransactionalIntegrationTests.java @@ -42,6 +42,7 @@ import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedReg 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.transaction.config.EnableGemfireCacheTransactions; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Service; @@ -55,7 +56,7 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** - * Integration tests asserting the proper configuration and behavior of Apache Geode/Pivotal GemFire + * Integration Tests asserting the proper configuration and behavior of Apache Geode/Pivotal GemFire * cache Transactions inside a Spring application context when using SDG to configure * the {@link CacheTransactionManager}. * @@ -72,6 +73,7 @@ import lombok.RequiredArgsConstructor; * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions * @see org.springframework.data.gemfire.repository.config.EnableGemfireRepositories + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport * @see org.springframework.data.gemfire.transaction.config.EnableGemfireCacheTransactions * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner @@ -80,7 +82,7 @@ import lombok.RequiredArgsConstructor; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class CommitConflictExceptionTransactionalIntegrationTests { +public class CommitConflictExceptionTransactionalIntegrationTests extends IntegrationTestsSupport { @Autowired private CustomerService customerService; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java index 650e44b4..a6907835 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests.java @@ -33,7 +33,6 @@ import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.client.ClientCache; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.OptimisticLockingFailureException; @@ -126,11 +125,7 @@ public class ConcurrentClientTransactionalDataAccessWithRollbackIntegrationTests static class TestGeodeServerConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(TestGeodeServerConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(TestGeodeServerConfiguration.class, args); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/config/EnableGemfireCacheTransactionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/config/EnableGemfireCacheTransactionsIntegrationTests.java index fcb23926..2f2cd680 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/config/EnableGemfireCacheTransactionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/transaction/config/EnableGemfireCacheTransactionsIntegrationTests.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.transaction.config; -import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import javax.annotation.Resource; @@ -30,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.transaction.GemfireTransactionManager; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; @@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** - * Integration tests for {@link EnableGemfireCacheTransactions} and {@link GemfireCacheTransactionsConfiguration}. + * Integration Tests for {@link EnableGemfireCacheTransactions} and {@link GemfireCacheTransactionsConfiguration}. * * @author John Blum * @see org.junit.Test @@ -57,7 +57,7 @@ import org.springframework.transaction.annotation.Transactional; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class EnableGemfireCacheTransactionsIntegrationTests { +public class EnableGemfireCacheTransactionsIntegrationTests extends IntegrationTestsSupport { @Resource(name = "Example") private Region example; @@ -73,6 +73,7 @@ public class EnableGemfireCacheTransactionsIntegrationTests { @Test public void transactionManagerIsConfigured() { + assertThat(this.gemfireCache).isNotNull(); assertThat(this.transactionManager).isNotNull(); assertThat(this.transactionManager.getCache()).isSameAs(this.gemfireCache); @@ -91,6 +92,7 @@ public class EnableGemfireCacheTransactionsIntegrationTests { @Test(expected = RuntimeException.class) public void doInTransactionRollsback() { + try { assertThat(example).doesNotContainKey(2); transactionalService.doInTransactionRollsBack(2, "fail"); @@ -108,7 +110,7 @@ public class EnableGemfireCacheTransactionsIntegrationTests { @SuppressWarnings("unused") @EnableGemfireCacheTransactions - @PeerCacheApplication(name = "EnableGemfireCacheTransactionsIntegrationTests", logLevel = "warning") + @PeerCacheApplication(name = "EnableGemfireCacheTransactionsIntegrationTests") static class TestConfiguration { @Bean("Example") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests.java index 309e2e48..2143eca6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests.java @@ -30,8 +30,7 @@ import org.apache.geode.cache.asyncqueue.AsyncEventQueue; import org.apache.geode.cache.wan.GatewaySender; 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.data.gemfire.tests.unit.annotation.GemFireUnitTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -46,15 +45,14 @@ import org.springframework.util.StringUtils; * @see org.apache.geode.cache.asyncqueue.AsyncEventListener * @see org.apache.geode.cache.asyncqueue.AsyncEventQueue * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport - * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer + * @see org.springframework.data.gemfire.tests.unit.annotation.GemFireUnitTest * @see org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringRunner * @since 1.0.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "asyncEventQueueWithListener.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@GemFireUnitTest @SuppressWarnings("unused") public class AsyncEventQueueWithListenerIntegrationTests extends IntegrationTestsSupport { @@ -164,6 +162,5 @@ public class AsyncEventQueueWithListenerIntegrationTests extends IntegrationTest public String toString() { return (StringUtils.hasText(getName()) ? getName() : getClass().getName()); } - } } diff --git a/spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTests-context.xml b/spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTests-context.xml index 85f5882b..3aa21c36 100644 --- a/spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - SpringServerLauncherCacheProviderIntegrationTest + SpringServerLauncherCacheProviderIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml index 0000180d..497f5801 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/allowRegionBeanDefinitionOverridesTest.xml @@ -9,12 +9,14 @@ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd "> + + AllowBeanDefinitionOverridesTest error - + + ClientCacheManagerIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/cacheUsingLocalConfigurationIntegrationTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/cacheUsingLocalConfigurationIntegrationTest.xml index 3ee19504..b0448eff 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/cacheUsingLocalConfigurationIntegrationTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/cacheUsingLocalConfigurationIntegrationTest.xml @@ -20,7 +20,7 @@ + use-cluster-configuration="false"/> diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-context.xml index 8d8fd338..392bfe86 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-context.xml @@ -1,23 +1,27 @@ + + - ClientCacheIndexingTestServer + ClientCacheIndexingIntegrationTests error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-server-context.xml index 3f8abf8c..ca343d68 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheIndexingIntegrationTests-server-context.xml @@ -1,22 +1,26 @@ + + - ClientCacheIndexingTestServer + ClientCacheIndexingIntegrationTestsServer error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-context.xml index 80b3a27d..40a8e0d5 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-context.xml @@ -1,22 +1,27 @@ + + + ClientCachePoolIntegrationTests error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-server-context.xml index 0059ae5c..0c42a1f7 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCachePoolIntegrationTests-server-context.xml @@ -1,23 +1,27 @@ + + - ClientCachePoolTestsServer + ClientCachePoolIntegrationTestsServer error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests-server-context.xml index f159db17..43ff506e 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/client/ClientCacheVariableServersIntegrationTests-server-context.xml @@ -20,11 +20,9 @@ - - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subscription-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheSubscriptionNamespaceIntegrationTests-context.xml similarity index 94% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subscription-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheSubscriptionNamespaceIntegrationTests-context.xml index 9ea25464..f5ebe54d 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subscription-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheSubscriptionNamespaceIntegrationTests-context.xml @@ -10,7 +10,7 @@ " default-lazy-init="true"> - SubscriptionNamespaceTest + CacheSubscriptionNamespaceIntegrationTests error @@ -25,7 +25,6 @@ - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/cache-using-pdx-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests-context.xml similarity index 93% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/cache-using-pdx-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests-context.xml index 85a66eb0..1ddf7038 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/cache-using-pdx-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - CacheUsingPdxNamespaceTest + CacheUsingPdxNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutIntegrationTests-context.xml similarity index 99% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutIntegrationTests-context.xml index 7185ee37..b2e0e654 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutIntegrationTests-context.xml @@ -15,6 +15,7 @@ + @@ -77,13 +78,13 @@ - + - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/function-service-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests-context.xml similarity index 85% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/function-service-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests-context.xml index 4c00fed3..7ade9c13 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/function-service-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceIntegrationTests-context.xml @@ -9,11 +9,11 @@ - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceIntegrationTests-context.xml similarity index 86% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceIntegrationTests-context.xml index 9ccec8b9..45544424 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceIntegrationTests-context.xml @@ -10,7 +10,7 @@ " default-lazy-init="true"> - GemfireV7GatewayNamespaceTest + GemfireV7GatewayNamespaceIntegrationTests error @@ -28,7 +28,7 @@ persistent="true" order-policy="KEY"> - + @@ -51,10 +51,10 @@ socket-buffer-size="16536" socket-read-timeout="3000"> - + - + @@ -63,7 +63,7 @@ - + @@ -73,11 +73,11 @@ manual-start="true"> - + - + @@ -88,7 +88,7 @@ - - + + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v8-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests-context.xml similarity index 96% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v8-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests-context.xml index 5889ba34..269e8e1e 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/gateway-v8-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceIntegrationTests-context.xml @@ -11,7 +11,7 @@ "> - GemfireV8GatewayNamespaceTest + GemfireV8GatewayNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceIntegrationTests.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceIntegrationTests.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests-context.xml index 8671af6e..b5c914d3 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests-context.xml @@ -10,6 +10,8 @@ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd "> + + InvalidRegionExpirationAttributesNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/jndi-binding-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/JndiBindingsNamespaceIntegrationTests-context.xml similarity index 96% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/jndi-binding-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/JndiBindingsNamespaceIntegrationTests-context.xml index 1c015adf..91e166ee 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/jndi-binding-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/JndiBindingsNamespaceIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - JndiBindingNamespaceConfig + JndiBindingsNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/jndi-binding-with-property-placeholders-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests-context.xml similarity index 97% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/jndi-binding-with-property-placeholders-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests-context.xml index fd014a47..9ebea201 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/jndi-binding-with-property-placeholders-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests-context.xml @@ -12,7 +12,7 @@ "> - JndiBindingWithPropertyPlaceholdersNamespaceConfig + JndiBindingsWithPropertyPlaceholdersNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheIntegrationTests-context.xml similarity index 94% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheIntegrationTests-context.xml index 6f2b6570..7494172b 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - MultipleCacheTest + MultipleCacheIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/partitioned-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests-context.xml similarity index 98% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/partitioned-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests-context.xml index 39381c5b..4eb5a992 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/partitioned-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceIntegrationTests-context.xml @@ -13,7 +13,7 @@ "> - PartitionedNamespaceConfig + PartitionedRegionNamespaceIntegrationTests error 64m diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/pool-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests-context.xml similarity index 97% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/pool-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests-context.xml index 9e3e4856..bb6125f3 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/pool-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/PoolNamespaceIntegrationTests-context.xml @@ -14,6 +14,7 @@ + PoolNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregion-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests-context.xml similarity index 97% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregion-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests-context.xml index 73866e39..05833d01 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregion-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/SubRegionNamespaceIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - SubRegionNamespaceConfig + SubRegionNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregionsubelement-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests-context.xml similarity index 96% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregionsubelement-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests-context.xml index f13a8744..cbf7677c 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/subregionsubelement-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - SubRegionSubElementNamespaceTest + SubRegionSubElementNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests-context.xml similarity index 84% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests-context.xml index 16f59145..151462e3 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceIntegrationTests-context.xml @@ -7,6 +7,8 @@ http://www.springframework.org/schema/geode https://www.springframework.org/schema/geode/spring-geode.xsd "> + + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TransactionManagerNamespaceIntegrationTests-context.xml similarity index 92% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TransactionManagerNamespaceIntegrationTests-context.xml index 6c262bd9..0e252022 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TransactionManagerNamespaceIntegrationTests-context.xml @@ -9,7 +9,7 @@ "> - TransactionNamespaceTest + TransactionManagerNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml index f244079c..b9ce34bd 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableClientRegionLookupsTest.xml @@ -10,6 +10,7 @@ "> + EnableClientRegionLookupsTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableRegionLookupsTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableRegionLookupsTest.xml index c5f316e0..8afbc8f9 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableRegionLookupsTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/enableRegionLookupsTest.xml @@ -10,7 +10,7 @@ "> - springGemFireEnableRegionLookupsTest + EnableRegionLookupsTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-context.xml index 36715f8a..76fa4c2d 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-context.xml @@ -1,22 +1,27 @@ + + + ExceptionThrowingFunctionExecutionIntegrationTests error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-server-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-server-context.xml index 6ff1b922..1291a53a 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-server-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/ExceptionThrowingFunctionExecutionIntegrationTests-server-context.xml @@ -10,24 +10,17 @@ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd "> - - localhost - localhost - 1 - 12480 - - - + - ExceptionThrowingFunctionExecutionIntegrationTestServer + ExceptionThrowingFunctionExecutionIntegrationTestsServer error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/GemfireFunctionProxyFactoryBeanTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/GemfireFunctionProxyFactoryBeanTest-context.xml deleted file mode 100644 index 9511f9bb..00000000 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/GemfireFunctionProxyFactoryBeanTest-context.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - GemfireFunctionProxyFactoryBeanTest - false - error - - - - - - - - - - - - - - - - - - - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionExecutionCacheClientTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests-context.xml similarity index 92% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionExecutionCacheClientTests-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests-context.xml index 45259b78..0a38a79a 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionExecutionCacheClientTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionExecutionClientCacheIntegrationTests-context.xml @@ -10,6 +10,7 @@ "> + FunctionExecutionClientCacheIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheIntegrationTests-context.xml similarity index 94% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheIntegrationTests-context.xml index 8ed5df23..7b6752e1 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/FunctionsWithClientCacheIntegrationTests-context.xml @@ -12,6 +12,7 @@ "> + FunctionsWithClientCacheIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientRegionLookupTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientRegionLookupTest.xml index d75e6ec7..28a31e3a 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientRegionLookupTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientRegionLookupTest.xml @@ -10,6 +10,7 @@ "> + NoClientRegionLookupTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientSubRegionLookupTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientSubRegionLookupTest.xml index 8d6d921a..e30ada70 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientSubRegionLookupTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noClientSubRegionLookupTest.xml @@ -10,6 +10,7 @@ "> + NoClientSubRegionLookupTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml index c6cbc6ec..cabe35a6 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noDuplicateRegionDefinitionsTest.xml @@ -9,8 +9,10 @@ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd "> + + - springGemFireNoDuplicateRegionDefinitionsTest + NoDuplicateRegionDefinitionsTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noLocalRegionLookupTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noLocalRegionLookupTest.xml index bc24ab0a..e5a31b2f 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noLocalRegionLookupTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noLocalRegionLookupTest.xml @@ -10,7 +10,7 @@ "> - springGemFireNoLocalRegionLookupTest + NoLocalRegionLookupTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noPartitionRegionLookupTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noPartitionRegionLookupTest.xml index df20528c..bc69bdca 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noPartitionRegionLookupTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noPartitionRegionLookupTest.xml @@ -10,7 +10,7 @@ "> - springGemFireNoPartitionRegionLookupTest + NoPartitionRegionLookupTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noReplicateRegionLookupTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noReplicateRegionLookupTest.xml index 6cfd1750..23d4344e 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noReplicateRegionLookupTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noReplicateRegionLookupTest.xml @@ -10,7 +10,7 @@ "> - springGemFireNoReplicateRegionLookupTest + NoReplicateRegionLookupTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noSubRegionLookupTest.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noSubRegionLookupTest.xml index 6466a933..1c20940d 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noSubRegionLookupTest.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/noSubRegionLookupTest.xml @@ -10,7 +10,7 @@ "> - springGemFireNoSubRegionLookupTest + NoSubRegionLookupTest error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/simple-config.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/WiringInstantiatorIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/simple-config.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/WiringInstantiatorIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests-context.xml index 5d638ca3..ffc38bd5 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceIntegrationTests-context.xml @@ -2,7 +2,7 @@ - JSONRegionAdviceTest + JSONRegionAdviceIntegrationTests error - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTests-context.xml similarity index 91% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTests-context.xml index 19d6562e..4d1ad5d7 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotServiceImportExportIntegrationTests-context.xml @@ -12,13 +12,13 @@ "> - SnapshotServiceImportExportIntegrationTest + SnapshotServiceImportExportIntegrationTests error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/asyncEventQueueWithListener.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests-context.xml similarity index 96% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/asyncEventQueueWithListener.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests-context.xml index 3747dd38..36e9ac09 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/asyncEventQueueWithListener.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTests-context.xml @@ -11,7 +11,7 @@ "> - AsyncEventQueueWithListenerTest + AsyncEventQueueWithListenerIntegrationTests error