diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java index fa0d81ed..1ef3e39c 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/PartitionedRegionFactoryBean.java @@ -16,14 +16,21 @@ package org.springframework.data.gemfire; import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionFactory; +import org.springframework.beans.factory.FactoryBean; import org.springframework.data.gemfire.util.RegionUtils; import org.springframework.util.Assert; /** + * Spring {@link FactoryBean} used to create an Apache Geode {@literal PARTITION} {@link Region}. + * * @author David Turanski * @author John Blum + * @see org.apache.geode.cache.Region + * @see org.apache.geode.cache.RegionFactory + * @see org.springframework.beans.factory.BeanFactory */ public class PartitionedRegionFactoryBean extends PeerRegionFactoryBean { @@ -36,8 +43,8 @@ public class PartitionedRegionFactoryBean extends PeerRegionFactoryBean)! - Assert.isTrue(dataPolicy.withPartitioning(), String.format( - "Data Policy [%s] is not supported in Partitioned Regions.", dataPolicy)); + Assert.isTrue(dataPolicy.withPartitioning(), + String.format("Data Policy [%s] is not supported in Partitioned Regions.", dataPolicy)); } // Validate the data-policy and persistent attributes are compatible when specified! diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/PeerRegionFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/PeerRegionFactoryBean.java index 4fea69d6..c2f807d1 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/PeerRegionFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/PeerRegionFactoryBean.java @@ -232,12 +232,12 @@ public abstract class PeerRegionFactoryBean extends ConfigurableRegionFact } /** - * Creates an instance of {@link RegionFactory} with the given {@link Cache} which is then used to construct, - * configure and initialize the {@link Region} specified by this {@link PeerRegionFactoryBean}. + * Create a new instance of {@link RegionFactory} initialized with the given {@link Cache} that is then used + * to construct, configure and initialize the {@link Region} specified by this {@link PeerRegionFactoryBean}. * * @param cache reference to the {@link Cache}. - * @return a {@link RegionFactory} used to construct, configure and initialized the {@link Region} specified by - * this {@link PeerRegionFactoryBean}. + * @return a {@link RegionFactory} used to construct, configure and initialize the {@link Region} + * specified by this {@link PeerRegionFactoryBean}. * @see org.apache.geode.cache.Cache#createRegionFactory(org.apache.geode.cache.RegionShortcut) * @see org.apache.geode.cache.Cache#createRegionFactory(org.apache.geode.cache.RegionAttributes) * @see org.apache.geode.cache.Cache#createRegionFactory() diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/ScopeType.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/ScopeType.java index a74ba295..35f488b5 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/ScopeType.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/ScopeType.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire; import org.apache.geode.cache.Scope; @@ -29,6 +28,7 @@ import org.springframework.util.StringUtils; */ @SuppressWarnings("unused") public enum ScopeType { + DISTRIBUTED_ACK(Scope.DISTRIBUTED_ACK), DISTRIBUTED_NO_ACK(Scope.DISTRIBUTED_NO_ACK), GLOBAL(Scope.GLOBAL), @@ -42,7 +42,7 @@ public enum ScopeType { * @param gemfireScope the GemFire Scope paired with this enumerated value. * @see org.apache.geode.cache.Scope */ - ScopeType(final Scope gemfireScope) { + ScopeType(Scope gemfireScope) { this.gemfireScope = gemfireScope; } @@ -55,8 +55,8 @@ public enum ScopeType { * @see org.apache.geode.cache.Scope * @see #getScope() */ - public static Scope getScope(final ScopeType scopeType) { - return (scopeType != null ? scopeType.getScope() : null); + public static Scope getScope(ScopeType scopeType) { + return scopeType != null ? scopeType.getScope() : null; } /** @@ -69,6 +69,7 @@ public enum ScopeType { * @see #values() */ public static ScopeType valueOf(final Scope scope) { + for (ScopeType scopeType : values()) { if (scopeType.getScope().equals(scope)) { return scopeType; @@ -89,6 +90,7 @@ public enum ScopeType { * @see #transform(String) */ public static ScopeType valueOfIgnoreCase(String name) { + name = transform(name); for (ScopeType scopeType : values()) { @@ -108,8 +110,8 @@ public enum ScopeType { * @return a String value with underscores for hyphens and all leading/trailing whitespace trimmed, or null * if the given String name is null. */ - private static String transform(final String name) { - return (StringUtils.hasText(name) ? name.trim().replaceAll("-", "_") : name); + private static String transform(String name) { + return StringUtils.hasText(name) ? name.trim().replaceAll("-", "_") : name; } /** @@ -119,7 +121,6 @@ public enum ScopeType { * @see org.apache.geode.cache.Scope */ public Scope getScope() { - return gemfireScope; + return this.gemfireScope; } - } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java index 15f97ea1..2ace37fc 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java @@ -148,12 +148,24 @@ public class ClientRegionFactoryBean extends ConfigurableRegionFactoryBean @Override public void afterPropertiesSet() throws Exception { + initializePoolResolver(); + super.afterPropertiesSet(); + } + + /** + * Initializes the {@literal default} {@link PoolResolver} and optionally sets the main {@link PoolResolver} + * used to resolve {@link Pool} objects from Apache Geode if not configured by the user. + * + * @see org.springframework.data.gemfire.client.PoolResolver + * @see org.springframework.data.gemfire.client.support.BeanFactoryPoolResolver + * @see org.springframework.data.gemfire.client.support.PoolManagerPoolResolver + */ + void initializePoolResolver() { + this.defaultPoolResolver = ComposablePoolResolver.compose(new BeanFactoryPoolResolver(getBeanFactory()), new PoolManagerPoolResolver()); - this.poolResolver = defaultPoolResolver; - - super.afterPropertiesSet(); + this.poolResolver = this.poolResolver != null ? this.poolResolver : this.defaultPoolResolver; } /** diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConfiguration.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConfiguration.java index 37138efa..abad4fc7 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConfiguration.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsConfiguration.java @@ -309,6 +309,7 @@ public class CachingDefinedRegionsConfiguration extends AbstractAnnotationConfig GemFireCache gemfireCache = beanFactory.getBean(GemFireCache.class); + regionFactoryBean.setBeanFactory(beanFactory); regionFactoryBean.setCache(gemfireCache); regionFactoryBean.setClientRegionShortcut(resolveClientRegionShortcut()); regionFactoryBean.setRegionConfigurers(resolveRegionConfigurers()); diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CompressionConfiguration.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CompressionConfiguration.java index 864b08bc..f5da762e 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CompressionConfiguration.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/CompressionConfiguration.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; import static java.util.Arrays.stream; diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/EnableCompression.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/EnableCompression.java index a1e13e44..f6e0a26c 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/EnableCompression.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/EnableCompression.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; import static org.springframework.data.gemfire.config.annotation.CompressionConfiguration.SNAPPY_COMPRESSOR_BEAN_NAME; diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessor.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessor.java index dafe3bf9..5fd0f58f 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessor.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessor.java @@ -26,8 +26,11 @@ import org.apache.geode.cache.Scope; import org.apache.geode.cache.wan.GatewaySender; import org.springframework.beans.BeansException; +import org.springframework.beans.PropertyEditorRegistrar; +import org.springframework.beans.PropertyEditorRegistry; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.core.Ordered; import org.springframework.core.convert.converter.Converter; import org.springframework.data.gemfire.IndexMaintenancePolicyConverter; import org.springframework.data.gemfire.IndexMaintenancePolicyType; @@ -56,10 +59,20 @@ import org.springframework.data.gemfire.wan.OrderPolicyConverter; * @author John Blum * @see java.beans.PropertyEditor * @see java.beans.PropertyEditorSupport + * @see org.springframework.beans.PropertyEditorRegistrar + * @see org.springframework.beans.PropertyEditorRegistry * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor * @since 1.6.0 */ -public class CustomEditorBeanFactoryPostProcessor implements BeanFactoryPostProcessor { +public class CustomEditorBeanFactoryPostProcessor implements BeanFactoryPostProcessor, Ordered { + + /** + * {@inheritDoc} + */ + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE; + } /** * {@inheritDoc} @@ -67,21 +80,52 @@ public class CustomEditorBeanFactoryPostProcessor implements BeanFactoryPostProc @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - beanFactory.registerCustomEditor(ConnectionEndpoint.class, StringToConnectionEndpointConverter.class); - //beanFactory.registerCustomEditor(ConnectionEndpoint[].class, ConnectionEndpointArrayToIterableConverter.class); - beanFactory.registerCustomEditor(ConnectionEndpointList.class, StringToConnectionEndpointListConverter.class); - beanFactory.registerCustomEditor(EvictionAction.class, EvictionActionConverter.class); - beanFactory.registerCustomEditor(EvictionPolicyType.class, EvictionPolicyConverter.class); - beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class); - beanFactory.registerCustomEditor(IndexMaintenancePolicyType.class, IndexMaintenancePolicyConverter.class); - beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class); - beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class); - beanFactory.registerCustomEditor(InterestResultPolicy.class, InterestResultPolicyConverter.class); - beanFactory.registerCustomEditor(GatewaySender.OrderPolicy.class, OrderPolicyConverter.class); - beanFactory.registerCustomEditor(Scope.class, ScopeConverter.class); - beanFactory.registerCustomEditor(SubscriptionEvictionPolicy.class, SubscriptionEvictionPolicyConverter.class); + beanFactory.addPropertyEditorRegistrar(new CustomEditorPropertyEditorRegistrar()); + //registerCustomEditors(beanFactory); } + @SuppressWarnings("unused") + private void registerCustomEditors(ConfigurableListableBeanFactory beanFactory) { + + if (beanFactory != null) { + beanFactory.registerCustomEditor(ConnectionEndpoint.class, StringToConnectionEndpointConverter.class); + //beanFactory.registerCustomEditor(ConnectionEndpoint[].class, ConnectionEndpointArrayToIterableConverter.class); + beanFactory.registerCustomEditor(ConnectionEndpointList.class, StringToConnectionEndpointListConverter.class); + beanFactory.registerCustomEditor(EvictionAction.class, EvictionActionConverter.class); + beanFactory.registerCustomEditor(EvictionPolicyType.class, EvictionPolicyConverter.class); + beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class); + beanFactory.registerCustomEditor(IndexMaintenancePolicyType.class, IndexMaintenancePolicyConverter.class); + beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class); + beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class); + beanFactory.registerCustomEditor(InterestResultPolicy.class, InterestResultPolicyConverter.class); + beanFactory.registerCustomEditor(GatewaySender.OrderPolicy.class, OrderPolicyConverter.class); + beanFactory.registerCustomEditor(Scope.class, ScopeConverter.class); + beanFactory.registerCustomEditor(SubscriptionEvictionPolicy.class, SubscriptionEvictionPolicyConverter.class); + } + } + + public static class CustomEditorPropertyEditorRegistrar implements PropertyEditorRegistrar { + + @Override + public void registerCustomEditors(PropertyEditorRegistry registry) { + + if (registry != null) { + registry.registerCustomEditor(ConnectionEndpoint.class, new StringToConnectionEndpointConverter()); + //registry.registerCustomEditor(ConnectionEndpoint[].class, new ConnectionEndpointArrayToIterableConverter())); + registry.registerCustomEditor(ConnectionEndpointList.class, new StringToConnectionEndpointListConverter()); + registry.registerCustomEditor(EvictionAction.class, new EvictionActionConverter()); + registry.registerCustomEditor(EvictionPolicyType.class, new EvictionPolicyConverter()); + registry.registerCustomEditor(ExpirationAction.class, new ExpirationActionConverter()); + registry.registerCustomEditor(IndexMaintenancePolicyType.class, new IndexMaintenancePolicyConverter()); + registry.registerCustomEditor(IndexType.class, new IndexTypeConverter()); + registry.registerCustomEditor(InterestPolicy.class, new InterestPolicyConverter()); + registry.registerCustomEditor(InterestResultPolicy.class, new InterestResultPolicyConverter()); + registry.registerCustomEditor(GatewaySender.OrderPolicy.class, new OrderPolicyConverter()); + registry.registerCustomEditor(Scope.class, new ScopeConverter()); + registry.registerCustomEditor(SubscriptionEvictionPolicy.class, new SubscriptionEvictionPolicyConverter()); + } + } + } public static class ConnectionEndpointArrayToIterableConverter extends PropertyEditorSupport implements Converter> { diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractPeerRegionParser.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractPeerRegionParser.java index 9b102201..43610e2c 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractPeerRegionParser.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractPeerRegionParser.java @@ -19,13 +19,13 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.asyncqueue.AsyncEventQueue; import org.apache.geode.cache.wan.GatewaySender; -import org.w3c.dom.Element; - import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.w3c.dom.Element; + /** - * Abstract Spring XML Parser for peer {@link Region} bean definitions. + * Abstract Spring XML parser for peer {@link Region} bean definitions. * * @author John Blum * @see org.apache.geode.cache.Region @@ -33,11 +33,15 @@ import org.springframework.beans.factory.xml.ParserContext; * @see org.apache.geode.cache.wan.GatewaySender * @see org.springframework.beans.factory.support.BeanDefinitionBuilder * @see org.springframework.beans.factory.xml.ParserContext + * @see org.springframework.data.gemfire.config.xml.AbstractRegionParser * @see org.w3c.dom.Element * @since 2.2.0 */ public abstract class AbstractPeerRegionParser extends AbstractRegionParser { + /** + * @inheritDoc + */ @Override protected void doParseRegionConfiguration(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder regionAttributesBuilder, boolean subRegion) { diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractRegionParser.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractRegionParser.java index da92d710..c6268c67 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractRegionParser.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/AbstractRegionParser.java @@ -22,12 +22,9 @@ import java.util.Optional; import org.apache.geode.cache.Region; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Element; - import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValue; +import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -35,11 +32,16 @@ import org.springframework.beans.factory.support.ManagedArray; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.PeerRegionFactoryBean; +import org.springframework.lang.NonNull; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Element; + /** * Abstract base class encapsulating functionality common to all Region parsers. * @@ -50,6 +52,10 @@ import org.springframework.util.xml.DomUtils; */ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { + protected static final String REGION_DEFINITION_SUFFIX = "region"; + protected static final String REGION_TEMPLATE_SUFFIX = "-template"; + protected static final String TEMPLATE_ATTRIBUTE = "template"; + protected final Logger logger = LoggerFactory.getLogger(getClass()); /** @@ -60,6 +66,13 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { return getRegionFactoryClass(); } + /** + * Return the {@link Class type} of the {@link Region} {@link FactoryBean}. + * + * @return the {@link Class type} of the {@link Region} {@link FactoryBean}. + * @see org.springframework.beans.factory.FactoryBean + * @see java.lang.Class + */ protected abstract Class getRegionFactoryClass(); /** @@ -68,23 +81,41 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { @Override protected String getParentName(Element element) { - String regionTemplate = element.getAttribute("template"); + String regionTemplate = element.getAttribute(TEMPLATE_ATTRIBUTE); return StringUtils.hasText(regionTemplate) ? regionTemplate : super.getParentName(element); } - protected boolean isRegionTemplate(Element element) { + /** + * Determines whether the given SDG XML namespace configuration {@link Element} defines a {@link Region} template + * used as the base configuration for one or more {@link Region Regions}. + * + * @param element SDG XML namespace {@link Element}. + * @return a boolean value indicating whether the given SDG XML namespace configuration {@link Element} + * defines a {@link Region} template. + * @see org.w3c.dom.Element + */ + protected boolean isRegionTemplate(@NonNull Element element) { String localName = element.getLocalName(); - return localName != null && localName.endsWith("-template"); + return localName != null && localName.endsWith(REGION_TEMPLATE_SUFFIX); } - protected boolean isSubRegion(Element element) { + /** + * Determines whether the current SDG XML namespace {@link Region} {@link Element} is a {@link Region Sub-Region} + * definition. + * + * @param element SDG XML namespace {@link Region} {@link Element} to evaluate as a {@link Region Sub-Region}. + * @return a boolean value indicating whether the current SDG XML namespace {@link Region} {@link Element} + * is a {@link Region Sub-Region} definition. + * @see org.w3c.dom.Element + */ + protected boolean isSubRegion(@NonNull Element element) { String localName = element.getParentNode().getLocalName(); - return localName != null && localName.endsWith("region"); + return localName != null && localName.endsWith(REGION_DEFINITION_SUFFIX); } /** @@ -93,7 +124,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - super.doParse(element, builder); + super.doParse(element, parserContext, builder); builder.setAbstract(isRegionTemplate(element)); diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheParser.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheParser.java index d3212ec5..c7642a91 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheParser.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/CacheParser.java @@ -21,6 +21,8 @@ import java.util.Optional; import org.apache.geode.internal.datasource.ConfigProperty; import org.springframework.beans.factory.BeanDefinitionStoreException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; @@ -30,10 +32,14 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.config.support.CustomEditorBeanFactoryPostProcessor; import org.springframework.data.gemfire.config.support.GemfireFeature; import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -43,18 +49,18 @@ import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; /** - * {@link BeanDefinitionParser} for the <gfe:cache> SDG XML Namespace (XSD) element. + * Spring {@link BeanDefinitionParser} for the <gfe:cache> SDG XML namespace element. * * @author Costin Leau * @author Oliver Gierke * @author David Turanski * @author John Blum * @author Patrick Johnson - * @see org.w3c.dom.Element * @see org.springframework.beans.factory.support.AbstractBeanDefinition * @see org.springframework.beans.factory.support.BeanDefinitionBuilder * @see org.springframework.beans.factory.support.BeanDefinitionRegistry * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser + * @see org.springframework.beans.factory.xml.BeanDefinitionParser * @see org.springframework.beans.factory.xml.ParserContext * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.w3c.dom.Element @@ -77,7 +83,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { super.doParse(element, cacheBuilder); - registerGemFireBeanFactoryPostProcessors(getRegistry(parserContext)); + registerGemFirePropertyEditorRegistrarWithBeanFactory(getRegistry(parserContext)); ParsingUtils.setPropertyValue(element, cacheBuilder, "cache-xml-location", "cacheXml"); ParsingUtils.setPropertyReference(element, cacheBuilder, "properties-ref", "properties"); @@ -92,7 +98,6 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { ParsingUtils.setPropertyValue(element, cacheBuilder, "lock-lease"); ParsingUtils.setPropertyValue(element, cacheBuilder, "lock-timeout"); ParsingUtils.setPropertyValue(element, cacheBuilder, "message-sync-interval"); - parsePdxDiskStore(element, parserContext, cacheBuilder); ParsingUtils.setPropertyValue(element, cacheBuilder, "pdx-ignore-unread-fields"); ParsingUtils.setPropertyValue(element, cacheBuilder, "pdx-read-serialized"); ParsingUtils.setPropertyValue(element, cacheBuilder, "pdx-persistent"); @@ -100,6 +105,21 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { ParsingUtils.setPropertyValue(element, cacheBuilder, "search-timeout"); ParsingUtils.setPropertyValue(element, cacheBuilder, "use-cluster-configuration"); + parsePdxDiskStore(element, parserContext, cacheBuilder); + parseJndiBindings(element, parserContext, cacheBuilder); + + Element gatewayConflictResolver = + DomUtils.getChildElementByTagName(element, "gateway-conflict-resolver"); + + if (gatewayConflictResolver != null) { + + ParsingUtils.throwExceptionWhenGemFireFeatureUnavailable(GemfireFeature.WAN, element.getLocalName(), + "gateway-conflict-resolver", parserContext); + + cacheBuilder.addPropertyValue("gatewayConflictResolver", ParsingUtils.parseRefOrSingleNestedBeanDeclaration( + gatewayConflictResolver, parserContext, cacheBuilder)); + } + List transactionListeners = DomUtils.getChildElementsByTagName(element, "transaction-listener"); @@ -121,32 +141,29 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { cacheBuilder.addPropertyValue("transactionWriter", ParsingUtils.parseRefOrNestedBeanDeclaration(transactionWriter, parserContext, cacheBuilder)); } - - Element gatewayConflictResolver = - DomUtils.getChildElementByTagName(element, "gateway-conflict-resolver"); - - if (gatewayConflictResolver != null) { - - ParsingUtils.throwExceptionWhenGemFireFeatureUnavailable(GemfireFeature.WAN, element.getLocalName(), - "gateway-conflict-resolver", parserContext); - - cacheBuilder.addPropertyValue("gatewayConflictResolver", ParsingUtils.parseRefOrSingleNestedBeanDeclaration( - gatewayConflictResolver, parserContext, cacheBuilder)); - } - - parseJndiBindings(element, cacheBuilder); } - protected BeanDefinitionRegistry getRegistry(ParserContext parserContext) { + protected @NonNull BeanDefinitionRegistry getRegistry(@NonNull ParserContext parserContext) { return parserContext.getRegistry(); } - private void registerGemFireBeanFactoryPostProcessors(BeanDefinitionRegistry registry) { + protected @Nullable BeanFactory resolveBeanFactory(@Nullable BeanDefinitionRegistry registry) { - AbstractBeanDefinition customEditorBeanFactoryPostProcessorDefinition = - BeanDefinitionBuilder.genericBeanDefinition(CustomEditorBeanFactoryPostProcessor.class).getBeanDefinition(); + return registry instanceof ConfigurableApplicationContext ? ((ConfigurableApplicationContext) registry).getBeanFactory() + : registry instanceof ApplicationContext ? ((ApplicationContext) registry).getAutowireCapableBeanFactory() + : registry instanceof ConfigurableListableBeanFactory ? (ConfigurableListableBeanFactory) registry + : registry instanceof BeanFactory ? (BeanFactory) registry + : null; + } - BeanDefinitionReaderUtils.registerWithGeneratedName(customEditorBeanFactoryPostProcessorDefinition, registry); + private void registerGemFirePropertyEditorRegistrarWithBeanFactory(BeanDefinitionRegistry registry) { + + Optional.ofNullable(registry) + .map(this::resolveBeanFactory) + .filter(ConfigurableListableBeanFactory.class::isInstance) + .map(ConfigurableListableBeanFactory.class::cast) + .ifPresent(beanFactory -> beanFactory.addPropertyEditorRegistrar(new CustomEditorBeanFactoryPostProcessor + .CustomEditorPropertyEditorRegistrar())); } private void parsePdxDiskStore(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { @@ -178,7 +195,8 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { return builder.getBeanDefinition(); } - private void parseJndiBindings(Element element, BeanDefinitionBuilder cacheBuilder) { + @SuppressWarnings("unused") + private void parseJndiBindings(Element element, ParserContext parserContext, BeanDefinitionBuilder cacheBuilder) { List jndiBindings = DomUtils.getChildElementsByTagName(element, "jndi-binding"); diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ClientCacheParser.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ClientCacheParser.java index 36366348..efde5817 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ClientCacheParser.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ClientCacheParser.java @@ -15,13 +15,13 @@ */ package org.springframework.data.gemfire.config.xml; -import org.w3c.dom.Element; - import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; +import org.w3c.dom.Element; + /** * {@link BeanDefinitionParser} for the <gfe:client-cache> SDG XML Namespace (XSD) element. * diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/GemfireNamespaceHandler.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/GemfireNamespaceHandler.java index 57cac736..f25f2dec 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/GemfireNamespaceHandler.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/GemfireNamespaceHandler.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.xml; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; @@ -32,6 +31,7 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport { @Override public void init() { + registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenParser()); registerBeanDefinitionParser("async-event-queue", new AsyncEventQueueParser()); registerBeanDefinitionParser("auto-region-lookup", new AutoRegionLookupParser()); diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ParsingUtils.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ParsingUtils.java index 353ff032..6030b2a7 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ParsingUtils.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/ParsingUtils.java @@ -21,8 +21,6 @@ import org.apache.geode.cache.LossAction; import org.apache.geode.cache.MembershipAttributes; import org.apache.geode.cache.ResumptionAction; -import org.w3c.dom.Element; - import org.springframework.beans.PropertyValue; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; @@ -39,6 +37,8 @@ import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + /** * Utilities used by the Spring Data GemFire XML Namespace Parsers. * @@ -394,10 +394,13 @@ abstract class ParsingUtils { setPropertyValue(element, regionAttributesBuilder, "publisher"); setPropertyValue(element, regionAttributesBuilder, "value-constraint"); - String concurrencyChecksEnabled = element.getAttribute("concurrency-checks-enabled"); + if (element.hasAttribute("concurrency-checks-enabled")) { - if (StringUtils.hasText(concurrencyChecksEnabled)) { - ParsingUtils.setPropertyValue(element, regionAttributesBuilder, "concurrency-checks-enabled"); + String concurrencyChecksEnabled = element.getAttribute("concurrency-checks-enabled"); + + if (StringUtils.hasText(concurrencyChecksEnabled)) { + setPropertyValue(element, regionAttributesBuilder, "concurrency-checks-enabled"); + } } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/PartitionedRegionParser.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/PartitionedRegionParser.java index d4053663..20b109d3 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/PartitionedRegionParser.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/config/xml/PartitionedRegionParser.java @@ -17,8 +17,6 @@ package org.springframework.data.gemfire.config.xml; import java.util.List; -import org.w3c.dom.Element; - import org.springframework.beans.PropertyValue; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -32,6 +30,8 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + /** * Bean definition parser for the <gfe:partitioned-region> SDG XML namespace (XSD) element. * @@ -76,7 +76,7 @@ class PartitionedRegionParser extends AbstractPeerRegionParser { BeanDefinitionBuilder partitionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition(PartitionAttributesFactoryBean.class); - mergeTemplateRegionPartitionAttributes(element, parserContext, regionBuilder, partitionAttributesBuilder); + mergeRegionTemplatePartitionAttributes(element, parserContext, regionBuilder, partitionAttributesBuilder); parseCollocatedWith(element, regionBuilder, partitionAttributesBuilder, "colocated-with"); ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "copies", "redundantCopies"); @@ -86,21 +86,24 @@ class PartitionedRegionParser extends AbstractPeerRegionParser { ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "total-buckets", "totalNumBuckets"); ParsingUtils.setPropertyValue(element, partitionAttributesBuilder, "total-max-memory"); - Element partitionListenerSubElement = DomUtils.getChildElementByTagName(element, "partition-listener"); + Element partitionListenerSubElement = + DomUtils.getChildElementByTagName(element, "partition-listener"); if (partitionListenerSubElement != null) { partitionAttributesBuilder.addPropertyValue("partitionListeners", parsePartitionListeners(partitionListenerSubElement, parserContext, regionBuilder)); } - Element partitionResolverSubElement = DomUtils.getChildElementByTagName(element, "partition-resolver"); + Element partitionResolverSubElement = + DomUtils.getChildElementByTagName(element, "partition-resolver"); if (partitionResolverSubElement != null) { partitionAttributesBuilder.addPropertyValue("partitionResolver", parsePartitionResolver(partitionResolverSubElement, parserContext, regionBuilder)); } - List fixedPartitionSubElements = DomUtils.getChildElementsByTagName(element, "fixed-partition"); + List fixedPartitionSubElements = + DomUtils.getChildElementsByTagName(element, "fixed-partition"); if (!CollectionUtils.isEmpty(fixedPartitionSubElements)){ @@ -122,10 +125,11 @@ class PartitionedRegionParser extends AbstractPeerRegionParser { partitionAttributesBuilder.addPropertyValue("fixedPartitionAttributes", fixedPartitionAttributes); } - regionAttributesBuilder.addPropertyValue("partitionAttributes", partitionAttributesBuilder.getBeanDefinition()); + regionAttributesBuilder.addPropertyValue("partitionAttributes", + partitionAttributesBuilder.getBeanDefinition()); } - void mergeTemplateRegionPartitionAttributes(Element element, ParserContext parserContext, + void mergeRegionTemplatePartitionAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder partitionAttributesBuilder) { String regionTemplateName = getParentName(element); @@ -153,9 +157,12 @@ class PartitionedRegionParser extends AbstractPeerRegionParser { } } else { - parserContext.getReaderContext().error(String.format( - "The Region template [%1$s] must be 'defined before' the Region [%2$s] referring to the template!", - regionTemplateName, resolveId(element, regionBuilder.getRawBeanDefinition(), parserContext)), element); + + String message = + String.format("The Region template [%1$s] must be defined before the Region [%2$s] referring to the template!", + regionTemplateName, resolveId(element, regionBuilder.getRawBeanDefinition(), parserContext)); + + parserContext.getReaderContext().error(message, element); } } } @@ -164,8 +171,8 @@ class PartitionedRegionParser extends AbstractPeerRegionParser { BeanDefinitionBuilder partitionAttributesBuilder, String attributeName) { // NOTE rather than using a dependency (with depends-on) we could also set the colocatedWith property of the - // PartitionAttributesFactoryBean with a reference to the Region "this" Partitioned Region will be colocated - // with, where the colocated-with attribute refers to the the bean name/alias of the other, depended on Region + // PartitionAttributesFactoryBean with a reference to the Region "this" Partitioned Region will be collocated + // with, where the collocated-with attribute refers to the the bean name/alias of the other, depended on Region // providing that the Region's name is also a bean alias of the bean definition. //ParsingUtils.setPropertyReference(element, partitionAttributesBuilder, attributeName, "colocatedWith"); diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/wan/GatewayReceiverFactoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/wan/GatewayReceiverFactoryBean.java index f84e7eaf..bfbbfdee 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/wan/GatewayReceiverFactoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/wan/GatewayReceiverFactoryBean.java @@ -81,10 +81,13 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean< super(cache); } + /** + * @inheritDoc + */ @Override protected void doInit() { - GatewayReceiverFactory gatewayReceiverFactory = this.cache.createGatewayReceiverFactory(); + GatewayReceiverFactory gatewayReceiverFactory = getCache().createGatewayReceiverFactory(); StreamSupport.stream(CollectionUtils.nullSafeIterable(this.gatewayReceiverConfigurers).spliterator(), false) .forEach(it -> it.configure(getName(), this)); 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 4f9bcbef..8ebbaf55 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 @@ -51,9 +51,8 @@ public abstract class RecreatingSpringApplicationContextTest extends Integration } @After - public void destroyContext() { - if (applicationContext != null) { - applicationContext.destroy(); - } + public void closeContext() { + closeApplicationContext(this.applicationContext); + destroyAllGemFireMockObjects(); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionDataPolicyShortcutsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionDataPolicyShortcutsIntegrationTests.java index 0dc07e5d..d2dda7ba 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionDataPolicyShortcutsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/RegionDataPolicyShortcutsIntegrationTests.java @@ -30,6 +30,7 @@ import org.apache.geode.cache.RegionShortcut; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; +import org.springframework.data.gemfire.util.RegionUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -48,8 +49,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @since 1.4.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "region-datapolicy-shortcuts.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsSupport { @@ -78,7 +78,7 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS private Region shortcutOverrides; @Test - public void testLocalRegionWithDataPolicy() { + public void localRegionWithDataPolicyIsCorrect() { assertThat(localWithDataPolicy) .describedAs("A reference to the 'LocalWithDataPolicy' Region was not property configured!") @@ -91,7 +91,7 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS } @Test - public void testLocalRegionWithShortcut() { + public void localRegionWithShortcutIsCorrect() { assertThat(localWithShortcut) .describedAs("A reference to the 'LocalWithShortcut' Region was not property configured!") @@ -104,7 +104,7 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS } @Test - public void testPartitionRegionWithDataPolicy() { + public void partitionRegionWithDataPolicyIsCorrect() { assertThat(partitionWithDataPolicy) .describedAs("A reference to the 'PartitionWithDataPolicy' Region was not property configured!") @@ -117,7 +117,7 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS } @Test - public void testPartitionRegionWithShortcut() { + public void partitionRegionWithShortcutIsCorrect() { assertThat(partitionWithShortcut) .describedAs("A reference to the 'PartitionWithShortcut' Region was not property configured!") @@ -130,7 +130,7 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS } @Test - public void testReplicateRegionWithDataPolicy() { + public void replicateRegionWithDataPolicyIsCorrect() { assertThat(replicateWithDataPolicy) .describedAs("A reference to the 'ReplicateWithDataPolicy' Region was not property configured!") @@ -143,7 +143,7 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS } @Test - public void testReplicateRegionWithShortcut() { + public void replicateRegionWithShortcutIsCorrect() { assertThat(replicateWithShortcut) .describedAs("A reference to the 'ReplicateWithShortcut' Region was not property configured!") @@ -156,14 +156,14 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS } @Test - public void testShortcutDefaultsRegion() { + public void shortcutDefaultsRegionIsCorrect() { assertThat(shortcutDefaults) .describedAs("A reference to the 'ShortcutDefaults' Region was not properly configured!") .isNotNull(); assertThat(shortcutDefaults.getName()).isEqualTo("ShortcutDefaults"); - assertThat(shortcutDefaults.getFullPath()).isEqualTo("/ShortcutDefaults"); + assertThat(shortcutDefaults.getFullPath()).isEqualTo(RegionUtils.toRegionPath("ShortcutDefaults")); assertThat(shortcutDefaults.getAttributes()).isNotNull(); assertThat(shortcutDefaults.getAttributes().getCloningEnabled()).isFalse(); assertThat(shortcutDefaults.getAttributes().getConcurrencyChecksEnabled()).isTrue(); @@ -173,6 +173,7 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS assertThat(shortcutDefaults.getAttributes().getInitialCapacity()).isEqualTo(101); assertThat(new Float(shortcutDefaults.getAttributes().getLoadFactor())).isEqualTo(new Float(0.85f)); assertThat(shortcutDefaults.getAttributes().getKeyConstraint()).isEqualTo(Long.class); + assertThat(shortcutDefaults.getAttributes().getMulticastEnabled()).isFalse(); assertThat(shortcutDefaults.getAttributes().getValueConstraint()).isEqualTo(String.class); assertThat(shortcutDefaults.getAttributes().getEvictionAttributes()).isNotNull(); assertThat(shortcutDefaults.getAttributes().getEvictionAttributes().getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); @@ -183,14 +184,14 @@ public class RegionDataPolicyShortcutsIntegrationTests extends IntegrationTestsS } @Test - public void testShortcutOverridesRegion() { + public void shortcutOverridesRegionIsCorrect() { assertThat(shortcutOverrides) .describedAs("A reference to the 'ShortcutOverrides' Region was not properly configured!") .isNotNull(); assertThat(shortcutOverrides.getName()).isEqualTo("ShortcutOverrides"); - assertThat(shortcutOverrides.getFullPath()).isEqualTo("/ShortcutOverrides"); + assertThat(shortcutOverrides.getFullPath()).isEqualTo(RegionUtils.toRegionPath("ShortcutOverrides")); assertThat(shortcutOverrides.getAttributes()).isNotNull(); assertThat(shortcutOverrides.getAttributes().getCloningEnabled()).isTrue(); assertThat(shortcutOverrides.getAttributes().getConcurrencyChecksEnabled()).isFalse(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanUnitTests.java index 612db8a6..dd615638 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanUnitTests.java @@ -22,17 +22,21 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; 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 static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; import java.io.InputStream; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.EvictionAttributes; @@ -57,7 +61,10 @@ import org.springframework.data.gemfire.util.ArrayUtils; * @author David Turanski * @author John Blum * @see org.junit.Test + * @see org.mockito.Mock * @see org.mockito.Mockito + * @see org.mockito.Spy + * @see org.mockito.junit.MockitoJUnitRunner * @see org.apache.geode.cache.EvictionAttributes * @see org.apache.geode.cache.ExpirationAttributes * @see org.apache.geode.cache.Region @@ -67,17 +74,25 @@ import org.springframework.data.gemfire.util.ArrayUtils; * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean */ @SuppressWarnings("rawtypes") +@RunWith(MockitoJUnitRunner.class) public class ClientRegionFactoryBeanUnitTests { + @Mock + private BeanFactory mockBeanFactory; + + @Spy private ClientRegionFactoryBean factoryBean; @Before public void setup() { - this.factoryBean = spy(new ClientRegionFactoryBean<>()); + + this.factoryBean.setBeanFactory(this.mockBeanFactory); + this.factoryBean.initializePoolResolver(); } @After public void tearDown() throws Exception { + this.factoryBean.destroy(); this.factoryBean = null; } @@ -86,8 +101,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings({ "deprecation", "unchecked" }) public void createRegionUsingDefaultShortcut() throws Exception { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientCache mockClientCache = mock(ClientCache.class); ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); @@ -102,7 +115,6 @@ public class ClientRegionFactoryBeanUnitTests { when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL))) .thenReturn(mockClientRegionFactory); when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion); - when(mockPool.getName()).thenReturn("TestPoolTwo"); when(mockRegionAttributes.getCloningEnabled()).thenReturn(false); when(mockRegionAttributes.getCompressor()).thenReturn(mock(Compressor.class)); when(mockRegionAttributes.getConcurrencyChecksEnabled()).thenReturn(true); @@ -167,8 +179,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings({ "deprecation", "unchecked" }) public void createRegionUsingDefaultPersistentShortcut() throws Exception { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientCache mockClientCache = mock(ClientCache.class); ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); @@ -205,8 +215,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void createRegionWithSpecifiedShortcut() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientCache mockClientCache = mock(ClientCache.class); ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); @@ -236,8 +244,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void createRegionAsSubRegion() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientCache mockClientCache = mock(ClientCache.class); ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); @@ -288,8 +294,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void configurePoolFromClientRegionFactoryBeanAndEagerlyInitializePool() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); Pool mockPool = mock(Pool.class); @@ -308,8 +312,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void configurePoolFromClientRegionFactoryBeanEvenWhenRegionAttributesPoolNameIsSet() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); Pool mockPool = mock(Pool.class); @@ -334,8 +336,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void configurePoolFromRegionAttributesAndEagerlyInitializePool() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); Pool mockPool = mock(Pool.class); @@ -358,8 +358,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void configurePoolThrowsExceptionWhileEagerlyInitializingPool() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); when(mockBeanFactory.getBean(anyString(), eq(Pool.class))).thenThrow(new BeanCreationException("test")); @@ -387,8 +385,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void doesNotConfigurePoolWhenClientRegionFactoryBeanPoolIsDefaultPool() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); factoryBean.setBeanFactory(mockBeanFactory); @@ -405,8 +401,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void doesNotConfigurePoolWhenRegionAttributesPoolIsDefaultPool() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); RegionAttributes mockRegionAttributes = mock(RegionAttributes.class); @@ -428,8 +422,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void doesNotConfigurePoolWhenDeclaredPoolIsEmpty() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); RegionAttributes mockRegionAttributes = mock(RegionAttributes.class); @@ -452,8 +444,6 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void doesNotConfigurePoolWhenDeclaredPoolIsNull() { - BeanFactory mockBeanFactory = mock(BeanFactory.class); - ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class); RegionAttributes mockRegionAttributes = mock(RegionAttributes.class); @@ -780,12 +770,11 @@ public class ClientRegionFactoryBeanUnitTests { @SuppressWarnings("unchecked") public void destroyCallsRegionDestroy() throws Exception { - Region mockRegion = mock(Region.class, "MockRegion"); + Region mockRegion = mock(Region.class, withSettings().lenient()); - RegionService mockRegionService = mock(RegionService.class, "MockRegionService"); + RegionService mockRegionService = mock(RegionService.class); when(mockRegion.getRegionService()).thenReturn(mockRegionService); - when(mockRegionService.isClosed()).thenReturn(false); doReturn(mockRegion).when(factoryBean).getObject(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunctionUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunctionUnitTests.java index 54262b04..5a5b4dda 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunctionUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunctionUnitTests.java @@ -139,7 +139,7 @@ public class ListRegionsOnServerFunctionUnitTests { @Test public void getIdIsFullyQualifiedClassName() { - assertThat(function.getId()).isEqualTo(ListRegionsOnServerFunction.class.getName()); + assertThat(function.getId()).startsWith(ListRegionsOnServerFunction.class.getName()); } @Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java index 44f98fb4..1bf0ee40 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/AbstractGeodeSecurityIntegrationTests.java @@ -227,7 +227,7 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ForkingClien public static class GeodeServerConfiguration { public static void main(String[] args) { - runSpringApplication(GeodeServerConfiguration.class, args).refresh(); + runSpringApplication(GeodeServerConfiguration.class, args); } @Autowired 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 2dd0eac0..e4c1d615 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 @@ -18,7 +18,6 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -30,10 +29,8 @@ import org.apache.geode.cache.Region; import org.springframework.cache.annotation.CacheConfig; 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.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.CollectionUtils; import org.springframework.stereotype.Service; @@ -50,41 +47,26 @@ import org.springframework.stereotype.Service; * @see org.springframework.cache.annotation.Cacheable * @see org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions * @see org.springframework.data.gemfire.config.annotation.CachingDefinedRegionsConfiguration - * @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.stereotype.Service * @see Add support for @CacheConfig in @EnableCachingDefinedRegions * @since 2.2.0 */ @SuppressWarnings("unused") -public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests extends IntegrationTestsSupport { - - private ConfigurableApplicationContext applicationContext; +public class CachingDefinedRegionsConsidersCacheConfigCacheNamesIntegrationTests + extends SpringApplicationContextIntegrationTestsSupport { @After - public void closeApplicationContext() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - } - - private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(); - - applicationContext.register(annotatedClasses); - applicationContext.registerShutdownHook(); - applicationContext.refresh(); - - this.applicationContext = applicationContext; - - return applicationContext; + public void tearDown() { + destroyAllGemFireMockObjects(); } private Set resolveCacheRegionNames(Class... annotatedClasses) { newApplicationContext(annotatedClasses); - GemFireCache cache = this.applicationContext.getBean(GemFireCache.class); + GemFireCache cache = getBean(GemFireCache.class); assertThat(cache).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsUsesCacheConfigCacheNamesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsUsesCacheConfigCacheNamesIntegrationTests.java index 049bd037..5eb3d79d 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsUsesCacheConfigCacheNamesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/CachingDefinedRegionsUsesCacheConfigCacheNamesIntegrationTests.java @@ -38,6 +38,7 @@ import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; @@ -56,6 +57,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.config.annotation.EnableCachingDefinedRegions * @see org.springframework.data.gemfire.config.annotation.CachingDefinedRegionsConfiguration * @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 Add support for @CacheConfig in @EnableCachingDefinedRegions @@ -146,8 +148,9 @@ public class CachingDefinedRegionsUsesCacheConfigCacheNamesIntegrationTests exte Arrays.asList(this.b, this.c).forEach(region -> assertThat(region).isEmpty()); } - @ClientCacheApplication + @ClientCacheApplication(name = "CachingDefinedRegionsUsesCacheConfigCacheNamesIntegrationTests") @EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL) + @EnableGemFireMockObjects static class TestConfiguration { @Bean 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 8e1b0db5..9954bd52 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 @@ -112,7 +112,6 @@ public class ClientCacheConfigurationIntegrationTests extends IntegrationTestsSu @EnableGemFireMockObjects @ClientCacheApplication( name = "ClientCacheDefaultPoolWithCustomSocketFactoryConfiguration", - logLevel = "error", serverConnectionTimeout = 60000, socketFactoryBeanName = "mockSocketFactory" ) @@ -125,7 +124,7 @@ public class ClientCacheConfigurationIntegrationTests extends IntegrationTestsSu } @EnableGemFireMockObjects - @ClientCacheApplication(name = "ClientCacheDefaultPoolWithCustomSocketFactoryConfiguration", logLevel = "error") + @ClientCacheApplication(name = "ClientCacheDefaultPoolWithDefaultSocketFactoryConfiguration") static class ClientCacheDefaultPoolWithDefaultSocketFactoryConfiguration { @Bean 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 4768932c..bd093f01 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 @@ -20,7 +20,6 @@ import static org.mockito.Mockito.mock; import static org.springframework.data.gemfire.config.annotation.CompressionConfiguration.SNAPPY_COMPRESSOR_BEAN_NAME; import java.util.Arrays; -import java.util.Optional; import org.junit.After; import org.junit.Test; @@ -62,8 +61,8 @@ public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSup @After public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); - //GemFireMockObjectsSupport.destroy(); + closeApplicationContext(this.applicationContext); + destroyAllGemFireMockObjects(); } private ConfigurableApplicationContext newApplicationContext(Class... annotatedClasses) { @@ -132,7 +131,6 @@ public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSup LocalRegionFactoryBean localRegion = new LocalRegionFactoryBean<>(); localRegion.setCache(gemfireCache); - localRegion.setClose(false); localRegion.setPersistent(false); return localRegion; @@ -144,7 +142,6 @@ public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSup PartitionedRegionFactoryBean partitionRegion = new PartitionedRegionFactoryBean<>(); partitionRegion.setCache(gemfireCache); - partitionRegion.setClose(false); partitionRegion.setPersistent(false); return partitionRegion; @@ -156,7 +153,6 @@ public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSup ReplicatedRegionFactoryBean replicateRegion = new ReplicatedRegionFactoryBean<>(); replicateRegion.setCache(gemfireCache); - replicateRegion.setClose(false); replicateRegion.setPersistent(false); return replicateRegion; @@ -176,7 +172,6 @@ public class EnableCompressionConfigurationUnitTests extends IntegrationTestsSup ClientRegionFactoryBean clientRegion = new ClientRegionFactoryBean<>(); clientRegion.setCache(gemfireCache); - clientRegion.setClose(false); clientRegion.setShortcut(ClientRegionShortcut.LOCAL); return clientRegion; 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 170506a4..8e296a24 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 @@ -89,6 +89,8 @@ import lombok.Data; * @see org.springframework.data.gemfire.config.annotation.EnableContinuousQueries * @see org.springframework.data.gemfire.listener.annotation.ContinuousQuery * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 2.0.1 */ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTestsSupport { @@ -107,12 +109,12 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe ErrorHandler mockErrorHandler = applicationContext.getBean("mockErrorHandler", ErrorHandler.class); + Executor mockTaskExecutor = applicationContext.getBean("mockTaskExecutor", Executor.class); + Pool mockPool = applicationContext.getBean("mockPool", Pool.class); QueryService mockQueryService = applicationContext.getBean("mockQueryService", QueryService.class); - Executor mockTaskExecutor = applicationContext.getBean("mockTaskExecutor", Executor.class); - assertThat(applicationContext.containsBean("continuousQueryListenerContainer")).isTrue(); ContinuousQueryListenerContainer container = @@ -128,6 +130,7 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe } finally { IOUtils.close(applicationContext); + GemFireMockObjectsSupport.destroy(); } } @@ -162,6 +165,7 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe } finally { IOUtils.close(applicationContext); + GemFireMockObjectsSupport.destroy(); } } @@ -336,8 +340,8 @@ public class EnableContinuousQueriesConfigurationUnitTests extends IntegrationTe static class TestContinuousQueryComponent { @ContinuousQuery(name = "TestQuery", query = "SELECT * FROM /Example") - public void handle(CqEvent event) { - } + public void handle(CqEvent event) { } + } @Data 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 c742443d..ca9bc700 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 @@ -384,13 +384,13 @@ public class EnableEntityDefinedRegionsUnitTests extends IntegrationTestsSupport Region accounts = this.applicationContext.getBean("Sessions", Region.class); assertRegionWithAttributes(accounts, "Sessions", DataPolicy.REPLICATE, - null, true, false, null, Scope.DISTRIBUTED_NO_ACK); + null, true, false, null, Scope.DISTRIBUTED_ACK); Region genericRegionEntity = this.applicationContext.getBean("GenericRegionEntity", Region.class); assertRegionWithAttributes(genericRegionEntity, "GenericRegionEntity", DataPolicy.REPLICATE, - null, true, false, null, Scope.DISTRIBUTED_NO_ACK); + null, true, false, null, Scope.DISTRIBUTED_ACK); Region localRegionEntity = this.applicationContext.getBean("LocalRegionEntity", Region.class); 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 9d9fa772..8904c65a 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 @@ -17,8 +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; @@ -29,12 +27,11 @@ 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.eviction.EvictionActionType; import org.springframework.data.gemfire.eviction.EvictionPolicyType; 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; @@ -45,25 +42,18 @@ import org.springframework.stereotype.Service; * @see org.apache.geode.cache.Region * @see org.springframework.data.gemfire.config.annotation.EnableEviction * @see org.springframework.data.gemfire.config.annotation.EvictionConfiguration - * @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 EnableEvictionConfigurationIntegrationTests extends IntegrationTestsSupport { +public class EnableEvictionConfigurationIntegrationTests 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) { - this.applicationContext = new AnnotationConfigApplicationContext(annotatedClasses); - return this.applicationContext; + destroyAllGemFireMockObjects(); } @SuppressWarnings("unchecked") @@ -115,7 +105,7 @@ public class EnableEvictionConfigurationIntegrationTests extends IntegrationTest "People", EvictionActionType.OVERFLOW_TO_DISK, 10000); } - @ClientCacheApplication(name = "EnableEvictionConfigurationIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL) + @ClientCacheApplication(name = "EnableEvictionConfigurationIntegrationTests") @EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL) @EnableEviction(policies = @EnableEviction.EvictionPolicy(maximum = 100)) @EnableGemFireMockObjects 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 a29e4bab..8227aa90 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 @@ -17,36 +17,27 @@ package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import static org.springframework.data.gemfire.config.annotation.EnableEviction.EvictionPolicy; -import java.util.concurrent.atomic.AtomicReference; - import org.junit.After; import org.junit.Test; -import org.mockito.stubbing.Answer; import org.apache.geode.cache.Cache; import org.apache.geode.cache.EvictionAttributes; import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.RegionFactory; 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.context.annotation.Configuration; 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.mock.annotation.EnableGemFireMockObjects; import org.springframework.data.gemfire.util.ArrayUtils; /** @@ -61,6 +52,7 @@ import org.springframework.data.gemfire.util.ArrayUtils; * @see org.springframework.data.gemfire.config.annotation.EvictionConfiguration * @see org.springframework.data.gemfire.eviction.EvictionAttributesFactoryBean * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects * @since 1.9.0 */ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSupport { @@ -69,9 +61,8 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor @After public void tearDown() { - if (applicationContext != null) { - applicationContext.close(); - } + closeApplicationContext(this.applicationContext); + destroyAllGemFireMockObjects(); } private void assertEvictionAttributes(Region region, EvictionAttributes expectedEvictionAttributes) { @@ -180,50 +171,11 @@ public class EnableEvictionConfigurationUnitTests extends IntegrationTestsSuppor lastMatchingEvictionAttributes); } - @Configuration + @PeerCacheApplication + @EnableGemFireMockObjects @SuppressWarnings("unused") static class CacheRegionConfiguration { - @Bean("mockCache") - @SuppressWarnings("unchecked") - Cache mockCache() { - - Cache mockCache = mock(Cache.class); - - RegionFactory mockRegionFactory = mock(RegionFactory.class); - - AtomicReference evictionAttributes = new AtomicReference<>(null); - - when(mockCache.createRegionFactory()).thenReturn(mockRegionFactory); - - when(mockRegionFactory.setEvictionAttributes(any(EvictionAttributes.class))) - .thenAnswer((Answer>) invocation -> { - evictionAttributes.set(invocation.getArgument(0)); - return (RegionFactory) invocation.getMock(); - } - ); - - when(mockRegionFactory.create(anyString())) - .thenAnswer(invocation -> { - - String regionName = invocation.getArgument(0); - - Region mockRegion = mock(Region.class, regionName); - - RegionAttributes mockRegionAttributes = - mock(RegionAttributes.class, regionName.concat("Attributes")); - - doReturn(regionName).when(mockRegion).getName(); - doReturn(String.format("%1$s%2$s", Region.SEPARATOR, regionName)).when(mockRegion).getFullPath(); - doReturn(mockRegion).when(mockRegion).getAttributes(); - doReturn(evictionAttributes.get()).when(mockRegionAttributes).getEvictionAttributes(); - - return mockRegion; - }); - - return mockCache; - } - @Bean("PartitionRegion") PartitionedRegionFactoryBean mockPartitionRegion(Cache gemfireCache) { 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 303145ce..daaf1a6c 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 @@ -132,7 +132,7 @@ public class PeerCacheApplicationWithAddedCacheServerIntegrationTests } @EnableCacheServer - @PeerCacheApplication + @PeerCacheApplication(name = "PeerCacheApplicationWithAddedCacheServerIntegrationTests") static class TestPeerCacheConfiguration { } } 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 9d1f0732..31bb79c4 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,7 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import java.net.InetSocketAddress; -import java.util.Optional; import org.junit.After; import org.junit.Test; @@ -62,7 +61,7 @@ public class PoolPropertiesIntegrationTests extends IntegrationTestsSupport { @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/RegionConfigurerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionConfigurerIntegrationTests.java index 8595aad8..b1e23e10 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 @@ -66,10 +66,7 @@ public class RegionConfigurerIntegrationTests extends IntegrationTestsSupport { @After public void tearDown() { - - Optional.ofNullable(this.applicationContext) - .ifPresent(ConfigurableApplicationContext::close); - + closeApplicationContext(this.applicationContext); destroyAllGemFireMockObjects(); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java index a69596c3..0c9a4a71 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/RegionDataAccessTracingAspectUnitTests.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Resource; +import org.junit.After; import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; @@ -76,6 +77,11 @@ public class RegionDataAccessTracingAspectUnitTests extends IntegrationTestsSupp Thread.currentThread().getContextClassLoader())); } + @After + public void tearDown() { + TestAppender.getInstance().clear(); + } + @Resource(name = "ClientRegion") private Region region; @@ -172,6 +178,7 @@ public class RegionDataAccessTracingAspectUnitTests extends IntegrationTestsSupp @Test public void logsRegionInvalidate() { + this.region.put("testKey", "testValue"); this.region.invalidate("testKey"); String logMessage = TestAppender.getInstance().lastLogMessage(); @@ -186,6 +193,7 @@ public class RegionDataAccessTracingAspectUnitTests extends IntegrationTestsSupp @Test public void logsRegionInvalidateWithCallbackArgument() { + this.region.put("testKey", "testValue"); this.region.invalidate("testKey", regionCallbackArgument(new AtomicBoolean(false))); String logMessage = TestAppender.getInstance().lastLogMessage(); @@ -270,6 +278,7 @@ public class RegionDataAccessTracingAspectUnitTests extends IntegrationTestsSupp @Test public void logsRegionLocalInvalidate() { + this.region.put("testKey", "testValue"); this.region.localInvalidate("testKey"); String logMessage = TestAppender.getInstance().lastLogMessage(); @@ -284,6 +293,7 @@ public class RegionDataAccessTracingAspectUnitTests extends IntegrationTestsSupp @Test public void logsRegionLocalInvalidateWithCallbackArgument() { + this.region.put("testKey", "testValue"); this.region.localInvalidate("testKey", regionCallbackArgument(new AtomicBoolean(false))); String logMessage = TestAppender.getInstance().lastLogMessage(); @@ -529,7 +539,7 @@ public class RegionDataAccessTracingAspectUnitTests extends IntegrationTestsSupp } @ClientCacheApplication - @EnableGemFireMockObjects + @EnableGemFireMockObjects() @EnableRegionDataAccessTracing static class TestConfiguration { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java index 1e38e2a6..4a27d886 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java @@ -103,7 +103,7 @@ public class AutoRegionLookupBeanPostProcessorUnitTests { } catch (IllegalArgumentException expected) { - assertThat(expected).hasMessage("BeanFactory [%1$s] must be an instance of %2$s", + assertThat(expected).hasMessageStartingWith("BeanFactory [%1$s] must be an instance of %2$s", mockBeanFactory.getClass().getName(), ConfigurableListableBeanFactory.class.getSimpleName()); assertThat(expected).hasNoCause(); @@ -120,7 +120,7 @@ public class AutoRegionLookupBeanPostProcessorUnitTests { } catch (IllegalArgumentException expected) { - assertThat(expected).hasMessage("BeanFactory [null] must be an instance of %s", + assertThat(expected).hasMessageStartingWith("BeanFactory [null] must be an instance of %s", ConfigurableListableBeanFactory.class.getSimpleName()); assertThat(expected).hasNoCause(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java index b400d04a..1af6002f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.support; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -32,7 +32,7 @@ import org.apache.geode.cache.InterestResultPolicy; import org.apache.geode.cache.Scope; import org.apache.geode.cache.wan.GatewaySender; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.PropertyEditorRegistry; import org.springframework.data.gemfire.IndexMaintenancePolicyConverter; import org.springframework.data.gemfire.IndexMaintenancePolicyType; import org.springframework.data.gemfire.IndexType; @@ -52,59 +52,61 @@ import org.springframework.data.gemfire.wan.OrderPolicyConverter; import org.springframework.util.StringUtils; /** - * Unit tests for {@link CustomEditorBeanFactoryPostProcessor}. + * Unit Tests for {@link CustomEditorBeanFactoryPostProcessor}. * * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see CustomEditorBeanFactoryPostProcessor + * @see org.springframework.data.gemfire.config.support.CustomEditorBeanFactoryPostProcessor * @since 1.6.0 */ -@SuppressWarnings("deprecation") public class CustomEditorBeanFactoryPostProcessorUnitTests { - protected ConnectionEndpoint newConnectionEndpoint(String host, int port) { + private ConnectionEndpoint newConnectionEndpoint(String host, int port) { return new ConnectionEndpoint(host, port); } @Test public void customEditorRegistrationIsSuccessful() { - ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class); - new CustomEditorBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory); + PropertyEditorRegistry mockRegistry = mock(PropertyEditorRegistry.class); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint.class), - eq(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointConverter.class)); + new CustomEditorBeanFactoryPostProcessor.CustomEditorPropertyEditorRegistrar().registerCustomEditors(mockRegistry); + + verify(mockRegistry, times(1)).registerCustomEditor(eq(ConnectionEndpoint.class), + isA(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointConverter.class)); //verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint[].class), // eq(CustomEditorBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpointList.class), - eq(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointListConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionAction.class), - eq(EvictionActionConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionPolicyType.class), - eq(EvictionPolicyConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ExpirationAction.class), - eq(ExpirationActionConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexMaintenancePolicyType.class), - eq(IndexMaintenancePolicyConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexType.class), - eq(IndexTypeConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestPolicy.class), - eq(InterestPolicyConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestResultPolicy.class), - eq(InterestResultPolicyConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(Scope.class), eq(ScopeConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(GatewaySender.OrderPolicy.class), - eq(OrderPolicyConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(Scope.class), eq(ScopeConverter.class)); - verify(mockBeanFactory, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class), - eq(SubscriptionEvictionPolicyConverter.class)); - verifyNoMoreInteractions(mockBeanFactory); + verify(mockRegistry, times(1)).registerCustomEditor(eq(ConnectionEndpointList.class), + isA(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointListConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(EvictionAction.class), + isA(EvictionActionConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(EvictionPolicyType.class), + isA(EvictionPolicyConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(ExpirationAction.class), + isA(ExpirationActionConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(IndexMaintenancePolicyType.class), + isA(IndexMaintenancePolicyConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(IndexType.class), + isA(IndexTypeConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(InterestPolicy.class), + isA(InterestPolicyConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(InterestResultPolicy.class), + isA(InterestResultPolicyConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(Scope.class), isA(ScopeConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(GatewaySender.OrderPolicy.class), + isA(OrderPolicyConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(Scope.class), isA(ScopeConverter.class)); + verify(mockRegistry, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class), + isA(SubscriptionEvictionPolicyConverter.class)); + + verifyNoMoreInteractions(mockRegistry); } @Test @SuppressWarnings("unchecked") public void connectionEndpointArrayToIterableConversionIsSuccessful() { + ConnectionEndpoint[] array = { newConnectionEndpoint("localhost", 10334), newConnectionEndpoint("localhost", 40404) @@ -126,6 +128,7 @@ public class CustomEditorBeanFactoryPostProcessorUnitTests { @Test public void stringToConnectionEndpointConversionIsSuccessful() { + String hostPort = "skullbox[54321]"; ConnectionEndpoint connectionEndpoint = new CustomEditorBeanFactoryPostProcessor @@ -138,6 +141,7 @@ public class CustomEditorBeanFactoryPostProcessorUnitTests { @Test public void stringToConnectionEndpointListConversionIsSuccessful() { + String[] hostsPorts = { "toolbox[10334]", "skullbox", "[40404]" }; String source = StringUtils.arrayToCommaDelimitedString(hostsPorts); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests.java index a461f570..37fc799b 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests.java @@ -36,6 +36,7 @@ import org.apache.geode.cache.wan.GatewayQueueEvent; 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.test.context.junit4.SpringRunner; @@ -48,13 +49,14 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.apache.geode.cache.asyncqueue.AsyncEventQueue * @see org.springframework.data.gemfire.config.AsyncEventQueueParser * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer * @see org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.0.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("all") public class AsyncEventQueueNamespaceIntegrationTests extends IntegrationTestsSupport { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests.java index 56a37270..3b59f09e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests.java @@ -21,6 +21,7 @@ import static org.springframework.data.gemfire.support.GemfireBeanFactoryLocator import java.util.Properties; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,6 +36,7 @@ import org.springframework.core.io.Resource; import org.springframework.data.gemfire.CacheFactoryBean; 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; @@ -48,25 +50,33 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.data.gemfire.CacheFactoryBean * @see org.springframework.data.gemfire.config.xml.CacheParser * @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 +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired @SuppressWarnings("unused") private ApplicationContext applicationContext; + @Before + public void setup() { + assertThat(this.applicationContext.getBean("gemfireCache")) + .isNotEqualTo(this.applicationContext.getBean("cache-with-name")); + } + @Test - public void testNoNamedCache() { + public void noNamedCacheConfigurationIsCorrect() { assertThat(applicationContext.containsBean("gemfireCache")).isTrue(); assertThat(applicationContext.containsBean("gemfire-cache")).isTrue(); CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + assertThat(cacheFactoryBean.getBeanName()).isEqualTo("gemfireCache"); assertThat(cacheFactoryBean.getCacheXml()).isNull(); Properties gemfireProperties = cacheFactoryBean.getProperties(); @@ -84,19 +94,23 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { assertThat(gemfireCache).isNotNull(); assertThat(gemfireCache.getDistributedSystem()).isNotNull(); assertThat(gemfireCache.getDistributedSystem().getProperties()).isNotNull(); - assertThat(gemfireCache.getDistributedSystem().getProperties().containsKey("disable-auto-reconnect")).isNotNull(); + assertThat(gemfireCache.getDistributedSystem().getProperties().containsKey("disable-auto-reconnect")).isTrue(); assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties() .getProperty("disable-auto-reconnect"))).isTrue(); + assertThat(gemfireCache.getDistributedSystem().getProperties().containsKey("use-cluster-configuration")).isTrue(); + assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties() + .getProperty("use-cluster-configuration"))).isFalse(); } @Test - public void testNamedCache() { + public void namedCacheConfigurationIsCorrect() { assertThat(applicationContext.containsBean("cache-with-name")).isTrue(); CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&cache-with-name", CacheFactoryBean.class); + assertThat(cacheFactoryBean.getBeanName()).isEqualTo("cache-with-name"); assertThat(cacheFactoryBean.getCacheXml()).isNull(); Properties gemfireProperties = cacheFactoryBean.getProperties(); @@ -109,17 +123,20 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { assertThat(gemfireProperties.containsKey("use-cluster-configuration")).isTrue(); assertThat(Boolean.parseBoolean(gemfireProperties.getProperty("use-cluster-configuration"))).isFalse(); - Cache gemfireCache = applicationContext.getBean("gemfireCache", Cache.class); + Cache gemfireCache = applicationContext.getBean("cache-with-name", Cache.class); - assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties() - .getProperty("disable-auto-reconnect"))).isTrue(); + assertThat(gemfireCache).isNotNull(); + assertThat(gemfireCache.getDistributedSystem()).isNotNull(); - assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties() - .getProperty("use-cluster-configuration"))).isFalse(); + Properties distributedSystemProperties = gemfireCache.getDistributedSystem().getProperties(); + + assertThat(distributedSystemProperties).isNotNull(); + assertThat(Boolean.parseBoolean(distributedSystemProperties.getProperty("disable-auto-reconnect"))).isTrue(); + assertThat(Boolean.parseBoolean(distributedSystemProperties.getProperty("use-cluster-configuration"))).isFalse(); } @Test - public void testCacheWithAutoReconnectDisabled() { + public void cacheWithAutoReconnectDisabledIsCorrect() { assertThat(applicationContext.containsBean("cache-with-auto-reconnect-disabled")).isTrue(); @@ -135,7 +152,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test - public void testCacheWithAutoReconnectEnabled() { + public void cacheWithAutoReconnectEnabledIsCorrect() { assertThat(applicationContext.containsBean("cache-with-auto-reconnect-enabled")).isTrue(); @@ -151,7 +168,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test - public void testCacheWithGatewayConflictResolver() { + public void cacheWithGatewayConflictResolverIsCorrect() { Cache cache = applicationContext.getBean("cache-with-gateway-conflict-resolver", Cache.class); @@ -159,7 +176,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test(expected = IllegalStateException.class) - public void testCacheWithNoBeanFactoryLocator() { + public void cacheWithNoBeanFactoryLocatorIsCorrect() { assertThat(applicationContext.containsBean("cache-with-no-bean-factory-locator")).isTrue(); @@ -172,7 +189,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test - public void testCacheWithUseClusterConfigurationDisabled() { + public void cacheWithUseClusterConfigurationDisabledIsCorrect() { assertThat(applicationContext.containsBean("cache-with-use-cluster-configuration-disabled")).isTrue(); @@ -189,7 +206,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test - public void testCacheWithUseClusterConfigurationEnabled() { + public void cacheWithUseClusterConfigurationEnabledIsCorrect() { assertThat(applicationContext.containsBean("cache-with-use-cluster-configuration-enabled")).isTrue(); @@ -206,7 +223,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test - public void testCacheWithXmlAndProperties() throws Exception { + public void cacheWithXmlAndPropertiesConfigurationIsCorrect() throws Exception { assertThat(applicationContext.containsBean("cache-with-xml-and-props")).isTrue(); @@ -225,7 +242,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test - public void testHeapTunedCache() { + public void heapTunedCacheIsCorrect() { assertThat(applicationContext.containsBean("heap-tuned-cache")).isTrue(); @@ -240,7 +257,7 @@ public class CacheNamespaceIntegrationTests extends IntegrationTestsSupport { } @Test - public void testOffHeapTunedCache() { + public void offHeapTunedCacheIsCorrect() { assertThat(applicationContext.containsBean("off-heap-tuned-cache")).isTrue(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceIntegrationTests.java index 5611c063..6235aa16 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceIntegrationTests.java @@ -46,8 +46,7 @@ import org.springframework.util.StringUtils; * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "server-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") public class CacheServerNamespaceIntegrationTests extends IntegrationTestsSupport { @@ -56,7 +55,7 @@ public class CacheServerNamespaceIntegrationTests extends IntegrationTestsSuppor @Test @SuppressWarnings("deprecation") - public void testBasicCacheServer() { + public void basicCacheServerConfigurationIsCorrect() { CacheServer cacheServer = applicationContext.getBean("advanced-config", CacheServer.class); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheParserUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheParserUnitTests.java index da06a6d6..584be8ef 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheParserUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheParserUnitTests.java @@ -14,13 +14,14 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +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; @@ -34,22 +35,23 @@ import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** - * Unit tests for {@link ClientCacheParser}. + * Unit Tests for {@link ClientCacheParser}. * * @author John Blum * @author Patrick Johnson * @see org.junit.Test * @see org.mockito.Mock * @see org.mockito.Mockito + * @see org.mockito.Spy * @see org.mockito.junit.MockitoJUnitRunner * @see org.springframework.data.gemfire.config.xml.ClientCacheParser + * @see org.w3c.dom.Element * @since 1.8.0 */ @RunWith(MockitoJUnitRunner.class) @@ -58,15 +60,15 @@ public class ClientCacheParserUnitTests { @Mock private Element mockElement; - protected void assertPropertyIsPresent(BeanDefinition beanDefinition, String propertyName) { + private void assertPropertyIsPresent(BeanDefinition beanDefinition, String propertyName) { assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isTrue(); } - protected void assertPropertyIsNotPresent(BeanDefinition beanDefinition, String propertyName) { + private void assertPropertyIsNotPresent(BeanDefinition beanDefinition, String propertyName) { assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isFalse(); } - protected void assertPropertyValueEquals(BeanDefinition beanDefinition, String propertyName, + private void assertPropertyValueEquals(BeanDefinition beanDefinition, String propertyName, Object expectedPropertyValue) { assertPropertyIsPresent(beanDefinition, propertyName); @@ -82,6 +84,7 @@ public class ClientCacheParserUnitTests { @Test public void doParseSetsProperties() { + NodeList mockNodeList = mock(NodeList.class); when(mockElement.getAttribute(eq("durable-client-id"))).thenReturn("123"); @@ -94,15 +97,11 @@ public class ClientCacheParserUnitTests { BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition(); - final BeanDefinitionRegistry mockRegistry = mock(BeanDefinitionRegistry.class); + BeanDefinitionRegistry mockRegistry = mock(BeanDefinitionRegistry.class); - when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false); + ClientCacheParser clientCacheParser = spy(new ClientCacheParser()); - ClientCacheParser clientCacheParser = new ClientCacheParser() { - @Override protected BeanDefinitionRegistry getRegistry(ParserContext parserContext) { - return mockRegistry; - } - }; + doReturn(mockRegistry).when(clientCacheParser).getRegistry(any()); clientCacheParser.doParse(mockElement, null, clientCacheBuilder); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests.java index b67b4550..7c4f9dac 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests.java @@ -34,7 +34,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "index-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings({ "deprecation", "unused" }) public class IndexNamespaceIntegrationTests extends IntegrationTestsSupport { @@ -74,6 +74,7 @@ public class IndexNamespaceIntegrationTests extends IntegrationTestsSupport { assertThat(complex.getName()).isEqualTo("complex-index"); assertThat(complex.getIndexedExpression()).isEqualTo("tsi.name"); assertThat(complex.getFromClause()).isEqualTo(Region.SEPARATOR + TEST_REGION_NAME + " tsi"); + assertThat(complex.getRegion()).isNotNull(); assertThat(complex.getRegion().getName()).isEqualTo(TEST_REGION_NAME); assertThat(complex.getType()).isEqualTo(org.apache.geode.cache.query.IndexType.HASH); } 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 8d47e88e..c2427619 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 @@ -30,7 +30,7 @@ import org.springframework.data.gemfire.tests.mock.beans.factory.config.GemFireM import org.xml.sax.SAXParseException; /** - * Unit Tests testing the proper syntax for declaring "custom" expiration attributes on a {@link Region}. + * Integration Tests testing the proper syntax for declaring "custom" expiration attributes on a {@link Region}. * * @author John Blum * @see org.junit.Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests.java index a7ae6799..64993f34 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests.java @@ -22,6 +22,8 @@ import org.junit.runner.RunWith; import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheListener; +import org.apache.geode.cache.CacheLoader; +import org.apache.geode.cache.CacheWriter; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionAttributes; @@ -41,7 +43,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; /** - * Integration Tests for the Local Region XML namespace configuration metadata. + * Integration Tests for the Local {@link Region} SDG XML namespace configuration metadata. * * @author Costin Leau * @author David Turanski @@ -56,7 +58,7 @@ import org.springframework.util.ObjectUtils; * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations="local-ns.xml", initializers = GemFireMockObjectsApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") public class LocalRegionNamespaceIntegrationTests extends IntegrationTestsSupport { @@ -116,9 +118,9 @@ public class LocalRegionNamespaceIntegrationTests extends IntegrationTestsSuppor assertThat(cacheListeners[0]).isSameAs(applicationContext.getBean("c-listener")); assertThat(cacheListeners[1] instanceof SimpleCacheListener).isTrue(); assertThat(cacheListeners[1]).isNotSameAs(cacheListeners[0]); - assertThat(TestUtils.readField("cacheLoader", complexRegionFactoryBean)) + assertThat(TestUtils.readField("cacheLoader", complexRegionFactoryBean)) .isSameAs(applicationContext.getBean("c-loader")); - assertThat(TestUtils.readField("cacheWriter", complexRegionFactoryBean)) + assertThat(TestUtils.readField("cacheWriter", complexRegionFactoryBean)) .isSameAs(applicationContext.getBean("c-writer")); } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests.java index 8b6fb23a..68633a19 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests.java @@ -17,31 +17,22 @@ package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doNothing; 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 static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.concurrent.atomic.AtomicReference; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.stubbing.Answer; -import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.lucene.LuceneIndex; -import org.apache.geode.cache.lucene.LuceneIndexFactory; import org.apache.geode.cache.lucene.LuceneSerializer; import org.apache.geode.cache.lucene.LuceneService; @@ -49,19 +40,21 @@ import org.apache.lucene.analysis.Analyzer; import org.springframework.beans.BeansException; import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.data.gemfire.search.lucene.LuceneServiceFactoryBean; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport; import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import lombok.SneakyThrows; + /** - * Unit tests for the {@link LuceneServiceParser} and {@link LuceneIndexParser}. + * Unit Tests for the {@link LuceneServiceParser} and {@link LuceneIndexParser}. * * @author John Blum * @see org.junit.Test @@ -189,104 +182,23 @@ public class LuceneNamespaceUnitTests extends IntegrationTestsSupport { assertThat(this.luceneIndexFour.getLuceneSerializer()).isEqualTo(luceneSerializer); } - public static class LuceneNamespaceUnitTestsBeanFactoryPostProcessor implements BeanFactoryPostProcessor { + public static class LuceneNamespaceUnitTestsBeanPostProcessor implements BeanPostProcessor { - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - beanFactory.getBeanDefinition("luceneService") - .setBeanClassName(MockLuceneServiceFactoryBean.class.getName()); - } - } + @SneakyThrows @Nullable @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - public static class MockLuceneServiceFactoryBean implements FactoryBean, InitializingBean { + if (bean instanceof LuceneServiceFactoryBean) { - private GemFireCache gemfireCache; + LuceneServiceFactoryBean factoryBean = spy((LuceneServiceFactoryBean) bean); - private LuceneService luceneService; + doNothing().when(factoryBean).afterPropertiesSet(); + doAnswer(invocation -> GemFireMockObjectsSupport.mockLuceneService(null)) + .when(factoryBean).getObject(); - @Override - public void afterPropertiesSet() throws Exception { - assertThat(this.gemfireCache).describedAs("GemFireCache must not be null").isNotNull(); - } + bean = factoryBean; + } - @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) - public LuceneService getObject() throws Exception { - - return Optional.ofNullable(this.luceneService).orElseGet(() -> { - - this.luceneService = mock(LuceneService.class); - - when(this.luceneService.createIndexFactory()).thenAnswer(invocation -> { - - LuceneIndexFactory mockLuceneIndexFactory = mock(LuceneIndexFactory.class); - - List fieldNames = new ArrayList<>(); - - when(mockLuceneIndexFactory.setFields((String[]) any())).thenAnswer(setFieldsInvocation -> { - Collections.addAll(fieldNames, toStringArray(setFieldsInvocation.getArguments())); - return mockLuceneIndexFactory; - }); - - Map fieldAnalyzers = new HashMap<>(); - - when(mockLuceneIndexFactory.setFields(any(Map.class))).thenAnswer(setFieldsInvocation -> { - fieldAnalyzers.putAll(setFieldsInvocation.getArgument(0)); - return mockLuceneIndexFactory; - }); - - AtomicReference luceneSerializer = new AtomicReference<>(null); - - when(mockLuceneIndexFactory.setLuceneSerializer(any())).thenAnswer(setLuceneSerializerInvocation -> { - luceneSerializer.set(setLuceneSerializerInvocation.getArgument(0)); - return mockLuceneIndexFactory; - }); - - Answer mockLuceneIndex = - mockLuceneIndex(this.luceneService, fieldAnalyzers, fieldNames, luceneSerializer); - - doAnswer(mockLuceneIndex).when(mockLuceneIndexFactory).create(anyString(), anyString()); - - return mockLuceneIndexFactory; - }); - - return this.luceneService; - }); - } - - @SuppressWarnings("rawtypes") - private Answer mockLuceneIndex(LuceneService mockLuceneService, - Map fieldAnalyzers, List fieldNames, - AtomicReference luceneSerializer) { - - return invocation -> { - - String indexName = invocation.getArgument(0); - String regionPath = invocation.getArgument(1); - - LuceneIndex mockLuceneIndex = mock(LuceneIndex.class, indexName); - - when(mockLuceneIndex.getFieldAnalyzers()).thenReturn(fieldAnalyzers); - when(mockLuceneIndex.getFieldNames()).thenReturn(asArray(fieldNames)); - when(mockLuceneIndex.getLuceneSerializer()).thenAnswer(it -> luceneSerializer.get()); - when(mockLuceneIndex.getName()).thenReturn(indexName); - when(mockLuceneIndex.getRegionPath()).thenReturn(regionPath); - when(mockLuceneService.getIndex(eq(indexName), eq(regionPath))).thenReturn(mockLuceneIndex); - - return mockLuceneIndex; - }; - } - - @Override - public Class getObjectType() { - - return Optional.ofNullable(this.luceneService) - .>map(LuceneService::getClass) - .orElse(LuceneService.class); - } - - public void setCache(GemFireCache gemfireCache) { - this.gemfireCache = gemfireCache; + return bean; } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java index e5c4e67a..aac60bb6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests.java @@ -17,6 +17,8 @@ package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; +import javax.annotation.Resource; + import org.junit.Test; import org.junit.runner.RunWith; @@ -26,8 +28,6 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.ResumptionAction; import org.apache.geode.distributed.Role; -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; @@ -47,33 +47,38 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings({ "deprecation", "unused" }) public class MembershipAttributesIntegrationTests extends IntegrationTestsSupport { - @Autowired - private ApplicationContext applicationContext; + @Resource(name = "secure") + private Region secure; + + @Resource(name = "simple") + private Region simple; @Test - public void membershipAttributesConfigurationIsCorrect() { + public void secureRegionMembershipAttributesConfigurationIsCorrect() { - Region simple = applicationContext.getBean("simple", Region.class); + MembershipAttributes membershipAttributes = secure.getAttributes().getMembershipAttributes(); + + assertThat(membershipAttributes).isNotNull(); + assertThat(membershipAttributes.getLossAction()).isEqualTo(LossAction.LIMITED_ACCESS); + assertThat(membershipAttributes.hasRequiredRoles()).isTrue(); + assertThat(membershipAttributes.getRequiredRoles().stream().map(Role::getName)) + .containsExactlyInAnyOrder("ROLE1", "ROLE2"); + assertThat(membershipAttributes.getResumptionAction()).isEqualTo(ResumptionAction.REINITIALIZE); + } + + @Test + public void simpleRegionMembershipAttributesConfigurationIsCorrect() { MembershipAttributes membershipAttributes = simple.getAttributes().getMembershipAttributes(); + assertThat(membershipAttributes).isNotNull(); + assertThat(membershipAttributes.getLossAction()).isEqualTo(LossAction.FULL_ACCESS); assertThat(membershipAttributes.hasRequiredRoles()).isFalse(); - - Region secure = applicationContext.getBean("secure", Region.class); - - membershipAttributes = secure.getAttributes().getMembershipAttributes(); - - assertThat(membershipAttributes.hasRequiredRoles()).isTrue(); - assertThat(membershipAttributes.getResumptionAction()).isEqualTo(ResumptionAction.REINITIALIZE); - assertThat(membershipAttributes.getLossAction()).isEqualTo(LossAction.LIMITED_ACCESS); - - for (Role role : membershipAttributes.getRequiredRoles()) { - assertThat("ROLE1".equals(role.getName()) || "ROLE2".equals(role.getName())).isTrue(); - } + assertThat(membershipAttributes.getRequiredRoles()).isEmpty(); + assertThat(membershipAttributes.getResumptionAction()).isEqualTo(ResumptionAction.NONE); } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests.java index 0d59e21f..34da50c8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests.java @@ -38,7 +38,7 @@ import org.springframework.test.context.junit4.SpringRunner; /** * Integration Tests testing the contract and functionality of the SDG {@link PeerRegionFactoryBean} class, - * and specifically the specification of the Apache Geode {@link Region} {@link DataPolicy}, when used as + * and specifically the specification of the Apache Geode {@link Region} {@link DataPolicy} when used as * raw bean definition in Spring XML configuration metadata. * * @author John Blum diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests.java index a2570de1..f628acc6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests.java @@ -34,7 +34,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration Tests for Apache Geode {@link Region} Eviction configuration settings ({@link EvictionAttributes}) + * Integration Tests for {@link Region} Eviction configuration settings ({@link EvictionAttributes}) * using SDG XML namespace configuration metadata. * * @author John Blum diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests.java index 6dd4b290..dffd57c7 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests.java @@ -36,8 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.Assert; /** - * Integration Tests with test cases testing the configuration of {@link ExpirationAttributes} settings - * on {@link Region} entries. + * Integration Tests testing the configuration of {@link ExpirationAttributes} settings on {@link Region} entries. * * @author John Blum * @see org.junit.Test diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests.java index 1817589d..d71a45c4 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests.java @@ -25,6 +25,7 @@ import org.junit.runner.RunWith; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.InterestPolicy; import org.apache.geode.cache.Region; +import org.apache.geode.cache.SubscriptionAttributes; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.mock.context.GemFireMockObjectsApplicationContextInitializer; @@ -32,13 +33,14 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration Tests with test cases testing the contract and functionality of declaring and defining Subscription - * Attributes for a {@link Region} in the SDG XML namespace (XSD) configuration metadata. + * Integration Tests testing the contract and functionality of declaring and defining {@link SubscriptionAttributes} + * for a {@link Region} in the SDG XML namespace configuration metadata. * * @author John Blum * @see org.junit.Test * @see org.junit.runner.RunWith * @see org.apache.geode.cache.Region + * @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 diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests.java index f58a1d9b..50f08747 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests.java @@ -45,7 +45,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ObjectUtils; /** - * Integration Tests for the Replicated Region XML namespace configuration metadata. + * Integration Tests for {@link DataPolicy#REPLICATE} {@link Region} XML namespace configuration metadata. * * @author Costin Leau * @author David Turanski @@ -60,16 +60,15 @@ import org.springframework.util.ObjectUtils; * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(locations = "replicated-ns.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class) -@SuppressWarnings("unused") +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) +@SuppressWarnings({ "rawtypes", "unused" }) public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; @Test - public void testSimpleReplicateRegion() throws Exception { + public void simpleReplicateRegionConfigurationIsCorrect() throws Exception { assertThat(applicationContext.containsBean("simple")).isTrue(); @@ -80,7 +79,7 @@ public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsS assertThat(TestUtils.readField("close", simpleRegionFactoryBean)).isEqualTo(false); assertThat(TestUtils.readField("scope", simpleRegionFactoryBean)).isNull(); - RegionAttributes simpleRegionAttributes = TestUtils.readField("attributes", simpleRegionFactoryBean); + RegionAttributes simpleRegionAttributes = simpleRegionFactoryBean.getAttributes(); assertThat(simpleRegionAttributes).isNotNull(); assertThat(simpleRegionAttributes.getConcurrencyChecksEnabled()).isFalse(); @@ -89,8 +88,8 @@ public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsS } @Test - @SuppressWarnings({ "deprecation", "rawtypes" }) - public void testPublishReplicateRegion() throws Exception { + @SuppressWarnings("deprecation") + public void publisherReplicateRegionConfigurationIsCorrect() throws Exception { assertThat(applicationContext.containsBean("pub")).isTrue(); @@ -101,15 +100,14 @@ public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsS assertThat(TestUtils.readField("name", publisherRegionFactoryBean)).isEqualTo("publisher"); assertThat(TestUtils.readField("scope", publisherRegionFactoryBean)).isEqualTo(Scope.DISTRIBUTED_ACK); - RegionAttributes publisherRegionAttributes = TestUtils.readField("attributes", publisherRegionFactoryBean); + RegionAttributes publisherRegionAttributes = publisherRegionFactoryBean.getAttributes(); assertThat(publisherRegionAttributes.getConcurrencyChecksEnabled()).isTrue(); assertThat(publisherRegionAttributes.getPublisher()).isFalse(); } @Test - @SuppressWarnings("rawtypes") - public void testComplexReplicateRegion() throws Exception { + public void complexReplicateRegionConfigurationIsCorrect() throws Exception { assertThat(applicationContext.containsBean("complex")).isTrue(); @@ -133,8 +131,7 @@ public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsS } @Test - @SuppressWarnings("rawtypes") - public void testReplicatedRegionWithAttributes() { + public void replicatedRegionWithAttributesConfigurationIsCorrect() { assertThat(applicationContext.containsBean("replicated-with-attributes")).isTrue(); @@ -165,7 +162,7 @@ public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsS } @Test - public void testReplicatedWithSynchronousIndexUpdates() { + public void replicatedWithSynchronousIndexUpdatesConfigurationIsCorrect() { assertThat(applicationContext.containsBean("replicated-with-synchronous-index-updates")).isTrue(); @@ -181,8 +178,7 @@ public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsS } @Test - @SuppressWarnings("rawtypes") - public void testRegionLookup() throws Exception { + public void regionLookupConfigurationIsCorrect() throws Exception { Cache cache = applicationContext.getBean(Cache.class); @@ -199,7 +195,7 @@ public class ReplicatedRegionNamespaceIntegrationTests extends IntegrationTestsS } @Test - public void testCompressedReplicateRegion() { + public void compressedReplicateRegionConfigurationIsCorrect() { assertThat(applicationContext.containsBean("Compressed")).isTrue(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests.java index 8cc9514e..b2759293 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests.java @@ -41,11 +41,8 @@ import org.apache.geode.cache.ExpirationAction; import org.apache.geode.cache.ExpirationAttributes; import org.apache.geode.cache.InterestPolicy; import org.apache.geode.cache.LoaderHelper; -import org.apache.geode.cache.LossAction; -import org.apache.geode.cache.MembershipAttributes; import org.apache.geode.cache.PartitionResolver; import org.apache.geode.cache.Region; -import org.apache.geode.cache.ResumptionAction; import org.apache.geode.cache.Scope; import org.apache.geode.cache.SubscriptionAttributes; import org.apache.geode.cache.asyncqueue.AsyncEvent; @@ -55,7 +52,6 @@ import org.apache.geode.cache.partition.PartitionListenerAdapter; import org.apache.geode.cache.util.CacheListenerAdapter; import org.apache.geode.cache.util.CacheWriterAdapter; import org.apache.geode.cache.util.ObjectSizer; -import org.apache.geode.distributed.Role; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanIsAbstractException; @@ -65,7 +61,6 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor 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.ObjectUtils; import org.springframework.util.StringUtils; /** @@ -187,27 +182,6 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu assertThat(Arrays.asList(gatewaySenderIds).containsAll(region.getAttributes().getGatewaySenderIds())).isTrue(); } - private void assertDefaultMembershipAttributes(MembershipAttributes membershipAttributes) { - - assumeNotNull(membershipAttributes); - assertMembershipAttributes(membershipAttributes, LossAction.FULL_ACCESS, ResumptionAction.NONE); - } - - private void assertMembershipAttributes(MembershipAttributes membershipAttributes, LossAction expectedLossAction, - ResumptionAction expectedResumptionAction, String... expectedRequiredRoles) { - - assertThat(membershipAttributes).as("The 'MembershipAttributes' must not be null!").isNotNull(); - assertThat(membershipAttributes.getLossAction()).isEqualTo(expectedLossAction); - assertThat(membershipAttributes.getResumptionAction()).isEqualTo(expectedResumptionAction); - - if (!ObjectUtils.isEmpty(expectedRequiredRoles)) { - for (Role membershipRole : membershipAttributes.getRequiredRoles()) { - assertThat(Arrays.asList(expectedRequiredRoles).contains(membershipRole.getName())) - .as(String.format("Role '%1$s' was not found!", membershipRole)).isTrue(); - } - } - } - private void assertPartitionListener(Region region, String... expectedNames) { assertThat(region).isNotNull(); @@ -235,6 +209,7 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu .isEqualTo(expectedName); } + @SuppressWarnings("unchecked") private void assertDefaultRegionAttributes(Region region) { assertThat(region).describedAs("The Region must not be null!").isNotNull(); @@ -346,7 +321,6 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu assertThat(nonTemplateBasedReplicateRegion.getAttributes().getKeyConstraint()).isNull(); assertThat(String.valueOf(nonTemplateBasedReplicateRegion.getAttributes().getLoadFactor())).isEqualTo("0.65"); assertThat(nonTemplateBasedReplicateRegion.getAttributes().isLockGrantor()).isFalse(); - assertDefaultMembershipAttributes(nonTemplateBasedReplicateRegion.getAttributes().getMembershipAttributes()); assertThat(nonTemplateBasedReplicateRegion.getAttributes().getPartitionAttributes()).isNull(); assertThat(nonTemplateBasedReplicateRegion.getAttributes().getScope()).isEqualTo(Scope.DISTRIBUTED_NO_ACK); assertThat(nonTemplateBasedReplicateRegion.getAttributes().getStatisticsEnabled()).isFalse(); @@ -383,7 +357,6 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu assertThat(templateBasedReplicateRegion.getAttributes().getKeyConstraint()).isEqualTo(String.class); assertThat(String.valueOf(templateBasedReplicateRegion.getAttributes().getLoadFactor())).isEqualTo("0.85"); assertThat(templateBasedReplicateRegion.getAttributes().isLockGrantor()).isTrue(); - assertDefaultMembershipAttributes(templateBasedReplicateRegion.getAttributes().getMembershipAttributes()); assertThat(templateBasedReplicateRegion.getAttributes().getPartitionAttributes()).isNull(); assertThat(templateBasedReplicateRegion.getAttributes().getScope()).isEqualTo(Scope.GLOBAL); assertThat(templateBasedReplicateRegion.getAttributes().getStatisticsEnabled()).isTrue(); @@ -421,8 +394,6 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu assertThat(templateBasedReplicateSubRegion.getAttributes().getKeyConstraint()).isEqualTo(Integer.class); assertThat(String.valueOf(templateBasedReplicateSubRegion.getAttributes().getLoadFactor())).isEqualTo("0.95"); assertThat(templateBasedReplicateSubRegion.getAttributes().isLockGrantor()).isFalse(); - assertMembershipAttributes(templateBasedReplicateSubRegion.getAttributes().getMembershipAttributes(), - LossAction.LIMITED_ACCESS, ResumptionAction.NONE, "readWriteNode"); assertThat(templateBasedReplicateSubRegion.getAttributes().getPartitionAttributes()).isNull(); assertThat(templateBasedReplicateSubRegion.getAttributes().getScope()).isEqualTo(Scope.DISTRIBUTED_NO_ACK); assertThat(templateBasedReplicateSubRegion.getAttributes().getStatisticsEnabled()).isTrue(); @@ -461,8 +432,6 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu assertThat(templateBasedReplicateRegionNoOverrides.getAttributes().getLoadFactor()) .isCloseTo(0.85f, offset(0.0f)); assertThat(templateBasedReplicateRegionNoOverrides.getAttributes().isLockGrantor()).isFalse(); - assertDefaultMembershipAttributes( - templateBasedReplicateRegionNoOverrides.getAttributes().getMembershipAttributes()); assertThat(templateBasedReplicateRegionNoOverrides.getAttributes().getPartitionAttributes()).isNull(); assertThat(templateBasedReplicateRegionNoOverrides.getAttributes().getScope()).isEqualTo(Scope.DISTRIBUTED_ACK); assertThat(templateBasedReplicateRegionNoOverrides.getAttributes().getStatisticsEnabled()).isTrue(); @@ -502,8 +471,6 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu assertThat(templateBasedPartitionRegion.getAttributes().getKeyConstraint()).isEqualTo(Date.class); assertThat(String.valueOf(templateBasedPartitionRegion.getAttributes().getLoadFactor())).isEqualTo("0.7"); assertThat(templateBasedPartitionRegion.getAttributes().isLockGrantor()).isFalse(); - assertMembershipAttributes(templateBasedPartitionRegion.getAttributes().getMembershipAttributes(), - LossAction.NO_ACCESS, ResumptionAction.REINITIALIZE, "admin", "root", "supertool"); assertThat(templateBasedPartitionRegion.getAttributes().getPartitionAttributes()).isNotNull(); assertThat(templateBasedPartitionRegion.getAttributes().getPartitionAttributes().getColocatedWith()) .isEqualTo("Neighbor"); @@ -557,7 +524,6 @@ public class TemplateRegionsNamespaceIntegrationTests extends IntegrationTestsSu assertThat(templateBasedLocalRegion.getAttributes().getKeyConstraint()).isEqualTo(Long.class); assertThat(String.valueOf(templateBasedLocalRegion.getAttributes().getLoadFactor())).isEqualTo("0.85"); assertThat(templateBasedLocalRegion.getAttributes().isLockGrantor()).isFalse(); - assertDefaultMembershipAttributes(templateBasedLocalRegion.getAttributes().getMembershipAttributes()); assertThat(templateBasedLocalRegion.getAttributes().getPartitionAttributes()).isNull(); assertThat(templateBasedLocalRegion.getAttributes().getScope()).isEqualTo(Scope.LOCAL); assertThat(templateBasedLocalRegion.getAttributes().getStatisticsEnabled()).isTrue(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TransactionEventHandlersIntegrationTests.java similarity index 92% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersIntegrationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TransactionEventHandlersIntegrationTests.java index 33695678..8540e44a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/xml/TransactionEventHandlersIntegrationTests.java @@ -33,8 +33,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration Tests for Apache Geode cache transaction event handling configuration declared in - * SDG XML namespace configuration metadata. + * Integration Tests for Apache Geode cache transaction event handlers (listeners) declared in SDG XML namespace + * configuration metadata. * * @author David Turanski * @author John Blum @@ -49,12 +49,9 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration( - locations = "tx-listeners-and-writers.xml", - initializers = GemFireMockObjectsApplicationContextInitializer.class -) +@ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class TxEventHandlersIntegrationTests extends IntegrationTestsSupport { +public class TransactionEventHandlersIntegrationTests extends IntegrationTestsSupport { @Autowired TestTransactionListener txListener1; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java index b9ccbc50..9daf7a51 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/expiration/AnnotationBasedExpirationConfigurationIntegrationTest.java @@ -17,8 +17,8 @@ package org.springframework.data.gemfire.expiration; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import javax.annotation.Resource; @@ -40,8 +40,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** - * Integration Tests with test cases testing the configuration of Annotation-defined expiration policies - * on {@link Region} entry TTL and TTI custom expiration settings. + * Integration Tests testing the configuration of Annotation-defined expiration policies on {@link Region} entry + * TTL and TTI custom expiration settings. * * @author John Blum * @see org.junit.Test @@ -115,7 +115,7 @@ public class AnnotationBasedExpirationConfigurationIntegrationTest extends Integ Region.Entry mockRegionEntry = mock(Region.Entry.class, "MockRegionEntry"); - when(mockRegionEntry.getValue()).thenReturn(value); + doReturn(value).when(mockRegionEntry).getValue(); return mockRegionEntry; } @@ -169,7 +169,7 @@ public class AnnotationBasedExpirationConfigurationIntegrationTest extends Integ assertExpiration(genericExpiration.getExpiry(mockRegionEntry(new RegionEntryGenericExpirationPolicy())), 60, ExpirationAction.DESTROY); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = EvaluationException.class) public void invalidExpirationAction() { try { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/CqCacheServerProcess.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/CqCacheServerProcess.java index fb73f8fe..63a03ad5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/CqCacheServerProcess.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/fork/CqCacheServerProcess.java @@ -13,31 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.fork; import java.io.IOException; import java.util.Scanner; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionFactory; import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.cache.Scope; import org.apache.geode.cache.server.CacheServer; import org.springframework.data.gemfire.ForkUtil; +import org.springframework.data.gemfire.util.SpringUtils; /** * @author Costin Leau * @author John Blum */ -@SuppressWarnings("unchecked") public class CqCacheServerProcess { - private static final int DEFAULT_CACHE_SERVER_PORT = 40404; + private static final int DEFAULT_CACHE_SERVER_PORT = CacheServer.DEFAULT_PORT; private static Region testCqRegion; @@ -45,7 +42,6 @@ public class CqCacheServerProcess { private static final String GEMFIRE_LOG_LEVEL = "error"; private static final String GEMFIRE_NAME = "CqServer"; - @SuppressWarnings("deprecation") public static void main(final String[] args) throws Exception { waitForShutdown(registerShutdownHook(startCacheServer(addRegion( newGemFireCache(GEMFIRE_NAME, GEMFIRE_LOG_LEVEL), "test-cq")))); @@ -60,9 +56,8 @@ public class CqCacheServerProcess { } private static Cache addRegion(Cache gemfireCache, String name) { - RegionFactory regionFactory = gemfireCache.createRegionFactory(RegionShortcut.REPLICATE); - regionFactory.setScope(Scope.DISTRIBUTED_ACK); + RegionFactory regionFactory = gemfireCache.createRegionFactory(RegionShortcut.REPLICATE); testCqRegion = regionFactory.create(name); @@ -70,9 +65,12 @@ public class CqCacheServerProcess { } private static Cache startCacheServer(Cache gemfireCache) throws IOException { + CacheServer cacheServer = gemfireCache.addCacheServer(); + cacheServer.setPort(getCacheServerPort(DEFAULT_CACHE_SERVER_PORT)); cacheServer.start(); + return gemfireCache; } @@ -81,21 +79,15 @@ public class CqCacheServerProcess { } private static Cache registerShutdownHook(Cache gemfireCache) { - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - if (gemfireCache != null) { - try { - gemfireCache.close(); - } - catch (CacheClosedException ignore) { - } - } - })); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> SpringUtils.safeDoOperation(() -> gemfireCache.close()))); return gemfireCache; } - @SuppressWarnings("deprecation") + @SuppressWarnings({ "deprecation", "unused" }) private static void waitForShutdown(Cache gemfireCache) throws IOException { + ForkUtil.createControlFile(CqCacheServerProcess.class.getName()); Scanner scanner = new Scanner(System.in); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests.java index 75088295..99663725 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests.java @@ -35,10 +35,17 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** + * Integration Tests for SDG Annotation-driver Apache Geode {@link Function} configuration. + * * @author David Turanski * @author John Blum * @see org.junit.Test + * @see org.apache.geode.cache.execute.Function + * @see org.apache.geode.cache.execute.FunctionService + * @see org.springframework.data.gemfire.function.annotation.GemfireFunction * @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 diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java index 531fefc1..47e24a45 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java @@ -18,6 +18,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.apache.geode.cache.Region; +import org.apache.geode.cache.execute.Function; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -33,11 +34,15 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; /** + * Integration Tests for the execution of Apache Geode {@link Function Functions} + * using SDG's {@link Function} execution annotation support. + * * @author David Turanski * @author John Blum */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = TestConfig.class, initializers = GemFireMockObjectsApplicationContextInitializer.class) +@ContextConfiguration(classes = FunctionExecutionIntegrationTests.TestConfiguration.class, + initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") public class FunctionExecutionIntegrationTests extends IntegrationTestsSupport { @@ -60,9 +65,11 @@ public class FunctionExecutionIntegrationTests extends IntegrationTestsSupport { assertThat(TestUtils.>readField("region", template)).isSameAs(regionOne); } + + @Configuration + @EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.two") + @ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests-context.xml") + static class TestConfiguration { } + } -@Configuration -@EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.two") -@ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests-context.xml") -class TestConfig { } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java index 0a808f95..8485f8ab 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/FunctionExecutionIntegrationTests.java @@ -65,7 +65,7 @@ public class FunctionExecutionIntegrationTests extends ForkingClientServerIntegr .set("name", FunctionExecutionIntegrationTests.class.getSimpleName()) .set("log-level", "error") .setPoolSubscriptionEnabled(true) - .addPoolServer("localhost", Integer.getInteger(GEMFIRE_POOL_SERVERS_PROPERTY)) + .addPoolServer("localhost", Integer.getInteger(GEMFIRE_CACHE_SERVER_PORT_PROPERTY)) .create(); assertThat(this.gemfireCache).isNotNull(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java index 30e34405..948dbb2f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/execution/GemfireFunctionTemplateIntegrationTests.java @@ -64,7 +64,7 @@ public class GemfireFunctionTemplateIntegrationTests extends ForkingClientServer .set("name", GemfireFunctionTemplateIntegrationTests.class.getSimpleName()) .set("log-level", "error") .setPoolSubscriptionEnabled(true) - .addPoolServer("localhost", Integer.getInteger(GEMFIRE_POOL_SERVERS_PROPERTY)) + .addPoolServer("localhost", Integer.getInteger(GEMFIRE_CACHE_SERVER_PORT_PROPERTY)) .create(); assertThat(this.gemfireCache).isNotNull(); @@ -88,7 +88,7 @@ public class GemfireFunctionTemplateIntegrationTests extends ForkingClientServer } @Test - public void testFunctionTemplates() { + public void functionTemplatesAreCorrect() { verifyFunctionTemplateExecution(new GemfireOnRegionFunctionTemplate(gemfireRegion)); verifyFunctionTemplateExecution(new GemfireOnServerFunctionTemplate(gemfireCache)); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTests.java index ba4e771f..048564de 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/FunctionResultTypeIntegrationTests.java @@ -15,7 +15,6 @@ package org.springframework.data.gemfire.function.result; import static org.assertj.core.api.Assertions.assertThat; import java.math.BigDecimal; -import java.util.Collections; import java.util.List; import org.junit.Test; @@ -27,9 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; -import org.springframework.data.gemfire.function.annotation.FunctionId; -import org.springframework.data.gemfire.function.annotation.GemfireFunction; -import org.springframework.data.gemfire.function.annotation.OnRegion; import org.springframework.data.gemfire.function.config.EnableGemfireFunctionExecutions; import org.springframework.data.gemfire.function.config.EnableGemfireFunctions; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; @@ -53,12 +49,12 @@ import org.springframework.test.context.junit4.SpringRunner; * @see org.springframework.test.context.junit4.SpringRunner */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = FunctionResultTypeIntegrationTests.TestGeodeConfiguration.class) +@ContextConfiguration(classes = FunctionResultTypeIntegrationTests.TestConfiguration.class) @SuppressWarnings("unused") public class FunctionResultTypeIntegrationTests extends IntegrationTestsSupport { @Autowired - private FunctionExecutions functionExecutions; + private MixedResultTypeFunctionExecutions functionExecutions; @Test public void singleResultFunctionsExecuteCorrectly() { @@ -79,12 +75,12 @@ public class FunctionResultTypeIntegrationTests extends IntegrationTestsSupport } @PeerCacheApplication(name = "FunctionResultTypeIntegrationTests") - @EnableGemfireFunctionExecutions(basePackageClasses = FunctionExecutions.class) + @EnableGemfireFunctionExecutions(basePackageClasses = MixedResultTypeFunctionExecutions.class) @EnableGemfireFunctions - public static class TestGeodeConfiguration { + public static class TestConfiguration { @Bean("Numbers") - protected ReplicatedRegionFactoryBean numbersRegion(GemFireCache gemFireCache) { + ReplicatedRegionFactoryBean numbersRegion(GemFireCache gemFireCache) { ReplicatedRegionFactoryBean numbersRegion = new ReplicatedRegionFactoryBean<>(); @@ -94,33 +90,9 @@ public class FunctionResultTypeIntegrationTests extends IntegrationTestsSupport return numbersRegion; } - @GemfireFunction(id = "returnSingleObject", hasResult = true) - public BigDecimal returnSingleObject() { - return new BigDecimal(5); - } - - @GemfireFunction(id = "returnList", hasResult = true) - public List returnList() { - return Collections.singletonList(new BigDecimal(10)); - } - - @GemfireFunction(id = "returnPrimitive", hasResult = true) - public int returnPrimitive() { - return 7; + @Bean + MixedResultTypeFunctions functions() { + return new MixedResultTypeFunctions(); } } } - -@OnRegion(region = "Numbers") -interface FunctionExecutions { - - @FunctionId("returnSingleObject") - BigDecimal returnFive(); - - @FunctionId("returnList") - List returnList(); - - @FunctionId("returnPrimitive") - int returnPrimitive(); - -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/MixedResultTypeFunctionExecutions.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/MixedResultTypeFunctionExecutions.java new file mode 100644 index 00000000..18fcc166 --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/MixedResultTypeFunctionExecutions.java @@ -0,0 +1,47 @@ +/* + * Copyright 2020 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.function.result; + +import java.math.BigDecimal; +import java.util.List; + +import org.apache.geode.cache.execute.Function; + +import org.springframework.data.gemfire.function.annotation.FunctionId; +import org.springframework.data.gemfire.function.annotation.OnRegion; + +/** + * The MixedResultTypeFunctionExecutions class declares various Apache Geode {@link Function Functions} + * * using SDG's {@link Function} implementation annotation support. + * + * @author John Blum + * @see org.springframework.data.gemfire.function.annotation.FunctionId + * @see org.springframework.data.gemfire.function.annotation.OnRegion + * @since 2.6.0 + */ +@OnRegion(region = "Numbers") +interface MixedResultTypeFunctionExecutions { + + @FunctionId("returnSingleObject") + BigDecimal returnFive(); + + @FunctionId("returnList") + List returnList(); + + @FunctionId("returnPrimitive") + int returnPrimitive(); + +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/MixedResultTypeFunctions.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/MixedResultTypeFunctions.java new file mode 100644 index 00000000..787b84a0 --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/function/result/MixedResultTypeFunctions.java @@ -0,0 +1,55 @@ +/* + * Copyright 2020 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.function.result; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; + +import org.apache.geode.cache.execute.Function; + +import org.springframework.data.gemfire.function.annotation.GemfireFunction; +import org.springframework.stereotype.Component; + +/** + * The {@link MixedResultTypeFunctions} class defines (implements) various Apache Geode {@link Function Functions} + * using SDG's {@link Function} implementation annotation support. + * + * @author John Blum + * @since 2.6.0 + * @see org.apache.geode.cache.execute.Function + * @see org.springframework.data.gemfire.function.annotation.GemfireFunction + * @see org.springframework.stereotype.Component + */ +@Component +@SuppressWarnings("unused") +public class MixedResultTypeFunctions { + + @GemfireFunction(id = "returnSingleObject", hasResult = true) + public BigDecimal returnSingleObject() { + return new BigDecimal(5); + } + + @GemfireFunction(id = "returnList", hasResult = true) + public List returnList() { + return Collections.singletonList(new BigDecimal(10)); + } + + @GemfireFunction(id = "returnPrimitive", hasResult = true) + public int returnPrimitive() { + return 7; + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java index bbe0b4c9..2f947022 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/ListenerContainerIntegrationTests.java @@ -35,6 +35,7 @@ import org.apache.geode.cache.query.CqEvent; import org.springframework.data.gemfire.fork.CqCacheServerProcess; import org.springframework.data.gemfire.listener.adapter.ContinuousQueryListenerAdapter; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +import org.springframework.data.gemfire.tests.process.ProcessWrapper; import org.springframework.data.gemfire.util.SpringUtils; /** @@ -67,9 +68,9 @@ public class ListenerContainerIntegrationTests extends ForkingClientServerIntegr gemfireCache = new ClientCacheFactory() .set("name", "ListenerContainerIntegrationTests") - .set("log-level", "warning") + .set("log-level", "error") .setPoolSubscriptionEnabled(true) - .addPoolServer(DEFAULT_HOSTNAME, Integer.getInteger(GEMFIRE_POOL_SERVERS_PROPERTY)) + .addPoolServer(DEFAULT_HOSTNAME, Integer.getInteger(GEMFIRE_CACHE_SERVER_PORT_PROPERTY)) .create(); String query = "SELECT * from /test-cq"; @@ -92,6 +93,8 @@ public class ListenerContainerIntegrationTests extends ForkingClientServerIntegr @Test public void testContainer() { + getGemFireServerProcess().ifPresent(ProcessWrapper::signal); + waitOn(() -> this.cqEvents.size() == 3, TimeUnit.SECONDS.toMillis(5)); assertThat(this.cqEvents.size()).isEqualTo(3); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests.java index 1eda587e..a70efb92 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests.java @@ -17,7 +17,6 @@ package org.springframework.data.gemfire.listener.adapter; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,9 +26,8 @@ import org.apache.geode.cache.query.CqQuery; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.fork.CqCacheServerProcess; import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer; -import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; +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; @@ -41,10 +39,11 @@ import org.springframework.test.context.junit4.SpringRunner; * @author John Blum * @see org.junit.Test * @see org.apache.geode.cache.client.ClientCache + * @see org.apache.geode.cache.client.Pool * @see org.apache.geode.cache.query.CqQuery * @see org.springframework.data.gemfire.fork.CqCacheServerProcess * @see org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer - * @see org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport + * @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 @@ -52,12 +51,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class ContainerXmlConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { - - @BeforeClass - public static void startGemFireServer() throws Exception { - startGemFireServer(CqCacheServerProcess.class); - } +public class ContainerXmlConfigurationIntegrationTests extends IntegrationTestsSupport { @Autowired private ApplicationContext applicationContext; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/mapping/GemfirePersistentEntityUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/mapping/GemfirePersistentEntityUnitTests.java index c5443d28..bff9a3ea 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/mapping/GemfirePersistentEntityUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/mapping/GemfirePersistentEntityUnitTests.java @@ -147,7 +147,7 @@ public class GemfirePersistentEntityUnitTests { assertThat(identifierAccessor.getIdentifier()).isEqualTo(1L); } - @Test + @Test(expected = MappingException.class) public void identifierForAmbiguousIdAnnotatedFieldAndIdAnnotatedPropertyEntityThrowsMappingException() { AmbiguousIdAnnotatedFieldAndIdAnnotatedPropertyEntity entity = diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBeanUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBeanUnitTests.java index 01eb9967..4fe82183 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBeanUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBeanUnitTests.java @@ -58,7 +58,7 @@ public class GemfireRepositoryFactoryBeanUnitTests { } catch (IllegalStateException expected) { - assertThat(expected).hasMessage("GemfireMappingContext"); + assertThat(expected).hasMessage("GemfireMappingContext must not be null"); throw expected; } 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 b54eb454..4681fb87 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 @@ -18,7 +18,6 @@ package org.springframework.data.gemfire.repository.support; import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; -import java.util.Collections; import javax.annotation.Resource; @@ -32,21 +31,16 @@ import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; 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.Profile; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.config.annotation.CacheServerApplication; import org.springframework.data.gemfire.config.annotation.ClientCacheApplication; -import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer; import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; import org.springframework.data.gemfire.config.annotation.EnablePdx; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; -import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.data.repository.CrudRepository; import org.springframework.test.context.ContextConfiguration; @@ -81,7 +75,7 @@ public class SimpleGemfireRepositoryRegionDeleteAllIntegrationTests extends Fork @BeforeClass public static void startGeodeServer() throws Exception { - startGemFireServer(GeodeServerTestConfiguration.class); + startGemFireServer(GeodeServerTestConfiguration.class, "-Dspring.profiles.active=partition"); } @Resource(name = "Users") @@ -130,31 +124,13 @@ public class SimpleGemfireRepositoryRegionDeleteAllIntegrationTests extends Fork @EnablePdx @EnableEntityDefinedRegions(basePackageClasses = User.class) @EnableGemfireRepositories(basePackageClasses = UserRepository.class) - static class GeodeClientTestConfiguration { - - @Bean - static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } - - @Bean - ClientCacheConfigurer clientCachePoolPortConfigurer( - @Value("${" + GEMFIRE_CACHE_SERVER_PORT_PROPERTY + ":40404}") int port) { - - return (bean, clientCacheFactoryBean) -> clientCacheFactoryBean.setServers( - Collections.singletonList(new ConnectionEndpoint("localhost", port))); - } - } + static class GeodeClientTestConfiguration { } @CacheServerApplication static class GeodeServerTestConfiguration { public static void main(String[] args) { - - AnnotationConfigApplicationContext applicationContext = - new AnnotationConfigApplicationContext(GeodeServerTestConfiguration.class); - - applicationContext.registerShutdownHook(); + runSpringApplication(GeodeServerTestConfiguration.class); } @Bean("Users") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTests.java similarity index 92% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTests.java index d67cca6d..9bfbb871 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTests.java @@ -33,6 +33,7 @@ import org.apache.geode.cache.Region; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.GemfireTemplate; +import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.mapping.GemfireMappingContext; import org.springframework.data.gemfire.mapping.GemfirePersistentEntity; import org.springframework.data.gemfire.repository.GemfireRepository; @@ -62,11 +63,11 @@ import org.springframework.transaction.support.TransactionTemplate; @RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") -public class SimpleGemfireRepositoryTransactionalIntegrationTest extends IntegrationTestsSupport { +public class SimpleGemfireRepositoryTransactionalIntegrationTests extends IntegrationTestsSupport { // TODO add additional test cases for SimpleGemfireRepository (Region operations) in the presence of Transactions!!! - static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); + private static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); @Autowired private CustomerService customerService; @@ -74,7 +75,7 @@ public class SimpleGemfireRepositoryTransactionalIntegrationTest extends Integra @Resource(name = "Customers") private Region customers; - static Customer createCustomer(String firstName, String lastName) { + private static Customer createCustomer(String firstName, String lastName) { Customer customer = new SerializableCustomer(firstName, lastName); @@ -86,10 +87,12 @@ public class SimpleGemfireRepositoryTransactionalIntegrationTest extends Integra @Before public void setup() { - assertThat(this.customers).as("The 'Customers' Cache Region was not properly configured and initialized!") + assertThat(this.customers) + .describedAs("The 'Customers' Cache Region was not properly configured and initialized!") .isNotNull(); + assertThat(this.customers.getName()).isEqualTo("Customers"); - assertThat(this.customers.getFullPath()).isEqualTo("/Customers"); + assertThat(this.customers.getFullPath()).isEqualTo(GemfireUtils.toRegionPath("Customers")); assertThat(this.customers.isEmpty()).isTrue(); } @@ -99,7 +102,8 @@ public class SimpleGemfireRepositoryTransactionalIntegrationTest extends Integra } @Test - public void testDeleteAll() { + public void deleteAllIsCorrect() { + Collection expectedCustomers = new ArrayList<>(4); expectedCustomers.add(createCustomer("Jon", "Doe")); @@ -129,8 +133,7 @@ public class SimpleGemfireRepositoryTransactionalIntegrationTest extends Integra public static class SerializableCustomer extends Customer implements Serializable { - public SerializableCustomer() { - } + public SerializableCustomer() { } public SerializableCustomer(final Long id) { super(id); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/search/lucene/LuceneAccessorUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/search/lucene/LuceneAccessorUnitTests.java index 96bfb053..b6ec42cb 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/search/lucene/LuceneAccessorUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/search/lucene/LuceneAccessorUnitTests.java @@ -45,12 +45,10 @@ import org.springframework.dao.DataRetrievalFailureException; import org.springframework.data.gemfire.search.lucene.support.LuceneAccessorSupport; /** - * Unit tests for {@link LuceneAccessor}. + * Unit Tests for {@link LuceneAccessor}. * * @author John Blum - * @see org.junit.Rule * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.mockito.Mock * @see org.mockito.Mockito * @see org.mockito.Spy @@ -177,6 +175,7 @@ public class LuceneAccessorUnitTests { @Test public void resolveLuceneServiceLooksUpLuceneService() { + doReturn(mockCache).when(luceneAccessor).resolveCache(); doReturn(mockLuceneService).when(luceneAccessor).resolveLuceneService(eq(mockCache)); assertThat(luceneAccessor.getLuceneService()).isNull(); @@ -186,7 +185,7 @@ public class LuceneAccessorUnitTests { verify(luceneAccessor, times(1)).resolveLuceneService(eq(mockCache)); } - @Test + @Test(expected = IllegalArgumentException.class) public void resolveLuceneServiceThrowsIllegalArgumentExceptionWhenCacheIsNull() { try { @@ -226,7 +225,7 @@ public class LuceneAccessorUnitTests { verify(mockLuceneIndex, times(1)).getName(); } - @Test + @Test(expected = IllegalStateException.class) public void resolveIndexNameThrowsIllegalStateExceptionWhenIndexNameIsUnresolvable() { assertThat(luceneAccessor.getIndexName()).isNullOrEmpty(); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java index b76a60a6..05edae6a 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests.java @@ -45,6 +45,7 @@ import org.springframework.data.gemfire.snapshot.event.SnapshotApplicationEvent; import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.data.gemfire.tests.util.ThreadUtils; +import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -52,7 +53,7 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * Integration Tests with test cases testing the effects of the {@link SnapshotServiceFactoryBean} using Spring + * Integration Tests testing the effects of the {@link SnapshotServiceFactoryBean} using Spring * {@link ApplicationEvent ApplicationEvents} to trigger imports and exports of cache {@link Region} data. * * @author John Blum @@ -92,9 +93,10 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext private Region people; @BeforeClass - public static void setupBeforeClass() throws Exception { + public static void setupSnapshotDirectoryAndFiles() throws Exception { - snapshotsDirectory = new File(new File(FileSystemUtils.WORKING_DIRECTORY, "gemfire"), "snapshots"); + snapshotsDirectory = new File(new File(new File(FileSystemUtils.WORKING_DIRECTORY, "gemfire"), + "data"), "snapshots"); assertThat(snapshotsDirectory.isDirectory() || snapshotsDirectory.mkdirs()).isTrue(); @@ -107,10 +109,10 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext @AfterClass public static void tearDownAfterClass() { - //FileSystemUtils.deleteRecursive(snapshotsDirectory.getParentFile()); + //FileSystemUtils.deleteRecursive(snapshotsDirectory.getParentFile().getParentFile()); } - protected void assertPeople(Region targetRegion, Person... people) { + private void assertPeople(Region targetRegion, Person... people) { assertThat(targetRegion.size()).isEqualTo(people.length); @@ -118,32 +120,34 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext .forEach(person -> assertPerson(person, targetRegion.get(person.getId()))); } - protected void assertPerson(Person expectedPerson, Person actualPerson) { + private void assertPerson(Person expectedPerson, Person actualPerson) { - assertThat(actualPerson).as(String.format("Expected [%1$s]; but was [%2$s]", expectedPerson, actualPerson)) + assertThat(actualPerson) + .describedAs(String.format("Expected [%1$s]; but was [%2$s]", expectedPerson, actualPerson)) .isNotNull(); + assertThat(actualPerson.getId()).isEqualTo(expectedPerson.getId()); assertThat(actualPerson.getFirstname()).isEqualTo(expectedPerson.getFirstname()); assertThat(actualPerson.getLastname()).isEqualTo(expectedPerson.getLastname()); } - protected Person newPerson(String firstName, String lastName) { + private Person newPerson(String firstName, String lastName) { return new Person(ID_SEQUENCE.incrementAndGet(), firstName, lastName); } - protected Person put(Region targetRegion, Person person) { + private Person put(Region targetRegion, Person person) { targetRegion.putIfAbsent(person.getId(), person); return person; } - protected void wait(int seconds, int expectedDoeSize, int expectedEveryoneSize, int expectedHandySize) { + private void wait(int seconds, int expectedDoeSize, int expectedEveryoneSize, int expectedHandySize) { ThreadUtils.timedWait(TimeUnit.SECONDS.toMillis(seconds), 500, - () -> doe.size() < expectedDoeSize - || everyoneElse.size() < expectedEveryoneSize - || handy.size() < expectedHandySize); + () -> doe.size() == expectedDoeSize + || everyoneElse.size() == expectedEveryoneSize + || handy.size() == expectedHandySize); } @Test @@ -161,7 +165,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext eventPublisher.publishEvent(event); - wait(5, 2, 2, 1); + wait(15, 2, 2, 1); assertPeople(doe, jonDoe, janeDoe); assertPeople(everyoneElse, jackBlack, joeDirt); @@ -177,7 +181,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext eventPublisher.publishEvent(event); - wait(5, 5, 4, 3); + wait(15, 5, 4, 3); assertPeople(doe, jonDoe, janeDoe, cookieDoe, pieDoe, sourDoe); assertPeople(everyoneElse, jackBlack, joeDirt, jackHill, jillHill); @@ -197,18 +201,18 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext assertPeople(handy, jackHandy, randyHandy, sandyHandy, mandyHandy); } - protected static class LastNameSnapshotFilter implements SnapshotFilter { + static class LastNameSnapshotFilter implements SnapshotFilter { private final String lastName; - public LastNameSnapshotFilter(String lastName) { - Assert.hasText(lastName, "'lastName' must be specified"); + LastNameSnapshotFilter(String lastName) { + Assert.hasText(lastName, "lastName must be specified"); this.lastName = lastName; } protected String getLastName() { - Assert.state(StringUtils.hasText(lastName), "'lastName' was not properly initialized"); - return lastName; + Assert.state(StringUtils.hasText(this.lastName), "lastName was not properly initialized"); + return this.lastName; } @Override @@ -221,9 +225,9 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext } } - protected static class NotLastNameSnapshotFilter extends LastNameSnapshotFilter { + static class NotLastNameSnapshotFilter extends LastNameSnapshotFilter { - public NotLastNameSnapshotFilter(String lastName) { + NotLastNameSnapshotFilter(String lastName) { super(lastName); } @@ -233,7 +237,7 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext } } - protected static class SnapshotImportsMonitor { + public static class SnapshotImportsMonitor { @Autowired private ApplicationEventPublisher eventPublisher; @@ -246,7 +250,10 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext boolean triggerEvent = false; - for (File snapshotFile : nullSafeArray(snapshotsDirectory.listFiles(FileSystemUtils.FileOnlyFilter.INSTANCE))) { + File[] snapshotFiles = ArrayUtils.nullSafeArray(snapshotsDirectory + .listFiles(FileSystemUtils.FileOnlyFilter.INSTANCE), File.class); + + for (File snapshotFile : snapshotFiles) { triggerEvent |= isUnprocessedSnapshotFile(snapshotFile); } @@ -255,20 +262,16 @@ public class SnapshotApplicationEventTriggeredImportsExportsIntegrationTests ext } } - protected File[] nullSafeArray(File... files) { - return (files != null ? files : new File[0]); - } - - protected boolean isUnprocessedSnapshotFile(File snapshotFile) { + private boolean isUnprocessedSnapshotFile(File snapshotFile) { Long lastModified = snapshotFile.lastModified(); Long previousLastModified = snapshotFileLastModifiedMap.get(snapshotFile); - previousLastModified = (previousLastModified != null ? previousLastModified : lastModified); + previousLastModified = previousLastModified != null ? previousLastModified : lastModified; snapshotFileLastModifiedMap.put(snapshotFile, lastModified); - return !previousLastModified.equals(lastModified); + return previousLastModified < lastModified; } } } 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 4a33ac38..2af0e469 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 @@ -264,7 +264,7 @@ public class ConnectionEndpointUnitTests { } catch (IllegalArgumentException expected) { - assertThat(expected).hasMessage("'hostPort' must be specified"); + assertThat(expected).hasMessage("Host & Port [ ] must be specified"); assertThat(expected).hasNoCause(); throw expected; @@ -279,7 +279,7 @@ public class ConnectionEndpointUnitTests { } catch (IllegalArgumentException expected) { - assertThat(expected).hasMessage("'hostPort' must be specified"); + assertThat(expected).hasMessage("Host & Port [] must be specified"); assertThat(expected).hasNoCause(); throw expected; @@ -294,7 +294,7 @@ public class ConnectionEndpointUnitTests { } catch (IllegalArgumentException expected) { - assertThat(expected).hasMessage("'hostPort' must be specified"); + assertThat(expected).hasMessage("Host & Port [null] must be specified"); assertThat(expected).hasNoCause(); throw expected; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DeclarableSupportUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DeclarableSupportUnitTests.java index a3684dbe..e1aa7ec8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DeclarableSupportUnitTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/DeclarableSupportUnitTests.java @@ -100,7 +100,7 @@ public class DeclarableSupportUnitTests { assertThat(testDeclarableSupport.locateBeanFactory()).isSameAs(mockBeanFactoryOne); } - @Test + @Test(expected = IllegalArgumentException.class) public void locateBeanFactoryWithUnknownKeyHavingMultipleBeanFactoriesRegisteredThrowsIllegalArgumentException() { GemfireBeanFactoryLocator.BEAN_FACTORIES.put("keyOne", mockBeanFactoryOne); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationIntegrationTests.java new file mode 100644 index 00000000..771ee4fb --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationIntegrationTests.java @@ -0,0 +1,107 @@ +/* + * Copyright 2012-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.support; + +import static org.assertj.core.api.Assertions.fail; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.GemFireCheckedException; +import org.apache.geode.cache.query.FunctionDomainException; +import org.apache.geode.cache.query.QueryException; +import org.apache.geode.cache.query.QueryInvocationTargetException; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.data.gemfire.GemfireQueryException; +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.data.gemfire.util.SpringUtils; +import org.springframework.stereotype.Repository; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Tests Spring Data for Apache Geode checked persistence {@link Exception Exceptions} translation. + * + * @author David Turanski + * @author John Blum + * @see org.junit.Test + * @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + */ +@RunWith(SpringRunner.class) +@ContextConfiguration +@SuppressWarnings("unused") +public class GemfirePersistenceExceptionTranslationIntegrationTests extends IntegrationTestsSupport { + + @Autowired + private ApplicationContext applicationContext; + + @Autowired + private TestGemFireRepository gemfireRepository; + + @SuppressWarnings("all") + private void handleExceptionThrowingCall(SpringUtils.VoidReturningThrowableOperation operation) { + + try { + operation.run(); + fail("Should have thrown a QueryException"); + } + catch (GemfireQueryException ignore) { } + catch (Throwable cause) { + fail("Should have thrown a QueryException", cause); + } + } + + @Test + public void exceptionTranslationIsSuccessful() { + + handleExceptionThrowingCall(() -> this.gemfireRepository.doIt(new QueryException())); + handleExceptionThrowingCall(() -> this.gemfireRepository.doIt(new FunctionDomainException("test"))); + handleExceptionThrowingCall(() -> this.gemfireRepository.doIt(new QueryInvocationTargetException("test"))); + } + + @ClientCacheApplication + @EnableGemFireMockObjects + static class TestConfiguration { + + @Bean + PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationProcessor() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + @Bean + TestGemFireRepository gemFireRepository() { + return new TestGemFireRepository(); + } + } + + /** + * Wraps {@link GemFireCheckedException} in {@link RuntimeException}. + */ + @Repository + public static class TestGemFireRepository { + public void doIt(Exception cause) { + throw new RuntimeException(cause); + } + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationTest.java deleted file mode 100644 index 881ab00a..00000000 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012-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.support; - -import static org.assertj.core.api.Assertions.fail; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.apache.geode.cache.query.FunctionDomainException; -import org.apache.geode.cache.query.QueryException; -import org.apache.geode.cache.query.QueryInvocationTargetException; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.GemfireQueryException; -import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; -import org.springframework.stereotype.Repository; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@ContextConfiguration -@SuppressWarnings("unused") -public class GemfirePersistenceExceptionTranslationTest extends IntegrationTestsSupport { - - @Autowired - private ApplicationContext applicationContext; - - @Autowired - private GemFireRepo1 gemfireRepo1; - - @Test - public void test() { - - applicationContext.getBeansOfType(BeanPostProcessor.class); - - try { - gemfireRepo1.doit(new QueryException()); - fail("should throw a query exception"); - } - catch (GemfireQueryException ignore){ } - - try { - gemfireRepo1.doit(new FunctionDomainException("test")); - fail("should throw a query exception"); - } - catch (GemfireQueryException ignore) { } - - try { - gemfireRepo1.doit(new QueryInvocationTargetException("test")); - fail("should throw a query exception"); - } - catch (GemfireQueryException ignore) { } - } - - /** - * Wraps GemfireCheckedExceptions in RuntimeException - */ - @Repository - public static class GemFireRepo1 { - public void doit(Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java index eac88362..5e2e674e 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java @@ -97,6 +97,7 @@ public class WiringDeclarableSupportIntegrationTests extends IntegrationTestsSup } @Getter + @Setter @NoArgsConstructor @SuppressWarnings("unused") public static class TestCacheLoader extends WiringDeclarableSupport implements CacheLoader { diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java index 4543ea2a..5607c942 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import java.io.IOException; -import java.util.Scanner; import javax.annotation.Resource; @@ -65,7 +64,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @since 2.2.0 */ @RunWith(SpringRunner.class) -@ContextConfiguration +@ContextConfiguration(locations = "AsyncEventQueueByIdXmlConfigurationIntegrationTests-context.xml") @SuppressWarnings("unused") public class AsyncEventQueueByIdXmlConfigurationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { @@ -106,14 +105,13 @@ public class AsyncEventQueueByIdXmlConfigurationIntegrationTests extends Forking } @EnableLocator - @PeerCacheApplication + @PeerCacheApplication(name = "AsyncEventQueueByIdXmlConfigurationIntegrationTestsServer") static class GeodeServerConfiguration { public static void main(String[] args) { runSpringApplication(GeodeServerConfiguration.class, args); - - new Scanner(System.in).nextLine(); + block(); } @Bean("TestAsyncEventQueueOne") diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewayReceiverManualStartIntegrationTests.java similarity index 90% rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTests.java rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewayReceiverManualStartIntegrationTests.java index 845c8250..94decc10 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewayReceiverManualStartIntegrationTests.java @@ -48,7 +48,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration(initializers = GemFireMockObjectsApplicationContextInitializer.class) @SuppressWarnings("unused") -public class ManualGatewayReceiverStartIntegrationTests extends IntegrationTestsSupport { +public class GatewayReceiverManualStartIntegrationTests extends IntegrationTestsSupport { @Resource(name = "Auto") private GatewayReceiver autoGatewayReceiver; @@ -63,7 +63,7 @@ public class ManualGatewayReceiverStartIntegrationTests extends IntegrationTests } @Test - public void testAutoGatewayReceiver() { + public void autoGatewayReceiverConfigurationIsCorrect() { assertThat(autoGatewayReceiver) .describedAs("The 'Auto' GatewayReceiver was not properly configured or initialized!") @@ -76,7 +76,7 @@ public class ManualGatewayReceiverStartIntegrationTests extends IntegrationTests int gatewayReceiverPort = autoGatewayReceiver.getPort(); assertGreaterThanEqualToLessThanEqualTo(String.format( - "GatewayReceiver 'port' (%1$d) was not greater than equal to (%2$d) and less than equal to (%3$d)!", + "GatewayReceiver 'port' [%1$d] was not greater than equal to [%2$d] and less than equal to [%3$d]!", gatewayReceiverPort, autoGatewayReceiver.getStartPort(), autoGatewayReceiver.getEndPort()), gatewayReceiverPort, autoGatewayReceiver.getStartPort(), autoGatewayReceiver.getEndPort()); @@ -86,7 +86,7 @@ public class ManualGatewayReceiverStartIntegrationTests extends IntegrationTests } @Test - public void testManualGatewayReceiverConfiguration() throws IOException { + public void manualGatewayReceiverConfigurationIsCorrect() throws IOException { assertThat(manualGatewayReceiver) .describedAs("The 'Manual' GatewayReceiver was not properly configured or initialized!") @@ -103,7 +103,7 @@ public class ManualGatewayReceiverStartIntegrationTests extends IntegrationTests int gatewayReceiverPort = manualGatewayReceiver.getPort(); assertGreaterThanEqualToLessThanEqualTo(String.format( - "GatewayReceiver 'port' (%1$d) was not greater than equal to (%2$d) and less than equal to (%3$d)!", + "GatewayReceiver 'port' [%1$d] was not greater than equal to [%2$d] and less than equal to [%3$d]!", gatewayReceiverPort, manualGatewayReceiver.getStartPort(), manualGatewayReceiver.getEndPort()), gatewayReceiverPort, manualGatewayReceiver.getStartPort(), manualGatewayReceiver.getEndPort()); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java index 596f8739..29e70325 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests.java @@ -18,7 +18,6 @@ package org.springframework.data.gemfire.wan; import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; -import java.util.Scanner; import javax.annotation.Resource; @@ -76,7 +75,7 @@ public class GatewaySenderByIdXmlConfigurationIntegrationTests extends ForkingCl System.setProperty("spring.data.gemfire.locator.port", String.valueOf(port)); - geodeServer = run(GeodeServerConfiguration.class, "-Dspring.data.gemfire.locator.port=" + port); + geodeServer = run(GeodeServerApplication.class, "-Dspring.data.gemfire.locator.port=" + port); waitForServerToStart("localhost", port); } @@ -104,14 +103,13 @@ public class GatewaySenderByIdXmlConfigurationIntegrationTests extends ForkingCl } @EnableLocator - @PeerCacheApplication - static class GeodeServerConfiguration { + @PeerCacheApplication(name = "GatewaySenderByIdXmlConfigurationIntegrationTestsServer") + static class GeodeServerApplication { public static void main(String[] args) { - runSpringApplication(GeodeServerConfiguration.class, args); - - new Scanner(System.in).nextLine(); + runSpringApplication(GeodeServerApplication.class, args); + block(); } @Bean("TestGatewaySenderOne") diff --git a/spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTest-context.xml b/spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTest-context.xml rename to spring-data-geode/src/test/resources/SpringServerLauncherCacheProviderIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/region-datapolicy-shortcuts.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/RegionDataPolicyShortcutsIntegrationTests-context.xml similarity index 70% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/region-datapolicy-shortcuts.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/RegionDataPolicyShortcutsIntegrationTests-context.xml index 0ec3f17b..f077cc2c 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/region-datapolicy-shortcuts.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/RegionDataPolicyShortcutsIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - springGemFireRegionDataPolicyShortcutsIntegrationTest + RegionDataPolicyShortcutsIntegrationTests error @@ -26,14 +26,14 @@ + cloning-enabled="false" concurrency-checks-enabled="true" disk-synchronous="false" + ignore-jta="true" initial-capacity="101" load-factor="0.85f" key-constraint="java.lang.Long" + multicast-enabled="false" total-buckets="177" value-constraint="java.lang.String"/> + cloning-enabled="true" concurrency-checks-enabled="false" copies="3" disk-synchronous="true" + ignore-jta="false" initial-capacity="51" load-factor="0.72f" key-constraint="java.lang.String" + multicast-enabled="false" total-buckets="111" value-constraint="java.lang.Object"> diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests-context.xml index 9692adf2..76f3eba4 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/AsyncEventQueueNamespaceIntegrationTests-context.xml @@ -12,10 +12,8 @@ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd "> - - - AsyncEventQueueNamespaceTest + AsyncEventQueueNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests-context.xml index 632445da..b76426ab 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheNamespaceIntegrationTests-context.xml @@ -9,8 +9,6 @@ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd" default-lazy-init="true"> - - false error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/server-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheServerNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/server-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/CacheServerNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceIntegrationTests-context.xml similarity index 96% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceIntegrationTests-context.xml index f5081197..6ea76bc9 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceIntegrationTests-context.xml @@ -16,6 +16,7 @@ + ContinuousQueryListenerContainerNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/index-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests-context.xml similarity index 96% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/index-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests-context.xml index 2367f056..238cbf1e 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/index-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/IndexNamespaceIntegrationTests-context.xml @@ -21,7 +21,7 @@ - IndexNamespaceTest + IndexNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests-context.xml similarity index 94% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests-context.xml index 875a40bd..8671af6e 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceIntegrationTests-context.xml @@ -11,7 +11,7 @@ "> - InvalidRegionExpirationAttributesNamespaceTest + InvalidRegionExpirationAttributesNamespaceIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/local-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests-context.xml similarity index 97% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/local-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests-context.xml index 79004061..95e602bf 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/local-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceIntegrationTests-context.xml @@ -11,7 +11,7 @@ " default-lazy-init="true"> - LocalNamespaceConfig + LocalRegionNamespaceIntegrationTests error 64m diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests-context.xml index d82a73f4..eeae7197 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/LuceneNamespaceUnitTests-context.xml @@ -15,7 +15,7 @@ error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests-context.xml similarity index 87% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests-context.xml index ca527f6c..bf37a310 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/MembershipAttributesIntegrationTests-context.xml @@ -10,15 +10,14 @@ " default-lazy-init="true"> - MembershipAttributesNamespaceConfig + MembershipAttributesIntegrationTests error - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests-context.xml similarity index 97% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests-context.xml index 5e2f6aa0..40dbe15c 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceIntegrationTests-context.xml @@ -34,9 +34,9 @@ NOTE GemFire will switch the Region's DataPolicy when Entry Expiration Action settings are "LOCAL_[DESTROY|INVALIDATE]" based or the Eviction Action is "LOCAL_[DESTROY|INVALIDATE]". --> - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/replicated-ns.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/replicated-ns.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceIntegrationTests-context.xml similarity index 100% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceIntegrationTests-context.xml diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests-context.xml similarity index 96% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests-context.xml index 418cc959..1ebb1899 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceIntegrationTests-context.xml @@ -11,7 +11,7 @@ "> - TemplateRegionsNamespaceTest + TemplateRegionsNamespaceIntegrationTests error @@ -46,10 +46,8 @@ - - - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-listeners-and-writers.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TransactionEventHandlersIntegrationTests-context.xml similarity index 85% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-listeners-and-writers.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TransactionEventHandlersIntegrationTests-context.xml index dd70fddc..18ad16ee 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/tx-listeners-and-writers.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/TransactionEventHandlersIntegrationTests-context.xml @@ -26,8 +26,8 @@ - - - + + + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/support/PoolAlreadyExistsIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/support/PoolAlreadyExistsIntegrationTests-context.xml index e1db7cef..f6050db6 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/support/PoolAlreadyExistsIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/config/xml/support/PoolAlreadyExistsIntegrationTests-context.xml @@ -1,20 +1,17 @@ - - - ${gemfire.log-level:error} + PoolAlreadyExistsIntegrationTests + error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests-context.xml index 0bef8e05..83f79f9d 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/function/config/AnnotationDrivenFunctionsIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> + resource-pattern="**/AnnotationDrivenFunctionsIntegrationTests*.class"/> diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests-context.xml index d823b598..42d9d6cb 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/listener/adapter/ContainerXmlConfigurationIntegrationTests-context.xml @@ -16,7 +16,7 @@ - ContainerXmlSetupIntegrationTests + ContainerXmlConfigurationIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTests-context.xml similarity index 87% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTests-context.xml index 300fda8c..974a1ecb 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTests-context.xml @@ -13,20 +13,20 @@ "> - SimpleGemfireRepositoryTransactionalTest + SimpleGemfireRepositoryTransactionalIntegrationTests error - - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests-context.xml similarity index 80% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests-context.xml index 6a4a3d9b..2284e826 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/snapshot/SnapshotApplicationEventTriggeredImportsExportsIntegrationTests-context.xml @@ -17,7 +17,7 @@ "> - SnapshotApplicationEventTriggeredImportsExportsIntegrationTest + SnapshotApplicationEventTriggeredImportsExportsIntegrationTests error @@ -41,33 +41,31 @@ - + - - + - - + + - + - + diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationTest-context.xml deleted file mode 100644 index c5e63c25..00000000 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/support/GemfirePersistenceExceptionTranslationTest-context.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - GemfirePersistenceExceptionTranslation - error - - - - - - - - - diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests-context.xml index 8b2f52a3..8a670d7a 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/AsyncEventQueueByIdXmlConfigurationIntegrationTests-context.xml @@ -14,7 +14,7 @@ - AsyncEventQueueXmlConfigurationByIdIntegrationTests + AsyncEventQueueByIdXmlConfigurationIntegrationTests error localhost[${spring.data.gemfire.locator.port}] 1 diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTest-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/GatewayReceiverManualStartIntegrationTests-context.xml similarity index 93% rename from spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTest-context.xml rename to spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/GatewayReceiverManualStartIntegrationTests-context.xml index ab22b37d..8706074b 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/ManualGatewayReceiverStartIntegrationTest-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/GatewayReceiverManualStartIntegrationTests-context.xml @@ -10,7 +10,7 @@ "> - ManualGatewayReceiverStartIntegrationTest + GatewayReceiverManualStartIntegrationTests error diff --git a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests-context.xml b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests-context.xml index aff081a4..cf1bb6fc 100644 --- a/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests-context.xml +++ b/spring-data-geode/src/test/resources/org/springframework/data/gemfire/wan/GatewaySenderByIdXmlConfigurationIntegrationTests-context.xml @@ -14,7 +14,7 @@ - GatewaySenderXmlConfigurationByIdIntegrationTests + GatewaySenderByIdXmlConfigurationIntegrationTests error localhost[${spring.data.gemfire.locator.port}] 1