diff --git a/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java b/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java index f2ae594c..a346dad8 100644 --- a/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java @@ -25,7 +25,7 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.gemfire.util.CollectionUtils; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -43,7 +43,7 @@ import com.gemstone.gemfire.cache.query.QueryService; /** * Spring FactoryBean for easy declarative creation of GemFire Indexes. - * + * * @author Costin Leau * @author David Turanski * @author John Blum @@ -267,7 +267,7 @@ public class IndexFactoryBean implements InitializingBean, FactoryBean, B /** * Sets the underlying cache used for creating indexes. - * + * * @param cache cache used for creating indexes. */ public void setCache(RegionService cache) { @@ -276,7 +276,7 @@ public class IndexFactoryBean implements InitializingBean, FactoryBean, B /** * Sets the query service used for creating indexes. - * + * * @param service query service used for creating indexes. */ public void setQueryService(QueryService service) { diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java index 971bd5e7..1660c487 100644 --- a/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/ClientCacheFactoryBean.java @@ -38,7 +38,7 @@ import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.client.support.DefaultableDelegatingPoolAdapter; import org.springframework.data.gemfire.client.support.DelegatingPoolAdapter; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpointList; import org.springframework.data.gemfire.util.SpringUtils; diff --git a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java index c856a0ee..edc3f8bf 100644 --- a/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/ClientRegionFactoryBean.java @@ -26,7 +26,7 @@ import org.springframework.core.io.Resource; import org.springframework.data.gemfire.DataPolicyConverter; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.RegionLookupFactoryBean; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -371,7 +371,7 @@ public class ClientRegionFactoryBean extends RegionLookupFactoryBean /** * Set the interests for this client region. Both key and regex interest are * supported. - * + * * @param interests the interests to set */ public void setInterests(Interest[] interests) { diff --git a/src/main/java/org/springframework/data/gemfire/config/AnnotationDrivenBeanDefinitionParser.java b/src/main/java/org/springframework/data/gemfire/config/AnnotationDrivenBeanDefinitionParser.java deleted file mode 100644 index edd4012b..00000000 --- a/src/main/java/org/springframework/data/gemfire/config/AnnotationDrivenBeanDefinitionParser.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2002-2013 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.config; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.beans.factory.xml.BeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.data.gemfire.function.config.GemfireFunctionBeanPostProcessor; -import org.w3c.dom.Element; - -/** - * @author David Turanski - * - */ -public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { - - /* (non-Javadoc) - * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext) - */ - @Override - public BeanDefinition parse(Element element, ParserContext parserContext) { - registerGemfireFunctionBeanPostProcessor(element, parserContext); - return null; - } - - /** - * - */ - private void registerGemfireFunctionBeanPostProcessor(Element element, ParserContext parserContext) { - Object source = parserContext.extractSource(element); - RootBeanDefinition beanDefinition = new RootBeanDefinition(GemfireFunctionBeanPostProcessor.class); - beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); - beanDefinition.setSource(source); - BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, parserContext.getRegistry()); - } - -} diff --git a/src/main/java/org/springframework/data/gemfire/config/CreateDefinedIndexesApplicationListener.java b/src/main/java/org/springframework/data/gemfire/config/CreateDefinedIndexesApplicationListener.java deleted file mode 100644 index d8c2eb89..00000000 --- a/src/main/java/org/springframework/data/gemfire/config/CreateDefinedIndexesApplicationListener.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextRefreshedEvent; - -import com.gemstone.gemfire.cache.query.QueryService; - -/** - * The CreateDefinedIndexesApplicationListener class is a Spring ApplicationListener used to create - * all the GemFire Cache Region Indexes "defined" using the QueryService.defineXXXX(..) methods. - * - * @author John Blum - * @see org.springframework.context.ApplicationListener - * @see org.springframework.context.event.ContextRefreshedEvent - * @see com.gemstone.gemfire.cache.query.QueryService - * @since 1.7.0 - */ -public class CreateDefinedIndexesApplicationListener implements ApplicationListener { - - protected final Log logger = initLogger(); - - /** - * Attempts to create all defined Indexes using the QueryService, defineXXXX(..) API once - * the Spring ApplicationContext has been refreshed. - * - * @param event the ContextRefreshedEvent fired when the Spring ApplicationContext gets refreshed. - * @see #getCache(org.springframework.context.event.ContextRefreshedEvent) - * @see org.springframework.context.event.ContextRefreshedEvent - * @see com.gemstone.gemfire.cache.Cache#getQueryService() - * @see com.gemstone.gemfire.cache.client.ClientCache#getLocalQueryService() - * @see com.gemstone.gemfire.cache.query.QueryService#createDefinedIndexes() - */ - @Override - public void onApplicationEvent(final ContextRefreshedEvent event) { - try { - QueryService localQueryService = getQueryService(event); - - if (localQueryService != null) { - localQueryService.createDefinedIndexes(); - } - } - catch (Exception ignore) { - logger.warn(String.format("unable to create defined Indexes (if any): %1$s", ignore.getMessage())); - } - } - - /* (non-Javadoc) */ - Log initLogger() { - return LogFactory.getLog(getClass()); - } - - /* (non-Javadoc) */ - private QueryService getQueryService(final ContextRefreshedEvent event) { - ApplicationContext localApplicationContext = event.getApplicationContext(); - - return (localApplicationContext.containsBean(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE) ? - localApplicationContext.getBean(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE, - QueryService.class) : null); - } - -} diff --git a/src/main/java/org/springframework/data/gemfire/config/DiskWriteAttributesFactoryBean.java b/src/main/java/org/springframework/data/gemfire/config/DiskWriteAttributesFactoryBean.java deleted file mode 100644 index 0470be76..00000000 --- a/src/main/java/org/springframework/data/gemfire/config/DiskWriteAttributesFactoryBean.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config; - -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; - -/** - * Simple utility class used for defining nested factory-method like definitions - * w/o polluting the container with useless beans. - * - * @author Costin Leau - * @deprecated - */ -@Deprecated -@SuppressWarnings({ "deprecation", "unused" }) -class DiskWriteAttributesFactoryBean implements FactoryBean, InitializingBean { - - private com.gemstone.gemfire.cache.DiskWriteAttributes attributes; - - private com.gemstone.gemfire.cache.DiskWriteAttributesFactory attrFactory; - - @Override - public void afterPropertiesSet() { - attributes = attrFactory.create(); - } - - @Override - public com.gemstone.gemfire.cache.DiskWriteAttributes getObject() throws Exception { - return attributes; - } - - @Override - public Class getObjectType() { - return (attributes != null ? attributes.getClass() : com.gemstone.gemfire.cache.DiskWriteAttributes.class); - } - - @Override - public boolean isSingleton() { - return true; - } - - public void setDiskAttributesFactory(com.gemstone.gemfire.cache.DiskWriteAttributesFactory dwaf) { - this.attrFactory = dwaf; - } - -} diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/AddCacheServerConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/AddCacheServerConfiguration.java index 6b6b58bf..3508017e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/AddCacheServerConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/AddCacheServerConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.gemfire.server.CacheServerFactoryBean; /** diff --git a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessor.java similarity index 63% rename from src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanPostProcessor.java rename to src/main/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessor.java index 7865a4cc..fd1ab0e0 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanPostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessor.java @@ -14,11 +14,14 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; import java.util.Collections; import java.util.Set; +import com.gemstone.gemfire.cache.GemFireCache; +import com.gemstone.gemfire.cache.Region; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -27,20 +30,17 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; -import com.gemstone.gemfire.cache.GemFireCache; -import com.gemstone.gemfire.cache.Region; - /** - * The AutoRegionLookupBeanPostProcessor class is a Spring BeanPostProcessor that post processes a GemFireCache by - * registering all Cache Regions that have not been explicitly defined in the Spring application context. This is - * usually the case for Regions that have been defined in GemFire's native cache.xml or defined use GemFire 8's new - * cluster-based configuration service. + * The AutoRegionLookupBeanPostProcessor class is a Spring {@link BeanPostProcessor} that post processes + * a {@link GemFireCache} by registering all cache {@link Region Regions} that have not been explicitly + * defined in the Spring application context. This is usually the case for {@link Region Regions} that + * have been defined in GemFire's native {@literal cache.xml} or defined using GemFire 8's cluster-based + * configuration service. * * @author John Blum * @see org.springframework.beans.factory.BeanFactory * @see org.springframework.beans.factory.BeanFactoryAware * @see org.springframework.beans.factory.config.BeanPostProcessor - * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory * @see com.gemstone.gemfire.cache.GemFireCache * @see com.gemstone.gemfire.cache.Region * @since 1.5.0 @@ -49,26 +49,37 @@ public class AutoRegionLookupBeanPostProcessor implements BeanPostProcessor, Bea private ConfigurableListableBeanFactory beanFactory; + /** + * {@inheritDoc} + */ @Override - public final void setBeanFactory(final BeanFactory beanFactory) throws BeansException { + public final void setBeanFactory(BeanFactory beanFactory) throws BeansException { Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory, - String.format("The BeanFactory reference (%1$s) must be an instance of ConfigurableListableBeanFactory!", - ObjectUtils.nullSafeClassName(beanFactory))); + String.format("BeanFactory [%1$s] must be an instance of %2$s", + ObjectUtils.nullSafeClassName(beanFactory), ConfigurableListableBeanFactory.class.getSimpleName())); + this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; } + /* (non-Javadoc) */ protected ConfigurableListableBeanFactory getBeanFactory() { - Assert.state(this.beanFactory != null, "A reference to the BeanFactory was not properly configured and initialized!"); + Assert.state(this.beanFactory != null, "BeanFactory was not properly initialized"); return this.beanFactory; } + /** + * {@inheritDoc} + */ @Override - public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } + /** + * {@inheritDoc} + */ @Override - public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof GemFireCache) { registerCacheRegionsAsBeans((GemFireCache) bean); } @@ -76,13 +87,15 @@ public class AutoRegionLookupBeanPostProcessor implements BeanPostProcessor, Bea return bean; } - private void registerCacheRegionsAsBeans(final GemFireCache cache) { + /* (non-Javadoc) */ + void registerCacheRegionsAsBeans(GemFireCache cache) { for (Region region : cache.rootRegions()) { - registerRegionAsBean(region); + registerCacheRegionAsBean(region); } } - private void registerRegionAsBean(final Region region) { + /* (non-Javadoc) */ + void registerCacheRegionAsBean(Region region) { if (region != null) { String regionBeanName = getBeanName(region); @@ -91,19 +104,20 @@ public class AutoRegionLookupBeanPostProcessor implements BeanPostProcessor, Bea } for (Region subregion : nullSafeSubregions(region)) { - registerRegionAsBean(subregion); + registerCacheRegionAsBean(subregion); } } } - private Set> nullSafeSubregions(final Region parentRegion) { - Set> subregions = parentRegion.subregions(false); - return (subregions != null ? subregions : Collections.>emptySet()); - } - - private String getBeanName(final Region region) { + /* (non-Javadoc) */ + String getBeanName(Region region) { String regionFullPath = region.getFullPath(); return (regionFullPath.lastIndexOf(Region.SEPARATOR) > 0 ? regionFullPath : region.getName()); } + /* (non-Javadoc) */ + Set> nullSafeSubregions(Region parentRegion) { + Set> subregions = parentRegion.subregions(false); + return (subregions != null ? subregions : Collections.>emptySet()); + } } diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientRegionAndPoolBeanFactoryPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/support/ClientRegionPoolBeanFactoryPostProcessor.java similarity index 71% rename from src/main/java/org/springframework/data/gemfire/config/ClientRegionAndPoolBeanFactoryPostProcessor.java rename to src/main/java/org/springframework/data/gemfire/config/support/ClientRegionPoolBeanFactoryPostProcessor.java index ad6ed407..498c0469 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientRegionAndPoolBeanFactoryPostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/config/support/ClientRegionPoolBeanFactoryPostProcessor.java @@ -15,12 +15,9 @@ * */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Set; import org.springframework.beans.BeansException; @@ -30,22 +27,26 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.PoolFactoryBean; +import org.springframework.data.gemfire.util.SpringUtils; /** - * The ClientRegionAndPoolBeanFactoryPostProcessor class is a Spring {@link BeanFactoryPostProcessor} that ensures - * a proper dependency is declared between a GemFire client Region and the GemFire Pool it references and uses, if - * the GemFire Pool has been defined and configured in Spring (Data GemFire) configuration meta-data (XML). + * {@link ClientRegionPoolBeanFactoryPostProcessor} is a Spring {@link BeanFactoryPostProcessor} implementation + * ensuring a proper dependency is declared between a GemFire client {@link com.gemstone.gemfire.cache.Region} + * and the GemFire client {@link com.gemstone.gemfire.cache.client.Pool} it references and uses, providing + * the GemFire client {@link com.gemstone.gemfire.cache.client.Pool} has been defined and configured with + * Spring (Data GemFire) configuration meta-data (e.g. XML). * * @author John Blum * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor - * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory * @since 1.8.2 */ -public class ClientRegionAndPoolBeanFactoryPostProcessor implements BeanFactoryPostProcessor { +public class ClientRegionPoolBeanFactoryPostProcessor implements BeanFactoryPostProcessor { protected static final String POOL_NAME_PROPERTY = "poolName"; - /* (non-Javadoc)*/ + /** + * {@inheritDoc} + */ @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Set clientRegionBeanNames = new HashSet(); @@ -67,7 +68,7 @@ public class ClientRegionAndPoolBeanFactoryPostProcessor implements BeanFactoryP String poolName = getPoolName(clientRegionBean); if (poolBeanNames.contains(poolName)) { - addDependsOn(clientRegionBean, poolName); + SpringUtils.addDependsOn(clientRegionBean, poolName); } } } @@ -87,19 +88,4 @@ public class ClientRegionAndPoolBeanFactoryPostProcessor implements BeanFactoryP PropertyValue poolNameProperty = clientRegionBean.getPropertyValues().getPropertyValue(POOL_NAME_PROPERTY); return (poolNameProperty != null ? String.valueOf(poolNameProperty.getValue()) : null); } - - /* (non-Javadoc) */ - BeanDefinition addDependsOn(BeanDefinition bean, String beanName) { - String[] dependsOn = bean.getDependsOn(); - List dependsOnList = new ArrayList(); - - if (dependsOn != null) { - Collections.addAll(dependsOnList, dependsOn); - } - - dependsOnList.add(beanName); - bean.setDependsOn(dependsOnList.toArray(new String[dependsOnList.size()])); - - return bean; - } } diff --git a/src/main/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessor.java similarity index 73% rename from src/main/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessor.java rename to src/main/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessor.java index 553abaa4..2cff128c 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessor.java @@ -14,10 +14,17 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; import java.beans.PropertyEditorSupport; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.ExpirationAction; +import com.gemstone.gemfire.cache.InterestPolicy; +import com.gemstone.gemfire.cache.InterestResultPolicy; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.wan.GatewaySender; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -35,35 +42,32 @@ import org.springframework.data.gemfire.ScopeConverter; import org.springframework.data.gemfire.client.InterestResultPolicyConverter; import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy; import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter; +import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpointList; import org.springframework.data.gemfire.wan.OrderPolicyConverter; -import com.gemstone.gemfire.cache.EvictionAction; -import com.gemstone.gemfire.cache.ExpirationAction; -import com.gemstone.gemfire.cache.InterestPolicy; -import com.gemstone.gemfire.cache.InterestResultPolicy; -import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.cache.wan.GatewaySender; - /** - * The CustomEditorRegisteringBeanFactoryPostProcessor class is a Spring {@link BeanFactoryPostProcessor} used - * to register custom GemFire-specific JavaBeans {@link java.beans.PropertyEditor}s and Spring {@link Converter}s + * {@link CustomEditorBeanFactoryPostProcessor} is a Spring {@link BeanFactoryPostProcessor} implementation + * used to register custom {@link java.beans.PropertyEditor PropertyEditors} / Spring {@link Converter Converters} * that are used to perform type conversions between String-based configuration meta-data and actual GemFire - * or Spring Data GemFire defined enumerated types. + * or Spring Data GemFire defined (enumerated) types. * * @author John Blum * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor - * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory * @since 1.6.0 */ @SuppressWarnings({ "deprecation", "unused" }) -class CustomEditorRegisteringBeanFactoryPostProcessor implements BeanFactoryPostProcessor { +public class CustomEditorBeanFactoryPostProcessor implements BeanFactoryPostProcessor { - /* (non-Javadoc) */ + /** + * {@inheritDoc} + */ @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); @@ -80,10 +84,39 @@ class CustomEditorRegisteringBeanFactoryPostProcessor implements BeanFactoryPost public static class ConnectionEndpointArrayToIterableConverter extends PropertyEditorSupport implements Converter { + /** + * {@inheritDoc} + */ @Override public Iterable convert(ConnectionEndpoint[] source) { return ConnectionEndpointList.from(source); } } + /* (non-Javadoc) */ + public static class StringToConnectionEndpointConverter + extends AbstractPropertyEditorConverterSupport { + + /** + * {@inheritDoc} + */ + @Override + public ConnectionEndpoint convert(String source) { + return assertConverted(source, ConnectionEndpoint.parse(source), ConnectionEndpoint.class); + } + } + + /* (non-Javadoc) */ + public static class StringToConnectionEndpointListConverter + extends AbstractPropertyEditorConverterSupport { + + /** + * {@inheritDoc} + */ + @Override + public ConnectionEndpointList convert(String source) { + return assertConverted(source, ConnectionEndpointList.parse(0, source.split(",")), + ConnectionEndpointList.class); + } + } } diff --git a/src/main/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListener.java b/src/main/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListener.java new file mode 100644 index 00000000..6732aad9 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListener.java @@ -0,0 +1,87 @@ +/* + * Copyright 2010-2013 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.gemfire.config.support; + +import com.gemstone.gemfire.cache.query.MultiIndexCreationException; +import com.gemstone.gemfire.cache.query.QueryService; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.data.gemfire.config.xml.GemfireConstants; + +/** + * {@link DefinedIndexesApplicationListener} is a Spring {@link ApplicationListener} used to create all + * "defined" GemFire {@link com.gemstone.gemfire.cache.query.Index Indexes} by using the {@link QueryService}, + * {@literal defineXxxIndex(..)} methods. + * + * @author John Blum + * @see org.springframework.context.ApplicationContext + * @see org.springframework.context.ApplicationListener + * @see org.springframework.context.event.ContextRefreshedEvent + * @see com.gemstone.gemfire.cache.query.QueryService + * @since 1.7.0 + */ +public class DefinedIndexesApplicationListener implements ApplicationListener { + + protected final Log logger = initLogger(); + + /** + * Attempts to create all defined {@link com.gemstone.gemfire.cache.query.Index Indexes} using + * the {@link QueryService}, {@literal defineXxxIndex(..)} API once the Spring {@link ApplicationContext} + * has been refreshed. + * + * @param event {@link ContextRefreshedEvent} fired when the Spring {@link ApplicationContext} gets refreshed. + * @see org.springframework.context.event.ContextRefreshedEvent + * @see com.gemstone.gemfire.cache.query.QueryService#createDefinedIndexes() + * @see #getQueryService(ContextRefreshedEvent) + */ + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + try { + QueryService queryService = getQueryService(event); + + if (queryService != null) { + queryService.createDefinedIndexes(); + } + } + catch (MultiIndexCreationException ignore) { + logger.warn(String.format("Failed to create pre-defined Indexes: %s", ignore.getMessage()), ignore); + } + } + + /* (non-Javadoc) */ + Log initLogger() { + return LogFactory.getLog(getClass()); + } + + /* (non-Javadoc) */ + private QueryService getQueryService(ContextRefreshedEvent event) { + ApplicationContext applicationContext = event.getApplicationContext(); + String queryServiceBeanName = getQueryServiceBeanName(); + + return (applicationContext.containsBean(queryServiceBeanName) ? + applicationContext.getBean(queryServiceBeanName, QueryService.class) : null); + } + + /* (non-Javadoc) */ + private String getQueryServiceBeanName() { + return GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE; + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/support/DiskStoreBeanPostProcessor.java similarity index 62% rename from src/main/java/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessor.java rename to src/main/java/org/springframework/data/gemfire/config/support/DiskStoreBeanPostProcessor.java index 55d4acca..f46c1b1e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/config/support/DiskStoreBeanPostProcessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; import java.io.File; import java.lang.reflect.Field; @@ -28,13 +28,13 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - * The DiskStoreBeanPostProcessor class post processes any GemFire Disk Store DiskDir Spring beans defined - * in the application context to ensure that the Disk Store directory location (disk-dir) actually exists - * before creating the Disk Store. + * The {@link DiskStoreBeanPostProcessor} processes any GemFire {@link com.gemstone.gemfire.cache.DiskStore}, + * {@link DiskDir} Spring beans defined in the application context to ensure that the directory actually exists + * before creating the {@link com.gemstone.gemfire.cache.DiskStore}. * * @author John Blum * @see org.springframework.beans.factory.config.BeanPostProcessor - * @see org.springframework.data.gemfire.DiskStoreFactoryBean.DiskDir + * @see com.gemstone.gemfire.cache.DiskStore * @since 1.5.0 */ @SuppressWarnings("unused") @@ -42,11 +42,14 @@ public class DiskStoreBeanPostProcessor implements BeanPostProcessor { protected final Log log = LogFactory.getLog(getClass()); + /** + * {@inheritDoc} + */ @Override - public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (log.isDebugEnabled()) { - log.debug(String.format("Post Processing Bean (%1$s) of Type (%2$s) with Name (%3$s)...%n", bean, - ObjectUtils.nullSafeClassName(bean), beanName)); + log.debug(String.format("Processing Bean [%1$s] of Type [%2$s] with Name [%3$s] before initialization%n", + bean, ObjectUtils.nullSafeClassName(bean), beanName)); } if (bean instanceof DiskDir) { @@ -56,33 +59,43 @@ public class DiskStoreBeanPostProcessor implements BeanPostProcessor { return bean; } - private void createIfNotExists(final DiskDir diskDirectory) { + /** + * {@inheritDoc} + */ + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + /* (non-Javadoc) */ + private void createIfNotExists(DiskDir diskDirectory) { String location = readField(diskDirectory, "location"); File diskDirectoryFile = new File(location); Assert.isTrue(diskDirectoryFile.isDirectory() || diskDirectoryFile.mkdirs(), - String.format("Failed to create Disk Directory (%1$s)%n!", location)); + String.format("Failed to create Disk Directory [%s]%n", location)); if (log.isInfoEnabled()) { - log.info(String.format("The Disk Directory either exists or was created @ Location (%1$s).%n", location)); + log.info(String.format("Disk Directory is @ Location [%s].%n", location)); } } + /* (non-Javadoc) */ @SuppressWarnings("unchecked") - private T readField(final Object obj, final String fieldName) { + private T readField(Object obj, String fieldName) { try { Class type = obj.getClass(); Field field; do { field = type.getDeclaredField(fieldName); - type = type.getSuperclass(); // traverse up the object class hierarchy + type = type.getSuperclass(); } while (field == null && !Object.class.equals(type)); if (field == null) { - throw new NoSuchFieldException(String.format("Field (%1$s) does not exist on Object of type (%2$s)!", + throw new NoSuchFieldException(String.format("No field with name [%1$s] found on object of type [%2$s]", fieldName, ObjectUtils.nullSafeClassName(obj))); } @@ -91,14 +104,8 @@ public class DiskStoreBeanPostProcessor implements BeanPostProcessor { return (T) field.get(obj); } catch (Exception e) { - throw new RuntimeException(String.format("Failed to read field (%1$s) on Object of type (%2$s)!", + throw new RuntimeException(String.format("Failed to read field [%1$s] from object of type [%2$s]", fieldName, ObjectUtils.nullSafeClassName(obj)), e); } } - - @Override - public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { - return bean; - } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/PdxDiskStoreAwareBeanFactoryPostProcessor.java b/src/main/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessor.java similarity index 76% rename from src/main/java/org/springframework/data/gemfire/config/PdxDiskStoreAwareBeanFactoryPostProcessor.java rename to src/main/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessor.java index 7943cb36..7622bbc3 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PdxDiskStoreAwareBeanFactoryPostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessor.java @@ -14,23 +14,25 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; + +import com.gemstone.gemfire.cache.DiskStore; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.data.gemfire.util.ArrayUtils; +import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import com.gemstone.gemfire.cache.DiskStore; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; /** - * The PdxDiskStoreAwareBeanFactoryPostProcessor class is a BeanFactoryPostProcessor that modifies all Async Event Queue, - * Region and Disk Store beans in the Spring container to form a dependency on the Cache's PDX Disk Store bean. + * {@link PdxDiskStoreAwareBeanFactoryPostProcessor} is a Spring {@link BeanFactoryPostProcessor} that modifies + * all GemFire Async Event Queue, Region and Disk Store beans in the Spring container to form a dependency on + * the Cache's PDX {@link DiskStore} bean. + * * A persistent Region may contain PDX typed data, in which case, the PDX type meta-data stored to disk needs to be * loaded before the Region having PDX data is loaded from disk. * @@ -48,17 +50,32 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos private final String pdxDiskStoreName; - public PdxDiskStoreAwareBeanFactoryPostProcessor(final String pdxDiskStoreName) { - Assert.isTrue(StringUtils.hasText(pdxDiskStoreName), "The name of the PDX Disk Store must be specified!"); + /** + * Constructs an instance of the {@link PdxDiskStoreAwareBeanFactoryPostProcessor} class initialized with + * the given PDX {@link DiskStore} name. + * + * @param pdxDiskStoreName name of the GemFire PDX {@link DiskStore}. + * @throws IllegalArgumentException if the GemFire PDX {@link DiskStore} name is unspecified. + */ + public PdxDiskStoreAwareBeanFactoryPostProcessor(String pdxDiskStoreName) { + Assert.hasText(pdxDiskStoreName, "The PDX DiskStore name must be specified"); this.pdxDiskStoreName = pdxDiskStoreName; } + /** + * Returns the name of the GemFire PDX {@link DiskStore}. + * + * @return the name of the GemFire PDX {@link DiskStore}. + */ public String getPdxDiskStoreName() { return pdxDiskStoreName; } + /** + * {@inheritDoc} + */ @Override - public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException { + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { postProcessPdxDiskStoreDependencies(beanFactory, AsyncEventQueue.class, DiskStore.class, Region.class); } @@ -72,7 +89,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos * @param beanTypes an array of Class types indicating the type of beans to evaluate. * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getBeanNamesForType(Class) */ - private void postProcessPdxDiskStoreDependencies(final ConfigurableListableBeanFactory beanFactory, + private void postProcessPdxDiskStoreDependencies(ConfigurableListableBeanFactory beanFactory, final Class... beanTypes) { for (Class beanType : beanTypes) { for (String beanName : beanFactory.getBeanNamesForType(beanType)) { @@ -99,7 +116,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos * @see #getDependsOn(org.springframework.beans.factory.config.BeanDefinition) * @see org.springframework.beans.factory.config.BeanDefinition#setDependsOn(String[]) */ - private void addPdxDiskStoreDependency(final BeanDefinition beanDefinition) { + private void addPdxDiskStoreDependency(BeanDefinition beanDefinition) { String[] newDependsOn = (String[]) ArrayUtils.insert(getDependsOn(beanDefinition), 0, getPdxDiskStoreName()); beanDefinition.setDependsOn(newDependsOn); } @@ -114,8 +131,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessor implements BeanFactoryPos * @see #addPdxDiskStoreDependency(org.springframework.beans.factory.config.BeanDefinition) * @see org.springframework.beans.factory.config.BeanDefinition#getDependsOn() */ - private String[] getDependsOn(final BeanDefinition beanDefinition) { - return (beanDefinition.getDependsOn() != null ? beanDefinition.getDependsOn() : EMPTY_STRING_ARRAY); + private String[] getDependsOn(BeanDefinition beanDefinition) { + return SpringUtils.defaultIfNull(beanDefinition.getDependsOn(), EMPTY_STRING_ARRAY); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/AbstractRegionParser.java similarity index 89% rename from src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/AbstractRegionParser.java index 95f95629..b1a24651 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AbstractRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/AbstractRegionParser.java @@ -14,12 +14,15 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; +import com.gemstone.gemfire.cache.wan.GatewaySender; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.PropertyValue; @@ -36,42 +39,53 @@ import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; -import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; -import com.gemstone.gemfire.cache.wan.GatewaySender; - /** - * Abstract base class encapsulating functionality common to all Region Parsers. + * Abstract base class encapsulating functionality common to all Region parsers. * * @author David Turanski * @author John Blum + * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser + * @see org.springframework.data.gemfire.RegionFactoryBean */ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { protected final Log log = LogFactory.getLog(getClass()); + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return getRegionFactoryClass(); } + /* (non-Javadoc) */ protected abstract Class getRegionFactoryClass(); + /** + * {@inheritDoc} + */ @Override - protected String getParentName(final Element element) { + protected String getParentName(Element element) { String regionTemplate = element.getAttribute("template"); return (StringUtils.hasText(regionTemplate) ? regionTemplate : super.getParentName(element)); } - protected boolean isRegionTemplate(final Element element) { + /* (non-Javadoc) */ + protected boolean isRegionTemplate(Element element) { String localName = element.getLocalName(); return (localName != null && localName.endsWith("-template")); } - protected boolean isSubRegion(final Element element) { + /* (non-Javadoc) */ + protected boolean isSubRegion(Element element) { String localName = element.getParentNode().getLocalName(); return (localName != null && localName.endsWith("region")); } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, builder); @@ -79,13 +93,15 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { doParseRegion(element, parserContext, builder, isSubRegion(element)); } - protected abstract void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, - boolean subRegion); + /* (non-Javadoc) */ + protected abstract void doParseRegion(Element element, ParserContext parserContext, + BeanDefinitionBuilder builder, boolean subRegion); - protected void doParseCommonRegionConfiguration(Element element, ParserContext parserContext, + /* (non-Javadoc) */ + protected void doParseRegionConfiguration(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder regionAttributesBuilder, boolean subRegion) { - mergeTemplateRegionAttributes(element, parserContext, regionBuilder, regionAttributesBuilder); + mergeRegionTemplateAttributes(element, parserContext, regionBuilder, regionAttributesBuilder); String resolvedCacheRef = ParsingUtils.resolveCacheReference(element.getAttribute("cache-ref")); @@ -163,7 +179,8 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { } } - void mergeTemplateRegionAttributes(Element element, ParserContext parserContext, + /* (non-Javadoc) */ + void mergeRegionTemplateAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder regionAttributesBuilder) { String regionTemplateName = getParentName(element); @@ -183,13 +200,15 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { 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); + regionTemplateName, resolveId(element, regionBuilder.getRawBeanDefinition(), parserContext)), + element); } } } - BeanDefinition getRegionAttributesBeanDefinition(final BeanDefinition region) { - Assert.notNull(region, "The 'Region' BeanDefinition must not be null!"); + /* (non-Javadoc) */ + BeanDefinition getRegionAttributesBeanDefinition(BeanDefinition region) { + Assert.notNull(region, "BeanDefinition must not be null"); Object regionAttributes = null; @@ -201,10 +220,12 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { return (regionAttributes instanceof BeanDefinition ? (BeanDefinition) regionAttributes : null); } + /* (non-Javadoc) */ protected void parseCollectionOfCustomSubElements(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, String className, String subElementName, String propertyName) { - List subElements = DomUtils.getChildElementsByTagName(element, subElementName, - subElementName + "-ref"); + + List subElements = DomUtils.getChildElementsByTagName( + element, subElementName, subElementName + "-ref"); if (!CollectionUtils.isEmpty(subElements)) { ManagedArray array = new ManagedArray(className, subElements.size()); @@ -217,6 +238,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { } } + /* (non-Javadoc) */ protected void parseSubRegions(Element element, ParserContext parserContext, String resolvedCacheRef) { Map allSubRegionElements = new HashMap(); @@ -229,6 +251,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { } } + /* (non-Javadoc) */ private void findSubRegionElements(Element parent, String parentPath, Map allSubRegionElements) { for (Element element : DomUtils.getChildElements(parent)) { if (element.getLocalName().endsWith("region")) { @@ -240,11 +263,13 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { } } + /* (non-Javadoc) */ private String getRegionNameFromElement(Element element) { String name = element.getAttribute(NAME_ATTRIBUTE); return (StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE)); } + /* (non-Javadoc) */ private String buildSubRegionPath(String parentName, String regionName) { String regionPath = StringUtils.arrayToDelimitedString(new String[] { parentName, regionName }, "/"); if (!regionPath.startsWith("/")) { @@ -253,6 +278,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { return regionPath; } + /* (non-Javadoc) */ private BeanDefinition parseSubRegion(Element element, ParserContext parserContext, String subRegionPath, String cacheRef) { @@ -271,6 +297,7 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { return beanDefinition; } + /* (non-Javadoc) */ private String getParentRegionPathFrom(String regionPath) { int index = regionPath.lastIndexOf("/"); String parentPath = regionPath.substring(0, index); @@ -280,13 +307,12 @@ abstract class AbstractRegionParser extends AbstractSingleBeanDefinitionParser { return parentPath; } - protected void validateDataPolicyShortcutAttributesMutualExclusion(final Element element, - final ParserContext parserContext) { + /* (non-Javadoc) */ + protected void validateDataPolicyShortcutAttributesMutualExclusion(Element element, ParserContext parserContext) { if (element.hasAttribute("data-policy") && element.hasAttribute("shortcut")) { parserContext.getReaderContext().error(String.format( "Only one of [data-policy, shortcut] may be specified with element '%1$s'.", element.getTagName()), element); } } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/xml/AnnotationDrivenParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/AnnotationDrivenParser.java new file mode 100644 index 00000000..b8703f81 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/xml/AnnotationDrivenParser.java @@ -0,0 +1,63 @@ +/* + * Copyright 2002-2013 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package org.springframework.data.gemfire.config.xml; + +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; +import org.springframework.beans.factory.xml.BeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.function.config.GemfireFunctionBeanPostProcessor; +import org.w3c.dom.Element; + +/** + * A Spring {@link BeanDefinitionParser} to enable Spring Data GemFire Function annotation support. + * + * Bean definition parser for the <gfe:annotation-driven> SDG XML namespace (XSD) element. + * + * @author David Turanski + * @author John Blum + * @see org.springframework.beans.factory.xml.BeanDefinitionParser + * @see org.springframework.data.gemfire.function.config.GemfireFunctionBeanPostProcessor + */ +class AnnotationDrivenParser implements BeanDefinitionParser { + + /** + * {@inheritDoc} + */ + @Override + public BeanDefinition parse(Element element, ParserContext parserContext) { + registerGemfireFunctionBeanPostProcessor(element, parserContext); + return null; + } + + /** + * Registers the {@link GemfireFunctionBeanPostProcessor} as a bean with the Spring application context. + * + * @param element {@link Element} being parsed. + * @param parserContext {@link ParserContext} used capture contextual information while parsing. + */ + private void registerGemfireFunctionBeanPostProcessor(Element element, ParserContext parserContext) { + AbstractBeanDefinition gemfireFunctionBeanPostProcessor = BeanDefinitionBuilder + .rootBeanDefinition(GemfireFunctionBeanPostProcessor.class) + .setRole(BeanDefinition.ROLE_INFRASTRUCTURE) + .getBeanDefinition(); + + gemfireFunctionBeanPostProcessor.setSource(parserContext.extractSource(element)); + + BeanDefinitionReaderUtils.registerWithGeneratedName(gemfireFunctionBeanPostProcessor, + parserContext.getRegistry()); + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/AsyncEventQueueParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/AsyncEventQueueParser.java similarity index 90% rename from src/main/java/org/springframework/data/gemfire/config/AsyncEventQueueParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/AsyncEventQueueParser.java index d0a7681b..77b1632e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AsyncEventQueueParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/AsyncEventQueueParser.java @@ -13,33 +13,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.gemfire.config; + +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Bean definition parse for the <gfe:async-event-queue> SDG XML namespace element. + * Bean definition parser for the <gfe:async-event-queue> SDG XML namespace (XSD) element. * * @author David Turanski * @author John Blum * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser - * @see org.springframework.beans.factory.xml.ParserContext * @see org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean */ class AsyncEventQueueParser extends AbstractSingleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return AsyncEventQueueFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { @@ -82,8 +89,8 @@ class AsyncEventQueueParser extends AbstractSingleBeanDefinitionParser { } } + /* (non-Javadoc) */ private void parseAsyncEventListener(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - Element asyncEventListenerElement = DomUtils.getChildElementByTagName(element, "async-event-listener"); Object asyncEventListener = ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext, @@ -96,15 +103,16 @@ class AsyncEventQueueParser extends AbstractSingleBeanDefinitionParser { } } + /* (non-Javadoc) */ private void parseCache(Element element, BeanDefinitionBuilder builder) { String cacheRefAttribute = element.getAttribute("cache-ref"); - - String cacheName = (StringUtils.hasText(cacheRefAttribute) ? cacheRefAttribute - : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME); + String cacheName = SpringUtils.defaultIfEmpty(cacheRefAttribute, + GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME); builder.addConstructorArgReference(cacheName); } + /* (non-Javadoc) */ private void parseDiskStore(Element element, BeanDefinitionBuilder builder) { ParsingUtils.setPropertyValue(element, builder, "disk-store-ref"); diff --git a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanDefinitionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/AutoRegionLookupParser.java similarity index 59% rename from src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanDefinitionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/AutoRegionLookupParser.java index 2f0909ff..ea58154a 100644 --- a/src/main/java/org/springframework/data/gemfire/config/AutoRegionLookupBeanDefinitionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/AutoRegionLookupParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -22,34 +22,37 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.config.support.AutoRegionLookupBeanPostProcessor; import org.w3c.dom.Element; /** - * The AutoRegionLookupBeanDefinitionParser class is a Spring BeanDefinitionParser that registers a BeanPostProcessor - * that auto registers Regions defined in GemFire's native cache.xml format, or when using GemFire 8's cluster-based - * configuration service to define Regions, creating corresponding beans in the Spring context. + * Bean definition parser for the <gfe:auto-region-lookup> SDG XML namespace (XSD) element. + * + * This parser will register a Spring {@link org.springframework.beans.factory.config.BeanPostProcessor) + * that discovers all Regions defined in GemFire's native {@literal cache.xml} file, or when using + * GemFire 8's cluster-based configuration service to define Regions, to create corresponding beans + * in the Spring application context. * * @author John Blum - * @see org.springframework.beans.factory.config.BeanDefinition - * @see org.springframework.beans.factory.support.AbstractBeanDefinition - * @see org.springframework.beans.factory.support.BeanDefinitionBuilder * @see org.springframework.beans.factory.xml.BeanDefinitionParser - * @see org.springframework.beans.factory.xml.ParserContext - * @see org.springframework.data.gemfire.config.AutoRegionLookupBeanPostProcessor - * @see org.w3c.dom.Element + * @see org.springframework.data.gemfire.config.support.AutoRegionLookupBeanPostProcessor * @since 1.5.0 */ -class AutoRegionLookupBeanDefinitionParser implements BeanDefinitionParser { +class AutoRegionLookupParser implements BeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override - public BeanDefinition parse(final Element element, final ParserContext parserContext) { + public BeanDefinition parse(Element element, ParserContext parserContext) { registerAutoRegionLookupBeanPostProcessor(element, parserContext); return null; } - private void registerAutoRegionLookupBeanPostProcessor(final Element element, final ParserContext parserContext) { + /* (non-Javadoc) */ + private void registerAutoRegionLookupBeanPostProcessor(Element element, ParserContext parserContext) { AbstractBeanDefinition autoRegionLookupBeanPostProcessor = BeanDefinitionBuilder - .genericBeanDefinition(AutoRegionLookupBeanPostProcessor.class) + .rootBeanDefinition(AutoRegionLookupBeanPostProcessor.class) .setRole(BeanDefinition.ROLE_INFRASTRUCTURE) .getBeanDefinition(); @@ -58,5 +61,4 @@ class AutoRegionLookupBeanDefinitionParser implements BeanDefinitionParser { BeanDefinitionReaderUtils.registerWithGeneratedName(autoRegionLookupBeanPostProcessor, parserContext.getRegistry()); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/CacheParser.java similarity index 92% rename from src/main/java/org/springframework/data/gemfire/config/CacheParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/CacheParser.java index d21abb95..82b1c363 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/CacheParser.java @@ -14,10 +14,12 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.List; +import com.gemstone.gemfire.internal.datasource.ConfigProperty; + import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -28,7 +30,9 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; 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.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -36,23 +40,29 @@ import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; -import com.gemstone.gemfire.internal.datasource.ConfigProperty; - /** - * Parser for <cache> bean definitions. - * + * Bean definition parser for the <gfe:cache> SDG XML namespace (XSD) element. + * * @author Costin Leau * @author Oliver Gierke * @author David Turanski * @author John Blum + * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser + * @see org.springframework.data.gemfire.CacheFactoryBean */ class CacheParser extends AbstractSingleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return CacheFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, builder); @@ -119,9 +129,10 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { /* (non-Javadoc) */ void registerGemFireBeanFactoryPostProcessors(BeanDefinitionRegistry registry) { BeanDefinitionReaderUtils.registerWithGeneratedName(BeanDefinitionBuilder.genericBeanDefinition( - CustomEditorRegisteringBeanFactoryPostProcessor.class).getBeanDefinition(), registry); + CustomEditorBeanFactoryPostProcessor.class).getBeanDefinition(), registry); } + /* (non-Javadoc) */ private void parsePdxDiskStore(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { ParsingUtils.setPropertyValue(element, builder, "pdx-disk-store", "pdxDiskStoreName"); @@ -138,6 +149,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(pdxDiskStoreName), registry); } + /* (non-Javadoc) */ private AbstractBeanDefinition createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(String pdxDiskStoreName) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( PdxDiskStoreAwareBeanFactoryPostProcessor.class); @@ -145,6 +157,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { return builder.getBeanDefinition(); } + /* (non-Javadoc) */ private void parseDynamicRegionFactory(Element element, BeanDefinitionBuilder builder) { Element dynamicRegionFactory = DomUtils.getChildElementByTagName(element, "dynamic-region-factory"); @@ -155,6 +168,7 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { } } + /* (non-Javadoc) */ private BeanDefinitionBuilder buildDynamicRegionSupport(Element dynamicRegionFactory) { if (dynamicRegionFactory != null) { BeanDefinitionBuilder dynamicRegionSupport = BeanDefinitionBuilder.genericBeanDefinition( @@ -185,11 +199,12 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { } /** - * @param dynamicRegionSupport BDB for <dynamic-region-factory> element. + * @param dynamicRegionSupport {@link BeanDefinitionBuilder} for <gfe:dynamic-region-factory> element. */ protected void postProcessDynamicRegionSupport(Element element, BeanDefinitionBuilder dynamicRegionSupport) { } + /* (non-Javadoc) */ private void parseJndiBindings(Element element, BeanDefinitionBuilder builder) { List jndiBindings = DomUtils.getChildElementsByTagName(element, "jndi-binding"); @@ -240,6 +255,9 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { } } + /** + * {@inheritDoc} + */ @Override protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException { @@ -253,5 +271,4 @@ class CacheParser extends AbstractSingleBeanDefinitionParser { return name; } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java similarity index 83% rename from src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java index 9db99524..73468e40 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/CacheServerParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -22,48 +22,49 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.server.CacheServerFactoryBean; +import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Attr; import org.w3c.dom.Element; /** - * Namespace parser for "cache-server" element. + * Bean definition parser for the <gfe:cache-server< SDG XML namespace (XSD) element. * * @author Costin Leau * @author John Blum - * @see org.springframework.beans.factory.support.AbstractBeanDefinition - * @see org.springframework.beans.factory.support.BeanDefinitionBuilder * @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser * @see org.springframework.data.gemfire.server.CacheServerFactoryBean * @since 1.1.0 */ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return CacheServerFactoryBean.class; } - @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) - throws BeanDefinitionStoreException { - String name = super.resolveId(element, definition, parserContext); - return (StringUtils.hasText(name) ? name : "gemfireServer"); - } - + /** + * {@inheritDoc} + */ @Override protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) { return (super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName()) && !"cache-ref".equals(attribute.getName())); } + /** + * {@inheritDoc} + */ @Override protected void postProcess(BeanDefinitionBuilder builder, Element element) { - String cacheRefAttribute = element.getAttribute("cache-ref"); + String cacheRefAttribute = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME); - builder.addPropertyReference("cache", (StringUtils.hasText(cacheRefAttribute) ? cacheRefAttribute - : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); + builder.addPropertyReference("cache", SpringUtils.defaultIfEmpty( + cacheRefAttribute, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); String groupsAttribute = element.getAttribute("groups"); @@ -74,6 +75,7 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { parseSubscription(element, builder); } + /* (non-Javadoc) */ private void parseSubscription(Element element, BeanDefinitionBuilder builder) { Element subscriptionConfigElement = DomUtils.getChildElementByTagName(element, "subscription-config"); @@ -89,4 +91,14 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser { } } + /** + * {@inheritDoc} + */ + @Override + protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) + throws BeanDefinitionStoreException { + + String name = super.resolveId(element, definition, parserContext); + return (StringUtils.hasText(name) ? name : "gemfireServer"); + } } diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientCacheParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/ClientCacheParser.java similarity index 85% rename from src/main/java/org/springframework/data/gemfire/config/ClientCacheParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/ClientCacheParser.java index b7197e16..0e0a68b3 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientCacheParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/ClientCacheParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; @@ -22,23 +22,32 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean; import org.w3c.dom.Element; /** - * Parser for <client-cache;gt; definitions. - * + * Bean definition parser for the <gfe:client-cache> SDG XML namespace (XSD) element. + * * @author Costin Leau * @author David Turanski * @author Lyndon Adams * @author John Blum + * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean + * @see CacheParser */ class ClientCacheParser extends CacheParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return ClientCacheFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); + ParsingUtils.setPropertyValue(element, builder, "durable-client-id"); ParsingUtils.setPropertyValue(element, builder, "durable-client-timeout"); ParsingUtils.setPropertyValue(element, builder, "keep-alive"); @@ -46,9 +55,11 @@ class ClientCacheParser extends CacheParser { ParsingUtils.setPropertyValue(element, builder, "ready-for-events"); } + /** + * {@inheritDoc} + */ @Override protected void postProcessDynamicRegionSupport(Element element, BeanDefinitionBuilder dynamicRegionSupport) { ParsingUtils.setPropertyValue(element, dynamicRegionSupport, "pool-name"); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/ClientRegionParser.java similarity index 90% rename from src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/ClientRegionParser.java index abdfb7bf..115815bc 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/ClientRegionParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.List; @@ -30,21 +30,29 @@ import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Parser for <client-region;gt; bean definitions. + * Bean definition parser for the <gfe:client-region> SDG XML namespace (XSD) element. * - * To avoid eager evaluations, the region interests are declared as nested definition. + * To avoid eager evaluations, Region interests are declared as nested bean definitions. * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean + * @see AbstractRegionParser */ class ClientRegionParser extends AbstractRegionParser { + /** + * {@inheritDoc} + */ @Override protected Class getRegionFactoryClass() { return ClientRegionFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder, boolean subRegion) { @@ -72,7 +80,7 @@ class ClientRegionParser extends AbstractRegionParser { BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition( RegionAttributesFactoryBean.class); - mergeTemplateRegionAttributes(element, parserContext, regionBuilder, regionAttributesBuilder); + mergeRegionTemplateAttributes(element, parserContext, regionBuilder, regionAttributesBuilder); ParsingUtils.parseOptionalRegionAttributes(parserContext, element, regionAttributesBuilder); ParsingUtils.parseStatistics(element, regionAttributesBuilder); @@ -118,7 +126,8 @@ class ClientRegionParser extends AbstractRegionParser { } } - private void parseDiskStoreAttribute(final Element element, final BeanDefinitionBuilder builder) { + /* (non-Javadoc) */ + private void parseDiskStoreAttribute(Element element, BeanDefinitionBuilder builder) { String diskStoreRefAttribute = element.getAttribute("disk-store-ref"); if (StringUtils.hasText(diskStoreRefAttribute)) { @@ -127,12 +136,14 @@ class ClientRegionParser extends AbstractRegionParser { } } + /* (non-Javadoc) */ private void parseCommonInterestAttributes(Element element, BeanDefinitionBuilder builder) { ParsingUtils.setPropertyValue(element, builder, "durable", "durable"); ParsingUtils.setPropertyValue(element, builder, "result-policy", "policy"); ParsingUtils.setPropertyValue(element, builder, "receive-values", "receiveValues"); } + /* (non-Javadoc) */ private Object parseKeyInterest(Element keyInterestElement, ParserContext parserContext) { BeanDefinitionBuilder keyInterestBuilder = BeanDefinitionBuilder.genericBeanDefinition(Interest.class); @@ -143,6 +154,7 @@ class ClientRegionParser extends AbstractRegionParser { return keyInterestBuilder.getBeanDefinition(); } + /* (non-Javadoc) */ private Object parseRegexInterest(Element regexInterestElement) { BeanDefinitionBuilder regexInterestBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegexInterest.class); @@ -151,5 +163,4 @@ class ClientRegionParser extends AbstractRegionParser { return regexInterestBuilder.getBeanDefinition(); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/DiskStoreParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/DiskStoreParser.java similarity index 85% rename from src/main/java/org/springframework/data/gemfire/config/DiskStoreParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/DiskStoreParser.java index d36fd8eb..ec8abd1d 100644 --- a/src/main/java/org/springframework/data/gemfire/config/DiskStoreParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/DiskStoreParser.java @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.gemfire.config; + +package org.springframework.data.gemfire.config.xml; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -27,29 +28,28 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.DiskStoreFactoryBean; import org.springframework.data.gemfire.DiskStoreFactoryBean.DiskDir; +import org.springframework.data.gemfire.config.support.DiskStoreBeanPostProcessor; import org.springframework.util.CollectionUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Parser for <disk-store> bean definitions. + * Bean definition parser for the <gfe:disk-store> SDG XML namespace (XSD) element. * * @author David Turanski * @author John Blum - * @see org.springframework.beans.factory.support.AbstractBeanDefinition - * @see org.springframework.beans.factory.support.BeanDefinitionBuilder * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser * @see org.springframework.data.gemfire.DiskStoreFactoryBean - * @see org.w3c.dom.Element */ -public class DiskStoreParser extends AbstractSingleBeanDefinitionParser { +class DiskStoreParser extends AbstractSingleBeanDefinitionParser { - private static final AtomicBoolean registered = new AtomicBoolean(false); + private static final AtomicBoolean REGISTERED = new AtomicBoolean(false); - private static void registerDiskStoreBeanPostProcessor(final ParserContext parserContext) { - if (registered.compareAndSet(false, true)) { + /* (non-Javadoc) */ + private static void registerDiskStoreBeanPostProcessor(ParserContext parserContext) { + if (REGISTERED.compareAndSet(false, true)) { AbstractBeanDefinition diskStoreBeanPostProcessor = BeanDefinitionBuilder - .genericBeanDefinition(DiskStoreBeanPostProcessor.class) + .rootBeanDefinition(DiskStoreBeanPostProcessor.class) .setRole(BeanDefinition.ROLE_INFRASTRUCTURE) .getBeanDefinition(); @@ -58,11 +58,17 @@ public class DiskStoreParser extends AbstractSingleBeanDefinitionParser { } } + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return DiskStoreFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); @@ -102,5 +108,4 @@ public class DiskStoreParser extends AbstractSingleBeanDefinitionParser { builder.addPropertyValue("diskDirs", diskDirs); } } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/FunctionServiceParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/FunctionServiceParser.java similarity index 74% rename from src/main/java/org/springframework/data/gemfire/config/FunctionServiceParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/FunctionServiceParser.java index 3b5d05b1..eba319b0 100644 --- a/src/main/java/org/springframework/data/gemfire/config/FunctionServiceParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/FunctionServiceParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -22,26 +22,35 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.FunctionServiceFactoryBean; -import org.springframework.util.StringUtils; +import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Parser for <function-service;gt; definitions. + * Bean definition parser for the <gfe:function-service> SDG XML namespace (XSD) element. * * @author David Turanski * @author John Blum + * @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser + * @see org.springframework.data.gemfire.FunctionServiceFactoryBean */ class FunctionServiceParser extends AbstractSimpleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return FunctionServiceFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, builder); + builder.setLazyInit(false); Element functionElement = DomUtils.getChildElementByTagName(element, "function"); @@ -52,12 +61,15 @@ class FunctionServiceParser extends AbstractSimpleBeanDefinitionParser { } } + /** + * {@inheritDoc} + */ @Override - protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) + protected String resolveId(Element element, AbstractBeanDefinition beanDefinition, ParserContext parserContext) throws BeanDefinitionStoreException { - String resolvedId = super.resolveId(element, definition, parserContext); - return (StringUtils.hasText(resolvedId) ? resolvedId : GemfireConstants.DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME); - } + String resolvedId = super.resolveId(element, beanDefinition, parserContext); + return SpringUtils.defaultIfEmpty(resolvedId, GemfireConstants.DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME); + } } diff --git a/src/main/java/org/springframework/data/gemfire/config/GatewayReceiverParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/GatewayReceiverParser.java similarity index 81% rename from src/main/java/org/springframework/data/gemfire/config/GatewayReceiverParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GatewayReceiverParser.java index a404b9dc..94cde9b4 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GatewayReceiverParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GatewayReceiverParser.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.gemfire.config; + +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; -import org.springframework.util.StringUtils; import org.w3c.dom.Element; /** - * Spring BeanDefinitionParser for the <gfe:gateway-receiver> SDG (GFE) XML XSD namespace element. + * Bean definition parser for the <gfe:gateway-receiver> SDG XML namespace (XSD) element. * * @author David Turanski * @author John Blum @@ -32,17 +33,24 @@ import org.w3c.dom.Element; */ class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return GatewayReceiverFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - String cacheRef = element.getAttribute("cache-ref"); + String cacheRef = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME); + + builder.addConstructorArgReference(SpringUtils.defaultIfEmpty( + cacheRef, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); - builder.addConstructorArgReference((StringUtils.hasText(cacheRef) ? cacheRef - : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); builder.setLazyInit(false); ParsingUtils.setPropertyValue(element, builder, "bind-address"); @@ -54,5 +62,4 @@ class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser { ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size"); ParsingUtils.parseTransportFilters(element, parserContext, builder); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/GatewaySenderParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/GatewaySenderParser.java similarity index 89% rename from src/main/java/org/springframework/data/gemfire/config/GatewaySenderParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GatewaySenderParser.java index 777be593..00f57f01 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GatewaySenderParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GatewaySenderParser.java @@ -13,35 +13,45 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.gemfire.config; + +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Bean definition parser for the <gfe:gateway-sender> element in the SDG XML namespace. + * Bean definition parser for the <gfe:gateway-sender> SDG XML namespace (XSD) element. * * @author David Turanski * @author John Blum * @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser - * @see org.springframework.beans.factory.xml.ParserContext * @see org.springframework.data.gemfire.wan.GatewaySenderFactoryBean */ class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return GatewaySenderFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - parseCache(element, builder); + String cacheRef = element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME); + + builder.addConstructorArgReference(SpringUtils.defaultIfEmpty( + cacheRef, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); ParsingUtils.setPropertyValue(element, builder, NAME_ATTRIBUTE); ParsingUtils.setPropertyValue(element, builder, "alert-threshold"); @@ -97,12 +107,4 @@ class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser { } } } - - private void parseCache(final Element element, final BeanDefinitionBuilder builder) { - String cacheRef = element.getAttribute("cache-ref"); - - builder.addConstructorArgReference((StringUtils.hasText(cacheRef) ? cacheRef - : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); - } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireConstants.java b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireConstants.java similarity index 59% rename from src/main/java/org/springframework/data/gemfire/config/GemfireConstants.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GemfireConstants.java index 6ace0747..1ae29113 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireConstants.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireConstants.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; /** * The GemfireConstants class define constants for Spring GemFire component bean names. @@ -24,13 +24,10 @@ package org.springframework.data.gemfire.config; @SuppressWarnings("unused") public interface GemfireConstants { - static final String DEFAULT_GEMFIRE_CACHE_NAME = "gemfireCache"; - static final String DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE = "gemfireIndexDefinitionQueryService"; - static final String DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME = "gemfireFunctionService"; - static final String DEFAULT_GEMFIRE_POOL_NAME = "gemfirePool"; - static final String DEFAULT_GEMFIRE_TRANSACTION_MANAGER_NAME = "gemfireTransactionManager"; - - @Deprecated - static final String DEFAULT_GEMFIRE_TXMANAGER_NAME = DEFAULT_GEMFIRE_TRANSACTION_MANAGER_NAME; + String DEFAULT_GEMFIRE_CACHE_NAME = "gemfireCache"; + String DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE = "gemfireIndexDefinitionQueryService"; + String DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME = "gemfireFunctionService"; + String DEFAULT_GEMFIRE_POOL_NAME = "gemfirePool"; + String DEFAULT_GEMFIRE_TRANSACTION_MANAGER_NAME = "gemfireTransactionManager"; } diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireDataNamespaceHandler.java similarity index 88% rename from src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GemfireDataNamespaceHandler.java index dea27aa3..03a20a40 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireDataNamespaceHandler.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; import org.springframework.data.gemfire.function.config.FunctionExecutionBeanDefinitionParser; @@ -23,18 +23,22 @@ import org.springframework.data.repository.config.RepositoryBeanDefinitionParser import org.springframework.data.repository.config.RepositoryConfigurationExtension; /** - * Namespace handler for GemFire definitions. - * + * Spring {@link org.springframework.beans.factory.xml.NamespaceHandler} for Spring Data GemFire + * XML namespace (XSD) bean definitions. + * * @author Costin Leau * @author David Turanski * @author Oliver Gierke + * @author John Blum */ @SuppressWarnings("unused") class GemfireDataNamespaceHandler extends NamespaceHandlerSupport { + /** + * {@inheritDoc} + */ @Override public void init() { - // Repository namespace RepositoryConfigurationExtension extension = new GemfireRepositoryConfigurationExtension(); registerBeanDefinitionParser("datasource", new GemfireDataSourceParser()); registerBeanDefinitionParser("function-executions", new FunctionExecutionBeanDefinitionParser()); diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireDataSourceParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireDataSourceParser.java similarity index 88% rename from src/main/java/org/springframework/data/gemfire/config/GemfireDataSourceParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GemfireDataSourceParser.java index 043b87c2..0d482923 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireDataSourceParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireDataSourceParser.java @@ -1,16 +1,17 @@ /* * Copyright 2002-2013 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package org.springframework.data.gemfire.config; + +package org.springframework.data.gemfire.config.xml; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -25,8 +26,14 @@ import org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor; import org.w3c.dom.Element; /** + * Bean definition parser for the <gfe-data:datasource> SDG XML namespace (XSD) element. + * * @author David Turanski * @author John Blum + * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser + * @see org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor + * @see ClientCacheParser + * @see PoolParser */ class GemfireDataSourceParser extends AbstractBeanDefinitionParser { @@ -35,8 +42,8 @@ class GemfireDataSourceParser extends AbstractBeanDefinitionParser { protected final Log log = LogFactory.getLog(getClass()); - /* (non-Javadoc) - * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext) + /** + * {@inheritDoc} */ @Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { @@ -69,5 +76,4 @@ class GemfireDataSourceParser extends AbstractBeanDefinitionParser { return null; } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireListenerContainerParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireListenerContainerParser.java similarity index 83% rename from src/main/java/org/springframework/data/gemfire/config/GemfireListenerContainerParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GemfireListenerContainerParser.java index 71268bfb..80f13bc5 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireListenerContainerParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireListenerContainerParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.List; @@ -31,18 +31,26 @@ import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Parser for SGF <cq-listener-container> element. - * + * Bean definition parser for the <gfe:cq-listener-container> element. + * * @author Costin Leau * @author John Blum + * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser + * @see org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer */ class GemfireListenerContainerParser extends AbstractSingleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return ContinuousQueryListenerContainer.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { ParsingUtils.setPropertyReference(element, builder, "cache", "cache"); @@ -67,10 +75,13 @@ class GemfireListenerContainerParser extends AbstractSingleBeanDefinitionParser } /** - * Parses a listener definition. Returns the listener bean reference definition (of a {@link ContinuousQueryDefinition}). - * - * @param element - * @return + * Parses a listener bean definition. Returns the listener bean definition + * (of type {@link ContinuousQueryDefinition)). + * + * @param element XML DOM {@link Element} to parse. + * @return a Spring {@link BeanDefinition} for the GemFire Continuous Query (CQ) listener configuration. + * @see org.springframework.beans.factory.xml.BeanDefinition + * @see org.w3c.dom.Element */ private BeanDefinition parseListener(Element element) { BeanDefinitionBuilder continuousQueryListenerBuilder = BeanDefinitionBuilder.genericBeanDefinition( @@ -104,5 +115,4 @@ class GemfireListenerContainerParser extends AbstractSingleBeanDefinitionParser return continuousQueryBuilder.getBeanDefinition(); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireNamespaceHandler.java similarity index 83% rename from src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GemfireNamespaceHandler.java index 9625c937..6038b781 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireNamespaceHandler.java @@ -14,16 +14,14 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; -import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; -import org.springframework.beans.factory.xml.ParserContext; -import org.w3c.dom.Element; /** - * Spring NamespaceHandler for GemFire XML namespace (XSD) bean definitions. - * + * Spring {@link org.springframework.beans.factory.xml.NamespaceHandler} for Spring GemFire + * XML namespace (XSD) bean definitions. + * * @author Costin Leau * @author David Turanski * @author John Blum @@ -32,38 +30,31 @@ import org.w3c.dom.Element; @SuppressWarnings("unused") class GemfireNamespaceHandler extends NamespaceHandlerSupport { - @Override - public BeanDefinition parse(Element element, ParserContext parserContext) { - ParsingUtils.assertGemFireFeatureAvailable(element, parserContext); - return super.parse(element, parserContext); - } - @Override public void init() { - registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenBeanDefinitionParser()); + registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenParser()); + registerBeanDefinitionParser("async-event-queue", new AsyncEventQueueParser()); + registerBeanDefinitionParser("auto-region-lookup", new AutoRegionLookupParser()); registerBeanDefinitionParser("cache", new CacheParser()); registerBeanDefinitionParser("cache-server", new CacheServerParser()); - registerBeanDefinitionParser("auto-region-lookup", new AutoRegionLookupBeanDefinitionParser()); - registerBeanDefinitionParser("lookup-region", new LookupRegionParser()); - registerBeanDefinitionParser("region-template", new TemplateRegionParser()); - registerBeanDefinitionParser("local-region", new LocalRegionParser()); - registerBeanDefinitionParser("local-region-template", new LocalRegionParser()); - registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser()); - registerBeanDefinitionParser("partitioned-region-template", new PartitionedRegionParser()); - registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser()); - registerBeanDefinitionParser("replicated-region-template", new ReplicatedRegionParser()); - registerBeanDefinitionParser("async-event-queue", new AsyncEventQueueParser()); + registerBeanDefinitionParser("client-cache", new ClientCacheParser()); + registerBeanDefinitionParser("client-region", new ClientRegionParser()); + registerBeanDefinitionParser("client-region-template", new ClientRegionParser()); + registerBeanDefinitionParser("cq-listener-container", new GemfireListenerContainerParser()); registerBeanDefinitionParser("disk-store", new DiskStoreParser()); registerBeanDefinitionParser("function-service", new FunctionServiceParser()); registerBeanDefinitionParser("gateway-receiver", new GatewayReceiverParser()); registerBeanDefinitionParser("gateway-sender", new GatewaySenderParser()); registerBeanDefinitionParser("index", new IndexParser()); - registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser()); - registerBeanDefinitionParser("client-cache", new ClientCacheParser()); - registerBeanDefinitionParser("client-region", new ClientRegionParser()); - registerBeanDefinitionParser("client-region-template", new ClientRegionParser()); - registerBeanDefinitionParser("cq-listener-container", new GemfireListenerContainerParser()); + registerBeanDefinitionParser("local-region", new LocalRegionParser()); + registerBeanDefinitionParser("local-region-template", new LocalRegionParser()); + registerBeanDefinitionParser("lookup-region", new LookupRegionParser()); + registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser()); + registerBeanDefinitionParser("partitioned-region-template", new PartitionedRegionParser()); registerBeanDefinitionParser("pool", new PoolParser()); + registerBeanDefinitionParser("region-template", new TemplateRegionParser()); + registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser()); + registerBeanDefinitionParser("replicated-region-template", new ReplicatedRegionParser()); + registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser()); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireRegionAutoProxyParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireRegionAutoProxyParser.java similarity index 60% rename from src/main/java/org/springframework/data/gemfire/config/GemfireRegionAutoProxyParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/GemfireRegionAutoProxyParser.java index 0e5598b9..1f27e351 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireRegionAutoProxyParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireRegionAutoProxyParser.java @@ -1,16 +1,19 @@ /* * Copyright 2002-2013 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package org.springframework.data.gemfire.config; + +package org.springframework.data.gemfire.config.xml; + +import java.util.Collections; import org.springframework.aop.config.AopNamespaceUtils; import org.springframework.beans.factory.config.BeanDefinition; @@ -24,30 +27,40 @@ import org.springframework.util.StringUtils; import org.w3c.dom.Element; /** - * @author David Turanski + * Bean definition parser for the <gfe-data:json-region-auto-proxy< SDG XML namespace (XSD) element. * + * @author David Turanski + * @author John Blum + * @see org.springframework.beans.factory.xml.BeanDefinitionParser + * @see org.springframework.data.gemfire.support.JSONRegionAdvice */ -public class GemfireRegionAutoProxyParser implements BeanDefinitionParser { +class GemfireRegionAutoProxyParser implements BeanDefinitionParser { - /* (non-Javadoc) - * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext) + /** + * {@inheritDoc} */ @Override public BeanDefinition parse(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(parserContext, element); - BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(JSONRegionAdvice.class); - ParsingUtils.setPropertyValue(element, builder, "pretty-print"); - ParsingUtils.setPropertyValue(element, builder, "convert-returned-collections"); + + BeanDefinitionBuilder jsonRegionAdviceBuilder = BeanDefinitionBuilder.rootBeanDefinition( + JSONRegionAdvice.class).setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + + ParsingUtils.setPropertyValue(element, jsonRegionAdviceBuilder, "pretty-print"); + ParsingUtils.setPropertyValue(element, jsonRegionAdviceBuilder, "convert-returned-collections"); + String regionNames = element.getAttribute("included-regions"); + if (StringUtils.hasText(regionNames)) { String[] regions = StringUtils.commaDelimitedListToStringArray(regionNames); ManagedList regionList = new ManagedList(regions.length); - for (String regionRef : regions) { - regionList.add(regionRef); - } - builder.addPropertyValue("includedRegions", regionList); + Collections.addAll(regionList, regions); + jsonRegionAdviceBuilder.addPropertyValue("includedRegions", regionList); } - BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry()); - return builder.getBeanDefinition(); + + BeanDefinitionReaderUtils.registerWithGeneratedName(jsonRegionAdviceBuilder.getBeanDefinition(), + parserContext.getRegistry()); + + return jsonRegionAdviceBuilder.getBeanDefinition(); } } diff --git a/src/main/java/org/springframework/data/gemfire/config/IndexParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/IndexParser.java similarity index 77% rename from src/main/java/org/springframework/data/gemfire/config/IndexParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/IndexParser.java index fac0b6a6..8e92573e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/IndexParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/IndexParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.concurrent.atomic.AtomicBoolean; @@ -25,26 +25,27 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.IndexFactoryBean; +import org.springframework.data.gemfire.config.support.DefinedIndexesApplicationListener; import org.w3c.dom.Element; /** - * Namespace parser for <index;gt; bean definitions. - * + * Bean definition parser for <gfe:index> SDG XML namespace (XSD) element. + * * @author Costin Leau * @author John Blum - * @see org.springframework.beans.factory.support.BeanDefinitionBuilder - * @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser * @see org.springframework.data.gemfire.IndexFactoryBean + * @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser * @since 1.1.0 */ class IndexParser extends AbstractSimpleBeanDefinitionParser { - private static final AtomicBoolean registered = new AtomicBoolean(false); + private static final AtomicBoolean REGISTERED = new AtomicBoolean(false); - protected static void registerCreateDefinedIndexesApplicationListener(ParserContext parserContext) { - if (registered.compareAndSet(false, true)) { + /* (non-Javadoc) */ + protected static void registerDefinedIndexesApplicationListener(ParserContext parserContext) { + if (REGISTERED.compareAndSet(false, true)) { AbstractBeanDefinition createDefinedIndexesApplicationListener = BeanDefinitionBuilder - .genericBeanDefinition(CreateDefinedIndexesApplicationListener.class) + .rootBeanDefinition(DefinedIndexesApplicationListener.class) .setRole(BeanDefinition.ROLE_INFRASTRUCTURE) .getBeanDefinition(); @@ -53,20 +54,27 @@ class IndexParser extends AbstractSimpleBeanDefinitionParser { } } + + /** + * {@inheritDoc} + */ protected Class getBeanClass(Element element) { return IndexFactoryBean.class; } + /** + * {@inheritDoc} + */ + @Override + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + super.doParse(element, parserContext, builder); + registerDefinedIndexesApplicationListener(parserContext); + ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache"); + } + + /* (non-Javadoc) */ @Override protected boolean isEligibleAttribute(String attributeName) { return (!"cache-ref".equals(attributeName) && super.isEligibleAttribute(attributeName)); } - - @Override - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - registerCreateDefinedIndexesApplicationListener(parserContext); - ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache"); - super.doParse(element, parserContext, builder); - } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/LocalRegionParser.java similarity index 80% rename from src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/LocalRegionParser.java index 4672475b..130cc9cd 100644 --- a/src/main/java/org/springframework/data/gemfire/config/LocalRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/LocalRegionParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; @@ -23,18 +23,26 @@ import org.springframework.data.gemfire.RegionAttributesFactoryBean; import org.w3c.dom.Element; /** - * Parser for <local-region> bean definitions. + * Bean definition parser for the <gfe:local-region> SDG XML namespace (XSD) element. * * @author David Turanski * @author John Blum + * @see org.springframework.data.gemfire.LocalRegionFactoryBean + * @see AbstractRegionParser */ class LocalRegionParser extends AbstractRegionParser { + /** + * {@inheritDoc} + */ @Override protected Class getRegionFactoryClass() { return LocalRegionFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, boolean subRegion) { @@ -44,9 +52,8 @@ class LocalRegionParser extends AbstractRegionParser { BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition( RegionAttributesFactoryBean.class); - doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion); + doParseRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion); builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition()); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/LookupRegionParser.java similarity index 89% rename from src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/LookupRegionParser.java index 299788aa..1bff88a5 100644 --- a/src/main/java/org/springframework/data/gemfire/config/LookupRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/LookupRegionParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; @@ -26,28 +26,35 @@ import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; import com.gemstone.gemfire.cache.wan.GatewaySender; /** - * Parser for GFE <lookup-region> bean definitions. + * Bean definition parser for the <gfe:lookup-region> SDG XML namespace (XSD) element. * * @author Costin Leau * @author David Turanski * @author John Blum * @see org.springframework.data.gemfire.LookupRegionFactoryBean - * @see org.springframework.data.gemfire.config.AbstractRegionParser + * @see AbstractRegionParser */ class LookupRegionParser extends AbstractRegionParser { + /** + * {@inheritDoc} + */ @Override protected Class getRegionFactoryClass() { return LookupRegionFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, boolean subRegion) { super.doParse(element, builder); - String resolvedCacheRef = ParsingUtils.resolveCacheReference(element.getAttribute("cache-ref")); + String resolvedCacheRef = ParsingUtils.resolveCacheReference( + element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME)); builder.addPropertyReference("cache", resolvedCacheRef); @@ -87,5 +94,4 @@ class LookupRegionParser extends AbstractRegionParser { parseSubRegions(element, parserContext, resolvedCacheRef); } } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java b/src/main/java/org/springframework/data/gemfire/config/xml/ParsingUtils.java similarity index 98% rename from src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java rename to src/main/java/org/springframework/data/gemfire/config/xml/ParsingUtils.java index f71077da..875c9650 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/ParsingUtils.java @@ -14,10 +14,14 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.List; +import com.gemstone.gemfire.cache.LossAction; +import com.gemstone.gemfire.cache.MembershipAttributes; +import com.gemstone.gemfire.cache.ResumptionAction; + import org.springframework.beans.PropertyValue; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; @@ -30,14 +34,11 @@ import org.springframework.data.gemfire.ExpirationAttributesFactoryBean; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.SubscriptionAttributesFactoryBean; import org.springframework.data.gemfire.config.support.GemfireFeature; +import org.springframework.data.gemfire.util.SpringUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; -import com.gemstone.gemfire.cache.LossAction; -import com.gemstone.gemfire.cache.MembershipAttributes; -import com.gemstone.gemfire.cache.ResumptionAction; - /** * Utilities used by the Spring Data GemFire XML Namespace parsers. * @@ -110,19 +111,19 @@ abstract class ParsingUtils { /** * Utility method handling parsing of nested definition of the type: - * + * *
 	 *   
 	 * 
- * + * * or - * + * *
 	 *   
 	 *     
 	 *   
 	 * 
- * + * * @param element the XML element. * @return Bean reference or nested Bean definition. */ @@ -237,7 +238,7 @@ abstract class ParsingUtils { return false; } - + /** * Parses the subscription sub-element. Populates the given attribute factory with the proper attributes. * @@ -336,7 +337,7 @@ abstract class ParsingUtils { } } - @SuppressWarnings("unused") + @SuppressWarnings({ "deprecation", "unused" }) static void parseMembershipAttributes(ParserContext parserContext, Element element, BeanDefinitionBuilder regionAttributesBuilder) { @@ -389,7 +390,7 @@ abstract class ParsingUtils { return false; } - + private static boolean parseCustomExpiration(Element rootElement, ParserContext parserContext, String elementName, String propertyName, BeanDefinitionBuilder regionAttributesBuilder) { Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName); @@ -415,6 +416,7 @@ abstract class ParsingUtils { } } + @SuppressWarnings("unused") static void assertGemFireFeatureAvailable(Element element, ParserContext parserContext) { if (GemfireUtils.isGemfireFeatureUnavailable(element)) { parserContext.getReaderContext().error(String.format("'%1$s' is not supported in %2$s v%3$s", @@ -431,7 +433,7 @@ abstract class ParsingUtils { } static String resolveCacheReference(String cacheReference) { - return (StringUtils.hasText(cacheReference) ? cacheReference : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME); + return SpringUtils.defaultIfEmpty(cacheReference, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME); } static void setRegionReference(Element element, BeanDefinitionBuilder builder) { @@ -454,5 +456,4 @@ abstract class ParsingUtils { messagePrefix, GemfireUtils.GEMFIRE_VERSION), null); } } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/PartitionedRegionParser.java similarity index 92% rename from src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/PartitionedRegionParser.java index 0c0074b6..81a116d5 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/PartitionedRegionParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.List; @@ -33,21 +33,29 @@ import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Parser for <partitioned-region> bean definitions. + * Bean definition parser for the <gfe:partitioned-region> SDG XML namespace (XSD) element. * - * To avoid eager evaluations, the region attributes are declared as a nested definition. + * To avoid eager evaluations, Region attributes are declared as a nested bean definitions. * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean + * @see AbstractRegionParser */ class PartitionedRegionParser extends AbstractRegionParser { + /** + * {@inheritDoc} + */ @Override protected Class getRegionFactoryClass() { return PartitionedRegionFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override @SuppressWarnings("unchecked") protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder, @@ -58,7 +66,7 @@ class PartitionedRegionParser extends AbstractRegionParser { BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition( RegionAttributesFactoryBean.class); - doParseCommonRegionConfiguration(element, parserContext, regionBuilder, regionAttributesBuilder, subRegion); + doParseRegionConfiguration(element, parserContext, regionBuilder, regionAttributesBuilder, subRegion); regionBuilder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition()); @@ -110,6 +118,7 @@ class PartitionedRegionParser extends AbstractRegionParser { regionAttributesBuilder.addPropertyValue("partitionAttributes", partitionAttributesBuilder.getBeanDefinition()); } + /* (non-Javadoc) */ void mergeTemplateRegionPartitionAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder partitionAttributesBuilder) { @@ -143,6 +152,7 @@ class PartitionedRegionParser extends AbstractRegionParser { } } + /* (non-Javadoc) */ private void parseColocatedWith(Element element, BeanDefinitionBuilder regionBuilder, BeanDefinitionBuilder partitionAttributesBuilder, String attributeName) { // NOTE rather than using a dependency (with depends-on) we could also set the colocatedWith property of the @@ -160,14 +170,17 @@ class PartitionedRegionParser extends AbstractRegionParser { } } + /* (non-Javadoc) */ private Object parsePartitionResolver(Element subElement, ParserContext parserContext, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext, subElement, builder); } + /* (non-Javadoc) */ private Object parsePartitionListeners(Element subElement, ParserContext parserContext, BeanDefinitionBuilder builder) { + return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/PoolParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/PoolParser.java similarity index 96% rename from src/main/java/org/springframework/data/gemfire/config/PoolParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/PoolParser.java index 3bef6eb4..540899d1 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PoolParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/PoolParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -31,6 +31,7 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.client.PoolFactoryBean; +import org.springframework.data.gemfire.config.support.ClientRegionPoolBeanFactoryPostProcessor; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.support.ConnectionEndpointList; import org.springframework.data.gemfire.util.SpringUtils; @@ -39,14 +40,11 @@ import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Parser for <gfe:pool> bean definitions. + * Bean definition parser for the <gfe:pool> SDG XML namespace (XSD) element. * * @author Costin Leau * @author David Turanski * @author John Blum - * @see org.springframework.beans.factory.config.BeanDefinition - * @see org.springframework.beans.factory.support.BeanDefinitionBuilder - * @see org.springframework.beans.factory.support.BeanDefinitionRegistry * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser * @see org.springframework.data.gemfire.client.PoolFactoryBean */ @@ -69,7 +67,7 @@ class PoolParser extends AbstractSingleBeanDefinitionParser { static void registerInfrastructureComponents(ParserContext parserContext) { if (INFRASTRUCTURE_COMPONENTS_REGISTERED.compareAndSet(false, true)) { AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder - .genericBeanDefinition(ClientRegionAndPoolBeanFactoryPostProcessor.class) + .rootBeanDefinition(ClientRegionPoolBeanFactoryPostProcessor.class) .setRole(BeanDefinition.ROLE_INFRASTRUCTURE) .getBeanDefinition(); @@ -77,11 +75,17 @@ class PoolParser extends AbstractSingleBeanDefinitionParser { } } + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return PoolFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { diff --git a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionParser.java similarity index 80% rename from src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionParser.java index 83115245..acd3e0f7 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; @@ -23,19 +23,27 @@ import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.w3c.dom.Element; /** - * Parser for <replicated-region;gt; definitions. + * Bean definition parser for the <gfe:replicated-region> SDG XML namespace (XSD) element. * * @author Costin Leau * @author David Turanski * @author John Blum + * @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean + * @see AbstractRegionParser */ class ReplicatedRegionParser extends AbstractRegionParser { + /** + * {@inheritDoc} + */ @Override protected Class getRegionFactoryClass() { return ReplicatedRegionFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, boolean subRegion) { @@ -47,9 +55,8 @@ class ReplicatedRegionParser extends AbstractRegionParser { BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition( RegionAttributesFactoryBean.class); - doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion); + doParseRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion); builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition()); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/SnapshotServiceParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/SnapshotServiceParser.java similarity index 91% rename from src/main/java/org/springframework/data/gemfire/config/SnapshotServiceParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/SnapshotServiceParser.java index b1d25781..df11651f 100644 --- a/src/main/java/org/springframework/data/gemfire/config/SnapshotServiceParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/SnapshotServiceParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; @@ -26,23 +26,26 @@ import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; /** - * Parser for <gfe-data:snapshot-service> bean definition elements in Spring XML config. + * Bean definition parser for the <gfe-data:snapshot-service> SDG XML namespace (XSD) element. * * @author John Blum - * @see org.springframework.beans.factory.config.BeanDefinition - * @see org.springframework.beans.factory.support.BeanDefinitionBuilder * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser - * @see org.springframework.beans.factory.xml.ParserContext * @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean * @since 1.7.0 */ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(final Element element) { return SnapshotServiceFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); @@ -54,14 +57,17 @@ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser { builder.addPropertyValue("imports", parseImports(element, parserContext)); } + /* (non-Javadoc) */ private ManagedList parseExports(Element element, ParserContext parserContext) { return parseSnapshots(element, parserContext, "snapshot-export"); } + /* (non-Javadoc) */ private ManagedList parseImports(Element element, ParserContext parserContext) { return parseSnapshots(element, parserContext, "snapshot-import"); } + /* (non-Javadoc) */ private ManagedList parseSnapshots(Element element, ParserContext parserContext, String childTagName) { @@ -74,6 +80,7 @@ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser { return snapshotBeans; } + /* (non-Javadoc) */ private BeanDefinition parseSnapshotMetadata(Element snapshotMetadataElement, ParserContext parserContext) { BeanDefinitionBuilder snapshotMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition( SnapshotServiceFactoryBean.SnapshotMetadata.class); @@ -90,8 +97,8 @@ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser { return snapshotMetadataBuilder.getBeanDefinition(); } + /* (non-Javadoc) */ private boolean isSnapshotFilterSpecified(final Element snapshotMetadataElement) { return (snapshotMetadataElement.hasAttribute("filter-ref") || snapshotMetadataElement.hasChildNodes()); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/TemplateRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/TemplateRegionParser.java similarity index 75% rename from src/main/java/org/springframework/data/gemfire/config/TemplateRegionParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/TemplateRegionParser.java index f88dbc30..65cae2b1 100644 --- a/src/main/java/org/springframework/data/gemfire/config/TemplateRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/TemplateRegionParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; @@ -23,31 +23,34 @@ import org.springframework.data.gemfire.RegionFactoryBean; import org.w3c.dom.Element; /** - * The TemplateRegionParser class is a generic Region parser used to parse Region Template bean definitions in the - * Spring context configuration meta-data to encapsulate common Region 'attribute' configuration irrespective of the - * Region's Data Policy (e.g. REPLICATE, PARTITION). + * Bean definition parser for <gfe:*-region-template> SDG XML namespace (XSD) elements. * * @author John Blum * @see org.springframework.data.gemfire.RegionFactoryBean - * @see org.springframework.data.gemfire.config.AbstractRegionParser + * @see AbstractRegionParser * @since 1.5.0 */ class TemplateRegionParser extends AbstractRegionParser { + /** + * {@inheritDoc} + */ @Override protected Class getRegionFactoryClass() { return RegionFactoryBean.class; } + /** + * {@inheritDoc} + */ @Override protected void doParseRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, boolean subRegion) { BeanDefinitionBuilder regionAttributesBuilder = BeanDefinitionBuilder.genericBeanDefinition( RegionAttributesFactoryBean.class); - doParseCommonRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion); + doParseRegionConfiguration(element, parserContext, builder, regionAttributesBuilder, subRegion); builder.addPropertyValue("attributes", regionAttributesBuilder.getBeanDefinition()); } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/TransactionManagerParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/TransactionManagerParser.java similarity index 81% rename from src/main/java/org/springframework/data/gemfire/config/TransactionManagerParser.java rename to src/main/java/org/springframework/data/gemfire/config/xml/TransactionManagerParser.java index 8670e5e8..7cb8753e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/TransactionManagerParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/TransactionManagerParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -26,33 +26,41 @@ import org.springframework.util.StringUtils; import org.w3c.dom.Element; /** - * Parser for <transaction-manager> element bean definitions. - * + * Bean definition parser for the <gfe:transaction-manager> SDG XML namespace (XSD) element. + * * @author Costin Leau * @author John Blum + * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser + * @see org.springframework.data.gemfire.GemfireTransactionManager */ class TransactionManagerParser extends AbstractSingleBeanDefinitionParser { + /** + * {@inheritDoc} + */ @Override protected Class getBeanClass(Element element) { return GemfireTransactionManager.class; } + /** + * {@inheritDoc} + */ @Override protected void doParse(Element element, BeanDefinitionBuilder builder) { super.doParse(element, builder); ParsingUtils.setPropertyValue(element, builder, "copy-on-read", "copyOnRead"); - - String attr = element.getAttribute("cache-ref"); - // add cache reference (fallback to default if nothing is specified) - builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME)); - + builder.addPropertyReference("cache", ParsingUtils.resolveCacheReference(element)); } + /** + * {@inheritDoc} + */ @Override protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException { + String name = super.resolveId(element, definition, parserContext); if (!StringUtils.hasText(name)) { @@ -64,5 +72,4 @@ class TransactionManagerParser extends AbstractSingleBeanDefinitionParser { return name; } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/package-info.java b/src/main/java/org/springframework/data/gemfire/config/xml/package-info.java similarity index 62% rename from src/main/java/org/springframework/data/gemfire/config/package-info.java rename to src/main/java/org/springframework/data/gemfire/config/xml/package-info.java index d747a243..76a85f8e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/package-info.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/package-info.java @@ -1,7 +1,7 @@ /** - * This package provides classes and components for configuring GemFire using Spring Data GemFire's XML namespace - * support. See more details here... + * This package provides classes and components for configuring GemFire using Spring Data GemFire's + * XML namespace support. See more details here... * * Spring Data GemFire Core Schema (gfe) */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; diff --git a/src/main/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilder.java b/src/main/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilder.java index 82033bab..05e35990 100644 --- a/src/main/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilder.java +++ b/src/main/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilder.java @@ -1,11 +1,11 @@ /* * Copyright 2002-2013 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 - * + * * http://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. @@ -14,7 +14,7 @@ package org.springframework.data.gemfire.function.config; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.gemfire.function.execution.GemfireFunctionProxyFactoryBean; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java b/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java index 6ccb5bc5..07675dda 100644 --- a/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java +++ b/src/main/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainer.java @@ -37,7 +37,7 @@ import org.springframework.data.gemfire.GemfireQueryException; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.client.support.DefaultableDelegatingPoolAdapter; import org.springframework.data.gemfire.client.support.DelegatingPoolAdapter; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ErrorHandler; diff --git a/src/main/java/org/springframework/data/gemfire/support/AbstractPropertyEditorConverterSupport.java b/src/main/java/org/springframework/data/gemfire/support/AbstractPropertyEditorConverterSupport.java index a0e2b6d8..81bd19a2 100644 --- a/src/main/java/org/springframework/data/gemfire/support/AbstractPropertyEditorConverterSupport.java +++ b/src/main/java/org/springframework/data/gemfire/support/AbstractPropertyEditorConverterSupport.java @@ -35,32 +35,32 @@ public abstract class AbstractPropertyEditorConverterSupport extends Property implements Converter { /** - * Asserts that the given String was successfully converted into an instance of Class type T. + * Asserts that the given {@link String} was converted into an instance of {@link Class type} T. * - * @param source the String to convert. - * @param convertedValue the value of the String converted into instance of Class type T. - * @param type the target Class type of the converted value. - * @return the converted value of Class type T if not null. - * @throws java.lang.IllegalArgumentException if the String could not be converted into - * an instance of Class type T. + * @param source {@link String} to convert. + * @param convertedValue converted value of {@link Class type} T. + * @param type {@link Class type} of the converted value. + * @return the converted value. + * @throws java.lang.IllegalArgumentException if the {@link String} could not be converted into + * an instance of {@link Class type} T. */ - protected T assertConverted(final String source, final T convertedValue, final Class type) { - Assert.notNull(convertedValue, String.format("(%1$s) is not a valid %2$s!", source, type.getSimpleName())); + protected T assertConverted(String source, T convertedValue, Class type) { + Assert.notNull(convertedValue, String.format("[%1$s] is not a valid %2$s", source, type.getSimpleName())); return convertedValue; } /** - * Sets the value of this PropertyEditor with the given String converted to the appropriate Class type. + * Sets the value of this {@link java.beans.PropertyEditor} to the given {@link String} + * converted to the appropriate {@link Class type}. * - * @param text the String to convert. - * @throws java.lang.IllegalArgumentException if the String could not be converted into - * an instance of Class type T. + * @param text {@link String} to convert. + * @throws java.lang.IllegalArgumentException if the {@link String} could not be converted into + * an instance of {@link Class type} T. * @see #convert(Object) * @see #setValue(Object) */ @Override - public void setAsText(final String text) throws IllegalArgumentException { + public void setAsText(String text) throws IllegalArgumentException { setValue(convert(text)); } - } diff --git a/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpointList.java b/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpointList.java index f62f53dc..04a6b593 100644 --- a/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpointList.java +++ b/src/main/java/org/springframework/data/gemfire/support/ConnectionEndpointList.java @@ -98,7 +98,7 @@ public class ConnectionEndpointList extends AbstractList { */ public static ConnectionEndpointList parse(int defaultPort, String... hostsPorts) { List connectionEndpoints = new ArrayList( - ArrayUtils.length((Object) hostsPorts)); + ArrayUtils.length(hostsPorts)); for (String hostPort : ArrayUtils.nullSafeArray(hostsPorts, String.class)) { connectionEndpoints.add(ConnectionEndpoint.parse(hostPort, defaultPort)); diff --git a/src/main/java/org/springframework/data/gemfire/util/ArrayUtils.java b/src/main/java/org/springframework/data/gemfire/util/ArrayUtils.java index 703322f5..cb49c757 100644 --- a/src/main/java/org/springframework/data/gemfire/util/ArrayUtils.java +++ b/src/main/java/org/springframework/data/gemfire/util/ArrayUtils.java @@ -103,7 +103,7 @@ public abstract class ArrayUtils { * @return a boolean value indicating whether the given array is empty. * @see #length(Object...) */ - public static boolean isEmpty(Object... array) { + public static boolean isEmpty(Object[] array) { return (length(array) == 0); } @@ -113,7 +113,7 @@ public abstract class ArrayUtils { * @param array the array to determine it's length. * @return the length of the given array or 0 if the array reference is null. */ - public static int length(Object... array) { + public static int length(Object[] array) { return (array != null ? array.length : 0); } diff --git a/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java b/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java index 8a110ce8..67a982ab 100644 --- a/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java +++ b/src/main/java/org/springframework/data/gemfire/util/SpringUtils.java @@ -17,7 +17,12 @@ package org.springframework.data.gemfire.util; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.util.StringUtils; /** @@ -27,9 +32,22 @@ import org.springframework.util.StringUtils; * @since 1.8.0 */ @SuppressWarnings("unused") -// TODO rename this utiltiy class using a more intuitive, meaningful name +// TODO rename this utiltiy class using a more descriptive, intuitive and meaningful name public abstract class SpringUtils { + /* (non-Javadoc) */ + public static BeanDefinition addDependsOn(BeanDefinition bean, String beanName) { + String[] dependsOn = bean.getDependsOn(); + List dependsOnList = new ArrayList(); + + Collections.addAll(dependsOnList, ArrayUtils.nullSafeArray(dependsOn, String.class)); + + dependsOnList.add(beanName); + bean.setDependsOn(dependsOnList.toArray(new String[dependsOnList.size()])); + + return bean; + } + /* (non-Javadoc) */ public static String defaultIfEmpty(String value, String defaultValue) { return (StringUtils.hasText(value) ? value : defaultValue); @@ -40,6 +58,11 @@ public abstract class SpringUtils { return (value != null ? value : defaultValue); } + /* (non-Javadoc) */ + public static boolean equalsIgnoreNull(Object obj1, Object obj2) { + return (obj1 == null ? obj2 == null : obj1.equals(obj2)); + } + /* (non-Javadoc) */ public static String dereferenceBean(String beanName) { return String.format("%1$s%2$s", BeanFactory.FACTORY_BEAN_PREFIX, beanName); diff --git a/src/main/resources/META-INF/spring.handlers b/src/main/resources/META-INF/spring.handlers index 4f907e5b..94c877db 100644 --- a/src/main/resources/META-INF/spring.handlers +++ b/src/main/resources/META-INF/spring.handlers @@ -1,2 +1,2 @@ -http\://www.springframework.org/schema/gemfire=org.springframework.data.gemfire.config.GemfireNamespaceHandler -http\://www.springframework.org/schema/data/gemfire=org.springframework.data.gemfire.config.GemfireDataNamespaceHandler \ No newline at end of file +http\://www.springframework.org/schema/gemfire=org.springframework.data.gemfire.config.xml.GemfireNamespaceHandler +http\://www.springframework.org/schema/data/gemfire=org.springframework.data.gemfire.config.xml.GemfireDataNamespaceHandler diff --git a/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java index fb2825d6..1ad2d955 100644 --- a/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/CacheAutoReconnectIntegrationTests.java @@ -27,7 +27,7 @@ import org.junit.After; import org.junit.Test; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import com.gemstone.gemfire.cache.Cache; diff --git a/src/test/java/org/springframework/data/gemfire/EvictionActionConverterTest.java b/src/test/java/org/springframework/data/gemfire/EvictionActionConverterTest.java deleted file mode 100644 index db9d76be..00000000 --- a/src/test/java/org/springframework/data/gemfire/EvictionActionConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -import com.gemstone.gemfire.cache.EvictionAction; - -/** - * The EvictionActionTypeConverterTest class is a test suite of test cases testing the contract and functionality - * of the EvictionActionTypeConverter. - * - * @author John Blum - * @see org.junit.Test - * @see EvictionActionConverter - * @since 1.6.0 - */ -public class EvictionActionConverterTest { - - private EvictionActionConverter converter = new EvictionActionConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(EvictionAction.LOCAL_DESTROY, converter.convert("local_destroy")); - assertEquals(EvictionAction.NONE, converter.convert("None")); - assertEquals(EvictionAction.OVERFLOW_TO_DISK, converter.convert("OverFlow_TO_dIsk")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("invalid_value"); - } - catch (IllegalArgumentException expected) { - assertEquals("(invalid_value) is not a valid EvictionAction!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - assertNull(converter.getValue()); - converter.setAsText("Local_Destroy"); - assertEquals(EvictionAction.LOCAL_DESTROY, converter.getValue()); - converter.setAsText("overflow_to_disk"); - assertEquals(EvictionAction.OVERFLOW_TO_DISK, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("destroy"); - } - catch (IllegalArgumentException expected) { - assertEquals("(destroy) is not a valid EvictionAction!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/EvictionActionConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/EvictionActionConverterUnitTests.java new file mode 100644 index 00000000..5a93638d --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/EvictionActionConverterUnitTests.java @@ -0,0 +1,89 @@ +/* + * Copyright 2010-2013 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 + * + * http://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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import com.gemstone.gemfire.cache.EvictionAction; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link EvictionActionConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.EvictionActionConverter + * @see com.gemstone.gemfire.cache.EvictionAction + * @since 1.6.0 + */ +public class EvictionActionConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private EvictionActionConverter converter = new EvictionActionConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("local_destroy")).isEqualTo(EvictionAction.LOCAL_DESTROY); + assertThat(converter.convert("None")).isEqualTo(EvictionAction.NONE); + assertThat(converter.convert("OverFlow_TO_dIsk")).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[invalid_value] is not a valid EvictionAction"); + + converter.convert("invalid_value"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("Local_Destroy"); + assertThat(converter.getValue()).isEqualTo(EvictionAction.LOCAL_DESTROY); + converter.setAsText("overflow_to_disk"); + assertThat(converter.getValue()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK); + } + + @Test + public void setAsTextWithIllegalValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[destroy] is not a valid EvictionAction"); + + converter.setAsText("destroy"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/EvictionPolicyConverterTest.java b/src/test/java/org/springframework/data/gemfire/EvictionPolicyConverterTest.java deleted file mode 100644 index d4258522..00000000 --- a/src/test/java/org/springframework/data/gemfire/EvictionPolicyConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -/** - * The EvictionTypeConverterTest class is a test suite of test cases testing the contract and functionality - * of the EvictionTypeConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.EvictionPolicyConverter - * @see org.springframework.data.gemfire.EvictionPolicyType - * @since 1.6.0 - */ -public class EvictionPolicyConverterTest { - - private final EvictionPolicyConverter converter = new EvictionPolicyConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(EvictionPolicyType.ENTRY_COUNT, converter.convert("entry_count")); - assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, converter.convert("Heap_Percentage")); - assertEquals(EvictionPolicyType.MEMORY_SIZE, converter.convert("MEMorY_SiZe")); - assertEquals(EvictionPolicyType.NONE, converter.convert("NONE")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("LIFO_MEMORY"); - } - catch (IllegalArgumentException expected) { - assertEquals("(LIFO_MEMORY) is not a valid EvictionPolicyType!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - assertNull(converter.getValue()); - converter.setAsText("heap_percentage"); - assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, converter.getValue()); - converter.setAsText("NOne"); - assertEquals(EvictionPolicyType.NONE, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("LRU_COUNT"); - } - catch (IllegalArgumentException expected) { - assertEquals("(LRU_COUNT) is not a valid EvictionPolicyType!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/EvictionPolicyConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/EvictionPolicyConverterUnitTests.java new file mode 100644 index 00000000..2e0996ea --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/EvictionPolicyConverterUnitTests.java @@ -0,0 +1,88 @@ +/* + * Copyright 2010-2013 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 + * + * http://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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link EvictionPolicyConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.EvictionPolicyConverter + * @see org.springframework.data.gemfire.EvictionPolicyType + * @since 1.6.0 + */ +public class EvictionPolicyConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final EvictionPolicyConverter converter = new EvictionPolicyConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("entry_count")).isEqualTo(EvictionPolicyType.ENTRY_COUNT); + assertThat(converter.convert("Heap_Percentage")).isEqualTo(EvictionPolicyType.HEAP_PERCENTAGE); + assertThat(converter.convert("MEMorY_SiZe")).isEqualTo(EvictionPolicyType.MEMORY_SIZE); + assertThat(converter.convert("NONE")).isEqualTo(EvictionPolicyType.NONE); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[LIFO_MEMORY] is not a valid EvictionPolicyType"); + + converter.convert("LIFO_MEMORY"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("heap_percentage"); + assertThat(converter.getValue()).isEqualTo(EvictionPolicyType.HEAP_PERCENTAGE); + converter.setAsText("NOne"); + assertThat(converter.getValue()).isEqualTo(EvictionPolicyType.NONE); + } + + @Test + public void setAsTextWithIllegalValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[LRU_COUNT] is not a valid EvictionPolicyType"); + + converter.setAsText("LRU_COUNT"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/ExpirationActionConverterTest.java b/src/test/java/org/springframework/data/gemfire/ExpirationActionConverterTest.java deleted file mode 100644 index abac06c8..00000000 --- a/src/test/java/org/springframework/data/gemfire/ExpirationActionConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -import com.gemstone.gemfire.cache.ExpirationAction; - -/** - * The ExpirationActionTypeConverterTest class is a test suite of test cases testing the contract and functionality - * of the ExpirationActionTypeConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see ExpirationActionConverter - * @since 1.6.0 - */ -public class ExpirationActionConverterTest { - - private final ExpirationActionConverter converter = new ExpirationActionConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(ExpirationAction.DESTROY, converter.convert("destroy")); - assertEquals(ExpirationAction.INVALIDATE, converter.convert("inValidAte")); - assertEquals(ExpirationAction.LOCAL_DESTROY, converter.convert("LOCAL_dEsTrOy")); - assertEquals(ExpirationAction.LOCAL_INVALIDATE, converter.convert("Local_Invalidate")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("illegal_value"); - } - catch (IllegalArgumentException expected) { - assertEquals("(illegal_value) is not a valid ExpirationAction!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - converter.setAsText("InValidAte"); - assertEquals(ExpirationAction.INVALIDATE, converter.getValue()); - converter.setAsText("Local_Destroy"); - assertEquals(ExpirationAction.LOCAL_DESTROY, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("destruction"); - } - catch (IllegalArgumentException expected) { - assertEquals("(destruction) is not a valid ExpirationAction!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/ExpirationActionConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/ExpirationActionConverterUnitTests.java new file mode 100644 index 00000000..93b82c98 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/ExpirationActionConverterUnitTests.java @@ -0,0 +1,89 @@ +/* + * Copyright 2010-2013 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 + * + * http://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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import com.gemstone.gemfire.cache.ExpirationAction; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link ExpirationActionConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.ExpirationActionConverter + * @since 1.6.0 + */ +public class ExpirationActionConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final ExpirationActionConverter converter = new ExpirationActionConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("destroy")).isEqualTo(ExpirationAction.DESTROY); + assertThat(converter.convert("inValidAte")).isEqualTo(ExpirationAction.INVALIDATE); + assertThat(converter.convert("LOCAL_dEsTrOy")).isEqualTo(ExpirationAction.LOCAL_DESTROY); + assertThat(converter.convert("Local_Invalidate")).isEqualTo(ExpirationAction.LOCAL_INVALIDATE); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[illegal_value] is not a valid ExpirationAction"); + + converter.convert("illegal_value"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("InValidAte"); + assertThat(converter.getValue()).isEqualTo(ExpirationAction.INVALIDATE); + converter.setAsText("Local_Destroy"); + assertThat(converter.getValue()).isEqualTo(ExpirationAction.LOCAL_DESTROY); + } + + @Test + public void setAsTextWithIllegalValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[destruction] is not a valid ExpirationAction"); + + converter.setAsText("destruction"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/IndexFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/IndexFactoryBeanTest.java index a9a7ba82..5bc28f02 100644 --- a/src/test/java/org/springframework/data/gemfire/IndexFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/IndexFactoryBeanTest.java @@ -57,7 +57,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.util.ReflectionUtils; import com.gemstone.gemfire.cache.Cache; diff --git a/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterTest.java b/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterTest.java deleted file mode 100644 index 2503ecd8..00000000 --- a/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -/** - * The IndexMaintenanceTypeConverterTest class is a test suite of test case testing the contract and functionality - * of the IndexMaintenancePolicyConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.IndexMaintenancePolicyConverter - * @see org.springframework.data.gemfire.IndexMaintenancePolicyType - * @since 1.6.0 - */ -public class IndexMaintenancePolicyConverterTest { - - private final IndexMaintenancePolicyConverter converter = new IndexMaintenancePolicyConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(IndexMaintenancePolicyType.ASYNCHRONOUS, converter.convert("asynchronous")); - assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, converter.convert("Synchronous")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("sync"); - } - catch (IllegalArgumentException expected) { - assertEquals("(sync) is not a valid IndexMaintenancePolicyType!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - converter.setAsText("aSynchronous"); - assertEquals(IndexMaintenancePolicyType.ASYNCHRONOUS, converter.getValue()); - converter.setAsText("synchrONoUS"); - assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("async"); - } - catch (IllegalArgumentException expected) { - assertEquals("(async) is not a valid IndexMaintenancePolicyType!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterUnitTests.java new file mode 100644 index 00000000..a8b06a3b --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterUnitTests.java @@ -0,0 +1,86 @@ +/* + * Copyright 2010-2013 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 + * + * http://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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link IndexMaintenancePolicyConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.IndexMaintenancePolicyConverter + * @see org.springframework.data.gemfire.IndexMaintenancePolicyType + * @since 1.6.0 + */ +public class IndexMaintenancePolicyConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final IndexMaintenancePolicyConverter converter = new IndexMaintenancePolicyConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("asynchronous")).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS); + assertThat(converter.convert("Synchronous")).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[sync] is not a valid IndexMaintenancePolicyType"); + + converter.convert("sync"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("aSynchronous"); + assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS); + converter.setAsText("synchrONoUS"); + assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS); + } + + @Test + public void setAsTextWithIllegalValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[async] is not a valid IndexMaintenancePolicyType"); + + converter.setAsText("async"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/IndexTypeConverterTest.java b/src/test/java/org/springframework/data/gemfire/IndexTypeConverterTest.java deleted file mode 100644 index 9aaa5b83..00000000 --- a/src/test/java/org/springframework/data/gemfire/IndexTypeConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -/** - * The IndexTypeConverterTest class is a test suite of test cases testing the contract and functionality - * of the IndexTypeConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.IndexType - * @see org.springframework.data.gemfire.IndexTypeConverter - * @since 1.5.2 - */ -public class IndexTypeConverterTest { - - private final IndexTypeConverter converter = new IndexTypeConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(IndexType.FUNCTIONAL, converter.convert("FUNCTIONAL")); - assertEquals(IndexType.HASH, converter.convert("hASh")); - assertEquals(IndexType.KEY, converter.convert("Key")); - assertEquals(IndexType.PRIMARY_KEY, converter.convert("primary_KEY")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertWithIllegalValue() { - try { - converter.convert("function"); - } - catch (IllegalArgumentException expected) { - assertEquals("(function) is not a valid IndexType!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - assertNull(converter.getValue()); - converter.setAsText("HasH"); - assertEquals(IndexType.HASH, converter.getValue()); - converter.setAsText("key"); - assertEquals(IndexType.KEY, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("invalid"); - } - catch (IllegalArgumentException expected) { - assertEquals("(invalid) is not a valid IndexType!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/IndexTypeConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/IndexTypeConverterUnitTests.java new file mode 100644 index 00000000..509cbf18 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/IndexTypeConverterUnitTests.java @@ -0,0 +1,89 @@ +/* + * Copyright 2010-2013 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 + * + * http://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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link IndexTypeConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.IndexType + * @see org.springframework.data.gemfire.IndexTypeConverter + * @since 1.5.2 + */ +public class IndexTypeConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final IndexTypeConverter converter = new IndexTypeConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("FUNCTIONAL")).isEqualTo(IndexType.FUNCTIONAL); + assertThat(converter.convert("hASh")).isEqualTo(IndexType.HASH); + assertThat(converter.convert("hASH")).isEqualTo(IndexType.HASH); + assertThat(converter.convert("Key")).isEqualTo(IndexType.KEY); + assertThat(converter.convert("primary_KEY")).isEqualTo(IndexType.PRIMARY_KEY); + } + + @Test + public void convertWithIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[function] is not a valid IndexType"); + + converter.convert("function"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("HasH"); + assertThat(converter.getValue()).isEqualTo(IndexType.HASH); + converter.setAsText("key"); + assertThat(converter.getValue()).isEqualTo(IndexType.KEY); + } + + @Test + public void setAsTextWithIllegalValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[invalid] is not a valid IndexType"); + + converter.setAsText("invalid"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterTest.java b/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterTest.java deleted file mode 100644 index 3b84ce30..00000000 --- a/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -import com.gemstone.gemfire.cache.InterestPolicy; - -/** - * The InterestPolicyConverterTest class is a test suite of test cases testing the contract and functionality - * of the InterestPolicyConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.InterestPolicyConverter - * @see com.gemstone.gemfire.cache.InterestPolicy - * @since 1.6.0 - */ -public class InterestPolicyConverterTest { - - private InterestPolicyConverter converter = new InterestPolicyConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(InterestPolicy.ALL, converter.convert("all")); - assertEquals(InterestPolicy.CACHE_CONTENT, converter.convert("Cache_Content")); - assertEquals(InterestPolicy.CACHE_CONTENT, converter.convert("CACHE_ConTent")); - assertEquals(InterestPolicy.ALL, converter.convert("ALL")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("invalid_value"); - } - catch (IllegalArgumentException expected) { - assertEquals("(invalid_value) is not a valid InterestPolicy!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - converter.setAsText("aLl"); - assertEquals(InterestPolicy.ALL, converter.getValue()); - converter.setAsText("Cache_CoNTeNT"); - assertEquals(InterestPolicy.CACHE_CONTENT, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithInvalidValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("none"); - } - catch (IllegalArgumentException expected) { - assertEquals("(none) is not a valid InterestPolicy!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterUnitTests.java new file mode 100644 index 00000000..61d7b6ea --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterUnitTests.java @@ -0,0 +1,90 @@ +/* + * Copyright 2010-2013 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 + * + * http://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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import com.gemstone.gemfire.cache.InterestPolicy; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link InterestPolicyConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.InterestPolicyConverter + * @see com.gemstone.gemfire.cache.InterestPolicy + * @since 1.6.0 + */ +public class InterestPolicyConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private InterestPolicyConverter converter = new InterestPolicyConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("all")).isEqualTo(InterestPolicy.ALL); + assertThat(converter.convert("Cache_Content")).isEqualTo(InterestPolicy.CACHE_CONTENT); + assertThat(converter.convert("CACHE_ConTent")).isEqualTo(InterestPolicy.CACHE_CONTENT); + assertThat(converter.convert("ALL")).isEqualTo(InterestPolicy.ALL); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[invalid_value] is not a valid InterestPolicy"); + + converter.convert("invalid_value"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("aLl"); + assertThat(converter.getValue()).isEqualTo(InterestPolicy.ALL); + converter.setAsText("Cache_CoNTeNT"); + assertThat(converter.getValue()).isEqualTo(InterestPolicy.CACHE_CONTENT); + } + + @Test + public void setAsTextWithInvalidValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[none] is not a valid InterestPolicy"); + + converter.setAsText("none"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/ScopeConverterTest.java b/src/test/java/org/springframework/data/gemfire/ScopeConverterTest.java deleted file mode 100644 index d6fd0269..00000000 --- a/src/test/java/org/springframework/data/gemfire/ScopeConverterTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -import com.gemstone.gemfire.cache.Scope; - -/** - * The ScopeConverterTest class is a test suite of test cases testing the contract and functionality - * of the ScopeConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.ScopeConverter - * @since 1.6.0 - */ -public class ScopeConverterTest { - - private final ScopeConverter converter = new ScopeConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(Scope.DISTRIBUTED_ACK, converter.convert("distributed-ACK")); - assertEquals(Scope.DISTRIBUTED_NO_ACK, converter.convert(" Distributed_NO-aCK")); - assertEquals(Scope.LOCAL, converter.convert("loCAL ")); - assertEquals(Scope.GLOBAL, converter.convert(" GLOBal ")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("illegal-value"); - } - catch (IllegalArgumentException expected) { - assertEquals("(illegal-value) is not a valid Scope!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - assertNull(converter.getValue()); - converter.setAsText("DisTributeD-nO_Ack"); - assertEquals(Scope.DISTRIBUTED_NO_ACK, converter.getValue()); - converter.setAsText("distributed-ack"); - assertEquals(Scope.DISTRIBUTED_ACK, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("d!5tr!but3d-n0_@ck"); - } - catch (IllegalArgumentException expected) { - assertEquals("(d!5tr!but3d-n0_@ck) is not a valid Scope!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/ScopeConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/ScopeConverterUnitTests.java new file mode 100644 index 00000000..0a24be73 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/ScopeConverterUnitTests.java @@ -0,0 +1,90 @@ +/* + * Copyright 2010-2013 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 + * + * http://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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import com.gemstone.gemfire.cache.Scope; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link ScopeConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.ScopeConverter + * @see com.gemstone.gemfire.cache.Scope + * @since 1.6.0 + */ +public class ScopeConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final ScopeConverter converter = new ScopeConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("distributed-ACK")).isEqualTo(Scope.DISTRIBUTED_ACK); + assertThat(converter.convert(" Distributed_NO-aCK")).isEqualTo(Scope.DISTRIBUTED_NO_ACK); + assertThat(converter.convert("loCAL ")).isEqualTo(Scope.LOCAL); + assertThat(converter.convert(" GLOBal ")).isEqualTo(Scope.GLOBAL); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[illegal-value] is not a valid Scope"); + + converter.convert("illegal-value"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("DisTributeD-nO_Ack"); + assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_NO_ACK); + converter.setAsText("distributed-ack"); + assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_ACK); + } + + @Test + public void setAsTextWithIllegalValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[d!5tr!but3d-n0_@ck] is not a valid Scope"); + + converter.setAsText("d!5tr!but3d-n0_@ck"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/client/ClientCacheFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/client/ClientCacheFactoryBeanTest.java index 4b308b13..ff0277d2 100644 --- a/src/test/java/org/springframework/data/gemfire/client/ClientCacheFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/ClientCacheFactoryBeanTest.java @@ -60,7 +60,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.data.gemfire.GemfireUtils; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.gemfire.support.ConnectionEndpoint; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.data.gemfire.util.DistributedSystemUtils; diff --git a/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java index 02fdc3cb..ce2f422d 100644 --- a/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/ClientRegionFactoryBeanTest.java @@ -43,7 +43,7 @@ import org.junit.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.core.io.Resource; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.EvictionAttributes; diff --git a/src/test/java/org/springframework/data/gemfire/client/InterestResultPolicyConverterTest.java b/src/test/java/org/springframework/data/gemfire/client/InterestResultPolicyConverterTest.java deleted file mode 100644 index 759bbd31..00000000 --- a/src/test/java/org/springframework/data/gemfire/client/InterestResultPolicyConverterTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -import com.gemstone.gemfire.cache.InterestResultPolicy; - -/** - * The InterestResultPolicyConverterTest class is a test suite of test cases testing the contract and functionality - * of the InterestResultPolicyConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.client.InterestResultPolicyConverter - * @see org.springframework.data.gemfire.client.InterestResultPolicyType - * @see com.gemstone.gemfire.cache.InterestResultPolicy - * @since 1.6.0 - */ -public class InterestResultPolicyConverterTest { - - private final InterestResultPolicyConverter converter = new InterestResultPolicyConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(InterestResultPolicy.NONE, converter.convert("NONE")); - assertEquals(InterestResultPolicy.KEYS, converter.convert("Keys")); - assertEquals(InterestResultPolicy.KEYS_VALUES, converter.convert("kEyS_ValUes")); - assertEquals(InterestResultPolicy.NONE, converter.convert("nONe")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("illegal_value"); - } - catch (IllegalArgumentException expected) { - assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - assertNull(converter.getValue()); - converter.setAsText("NOne"); - assertEquals(InterestResultPolicy.NONE, converter.getValue()); - converter.setAsText("KeYs"); - assertEquals(InterestResultPolicy.KEYS, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("illegal_value"); - } - catch (IllegalArgumentException expected) { - assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/client/InterestResultPolicyConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/client/InterestResultPolicyConverterUnitTests.java new file mode 100644 index 00000000..5ec82327 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/client/InterestResultPolicyConverterUnitTests.java @@ -0,0 +1,90 @@ +/* + * Copyright 2010-2013 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 + * + * http://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.client; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import com.gemstone.gemfire.cache.InterestResultPolicy; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link InterestResultPolicyConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.client.InterestResultPolicyConverter + * @see org.springframework.data.gemfire.client.InterestResultPolicyType + * @see com.gemstone.gemfire.cache.InterestResultPolicy + * @since 1.6.0 + */ +public class InterestResultPolicyConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final InterestResultPolicyConverter converter = new InterestResultPolicyConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("NONE")).isEqualTo(InterestResultPolicy.NONE); + assertThat(converter.convert("kEyS_ValUes")).isEqualTo(InterestResultPolicy.KEYS_VALUES); + assertThat(converter.convert("nONe")).isEqualTo(InterestResultPolicy.NONE); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[illegal_value] is not a valid InterestResultPolicy"); + + converter.convert("illegal_value"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("NOne"); + assertThat(converter.getValue()).isEqualTo(InterestResultPolicy.NONE); + converter.setAsText("KeYs"); + assertThat(converter.getValue()).isEqualTo(InterestResultPolicy.KEYS); + } + + @Test + public void setAsTextWithIllegalValue() { + try { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[illegal_value] is not a valid InterestResultPolicy"); + + converter.setAsText("illegal_value"); + } + finally { + assertThat(converter.getValue()).isNull(); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/AbstractRegionParserTest.java b/src/test/java/org/springframework/data/gemfire/config/AbstractRegionParserTest.java deleted file mode 100644 index 988a01c1..00000000 --- a/src/test/java/org/springframework/data/gemfire/config/AbstractRegionParserTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.matches; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.junit.Test; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.beans.factory.xml.XmlReaderContext; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * The AbstractRegionParserTest class is a test suite of test cases testing the contract and functionality of the - * AbstractRegionParser class. - * - * @author John Blum - * @see org.junit.Test - * @see org.mockito.Mockito - * @see org.springframework.data.gemfire.config.AbstractRegionParser - * @since 1.3.3 - */ -public class AbstractRegionParserTest { - - private AbstractRegionParser regionParser = new TestRegionParser(); - - @Test - public void testIsSubRegionWhen() { - Element mockElement = mock(Element.class); - Node mockNode = mock(Node.class); - - when(mockElement.getParentNode()).thenReturn(mockNode); - when(mockNode.getLocalName()).thenReturn("partitioned-region"); - - assertTrue(regionParser.isSubRegion(mockElement)); - } - - @Test - public void testIsSubRegionWhenLocalNameIsNull() { - Element mockElement = mock(Element.class); - Node mockNode = mock(Node.class); - - when(mockElement.getParentNode()).thenReturn(mockNode); - when(mockNode.getLocalName()).thenReturn(null); - - assertFalse(regionParser.isSubRegion(mockElement)); - } - - @Test - public void testIsSubRegionWhenLocalNameDoesNotEndWithRegion() { - Element mockElement = mock(Element.class); - Node mockNode = mock(Node.class); - - when(mockElement.getParentNode()).thenReturn(mockNode); - when(mockNode.getLocalName()).thenReturn("disk-store"); - - assertFalse(regionParser.isSubRegion(mockElement)); - } - - @Test - public void testValidateDataPolicyShortcutAttributesMutualExclusion() { - Element mockElement = mock(Element.class); - - when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false); - when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false); - - new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null); - - verify(mockElement).hasAttribute(eq("data-policy")); - verify(mockElement, never()).hasAttribute(eq("shortcut")); - } - - @Test - public void testValidateDataPolicyShortcutAttributesMutualExclusionWithDataPolicy() { - Element mockElement = mock(Element.class); - - when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true); - when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false); - - new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null); - - verify(mockElement).hasAttribute(eq("data-policy")); - verify(mockElement).hasAttribute(eq("shortcut")); - } - - @Test - public void testValidateDataPolicyShortcutAttributesMutualExclusionWithShortcut() { - Element mockElement = mock(Element.class); - - when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false); - when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true); - - new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null); - - verify(mockElement).hasAttribute(eq("data-policy")); - verify(mockElement, never()).hasAttribute(eq("shortcut")); - } - - @Test - public void testValidateDataPolicyShortcutAttributesMutualExclusionWithDataPolicyAndShortcut() { - Element mockElement = mock(Element.class); - XmlReaderContext mockReaderContext = mock(XmlReaderContext.class); - - ParserContext mockParserContext = new ParserContext(mockReaderContext, null); - - when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true); - when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true); - when(mockElement.getTagName()).thenReturn("local-region"); - - new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, mockParserContext); - - verify(mockReaderContext).error( - eq("Only one of [data-policy, shortcut] may be specified with element 'local-region'."), - eq(mockElement)); - } - - protected static class TestRegionParser extends AbstractRegionParser { - - @Override - protected Class getRegionFactoryClass() { - return getClass(); - } - - @Override - protected void doParseRegion(final Element element, final ParserContext parserContext, - final BeanDefinitionBuilder builder, final boolean subRegion) { - throw new UnsupportedOperationException("Not Implemented!"); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/config/CreateDefinedIndexesApplicationListenerTest.java b/src/test/java/org/springframework/data/gemfire/config/CreateDefinedIndexesApplicationListenerTest.java deleted file mode 100644 index 82d50446..00000000 --- a/src/test/java/org/springframework/data/gemfire/config/CreateDefinedIndexesApplicationListenerTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.startsWith; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.HashMap; - -import org.apache.commons.logging.Log; -import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.context.event.ContextRefreshedEvent; - -import com.gemstone.gemfire.cache.query.MultiIndexCreationException; -import com.gemstone.gemfire.cache.query.QueryService; - -/** - * The CreateDefinedIndexesApplicationListenerTest class is a test suite of test cases testing the contract - * and functionality of the CreateDefinedIndexesApplicationListener class. - * - * @author John Blum - * @see org.junit.Test - * @see org.mockito.Mockito - * @see org.springframework.context.ApplicationContext - * @see org.springframework.context.event.ContextRefreshedEvent - * @see org.springframework.data.gemfire.config.CreateDefinedIndexesApplicationListener - * @see com.gemstone.gemfire.cache.query.QueryService - * @since 1.7.0 - */ -public class CreateDefinedIndexesApplicationListenerTest { - - private CreateDefinedIndexesApplicationListener listener = new CreateDefinedIndexesApplicationListener(); - - @Test - public void createDefinedIndexesCalledOnContextRefreshedEvent() throws Exception { - ApplicationContext mockApplicationContext = mock(ApplicationContext.class, - "testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockApplicationContext"); - - ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class, - "testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockContextRefreshedEvent"); - - QueryService mockQueryService = mock(QueryService.class, - "testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockQueryService"); - - when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext); - when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE))) - .thenReturn(true); - when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), - eq(QueryService.class))).thenReturn(mockQueryService); - - listener.onApplicationEvent(mockEvent); - - verify(mockEvent, times(1)).getApplicationContext(); - verify(mockApplicationContext, times(1)).containsBean( - eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)); - verify(mockApplicationContext, times(1)).getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class)); - verify(mockQueryService, times(1)).createDefinedIndexes(); - } - - @Test - public void createDefinedIndexesNotCalledOnContextRefreshedEvent() throws Exception { - ApplicationContext mockApplicationContext = mock(ApplicationContext.class, - "testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockApplicationContext"); - - ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class, - "testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockContextRefreshedEvent"); - - QueryService mockQueryService = mock(QueryService.class, - "testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockQueryService"); - - when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext); - when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE))) - .thenReturn(false); - when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), - eq(QueryService.class))).thenReturn(mockQueryService); - - listener.onApplicationEvent(mockEvent); - - verify(mockEvent, times(1)).getApplicationContext(); - verify(mockApplicationContext, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)); - verify(mockApplicationContext, never()).getBean(anyString(), any(QueryService.class)); - verify(mockQueryService, never()).createDefinedIndexes(); - } - - @Test - public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception { - ApplicationContext mockApplicationContext = mock(ApplicationContext.class, - "testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockApplicationContext"); - - ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class, - "testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockContextRefreshedEvent"); - - QueryService mockQueryService = mock(QueryService.class, - "testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockQueryService"); - - when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext); - when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE))) - .thenReturn(true); - when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), - eq(QueryService.class))).thenReturn(mockQueryService); - when(mockQueryService.createDefinedIndexes()).thenThrow(new MultiIndexCreationException( - new HashMap(Collections.singletonMap("TestKey", new RuntimeException("TEST"))))); - - final Log mockLog = mock(Log.class, "testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockLog"); - - CreateDefinedIndexesApplicationListener listener = new CreateDefinedIndexesApplicationListener() { - @Override Log initLogger() { - return mockLog; - } - }; - - listener.onApplicationEvent(mockEvent); - - verify(mockEvent, times(1)).getApplicationContext(); - verify(mockApplicationContext, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)); - verify(mockApplicationContext, times(1)).getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class)); - verify(mockLog, times(1)).warn(startsWith("unable to create defined Indexes (if any):")); - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/config/CreateDefinedIndexesIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/config/CreateDefinedIndexesIntegrationTest.java deleted file mode 100644 index 5f5d4887..00000000 --- a/src/test/java/org/springframework/data/gemfire/config/CreateDefinedIndexesIntegrationTest.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.Serializable; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import javax.annotation.Resource; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.data.gemfire.test.support.IdentifierSequence; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.ObjectUtils; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.query.Index; -import com.gemstone.gemfire.cache.query.QueryService; - -/** - * The CreateDefinedIndexesIntegrationTest class is a test suite of test cases testing the functional behavior - * of the GemFire Cache Region Index "definition" and subsequent "creation" step in a SDG-configured application - * using a combination of "defined" and "created" Index beans in a Spring context. - * - * @author John Blum - * @see org.springframework.data.gemfire.IndexFactoryBean - * @see com.gemstone.gemfire.cache.Cache - * @see com.gemstone.gemfire.cache.Region - * @see com.gemstone.gemfire.cache.query.Index - * @see com.gemstone.gemfire.cache.query.QueryService - * @since 1.7.0 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@SuppressWarnings("unused") -public class CreateDefinedIndexesIntegrationTest { - - private static final List definedIndexNames = new ArrayList(3); - - @Autowired - private Cache gemfireCache; - - @Autowired - @Qualifier("IdIdx") - private Index id; - - @Autowired - @Qualifier("BirthDateIdx") - private Index birthDate; - - @Autowired - @Qualifier("FullNameIdx") - private Index fullName; - - @Autowired - @Qualifier("LastNameIdx") - private Index lastName; - - @Resource(name = "People") - private Region people; - - protected static Date createBirthDate(final int year, final int month, final int dayOfMonth) { - Calendar birthDate = Calendar.getInstance(); - birthDate.clear(); - birthDate.set(Calendar.YEAR, year); - birthDate.set(Calendar.MONTH, month); - birthDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); - return birthDate.getTime(); - } - - protected static Person createPerson(final String firstName, final String lastName, final Date birthDate) { - return createPerson(IdentifierSequence.nextId(), firstName, lastName, birthDate); - } - - protected static Person createPerson(final Long id, final String firstName, final String lastName, final Date birthDate) { - return new Person(id, firstName, lastName, birthDate); - } - - protected static Person put(final Region people, final Person person) { - people.put(person.getId(), person); - return person; - } - - @Before - public void setup() { - put(people, createPerson("Jon", "Doe", createBirthDate(1989, Calendar.NOVEMBER, 11))); - put(people, createPerson("Jane", "Doe", createBirthDate(1991, Calendar.APRIL, 4))); - put(people, createPerson("Pie", "Doe", createBirthDate(2008, Calendar.JUNE, 21))); - put(people, createPerson("Cookie", "Doe", createBirthDate(2008, Calendar.AUGUST, 14))); - } - - @Test - public void indexesCreated() { - QueryService queryService = gemfireCache.getQueryService(); - - //System.out.printf("GemFire Cache Indexes: %1$s%n", queryService.getIndexes()); - //System.out.printf("/Example Region Indexes: %1$s%n", queryService.getIndexes(people)); - - assertTrue(definedIndexNames.containsAll(Arrays.asList(id.getName(), birthDate.getName(), fullName.getName()))); - assertEquals(id, queryService.getIndex(people, id.getName())); - assertEquals(birthDate, queryService.getIndex(people, birthDate.getName())); - assertEquals(fullName, queryService.getIndex(people, fullName.getName())); - assertEquals(lastName, queryService.getIndex(people, lastName.getName())); - } - - public static class IndexBeanPostProcessor implements BeanPostProcessor { - - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof Index) { - if ("LastNameIdx".equals(beanName)) { - assertTrue(CacheFactory.getAnyInstance().getQueryService().getIndexes().contains(bean)); - assertTrue(beanName.equalsIgnoreCase(((Index) bean).getName())); - } - else { - definedIndexNames.add(beanName); - } - } - - return bean; - } - } - - public static class Person implements Serializable { - - protected static final String BIRTH_DATE_FORMAT_PATTERN = "yyyy/MM/dd"; - - private Date birthDate; - - private Long id; - - private String firstName; - private String lastName; - - public Person() { - } - - public Person(final Long id) { - this.id = id; - } - - public Person(final String firstName, final String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public Person(final String firstName, final String lastName, final Date birthDate) { - this(firstName, lastName); - this.birthDate = (birthDate != null ? (Date) birthDate.clone() : null); - } - - public Person(final Long id, final String firstName, final String lastName, final Date birthDate) { - this(firstName, lastName, birthDate); - this.id = id; - } - - public Long getId() { - return id; - } - - public Date getBirthDate() { - return birthDate; - } - - public String getFirstName() { - return firstName; - } - - public String getFullName() { - return String.format("%1$s %2$s", getFirstName(), getLastName()); - } - - public String getLastName() { - return lastName; - } - - protected static boolean equalsIgnoreNull(final Object obj1, final Object obj2) { - return (obj1 == null ? obj2 == null : obj1.equals(obj2)); - } - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - - if (!(obj instanceof Person)) { - return false; - } - - Person that = (Person) obj; - - return equalsIgnoreNull(getId(), that.getId()) - && (ObjectUtils.nullSafeEquals(getBirthDate(), that.getBirthDate())) - && (ObjectUtils.nullSafeEquals(getFirstName(), that.getFirstName()) - && (ObjectUtils.nullSafeEquals(getLastName(), that.getLastName()))); - } - - @Override - public int hashCode() { - int hashValue = 17; - hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getId()); - hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getBirthDate()); - hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getFirstName()); - hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getLastName()); - return hashValue; - } - - protected static String toString(final Date dateTime, final String DATE_FORMAT_PATTERN) { - return (dateTime == null ? null : new SimpleDateFormat(DATE_FORMAT_PATTERN).format(dateTime)); - } - - @Override - public String toString() { - return String.format("{ @type = %1$s, id = %2$d, firstName = %3$s, lastName = %4$s, birthDate = %5$s }", - getClass().getName(), getId(), getFirstName(), getLastName(), - toString(getBirthDate(), BIRTH_DATE_FORMAT_PATTERN)); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessorTest.java b/src/test/java/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessorTest.java deleted file mode 100644 index 79571134..00000000 --- a/src/test/java/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessorTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.data.gemfire.config; - -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.FileSystemUtils; - -/** - * The DiskStoreBeanPostProcessorTest class is a test suite of test cases testing the contract and functionality of - * the DiskStoreBeanPostProcessor class. - * - * @author John Blum - * @see org.junit.Test - * @see org.junit.runner.RunWith - * @see org.springframework.data.gemfire.config.DiskStoreBeanPostProcessor - * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @since 1.5.0 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class) -public class DiskStoreBeanPostProcessorTest { - - @BeforeClass - public static void testSuiteSetup() { - assertTrue("Failed to created directory './gemfire/disk-stores/local/ds2'!", - new File("./gemfire/disk-stores/local/ds2").mkdirs()); - } - - @AfterClass - public static void testSuiteTearDown() { - assertTrue("Failed to delete directory './gemfire'!", FileSystemUtils.deleteRecursively(new File("./gemfire"))); - assertTrue("Failed to delete directory './gfe'!", FileSystemUtils.deleteRecursively(new File("./gfe"))); - } - - @Test - public void testDiskStoreDirectoryLocationsExist() { - assertTrue(new File("./gemfire/disk-stores/ds1").isDirectory()); - assertTrue(new File("./gemfire/disk-stores/local/ds2").isDirectory()); - assertTrue(new File("./gemfire/disk-stores/remote/ds2").isDirectory()); - assertTrue(new File("./gfe/ds/local/store3").isDirectory()); - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java b/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java new file mode 100644 index 00000000..f36b80bd --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/support/AutoRegionLookupBeanPostProcessorUnitTests.java @@ -0,0 +1,267 @@ +/* + * Copyright 2012 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.springframework.data.gemfire.config.support; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +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.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import com.gemstone.gemfire.cache.GemFireCache; +import com.gemstone.gemfire.cache.Region; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.data.gemfire.util.CollectionUtils; + +/** + * Unit tests for {@link AutoRegionLookupBeanPostProcessor}. + * + * @author John Blum + * @see org.junit.Test + * @see org.mockito.Mock + * @see org.mockito.Mockito + * @see org.mockito.runners.MockitoJUnitRunner + * @see org.springframework.data.gemfire.config.support.AutoRegionLookupBeanPostProcessor + * @since 1.9.0 + */ +@RunWith(MockitoJUnitRunner.class) +public class AutoRegionLookupBeanPostProcessorUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessor; + + @Mock + private ConfigurableListableBeanFactory mockBeanFactory; + + @Before + public void setup() { + autoRegionLookupBeanPostProcessor = new AutoRegionLookupBeanPostProcessor(); + } + + protected Region mockRegion(String regionFullPath) { + Region mockRegion = mock(Region.class); + when(mockRegion.getFullPath()).thenReturn(regionFullPath); + when(mockRegion.getName()).thenReturn(toRegionName(regionFullPath)); + return mockRegion; + } + + protected String toRegionName(String regionFullPath) { + int index = regionFullPath.lastIndexOf(Region.SEPARATOR); + return (index > -1 ? regionFullPath.substring(index + 1) : regionFullPath); + } + + @Test + public void setAndGetBeanFactory() { + autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory); + + assertThat(autoRegionLookupBeanPostProcessor.getBeanFactory()).isSameAs(mockBeanFactory); + } + + @Test + public void setBeanFactoryToIncompatibleBeanFactoryType() { + BeanFactory mockBeanFactory = mock(BeanFactory.class); + + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage(String.format("BeanFactory [%1$s] must be an instance of %2$s", + mockBeanFactory.getClass().getName(), ConfigurableListableBeanFactory.class.getSimpleName())); + + autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory); + } + + @Test + public void setBeanFactoryToNull() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage(String.format("BeanFactory [null] must be an instance of %s", + ConfigurableListableBeanFactory.class.getSimpleName())); + + autoRegionLookupBeanPostProcessor.setBeanFactory(null); + } + + @Test + public void getBeanFactoryUninitialized() { + exception.expect(IllegalStateException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("BeanFactory was not properly initialized"); + + autoRegionLookupBeanPostProcessor.getBeanFactory(); + } + + @Test + public void postProcessBeforeInitializationReturnsBean() { + Object bean = new Object(); + + assertThat(autoRegionLookupBeanPostProcessor.postProcessBeforeInitialization(bean, "test")).isSameAs(bean); + } + + @Test + public void postProcessAfterInitializationWithNonGemFireCacheBean() { + Object bean = new Object(); + + AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessorSpy = + spy(this.autoRegionLookupBeanPostProcessor); + + assertThat(autoRegionLookupBeanPostProcessorSpy.postProcessAfterInitialization(bean, "test")).isSameAs(bean); + + verify(autoRegionLookupBeanPostProcessorSpy, never()).registerCacheRegionsAsBeans(any(GemFireCache.class)); + } + + @Test + public void registerCacheRegionsAsBeansIsSuccessful() { + Set> expected = CollectionUtils.asSet(mockRegion("one"), mockRegion("two"), mockRegion("three")); + final Set> actual = new HashSet>(expected.size()); + + AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessor = new AutoRegionLookupBeanPostProcessor() { + @Override void registerCacheRegionAsBean(Region region) { + actual.add(region); + } + }; + + GemFireCache mockGemFireCache = mock(GemFireCache.class); + + when(mockGemFireCache.rootRegions()).thenReturn(expected); + + autoRegionLookupBeanPostProcessor.registerCacheRegionsAsBeans(mockGemFireCache); + + assertThat(actual).isEqualTo(expected); + + verify(mockGemFireCache, times(1)).rootRegions(); + + for (Region region : expected) { + verifyZeroInteractions(region); + } + } + + @Test + public void registerCacheRegionAsBeanIsSuccessful() { + Region mockRegion = mockRegion("Example"); + + when(mockRegion.subregions(anyBoolean())).thenReturn(Collections.>emptySet()); + when(mockBeanFactory.containsBean(anyString())).thenReturn(false); + + autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory); + autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(mockRegion); + + verify(mockBeanFactory, times(1)).containsBean(eq("Example")); + verify(mockBeanFactory, times(1)).registerSingleton(eq("Example"), eq(mockRegion)); + verify(mockRegion, times(1)).getFullPath(); + verify(mockRegion, times(1)).getName(); + verify(mockRegion, times(1)).subregions(eq(false)); + } + + @Test + public void registerCacheRegionAsBeanRegistersSubRegionIgnoresRootRegion() { + Region mockRootRegion = mockRegion("Root"); + Region mockSubRegion = mockRegion("/Root/Sub"); + + when(mockRootRegion.subregions(anyBoolean())).thenReturn(CollectionUtils.>asSet(mockSubRegion)); + when(mockSubRegion.subregions(anyBoolean())).thenReturn(Collections.>emptySet()); + when(mockBeanFactory.containsBean(eq("Root"))).thenReturn(true); + when(mockBeanFactory.containsBean(eq("/Root/Sub"))).thenReturn(false); + + autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory); + autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(mockRootRegion); + + verify(mockBeanFactory, times(1)).containsBean(eq("Root")); + verify(mockBeanFactory, times(1)).containsBean(eq("/Root/Sub")); + verify(mockBeanFactory, never()).registerSingleton(eq("Root"), eq(mockRootRegion)); + verify(mockBeanFactory, times(1)).registerSingleton(eq("/Root/Sub"), eq(mockSubRegion)); + verify(mockRootRegion, times(1)).getFullPath(); + verify(mockRootRegion, times(1)).getName(); + verify(mockRootRegion, times(1)).subregions(eq(false)); + verify(mockSubRegion, times(1)).getFullPath(); + verify(mockSubRegion, never()).getName(); + verify(mockSubRegion, times(1)).subregions(eq(false)); + } + + @Test + public void registerNullCacheRegionAsBeanDoesNothing() { + autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory); + autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(null); + + verifyZeroInteractions(mockBeanFactory); + } + + @Test + public void getBeanNameReturnsRegionFullPath() { + Region mockRegion = mockRegion("/Parent/Child"); + + assertThat(autoRegionLookupBeanPostProcessor.getBeanName(mockRegion)).isEqualTo("/Parent/Child"); + + verify(mockRegion, times(1)).getFullPath(); + verify(mockRegion, never()).getName(); + } + + @Test + public void getBeanNameReturnsRegionName() { + Region mockRegion = mockRegion("/Example"); + + assertThat(autoRegionLookupBeanPostProcessor.getBeanName(mockRegion)).isEqualTo("Example"); + + verify(mockRegion, times(1)).getFullPath(); + verify(mockRegion, times(1)).getName(); + } + + @Test + public void nullSafeSubRegionsWhenSubRegionsIsNotNull() { + Set> mockSubRegions = CollectionUtils.asSet(mockRegion("one"), mockRegion("two")); + Region mockRegion = mockRegion("parent"); + + when(mockRegion.subregions(anyBoolean())).thenReturn(mockSubRegions); + + assertThat(autoRegionLookupBeanPostProcessor.nullSafeSubregions(mockRegion)).isEqualTo(mockSubRegions); + + verify(mockRegion, times(1)).subregions(eq(false)); + } + + @Test + public void nullSafeSubRegionsWhenSubRegionsIsNull() { + Region mockRegion = mockRegion("parent"); + + when(mockRegion.subregions(anyBoolean())).thenReturn(null); + + assertThat(autoRegionLookupBeanPostProcessor.nullSafeSubregions(mockRegion)).isEqualTo(Collections.emptySet()); + + verify(mockRegion, times(1)).subregions(eq(false)); + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionAndPoolBeanFactoryPostProcessorTests.java b/src/test/java/org/springframework/data/gemfire/config/support/ClientRegionPoolBeanFactoryPostProcessorUnitTests.java similarity index 65% rename from src/test/java/org/springframework/data/gemfire/config/ClientRegionAndPoolBeanFactoryPostProcessorTests.java rename to src/test/java/org/springframework/data/gemfire/config/support/ClientRegionPoolBeanFactoryPostProcessorUnitTests.java index ecf06221..69c5e404 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionAndPoolBeanFactoryPostProcessorTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/support/ClientRegionPoolBeanFactoryPostProcessorUnitTests.java @@ -15,13 +15,9 @@ * */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; @@ -33,13 +29,9 @@ import static org.mockito.Mockito.when; import java.util.Arrays; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.internal.matchers.VarargMatcher; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValue; @@ -47,32 +39,28 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.PoolFactoryBean; +import org.springframework.data.gemfire.test.support.MockitoMatchers; +import org.springframework.data.gemfire.util.ArrayUtils; /** - * The ClientRegionAndPoolBeanFactoryPostProcessorTests class is a test suite of test cases testing the contract - * and functionality of the {@link ClientRegionAndPoolBeanFactoryPostProcessor} class. + * Unit tests for {@link ClientRegionPoolBeanFactoryPostProcessor}. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.mockito.Mock * @see org.mockito.Mockito * @see org.mockito.runners.MockitoJUnitRunner - * @see org.springframework.data.gemfire.config.ClientRegionAndPoolBeanFactoryPostProcessor + * @see ClientRegionPoolBeanFactoryPostProcessor * @since 1.8.2 */ @RunWith(MockitoJUnitRunner.class) -public class ClientRegionAndPoolBeanFactoryPostProcessorTests { +public class ClientRegionPoolBeanFactoryPostProcessorUnitTests { @Mock private BeanDefinition mockBeanDefinition; - private ClientRegionAndPoolBeanFactoryPostProcessor beanFactoryPostProcessor = - new ClientRegionAndPoolBeanFactoryPostProcessor(); - - protected static T[] asArray(T... array) { - return array; - } + private ClientRegionPoolBeanFactoryPostProcessor beanFactoryPostProcessor = + new ClientRegionPoolBeanFactoryPostProcessor(); protected PropertyValue newPropertyValue(String name, Object value) { return new PropertyValue(name, value); @@ -82,10 +70,6 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests { return new MutablePropertyValues(Arrays.asList(propertyValues)); } - protected Matcher stringArrayMatcher(String... expected) { - return new ArrayMatcher(expected); - } - @Test public void postProcessBeanFactory() { BeanDefinition mockClientRegionBeanOne = mock(BeanDefinition.class, "MockClientRegionBeanOne"); @@ -99,16 +83,16 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests { when(mockPoolBean.getBeanClassName()).thenReturn(PoolFactoryBean.class.getName()); when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName()); when(mockBeanFactory.getBeanDefinitionNames()).thenReturn( - asArray("mockClientRegionBeanOne", "mockClientRegionBeanTwo", "mockGenericBean", "mockPoolBean")); + ArrayUtils.asArray("mockClientRegionBeanOne", "mockClientRegionBeanTwo", "mockGenericBean", "mockPoolBean")); when(mockBeanFactory.getBeanDefinition(eq("mockClientRegionBeanOne"))).thenReturn(mockClientRegionBeanOne); when(mockBeanFactory.getBeanDefinition(eq("mockClientRegionBeanTwo"))).thenReturn(mockClientRegionBeanTwo); when(mockBeanFactory.getBeanDefinition(eq("mockGenericBean"))).thenReturn(mockBeanDefinition); when(mockBeanFactory.getBeanDefinition(eq("mockPoolBean"))).thenReturn(mockPoolBean); - when(mockClientRegionBeanOne.getDependsOn()).thenReturn(asArray("mockClientCacheBean")); + when(mockClientRegionBeanOne.getDependsOn()).thenReturn(ArrayUtils.asArray("mockClientCacheBean")); when(mockClientRegionBeanOne.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue( - ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "mockPoolBean"))); + ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "mockPoolBean"))); when(mockClientRegionBeanTwo.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue( - ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "DEFAULT"))); + ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "DEFAULT"))); beanFactoryPostProcessor.postProcessBeanFactory(mockBeanFactory); @@ -121,8 +105,8 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests { verify(mockClientRegionBeanOne, times(1)).getBeanClassName(); verify(mockClientRegionBeanOne, times(1)).getPropertyValues(); verify(mockClientRegionBeanOne, times(1)).getDependsOn(); - verify(mockClientRegionBeanOne, times(1)).setDependsOn(argThat(stringArrayMatcher( - "mockClientCacheBean", "mockPoolBean"))); + verify(mockClientRegionBeanOne, times(1)).setDependsOn(argThat( + MockitoMatchers.stringArrayMatcher("mockClientCacheBean", "mockPoolBean"))); verify(mockClientRegionBeanTwo, times(1)).getBeanClassName(); verify(mockClientRegionBeanTwo, times(1)).getPropertyValues(); verify(mockClientRegionBeanTwo, never()).getDependsOn(); @@ -133,83 +117,43 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests { @Test public void isClientRegionBeanReturnsFalse() { when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName()); - assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition), is(false)); + assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition)).isFalse(); verify(mockBeanDefinition, times(1)).getBeanClassName(); } @Test public void isClientRegionBeanReturnsTrue() { when(mockBeanDefinition.getBeanClassName()).thenReturn(ClientRegionFactoryBean.class.getName()); - assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition), is(true)); + assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition)).isTrue(); verify(mockBeanDefinition, times(1)).getBeanClassName(); } @Test public void isPoolBeanReturnsFalse() { when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName()); - assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition), is(false)); + assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition)).isFalse(); verify(mockBeanDefinition, times(1)).getBeanClassName(); } @Test public void isPoolBeanReturnsTrue() { when(mockBeanDefinition.getBeanClassName()).thenReturn(PoolFactoryBean.class.getName()); - assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition), is(true)); + assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition)).isTrue(); verify(mockBeanDefinition, times(1)).getBeanClassName(); } + @Test + public void getPoolNameWhenPoolNamePropertyIsSpecifiedReturnsPoolBeanName() { + when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue( + ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "testPoolName"))); + assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition)).isEqualTo("testPoolName"); + verify(mockBeanDefinition, times(1)).getPropertyValues(); + } + @Test public void getPoolNameWhenPoolNamePropertyIsUnspecifiedReturnsNull() { when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues()); - assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition), is(nullValue(String.class))); + assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition)).isNull(); verify(mockBeanDefinition, times(1)).getPropertyValues(); } - - @Test - public void getPoolNameReturnsPoolBeanName() { - when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue( - ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "testPoolName"))); - assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition), is(equalTo("testPoolName"))); - verify(mockBeanDefinition, times(1)).getPropertyValues(); - } - - @Test - public void addDependsOnToExistingDependencies() { - when(mockBeanDefinition.getDependsOn()).thenReturn(asArray("testBeanNameOne", "testBeanNameTwo")); - assertThat(beanFactoryPostProcessor.addDependsOn(mockBeanDefinition, "testBeanNameThree"), - is(sameInstance(mockBeanDefinition))); - verify(mockBeanDefinition, times(1)).getDependsOn(); - verify(mockBeanDefinition, times(1)).setDependsOn(argThat(stringArrayMatcher( - "testBeanNameOne", "testBeanNameTwo", "testBeanNameThree"))); - } - - @Test - public void addDependsOnToNonExistingDependencies() { - when(mockBeanDefinition.getDependsOn()).thenReturn(null); - assertThat(beanFactoryPostProcessor.addDependsOn(mockBeanDefinition, "testBeanName"), - is(sameInstance(mockBeanDefinition))); - verify(mockBeanDefinition, times(1)).getDependsOn(); - verify(mockBeanDefinition, times(1)).setDependsOn(argThat(stringArrayMatcher("testBeanName"))); - } - - protected static final class ArrayMatcher extends BaseMatcher implements VarargMatcher { - - private final T[] expected; - - protected ArrayMatcher(T... expected) { - this.expected = expected; - } - - @Override - public boolean matches(Object item) { - Object[] actual = (item instanceof Object[] ? (Object[]) item : asArray(item)); - - return Arrays.equals(actual, expected); - } - - @Override - public void describeTo(Description description) { - description.appendText(String.format("expected (%1$s)", this.expected)); - } - } } diff --git a/src/test/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessorTest.java b/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java similarity index 62% rename from src/test/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessorTest.java rename to src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java index efb29869..87a9d37e 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CustomEditorRegisteringBeanFactoryPostProcessorTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/support/CustomEditorBeanFactoryPostProcessorUnitTests.java @@ -14,16 +14,21 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.ExpirationAction; +import com.gemstone.gemfire.cache.InterestPolicy; +import com.gemstone.gemfire.cache.InterestResultPolicy; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.wan.GatewaySender; import org.junit.Test; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -41,34 +46,38 @@ import org.springframework.data.gemfire.client.InterestResultPolicyConverter; import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy; import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter; import org.springframework.data.gemfire.support.ConnectionEndpoint; +import org.springframework.data.gemfire.support.ConnectionEndpointList; import org.springframework.data.gemfire.wan.OrderPolicyConverter; - -import com.gemstone.gemfire.cache.EvictionAction; -import com.gemstone.gemfire.cache.ExpirationAction; -import com.gemstone.gemfire.cache.InterestPolicy; -import com.gemstone.gemfire.cache.InterestResultPolicy; -import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.cache.wan.GatewaySender; +import org.springframework.util.StringUtils; /** - * The CustomEditorRegisteringBeanFactoryPostProcessorTest class... + * Unit tests for {@link CustomEditorBeanFactoryPostProcessor}. * * @author John Blum * @see org.junit.Test - * @see CustomEditorRegisteringBeanFactoryPostProcessor + * @see org.mockito.Mockito + * @see CustomEditorBeanFactoryPostProcessor * @since 1.6.0 */ @SuppressWarnings("deprecation") -public class CustomEditorRegisteringBeanFactoryPostProcessorTest { +public class CustomEditorBeanFactoryPostProcessorUnitTests { + + protected ConnectionEndpoint newConnectionEndpoint(String host, int port) { + return new ConnectionEndpoint(host, port); + } @Test - public void customEditorRegistration() { + public void customEditorRegistrationIsSuccessful() { ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class); - new CustomEditorRegisteringBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory); + new CustomEditorBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory); + verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint.class), + eq(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointConverter.class)); //verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint[].class), - // eq(CustomEditorRegisteringBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.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), @@ -89,32 +98,55 @@ public class CustomEditorRegisteringBeanFactoryPostProcessorTest { verify(mockBeanFactory, times(1)).registerCustomEditor(eq(Scope.class), eq(ScopeConverter.class)); verify(mockBeanFactory, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class), eq(SubscriptionEvictionPolicyConverter.class)); - } - - protected ConnectionEndpoint newConnectionEndpoint(String host, int port) { - return new ConnectionEndpoint(host, port); + verifyNoMoreInteractions(mockBeanFactory); } @Test @SuppressWarnings("unchecked") - public void connectionEndpointArrayToIterableConversion() { + public void connectionEndpointArrayToIterableConversionIsSuccessful() { ConnectionEndpoint[] array = { newConnectionEndpoint("localhost", 10334), newConnectionEndpoint("localhost", 40404) }; - Iterable iterable = new CustomEditorRegisteringBeanFactoryPostProcessor + Iterable iterable = new CustomEditorBeanFactoryPostProcessor .ConnectionEndpointArrayToIterableConverter().convert(array); - assertThat(iterable, is(notNullValue())); + assertThat(iterable).isNotNull(); int index = 0; for (ConnectionEndpoint connectionEndpoint : iterable) { - assertThat(connectionEndpoint, is(equalTo(array[index++]))); + assertThat(connectionEndpoint).isEqualTo(array[index++]); } - assertThat(index, is(equalTo(2))); + assertThat(index).isEqualTo(array.length); } + @Test + public void stringToConnectionEndpointConversionIsSuccessful() { + String hostPort = "skullbox[54321]"; + + ConnectionEndpoint connectionEndpoint = new CustomEditorBeanFactoryPostProcessor + .StringToConnectionEndpointConverter().convert(hostPort); + + assertThat(connectionEndpoint).isNotNull(); + assertThat(connectionEndpoint.getHost()).isEqualTo("skullbox"); + assertThat(connectionEndpoint.getPort()).isEqualTo(54321); + } + + @Test + public void stringToConnectionEndpointListConversionIsSuccessful() { + String[] hostsPorts = { "toolbox[10334]", "skullbox", "[40404]" }; + String source = StringUtils.arrayToCommaDelimitedString(hostsPorts); + + ConnectionEndpointList connectionEndpoints = new CustomEditorBeanFactoryPostProcessor + .StringToConnectionEndpointListConverter().convert(source); + + assertThat(connectionEndpoints).isNotNull(); + assertThat(connectionEndpoints.size()).isEqualTo(hostsPorts.length); + assertThat(connectionEndpoints.findOne("toolbox").getPort()).isEqualTo(10334); + assertThat(connectionEndpoints.findOne("skullbox").getPort()).isEqualTo(0); + assertThat(connectionEndpoints.findOne(40404).getHost()).isEqualTo("localhost"); + } } diff --git a/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListenerUnitTests.java b/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListenerUnitTests.java new file mode 100644 index 00000000..7c435a10 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesApplicationListenerUnitTests.java @@ -0,0 +1,137 @@ +/* + * Copyright 2010-2013 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.gemfire.config.support; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Matchers.startsWith; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.HashMap; + +import com.gemstone.gemfire.cache.query.MultiIndexCreationException; +import com.gemstone.gemfire.cache.query.QueryService; + +import org.apache.commons.logging.Log; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.context.ApplicationContext; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.data.gemfire.config.xml.GemfireConstants; + +/** + * Unit tests for {@link DefinedIndexesApplicationListener}. + * + * @author John Blum + * @see org.junit.Test + * @see org.mockito.Mockito + * @see org.mockito.runners.MockitoJUnitRunner + * @see DefinedIndexesApplicationListener + * @since 1.7.0 + */ +@RunWith(MockitoJUnitRunner.class) +public class DefinedIndexesApplicationListenerUnitTests { + + private static final String QUERY_SERVICE_BEAN_NAME = + GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE; + + @Mock + private ApplicationContext mockApplicationContext; + + @Mock + private ContextRefreshedEvent mockEvent; + + private DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener(); + + @Mock + private QueryService mockQueryService; + + @Before + public void setup() { + when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext); + } + + protected HashMap newHashMap(K key, V value) { + return new HashMap(Collections.singletonMap(key, value)); + } + + protected MultiIndexCreationException newMultiIndexCreationException(String key, Exception cause) { + return new MultiIndexCreationException(newHashMap(key, cause)); + } + + @Test + public void createDefinedIndexesCalledOnContextRefreshedEvent() throws Exception { + when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true); + when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class))) + .thenReturn(mockQueryService); + + listener.onApplicationEvent(mockEvent); + + verify(mockEvent, times(1)).getApplicationContext(); + verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME)); + verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)); + verify(mockQueryService, times(1)).createDefinedIndexes(); + } + + @Test + public void createDefinedIndexesNotCalledOnContextRefreshedEvent() throws Exception { + when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(false); + + listener.onApplicationEvent(mockEvent); + + verify(mockEvent, times(1)).getApplicationContext(); + verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME)); + verify(mockApplicationContext, never()).getBean(anyString(), any(QueryService.class)); + verify(mockQueryService, never()).createDefinedIndexes(); + } + + @Test + public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception { + when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true); + when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class))) + .thenReturn(mockQueryService); + when(mockQueryService.createDefinedIndexes()) + .thenThrow(newMultiIndexCreationException("TestKey", new RuntimeException("TEST"))); + + final Log mockLog = mock(Log.class); + + DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener() { + @Override Log initLogger() { + return mockLog; + } + }; + + listener.onApplicationEvent(mockEvent); + + verify(mockEvent, times(1)).getApplicationContext(); + verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME)); + verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)); + verify(mockQueryService, times(1)).createDefinedIndexes(); + verify(mockLog, times(1)).warn(startsWith("Failed to create pre-defined Indexes:"), + isA(MultiIndexCreationException.class)); + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesIntegrationTests.java new file mode 100644 index 00000000..de3d2d9e --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/support/DefinedIndexesIntegrationTests.java @@ -0,0 +1,227 @@ +/* + * Copyright 2010-2013 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.gemfire.config.support; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.data.gemfire.test.model.Person.newBirthDate; +import static org.springframework.data.gemfire.test.model.Person.newPerson; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.List; + +import javax.annotation.Resource; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.GemFireCache; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.query.Index; +import com.gemstone.gemfire.cache.query.QueryService; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.DependsOn; +import org.springframework.data.gemfire.IndexFactoryBean; +import org.springframework.data.gemfire.IndexType; +import org.springframework.data.gemfire.PartitionedRegionFactoryBean; +import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; +import org.springframework.data.gemfire.test.model.Gender; +import org.springframework.data.gemfire.test.model.Person; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Integration tests for {@link DefinedIndexesApplicationListener}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.IndexFactoryBean + * @see com.gemstone.gemfire.cache.Cache + * @see com.gemstone.gemfire.cache.Region + * @see com.gemstone.gemfire.cache.query.Index + * @see com.gemstone.gemfire.cache.query.QueryService + * @since 1.7.0 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +@SuppressWarnings("unused") +public class DefinedIndexesIntegrationTests { + + private static final List definedIndexNames = new ArrayList(3); + + @Autowired + private Cache gemfireCache; + + @Autowired + @Qualifier("IdIdx") + private Index id; + + @Autowired + @Qualifier("BirthDateIdx") + private Index birthDate; + + @Autowired + @Qualifier("LastNameIdx") + private Index lastName; + + @Autowired + @Qualifier("NameIdx") + private Index name; + + @Resource(name = "People") + private Region people; + + protected static Person put(Region people, Person person) { + people.put(person.getId(), person); + return person; + } + + @Before + public void setup() { + put(people, newPerson("Jon", "Doe", newBirthDate(1989, Calendar.NOVEMBER, 11), Gender.MALE)); + put(people, newPerson("Jane", "Doe", newBirthDate(1991, Calendar.APRIL, 4), Gender.FEMALE)); + put(people, newPerson("Pie", "Doe", newBirthDate(2008, Calendar.JUNE, 21), Gender.FEMALE)); + put(people, newPerson("Cookie", "Doe", newBirthDate(2008, Calendar.AUGUST, 14), Gender.FEMALE)); + } + + @Test + public void indexesCreated() { + QueryService queryService = gemfireCache.getQueryService(); + + List expectedDefinedIndexNames = Arrays.asList(id.getName(), birthDate.getName(), name.getName()); + + assertThat(definedIndexNames).isEqualTo(expectedDefinedIndexNames); + assertThat(id).isEqualTo(queryService.getIndex(people, id.getName())); + assertThat(birthDate).isEqualTo(queryService.getIndex(people, birthDate.getName())); + assertThat(lastName).isEqualTo(queryService.getIndex(people, lastName.getName())); + assertThat(name).isEqualTo(queryService.getIndex(people, name.getName())); + } + + @PeerCacheApplication(logLevel = "warning") + static class DefinedIndexesConfiguration { + + @Bean + // TODO remove when the Annotation config model includes support + DefinedIndexesApplicationListener indexApplicationListener() { + return new DefinedIndexesApplicationListener(); + } + + @Bean + BeanPostProcessor indexBeanPostProcessor() { + return new BeanPostProcessor() { + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + if (bean instanceof Index) { + if ("LastNameIdx".equals(beanName)) { + assertThat(CacheFactory.getAnyInstance().getQueryService().getIndexes().contains(bean)).isTrue(); + assertThat(beanName).isEqualToIgnoringCase(((Index) bean).getName()); + } + else { + definedIndexNames.add(beanName); + } + } + + return bean; + } + }; + } + + @Bean(name = "People") + PartitionedRegionFactoryBean peopleRegion(Cache gemfireCache) { + PartitionedRegionFactoryBean peopleRegion = new PartitionedRegionFactoryBean(); + + peopleRegion.setCache(gemfireCache); + peopleRegion.setClose(false); + peopleRegion.setPersistent(false); + + return peopleRegion; + } + + @Bean(name = "IdIdx") + @DependsOn("People") + IndexFactoryBean idIndex(GemFireCache gemFireCache) { + IndexFactoryBean idIndex = new IndexFactoryBean(); + + idIndex.setCache(gemFireCache); + idIndex.setDefine(true); + idIndex.setExpression("id"); + idIndex.setFrom("/People"); + idIndex.setName("IdIdx"); + idIndex.setType(IndexType.KEY); + + return idIndex; + } + + @Bean(name = "BirthDateIdx") + @DependsOn("People") + IndexFactoryBean birthDateIndex(GemFireCache gemFireCache) { + IndexFactoryBean birthDateIndex = new IndexFactoryBean(); + + birthDateIndex.setCache(gemFireCache); + birthDateIndex.setDefine(true); + birthDateIndex.setExpression("birthDate"); + birthDateIndex.setFrom("/People"); + birthDateIndex.setName("BirthDateIdx"); + birthDateIndex.setType(IndexType.HASH); + + return birthDateIndex; + } + + @Bean(name = "LastNameIdx") + @DependsOn("People") + IndexFactoryBean lastNameIndex(GemFireCache gemFireCache) { + IndexFactoryBean lastNameIndex = new IndexFactoryBean(); + + lastNameIndex.setCache(gemFireCache); + lastNameIndex.setExpression("lastName"); + lastNameIndex.setFrom("/People"); + lastNameIndex.setName("LastNameIdx"); + lastNameIndex.setType(IndexType.HASH); + + return lastNameIndex; + } + + @Bean(name = "NameIdx") + @DependsOn("People") + IndexFactoryBean nameIndex(GemFireCache gemFireCache) { + IndexFactoryBean nameIndex = new IndexFactoryBean(); + + nameIndex.setCache(gemFireCache); + nameIndex.setDefine(true); + nameIndex.setExpression("name"); + nameIndex.setFrom("/People"); + nameIndex.setName("NameIdx"); + nameIndex.setType(IndexType.FUNCTIONAL); + + return nameIndex; + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/support/DiskStoreBeanPostProcessorIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/support/DiskStoreBeanPostProcessorIntegrationTests.java new file mode 100644 index 00000000..79b72c12 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/support/DiskStoreBeanPostProcessorIntegrationTests.java @@ -0,0 +1,108 @@ +/* + * Copyright 2010-2013 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.gemfire.config.support; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.util.Arrays; +import java.util.Collections; + +import com.gemstone.gemfire.cache.GemFireCache; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.context.annotation.Bean; +import org.springframework.data.gemfire.DiskStoreFactoryBean; +import org.springframework.data.gemfire.config.annotation.PeerCacheApplication; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.FileSystemUtils; + +/** + * Integration tests for {@link DiskStoreBeanPostProcessor}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.config.support.DiskStoreBeanPostProcessor + * @since 1.5.0 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class DiskStoreBeanPostProcessorIntegrationTests { + + @BeforeClass + public static void testSuiteSetup() { + assertThat(new File("./gemfire/disk-stores/ds2/local").mkdirs()).isTrue(); + } + + @AfterClass + public static void testSuiteTearDown() { + assertThat(FileSystemUtils.deleteRecursively(new File("./gemfire"))).isTrue(); + assertThat(FileSystemUtils.deleteRecursively(new File("./gfe"))).isTrue(); + } + + @Test + public void diskStoreDirectoriesExist() { + assertThat(new File("./gemfire/disk-stores/ds1").isDirectory()).isTrue(); + assertThat(new File("./gemfire/disk-stores/ds2/local").isDirectory()).isTrue(); + assertThat(new File("./gemfire/disk-stores/ds2/remote").isDirectory()).isTrue(); + assertThat(new File("./gfe/ds/store3/local").isDirectory()).isTrue(); + } + + @PeerCacheApplication(logLevel = "warning") + @SuppressWarnings("unused") + static class DiskStoreBeanPostProcessorConfiguration { + + DiskStoreFactoryBean.DiskDir newDiskDir(String location) { + return new DiskStoreFactoryBean.DiskDir(location); + } + + @Bean + // TODO remove when the Annotation config model includes support + DiskStoreBeanPostProcessor diskStoreBeanPostProcessor() { + return new DiskStoreBeanPostProcessor(); + } + + @Bean + DiskStoreFactoryBean diskStoreOne(GemFireCache gemfireCache) { + DiskStoreFactoryBean diskStoreOne = new DiskStoreFactoryBean(); + diskStoreOne.setCache(gemfireCache); + diskStoreOne.setDiskDirs(Collections.singletonList(newDiskDir("./gemfire/disk-stores/ds1"))); + return diskStoreOne; + } + + @Bean + DiskStoreFactoryBean diskStoreTwo(GemFireCache gemfireCache) { + DiskStoreFactoryBean diskStoreTwo = new DiskStoreFactoryBean(); + diskStoreTwo.setCache(gemfireCache); + diskStoreTwo.setDiskDirs(Arrays.asList(newDiskDir("./gemfire/disk-stores/ds2/local"), + newDiskDir("./gemfire/disk-stores/ds2/remote"))); + return diskStoreTwo; + } + + @Bean + DiskStoreFactoryBean diskStoreThree(GemFireCache gemfireCache) { + DiskStoreFactoryBean diskStoreThree = new DiskStoreFactoryBean(); + diskStoreThree.setCache(gemfireCache); + diskStoreThree.setDiskDirs(Collections.singletonList(newDiskDir("./gfe/ds/store3/local"))); + return diskStoreThree; + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/PdxDiskStoreAwareBeanFactoryPostProcessorTest.java b/src/test/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests.java similarity index 70% rename from src/test/java/org/springframework/data/gemfire/config/PdxDiskStoreAwareBeanFactoryPostProcessorTest.java rename to src/test/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests.java index ad1bbf24..8cdacf71 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PdxDiskStoreAwareBeanFactoryPostProcessorTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/support/PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests.java @@ -14,12 +14,9 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; @@ -32,6 +29,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.gemstone.gemfire.cache.DiskStore; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; +import com.gemstone.gemfire.internal.cache.PartitionedRegion; + import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -40,54 +42,45 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.data.gemfire.CacheFactoryBean; - -import com.gemstone.gemfire.cache.DiskStore; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; -import com.gemstone.gemfire.internal.cache.PartitionedRegion; +import org.springframework.data.gemfire.util.ArrayUtils; /** - * The PdxDiskStoreAwareBeanFactoryPostProcessorTest class is a test suite of test cases testing the functionality - * of the PdxDiskStoreAwareBeanFactoryPostProcessor class. + * Unit tests for {@link PdxDiskStoreAwareBeanFactoryPostProcessor}. * * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.springframework.data.gemfire.config.PdxDiskStoreAwareBeanFactoryPostProcessor + * @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor * @see com.gemstone.gemfire.cache.DiskStore * @see com.gemstone.gemfire.cache.Region * @see com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue * @since 1.3.3 */ -public class PdxDiskStoreAwareBeanFactoryPostProcessorTest { +public class PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests { - protected static String[] toStringArray(final Collection collection) { + protected static boolean isBeanType(BeanDefinition beanDefinition, Class beanType) { + return (beanDefinition instanceof AbstractBeanDefinition + && ((AbstractBeanDefinition) beanDefinition).hasBeanClass() + && beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass())); + } + + protected static String[] toStringArray(Collection collection) { return collection.toArray(new String[collection.size()]); } - protected static boolean isEmpty(final Object[] array) { - return (array == null || array.length == 0); - } - - protected static boolean isBeanType(final BeanDefinition beanDefinition, final Class beanType) { - return (beanDefinition instanceof AbstractBeanDefinition - && ((AbstractBeanDefinition) beanDefinition).hasBeanClass() - && beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass())); - } - - protected ConfigurableListableBeanFactory createMockBeanFactory(final Map beanDefinitions) { + protected ConfigurableListableBeanFactory mockBeanFactory(final Map beanDefinitions) { final ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class); when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(toStringArray(beanDefinitions.keySet())); when(mockBeanFactory.getBeanNamesForType(isA(Class.class))).then(new Answer() { @Override - public String[] answer(final InvocationOnMock invocation) throws Throwable { + public String[] answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); - assertNotNull(arguments); - assertTrue(arguments.length == 1); - assertTrue(arguments[0] instanceof Class); + assertThat(arguments).isNotNull(); + assertThat(arguments.length).isEqualTo(1); + assertThat(arguments[0]).isInstanceOf(Class.class); Class beanType = (Class) arguments[0]; @@ -107,10 +100,10 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest { when(mockBeanFactory.getBeanDefinition(anyString())).then(new Answer() { @Override - public BeanDefinition answer(final InvocationOnMock invocation) throws Throwable { + public BeanDefinition answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); - assertNotNull(arguments); - assertTrue(arguments.length == 1); + assertThat(arguments).isNotNull(); + assertThat(arguments.length).isEqualTo(1); return beanDefinitions.get(String.valueOf(arguments[0])); } }); @@ -118,7 +111,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest { return mockBeanFactory; } - protected static BeanDefinitionBuilder createBeanDefinitionBuilder(Object beanClassObject, String... dependencies) { + protected static BeanDefinitionBuilder newBeanDefinitionBuilder(Object beanClassObject, String... dependencies) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); if (beanClassObject instanceof Class) { @@ -140,28 +133,28 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest { } protected static void assertDependencies(BeanDefinition beanDefinition, String... expectedDependencies) { - assertFalse(isEmpty(beanDefinition.getDependsOn())); - assertTrue(Arrays.asList(beanDefinition.getDependsOn()).equals(Arrays.asList(expectedDependencies))); + assertThat(ArrayUtils.isEmpty(beanDefinition.getDependsOn())).isFalse(); + assertThat(Arrays.asList(beanDefinition.getDependsOn()).equals(Arrays.asList(expectedDependencies))).isTrue(); } protected BeanDefinition defineBean(String beanClassName, String... dependencies) { - return createBeanDefinitionBuilder(beanClassName, dependencies).getBeanDefinition(); + return newBeanDefinitionBuilder(beanClassName, dependencies).getBeanDefinition(); } protected BeanDefinition defineCache() { - return createBeanDefinitionBuilder(CacheFactoryBean.class).getBeanDefinition(); + return newBeanDefinitionBuilder(CacheFactoryBean.class).getBeanDefinition(); } protected BeanDefinition defineAsyncEventQueue(String... dependencies) { - return createBeanDefinitionBuilder(AsyncEventQueue.class, dependencies).getBeanDefinition(); + return newBeanDefinitionBuilder(AsyncEventQueue.class, dependencies).getBeanDefinition(); } protected BeanDefinition defineDiskStore(String... dependencies) { - return createBeanDefinitionBuilder(DiskStore.class, dependencies).getBeanDefinition(); + return newBeanDefinitionBuilder(DiskStore.class, dependencies).getBeanDefinition(); } protected BeanDefinition defineRegion(Class regionClass, String... dependencies) { - return createBeanDefinitionBuilder(regionClass, dependencies).getBeanDefinition(); + return newBeanDefinitionBuilder(regionClass, dependencies).getBeanDefinition(); } protected BeanDefinition definePartitionedRegion(String... dependencies) { @@ -173,32 +166,33 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest { } @Test(expected = IllegalArgumentException.class) - public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithBlankDiskStoreName() { + public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithBlankDiskStoreName() { new PdxDiskStoreAwareBeanFactoryPostProcessor(" "); } @Test(expected = IllegalArgumentException.class) - public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithEmptyDiskStoreName() { + public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithEmptyDiskStoreName() { new PdxDiskStoreAwareBeanFactoryPostProcessor(""); } @Test(expected = IllegalArgumentException.class) - public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithNullDiskStoreName() { + public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithNullDiskStoreName() { new PdxDiskStoreAwareBeanFactoryPostProcessor(null); } @Test - public void testInitializedPdxDiskStoreAwareBeanFactoryPostProcessor() { + public void initializedPdxDiskStoreAwareBeanFactoryPostProcessor() { PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor = new PdxDiskStoreAwareBeanFactoryPostProcessor("testPdxDiskStoreName"); - assertNotNull(postProcessor); - assertEquals("testPdxDiskStoreName", postProcessor.getPdxDiskStoreName()); + assertThat(postProcessor).isNotNull(); + assertThat(postProcessor.getPdxDiskStoreName()).isEqualTo("testPdxDiskStoreName"); } @Test - public void testPostProcessBeanFactory() { - final Map beanDefinitions = new HashMap(13); + @SuppressWarnings("all") + public void postProcessBeanFactory() { + Map beanDefinitions = new HashMap(13); beanDefinitions.put("someBean", defineBean("org.company.app.domain.SomeBean", "someOtherBean")); beanDefinitions.put("gemfireCache", defineCache()); @@ -217,17 +211,17 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest { beanDefinitions.put("region3", definePartitionedRegion()); beanDefinitions.put("region4", definePartitionedRegion("queue2")); - final ConfigurableListableBeanFactory mockBeanFactory = createMockBeanFactory(beanDefinitions); + ConfigurableListableBeanFactory mockBeanFactory = mockBeanFactory(beanDefinitions); - final PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor = + PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor = new PdxDiskStoreAwareBeanFactoryPostProcessor("pdxDiskStore"); postProcessor.postProcessBeanFactory(mockBeanFactory); assertDependencies(beanDefinitions.get("someBean"), "someOtherBean"); - assertTrue(isEmpty(beanDefinitions.get("gemfireCache").getDependsOn())); - assertTrue(isEmpty(beanDefinitions.get("pdxDiskStore").getDependsOn())); - assertTrue(isEmpty(beanDefinitions.get("someOtherBean").getDependsOn())); + assertThat(ArrayUtils.isEmpty(beanDefinitions.get("gemfireCache").getDependsOn())).isTrue(); + assertThat(ArrayUtils.isEmpty(beanDefinitions.get("pdxDiskStore").getDependsOn())).isTrue(); + assertThat(ArrayUtils.isEmpty(beanDefinitions.get("someOtherBean").getDependsOn())).isTrue(); assertDependencies(beanDefinitions.get("queue1"), "pdxDiskStore", "someOtherBean"); assertDependencies(beanDefinitions.get("overflowDiskStore"), "pdxDiskStore"); assertDependencies(beanDefinitions.get("region1"), "pdxDiskStore", "overflowDiskStore"); @@ -241,5 +235,4 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest { assertDependencies(beanDefinitions.get("region3"), "pdxDiskStore"); assertDependencies(beanDefinitions.get("region4"), "pdxDiskStore", "queue2"); } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/xml/AbstractRegionParserUnitTests.java b/src/test/java/org/springframework/data/gemfire/config/xml/AbstractRegionParserUnitTests.java new file mode 100644 index 00000000..ee571630 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/xml/AbstractRegionParserUnitTests.java @@ -0,0 +1,276 @@ +/* + * Copyright 2010-2013 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.gemfire.config.xml; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isNull; +import static org.mockito.Matchers.matches; +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.when; + +import org.junit.Test; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.beans.factory.xml.XmlReaderContext; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Unit tests for {@link AbstractRegionParser}. + * + * @author John Blum + * @see org.junit.Test + * @see org.mockito.Mockito + * @see org.springframework.data.gemfire.config.xml.AbstractRegionParser + * @since 1.3.3 + */ +// TODO add more tests +public class AbstractRegionParserUnitTests { + + private AbstractRegionParser regionParser = new TestRegionParser(); + + protected void assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate(String localName) { + Element mockElement = mock(Element.class); + + when(mockElement.getLocalName()).thenReturn(localName); + assertThat(regionParser.isRegionTemplate(mockElement)).isEqualTo(nullSafeEndsWith(localName, "-template")); + verify(mockElement, times(1)).getLocalName(); + } + + protected void assertIsSubRegionWhenElementLocalNameEndsWithRegion(String localName) { + Element mockElement = mock(Element.class); + Node mockNode = mock(Node.class); + + when(mockElement.getParentNode()).thenReturn(mockNode); + when(mockNode.getLocalName()).thenReturn(localName); + + assertThat(regionParser.isSubRegion(mockElement)).isEqualTo(nullSafeEndsWith(localName, "region")); + + verify(mockElement, times(1)).getParentNode(); + verify(mockNode, times(1)).getLocalName(); + } + + protected boolean nullSafeEndsWith(String localName, String suffix) { + return (localName != null && localName.endsWith(suffix)); + } + + @Test + public void getBeanClassIsEqualToTestRegionFactoryBean() { + AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class); + Element mockElement = mock(Element.class); + + doReturn(AbstractRegionParserUnitTests.class).when(regionParserSpy).getRegionFactoryClass(); + + assertThat(regionParserSpy.getBeanClass(mockElement)).isEqualTo(AbstractRegionParserUnitTests.class); + + verify(regionParserSpy, times(1)).getBeanClass(eq(mockElement)); + verify(regionParserSpy, times(1)).getRegionFactoryClass(); + } + + @Test + public void getParentNameWhenTemplateIsSet() { + Element mockElement = mock(Element.class); + + when(mockElement.getAttribute(eq("template"))).thenReturn("test"); + assertThat(regionParser.getParentName(mockElement)).isEqualTo("test"); + verify(mockElement, times(1)).getAttribute(eq("template")); + } + + @Test + public void getParentNameWhenTemplateIsUnset() { + Element mockElement = mock(Element.class); + + when(mockElement.getAttribute(eq("template"))).thenReturn(null); + assertThat(regionParser.getParentName(mockElement)).isNull(); + verify(mockElement, times(1)).getAttribute(eq("template")); + } + + @Test + public void isRegionTemplateWithRegionTemplateElementsIsTrue() { + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("client-region-template"); + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("local-region-template"); + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("partitioned-region-template"); + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("replicated-region-template"); + } + + @Test + public void isRegionTemplateWithRegionElementsIsFalse() { + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("client-region"); + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("local-region"); + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("partitioned-region"); + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("replicated-region"); + } + + @Test + public void isRegionTemplateWhenElementLocalNameDoesNotEndWithTemplateIsFalse() { + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("disk-store"); + } + + @Test + public void isRegionTemplateWhenElementLocalNameIsNullIsFalse() { + assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate(null); + } + + @Test + public void isSubRegionWithRegionElementIsTrue() { + assertIsSubRegionWhenElementLocalNameEndsWithRegion("client-region"); + assertIsSubRegionWhenElementLocalNameEndsWithRegion("local-region"); + assertIsSubRegionWhenElementLocalNameEndsWithRegion("partitioned-region"); + assertIsSubRegionWhenElementLocalNameEndsWithRegion("replicated-region"); + } + + @Test + public void isSubRegionWithRegionTemplateElementIsFalse() { + assertIsSubRegionWhenElementLocalNameEndsWithRegion("client-region-template"); + assertIsSubRegionWhenElementLocalNameEndsWithRegion("local-region-template"); + assertIsSubRegionWhenElementLocalNameEndsWithRegion("partitioned-region-template"); + assertIsSubRegionWhenElementLocalNameEndsWithRegion("replicated-region-template"); + assertIsSubRegionWhenElementLocalNameEndsWithRegion("region-template"); + } + + @Test + public void isSubRegionWhenElementLocalNameDoesNotEndWithRegionIsFalse() { + assertIsSubRegionWhenElementLocalNameEndsWithRegion("disk-store"); + } + + @Test + public void isSubRegionWhenElementLocalNameIsNullIsFalse() { + assertIsSubRegionWhenElementLocalNameEndsWithRegion(null); + } + + @Test + public void doParseWithAbstractRegionTemplate() { + AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class); + + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); + + Element mockElement = mock(Element.class); + Node mockNode = mock(Node.class); + + when(mockElement.getLocalName()).thenReturn("partitioned-region-template"); + when(mockElement.getParentNode()).thenReturn(mockNode); + when(mockNode.getLocalName()).thenReturn("cache"); + + regionParserSpy.doParse(mockElement, null, builder); + + assertThat(builder.getRawBeanDefinition().isAbstract()).isTrue(); + + verify(regionParserSpy, times(1)).doParse(eq(mockElement), isNull(ParserContext.class), eq(builder)); + verify(regionParserSpy, times(1)).doParseRegion(eq(mockElement), isNull(ParserContext.class), + eq(builder), eq(false)); + } + + @Test + public void doParseWithNonAbstractSubRegion() { + AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class); + + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); + + Element mockElement = mock(Element.class); + Node mockNode = mock(Node.class); + + when(mockElement.getLocalName()).thenReturn("replicated-region"); + when(mockElement.getParentNode()).thenReturn(mockNode); + when(mockNode.getLocalName()).thenReturn("replicated-region"); + + regionParserSpy.doParse(mockElement, null, builder); + + assertThat(builder.getRawBeanDefinition().isAbstract()).isFalse(); + + verify(regionParserSpy, times(1)).doParse(eq(mockElement), isNull(ParserContext.class), eq(builder)); + verify(regionParserSpy, times(1)).doParseRegion(eq(mockElement), isNull(ParserContext.class), + eq(builder), eq(true)); + } + + @Test + public void validateDataPolicyShortcutAttributesMutualExclusion() { + Element mockElement = mock(Element.class); + + when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false); + when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false); + + regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null); + + verify(mockElement).hasAttribute(eq("data-policy")); + verify(mockElement, never()).hasAttribute(eq("shortcut")); + } + + @Test + public void validateDataPolicyShortcutAttributesMutualExclusionWithDataPolicy() { + Element mockElement = mock(Element.class); + + when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true); + when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false); + + regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null); + + verify(mockElement).hasAttribute(eq("data-policy")); + verify(mockElement).hasAttribute(eq("shortcut")); + } + + @Test + public void validateDataPolicyShortcutAttributesMutualExclusionWithShortcut() { + Element mockElement = mock(Element.class); + + when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false); + when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true); + + regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null); + + verify(mockElement).hasAttribute(eq("data-policy")); + verify(mockElement, never()).hasAttribute(eq("shortcut")); + } + + @Test + public void validateDataPolicyShortcutAttributesMutualExclusionWithDataPolicyAndShortcut() { + Element mockElement = mock(Element.class); + XmlReaderContext mockReaderContext = mock(XmlReaderContext.class); + + ParserContext mockParserContext = new ParserContext(mockReaderContext, null); + + when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true); + when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true); + when(mockElement.getTagName()).thenReturn("local-region"); + + regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, mockParserContext); + + verify(mockReaderContext).error( + eq("Only one of [data-policy, shortcut] may be specified with element 'local-region'."), + eq(mockElement)); + } + + protected static class TestRegionParser extends AbstractRegionParser { + + @Override + protected Class getRegionFactoryClass() { + return getClass(); + } + + @Override + protected void doParseRegion(Element element, ParserContext parserContext, + BeanDefinitionBuilder builder, boolean subRegion) { + + throw new UnsupportedOperationException("Not Implemented"); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/CacheNamespaceTest.java similarity index 97% rename from src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/CacheNamespaceTest.java index eb3fef18..ad75e7d2 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/CacheNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; @@ -27,6 +27,11 @@ import static org.junit.Assert.assertTrue; import java.util.Properties; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.util.GatewayConflictHelper; +import com.gemstone.gemfire.cache.util.GatewayConflictResolver; +import com.gemstone.gemfire.cache.util.TimestampedEntryEvent; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -36,17 +41,10 @@ import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.GemfireBeanFactoryLocator; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.ClientCacheFactoryBean; -import org.springframework.data.gemfire.test.GemfireProfileValueSource; -import org.springframework.test.annotation.ProfileValueSourceConfiguration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.util.ReflectionTestUtils; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.util.GatewayConflictHelper; -import com.gemstone.gemfire.cache.util.GatewayConflictResolver; -import com.gemstone.gemfire.cache.util.TimestampedEntryEvent; - /** * @author Costin Leau * @author John Blum @@ -223,5 +221,4 @@ public class CacheNamespaceTest{ throw new UnsupportedOperationException("Not Implemented!"); } } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceTest.java index b4159feb..6b20c3b2 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/CacheServerNamespaceTest.java @@ -14,12 +14,15 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.cache.server.CacheServer; +import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,9 +32,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StringUtils; -import com.gemstone.gemfire.cache.server.CacheServer; -import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig; - /** * The CacheServerNamespaceTest class is a test suite of test cases testing the functionality of the SDG XML namespace * when configuring a GemFire Cache Servers and Client Subscription. diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheSubscriptionTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/CacheSubscriptionTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionTest.java index 28f2d32e..86e9565a 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheSubscriptionTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/CacheSubscriptionTest.java @@ -14,12 +14,16 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.cache.InterestPolicy; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.SubscriptionAttributes; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,13 +33,9 @@ import org.springframework.data.gemfire.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.InterestPolicy; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.cache.SubscriptionAttributes; - /** * Test to ensure subscription policy can be applied to server regions. - * + * * @author Lyndon Adams * @author John Blum * @since 1.3.0 @@ -44,10 +44,10 @@ import com.gemstone.gemfire.cache.SubscriptionAttributes; @ContextConfiguration("subscription-ns.xml") @SuppressWarnings("unused") public class CacheSubscriptionTest{ - + @Autowired private ApplicationContext context; - + @Test public void testReplicatedRegionSubscriptionAllPolicy() throws Exception { assertTrue(context.containsBean("replicALL")); @@ -77,7 +77,7 @@ public class CacheSubscriptionTest{ assertNotNull(subscriptionAttributes); assertEquals(InterestPolicy.CACHE_CONTENT, subscriptionAttributes.getInterestPolicy()); } - + @Test public void testPartitionRegionSubscriptionDefaultPolicy() throws Exception { assertTrue(context.containsBean("partDEFAULT")); @@ -92,5 +92,5 @@ public class CacheSubscriptionTest{ assertNotNull(subscriptionAttributes); assertEquals(InterestPolicy.DEFAULT, subscriptionAttributes.getInterestPolicy()); } - + } diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheUsingPdxNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceTest.java similarity index 95% rename from src/test/java/org/springframework/data/gemfire/config/CacheUsingPdxNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceTest.java index 2b02e5a4..e80fc552 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheUsingPdxNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/CacheUsingPdxNamespaceTest.java @@ -14,24 +14,25 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.pdx.PdxSerializer; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.CacheFactoryBean; +import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.pdx.PdxSerializer; - /** * The CacheUsingPdxNamespaceTest class is a test suite of test case testing the Spring Data GemFire XML namespace * when PDX is configured in GemFire. diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientCacheNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/ClientCacheNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheNamespaceTest.java index 3980f741..ed987cde 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientCacheNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; @@ -23,6 +23,8 @@ import static org.junit.Assert.assertThat; import java.util.Properties; +import com.gemstone.gemfire.pdx.PdxSerializer; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -31,8 +33,6 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.pdx.PdxSerializer; - /** * The ClientCacheNamespaceTest class is a test suite of test cases testing the contract and functionality * of the Spring Data GemFire ClientCacheParser. diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientCacheParserTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheParserUnitTests.java similarity index 68% rename from src/test/java/org/springframework/data/gemfire/config/ClientCacheParserTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheParserUnitTests.java index 86c21060..38f50de5 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientCacheParserTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/ClientCacheParserUnitTests.java @@ -15,13 +15,9 @@ * */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -43,48 +39,62 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** - * The ClientCacheParserTest class is a test suite of test cases testing the contract and functionality of the - * ClientCacheParser class. + * Unit tests for {@link ClientCacheParser}. * * @author John Blum * @see org.junit.Test - * @see org.junit.runner.RunWith * @see org.mockito.Mock * @see org.mockito.Mockito * @see org.mockito.runners.MockitoJUnitRunner + * @see org.springframework.data.gemfire.config.xml.ClientCacheParser * @since 1.8.0 */ @RunWith(MockitoJUnitRunner.class) -public class ClientCacheParserTest { +public class ClientCacheParserUnitTests { @Mock private Element mockElement; + protected void assertPropertyIsPresent(BeanDefinition beanDefinition, String propertyName) { + assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isTrue(); + } + + protected void assertPropertyIsNotPresent(BeanDefinition beanDefinition, String propertyName) { + assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isFalse(); + } + + protected void assertPropertyValueEquals(BeanDefinition beanDefinition, String propertyName, + Object expectedPropertyValue) { + + assertPropertyIsPresent(beanDefinition, propertyName); + assertThat(beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue()) + .isEqualTo(expectedPropertyValue); + } + @Test @SuppressWarnings("all") public void beanClassEqualsClientCacheFactoryBean() { - assertThat((Class) new ClientCacheParser().getBeanClass(mockElement), - is(equalTo(ClientCacheFactoryBean.class))); + assertThat(new ClientCacheParser().getBeanClass(mockElement)).isEqualTo(ClientCacheFactoryBean.class); } @Test public void doParseSetsProperties() { NodeList mockNodeList = mock(NodeList.class); - when(mockNodeList.getLength()).thenReturn(0); when(mockElement.getAttribute(eq("durable-client-id"))).thenReturn("123"); when(mockElement.getAttribute(eq("durable-client-timeout"))).thenReturn("60"); when(mockElement.getAttribute(eq("keep-alive"))).thenReturn("false"); - when(mockElement.getAttribute(eq("pool-name"))).thenReturn("testPool"); + when(mockElement.getAttribute(eq("pool-name"))).thenReturn("TestPool"); when(mockElement.getAttribute(eq("ready-for-events"))).thenReturn(null); when(mockElement.getChildNodes()).thenReturn(mockNodeList); + when(mockNodeList.getLength()).thenReturn(0); + + BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition(); final BeanDefinitionRegistry mockRegistry = mock(BeanDefinitionRegistry.class); when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false); - BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition(); - ClientCacheParser clientCacheParser = new ClientCacheParser() { @Override protected BeanDefinitionRegistry getRegistry(ParserContext parserContext) { return mockRegistry; @@ -95,16 +105,16 @@ public class ClientCacheParserTest { BeanDefinition clientCacheBeanDefinition = clientCacheBuilder.getBeanDefinition(); - assertThat(clientCacheBeanDefinition, is(notNullValue())); + assertThat(clientCacheBeanDefinition).isNotNull(); PropertyValues propertyValues = clientCacheBeanDefinition.getPropertyValues(); - assertThat(propertyValues, is(notNullValue())); - assertThat((String) propertyValues.getPropertyValue("durableClientId").getValue(), is(equalTo("123"))); - assertThat((String) propertyValues.getPropertyValue("durableClientTimeout").getValue(), is(equalTo("60"))); - assertThat((String) propertyValues.getPropertyValue("keepAlive").getValue(), is(equalTo("false"))); - assertThat((String) propertyValues.getPropertyValue("poolName").getValue(), is(equalTo("testPool"))); - assertThat(propertyValues.getPropertyValue("readyForEvents"), is(nullValue())); + assertThat(propertyValues).isNotNull(); + assertPropertyValueEquals(clientCacheBeanDefinition, "durableClientId", "123"); + assertPropertyValueEquals(clientCacheBeanDefinition, "durableClientTimeout", "60"); + assertPropertyValueEquals(clientCacheBeanDefinition, "keepAlive", "false"); + assertPropertyValueEquals(clientCacheBeanDefinition, "poolName", "TestPool"); + assertPropertyIsNotPresent(clientCacheBeanDefinition, "readyForEvents"); verify(mockElement, times(1)).getAttribute(eq("durable-client-id")); verify(mockElement, times(1)).getAttribute(eq("durable-client-timeout")); @@ -115,7 +125,7 @@ public class ClientCacheParserTest { @Test public void postProcessDynamicRegionSupportParsesPoolName() { - when(mockElement.getAttribute(eq("pool-name"))).thenReturn("testPool"); + when(mockElement.getAttribute(eq("pool-name"))).thenReturn("TestPool"); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); @@ -123,12 +133,9 @@ public class ClientCacheParserTest { BeanDefinition beanDefinition = builder.getBeanDefinition(); - assertThat(beanDefinition, is(notNullValue())); - assertThat(beanDefinition.getPropertyValues(), is(notNullValue())); - assertThat(beanDefinition.getPropertyValues().getPropertyValue("poolName"), is(notNullValue())); - assertThat((String) beanDefinition.getPropertyValues().getPropertyValue("poolName").getValue(), is(equalTo("testPool"))); + assertThat(beanDefinition).isNotNull(); + assertPropertyValueEquals(beanDefinition, "poolName", "TestPool"); verify(mockElement, times(1)).getAttribute(eq("pool-name")); } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTest.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTest.java index f1b7ed64..56d43cac 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -33,22 +33,6 @@ import java.io.File; import java.io.FilenameFilter; import java.util.concurrent.atomic.AtomicReference; -import org.junit.AfterClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.SimpleCacheListener; -import org.springframework.data.gemfire.SimpleObjectSizer; -import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.client.ClientRegionFactoryBean; -import org.springframework.data.gemfire.client.Interest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.ObjectUtils; - import com.gemstone.gemfire.cache.CacheListener; import com.gemstone.gemfire.cache.CacheLoader; import com.gemstone.gemfire.cache.CacheLoaderException; @@ -66,6 +50,22 @@ import com.gemstone.gemfire.cache.client.ClientRegionShortcut; import com.gemstone.gemfire.cache.util.CacheWriterAdapter; import com.gemstone.gemfire.compression.Compressor; +import org.junit.AfterClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.SimpleCacheListener; +import org.springframework.data.gemfire.SimpleObjectSizer; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.data.gemfire.client.ClientRegionFactoryBean; +import org.springframework.data.gemfire.client.Interest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.ObjectUtils; + /** * The ClientRegionNamespaceTest class is a test suite of test cases testing the contract and functionality * of GemFire Client Region namespace support in SDG. @@ -74,7 +74,7 @@ import com.gemstone.gemfire.compression.Compressor; * @author David Turanski * @author John Blum * @see org.springframework.data.gemfire.client.ClientRegionFactoryBean - * @see org.springframework.data.gemfire.config.ClientRegionParser + * @see org.springframework.data.gemfire.config.xml.ClientRegionParser */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="client-ns.xml") @@ -374,5 +374,4 @@ public class ClientRegionNamespaceTest { } } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionUsingDataPolicyAndShortcutTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutTest.java similarity index 88% rename from src/test/java/org/springframework/data/gemfire/config/ClientRegionUsingDataPolicyAndShortcutTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutTest.java index 2c2acaa8..a5b4fb8f 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionUsingDataPolicyAndShortcutTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/ClientRegionUsingDataPolicyAndShortcutTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertTrue; @@ -35,7 +35,8 @@ public class ClientRegionUsingDataPolicyAndShortcutTest { @Test(expected = BeanDefinitionParsingException.class) public void testClientRegionBeanDefinitionWithDataPolicyAndShortcut() { try { - new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/client-region-using-datapolicy-and-shortcut.xml"); + new ClassPathXmlApplicationContext( + "/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml"); } catch (BeanDefinitionParsingException e) { assertTrue(e.getMessage().contains("Only one of [data-policy, shortcut] may be specified with element")); diff --git a/src/test/java/org/springframework/data/gemfire/config/ContinuousQueryListenerContainerNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/ContinuousQueryListenerContainerNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest.java index d9e6e07a..8fb16ec2 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ContinuousQueryListenerContainerNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -26,8 +26,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executor; + import javax.annotation.Resource; +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.query.CqListener; +import com.gemstone.gemfire.cache.query.CqQuery; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -43,10 +48,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ErrorHandler; -import com.gemstone.gemfire.cache.client.ClientCache; -import com.gemstone.gemfire.cache.query.CqListener; -import com.gemstone.gemfire.cache.query.CqQuery; - /** * The ContinuousQueryListenerContainerNamespaceTest class is a test suite of test cases testing the SDG XML namespace * for proper configuration and initialization of a ContinuousQueryListenerContainer bean component diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreAndEvictionRegionParsingTest.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreAndEvictionRegionParsingTest.java index 193662d6..da0b1939 100644 --- a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreAndEvictionRegionParsingTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -26,6 +26,22 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FilenameFilter; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CustomExpiry; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.DiskStore; +import com.gemstone.gemfire.cache.DiskStoreFactory; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.EvictionAlgorithm; +import com.gemstone.gemfire.cache.EvictionAttributes; +import com.gemstone.gemfire.cache.ExpirationAction; +import com.gemstone.gemfire.cache.ExpirationAttributes; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.Region.Entry; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.util.ObjectSizer; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -43,22 +59,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.FileSystemUtils; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CustomExpiry; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.DiskStore; -import com.gemstone.gemfire.cache.DiskStoreFactory; -import com.gemstone.gemfire.cache.EvictionAction; -import com.gemstone.gemfire.cache.EvictionAlgorithm; -import com.gemstone.gemfire.cache.EvictionAttributes; -import com.gemstone.gemfire.cache.ExpirationAction; -import com.gemstone.gemfire.cache.ExpirationAttributes; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.Region.Entry; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.cache.util.ObjectSizer; - /** * @author Costin Leau * @author David Turanski @@ -186,7 +186,7 @@ public class DiskStoreAndEvictionRegionParsingTest { assertEquals(400, regionTTI.getTimeout()); assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction()); } - + @Test @SuppressWarnings("rawtypes") @@ -194,10 +194,10 @@ public class DiskStoreAndEvictionRegionParsingTest { assertTrue(applicationContext.containsBean("replicated-data-custom-expiry")); RegionFactoryBean fb = applicationContext.getBean("&replicated-data-custom-expiry", RegionFactoryBean.class); RegionAttributes attrs = TestUtils.readField("attributes", fb); - + assertNotNull(attrs.getCustomEntryIdleTimeout()); assertNotNull(attrs.getCustomEntryTimeToLive()); - + assertTrue(attrs.getCustomEntryIdleTimeout() instanceof TestCustomExpiry); assertTrue(attrs.getCustomEntryTimeToLive() instanceof TestCustomExpiry); } diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceTest.java index b6dcc824..f7dfefe7 100644 --- a/src/test/java/org/springframework/data/gemfire/config/DiskStoreNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/DiskStoreNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull; import java.io.File; import java.util.Properties; +import com.gemstone.gemfire.cache.DiskStore; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -30,8 +32,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.DiskStore; - /** * The DiskStoreNamespaceTest class is a test suite of test cases testing the contract and functionality of using * Spring Data GemFire's XML namespace to configure GemFire Disk Stores. diff --git a/src/test/java/org/springframework/data/gemfire/config/DynamicRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/DynamicRegionNamespaceTest.java similarity index 95% rename from src/test/java/org/springframework/data/gemfire/config/DynamicRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/DynamicRegionNamespaceTest.java index 1ec13a2d..7e743443 100644 --- a/src/test/java/org/springframework/data/gemfire/config/DynamicRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/DynamicRegionNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -23,6 +23,9 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.DynamicRegionFactory; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -30,20 +33,17 @@ import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.DynamicRegionFactory; - /** * @author David Turanski - * + * * This requires a real cache */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/config/dynamic-region-ns.xml") +@ContextConfiguration("/org/springframework/data/gemfire/config/xml/dynamic-region-ns.xml") public class DynamicRegionNamespaceTest { @Autowired ApplicationContext ctx; - + @Test public void testBasicCache() throws Exception { DynamicRegionFactory drf = DynamicRegionFactory.get(); @@ -56,4 +56,4 @@ public class DynamicRegionNamespaceTest { assertFalse(config.registerInterest); assertEquals(File.separator + "foo", config.diskDir.getPath()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/gemfire/config/FunctionServiceNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceTest.java similarity index 97% rename from src/test/java/org/springframework/data/gemfire/config/FunctionServiceNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceTest.java index 7ba1dd6e..4cba1295 100644 --- a/src/test/java/org/springframework/data/gemfire/config/FunctionServiceNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/FunctionServiceNamespaceTest.java @@ -14,21 +14,21 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import com.gemstone.gemfire.cache.execute.FunctionAdapter; +import com.gemstone.gemfire.cache.execute.FunctionContext; +import com.gemstone.gemfire.cache.execute.FunctionService; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.execute.FunctionAdapter; -import com.gemstone.gemfire.cache.execute.FunctionContext; -import com.gemstone.gemfire.cache.execute.FunctionService; - /** * @author Costin Leau * @author David Turanski diff --git a/src/test/java/org/springframework/data/gemfire/config/GatewayReceiverAutoStartNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/GatewayReceiverAutoStartNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceTest.java index 5b072576..2eefe88a 100644 --- a/src/test/java/org/springframework/data/gemfire/config/GatewayReceiverAutoStartNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverAutoStartNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.wan.GatewayReceiver; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; @@ -31,8 +33,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StringUtils; -import com.gemstone.gemfire.cache.wan.GatewayReceiver; - /** * The GatewayReceiverAutoStartNamespaceTest class is a test suite of test cases testing the contract * and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD). diff --git a/src/test/java/org/springframework/data/gemfire/config/GatewayReceiverDefaultStartNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/GatewayReceiverDefaultStartNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceTest.java index 1be48e47..6b21a01e 100644 --- a/src/test/java/org/springframework/data/gemfire/config/GatewayReceiverDefaultStartNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverDefaultStartNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.wan.GatewayReceiver; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; @@ -31,8 +33,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StringUtils; -import com.gemstone.gemfire.cache.wan.GatewayReceiver; - /** * The GatewayReceiverDefaultStartNamespaceTest class is a test suite of test cases testing the contract * and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD). diff --git a/src/test/java/org/springframework/data/gemfire/config/GatewayReceiverManualStartNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/GatewayReceiverManualStartNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceTest.java index 6c455f8f..7345d196 100644 --- a/src/test/java/org/springframework/data/gemfire/config/GatewayReceiverManualStartNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/GatewayReceiverManualStartNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.wan.GatewayReceiver; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; @@ -30,8 +32,6 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.wan.GatewayReceiver; - /** * The GatewayReceiverManualStartNamespaceTest class is a test suite of test cases testing the contract * and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD). diff --git a/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java index f9a920c4..8aff8764 100644 --- a/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV7GatewayNamespaceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -27,15 +27,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.List; -import org.junit.AfterClass; -import org.junit.Test; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest; -import org.springframework.data.gemfire.RegionFactoryBean; -import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; -import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; - import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent; import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener; @@ -47,6 +38,15 @@ import com.gemstone.gemfire.cache.wan.GatewaySender; import com.gemstone.gemfire.cache.wan.GatewaySender.OrderPolicy; import com.gemstone.gemfire.cache.wan.GatewayTransportFilter; +import org.junit.AfterClass; +import org.junit.Test; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest; +import org.springframework.data.gemfire.RegionFactoryBean; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; +import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; + /** * The GemfireV7GatewayNamespaceTest class is a test suite of test cases testing the GemFire 7.0 WAN functionality * by configuring various Gateway senders and receivers. @@ -90,7 +90,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo */ @Override protected String location() { - return "/org/springframework/data/gemfire/config/gateway-v7-ns.xml"; + return "/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml"; } @Test @@ -275,5 +275,4 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo return false; } } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/GemfireV8GatewayNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceTest.java similarity index 97% rename from src/test/java/org/springframework/data/gemfire/config/GemfireV8GatewayNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceTest.java index 304231ad..ab7de8c1 100644 --- a/src/test/java/org/springframework/data/gemfire/config/GemfireV8GatewayNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/GemfireV8GatewayNamespaceTest.java @@ -14,13 +14,17 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.cache.EntryEvent; +import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter; +import com.gemstone.gemfire.cache.wan.GatewaySender; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,10 +33,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.EntryEvent; -import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter; -import com.gemstone.gemfire.cache.wan.GatewaySender; - /** * The GemfireV8GatewayNamespaceTest class is a test suite of test cases testing the contract and functionality of * GemFire 8 Gateway Sender/Receiver support. @@ -63,7 +63,7 @@ public class GemfireV8GatewayNamespaceTest { @Test public void testGatewaySenderEventSubstitutionFilter() { - assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!", + assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!", gatewaySenderWithEventSubstitutionFilter); assertEquals("gateway-sender-with-event-substitution-filter", gatewaySenderWithEventSubstitutionFilter.getId()); assertEquals(3, gatewaySenderWithEventSubstitutionFilter.getRemoteDSId()); diff --git a/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceTest.java similarity index 96% rename from src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceTest.java index f3d9ecb6..2d0be669 100644 --- a/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/IndexNamespaceTest.java @@ -14,21 +14,21 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.query.Index; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.query.Index; - /** * The IndexNamespaceTest is a test suite of test cases testing the functionality of GemFire Index creation using * the Spring Data GemFire XML namespace (XSD). @@ -37,7 +37,7 @@ import com.gemstone.gemfire.cache.query.Index; * @author David Turanski * @author John Blum * @see org.springframework.data.gemfire.IndexFactoryBean - * @see org.springframework.data.gemfire.config.IndexParser + * @see org.springframework.data.gemfire.config.xml.IndexParser * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner diff --git a/src/test/java/org/springframework/data/gemfire/config/InvalidRegionDefinitionUsingBeansNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionDefinitionUsingBeansNamespaceTest.java similarity index 90% rename from src/test/java/org/springframework/data/gemfire/config/InvalidRegionDefinitionUsingBeansNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionDefinitionUsingBeansNamespaceTest.java index bf5fdf3e..b9e6b767 100644 --- a/src/test/java/org/springframework/data/gemfire/config/InvalidRegionDefinitionUsingBeansNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionDefinitionUsingBeansNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -40,7 +40,8 @@ public class InvalidRegionDefinitionUsingBeansNamespaceTest { @Test(expected = IllegalArgumentException.class) public void testInvalidDataPolicyPersistentAttributeSettings() { try { - new ClassPathXmlApplicationContext("org/springframework/data/gemfire/config/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml"); + new ClassPathXmlApplicationContext( + "org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml"); } catch (BeanCreationException expected) { assertTrue(expected.getCause() instanceof IllegalArgumentException); diff --git a/src/test/java/org/springframework/data/gemfire/config/InvalidRegionExpirationAttributesNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/InvalidRegionExpirationAttributesNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest.java index ad48e8d3..cb726a08 100644 --- a/src/test/java/org/springframework/data/gemfire/config/InvalidRegionExpirationAttributesNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/org/springframework/data/gemfire/config/JndiBindingsPropertyPlaceholderTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsPropertyPlaceholderTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/JndiBindingsPropertyPlaceholderTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsPropertyPlaceholderTest.java index 9468f975..d3112535 100644 --- a/src/test/java/org/springframework/data/gemfire/config/JndiBindingsPropertyPlaceholderTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsPropertyPlaceholderTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -24,6 +24,8 @@ import static org.junit.Assert.fail; import java.util.List; import java.util.Map; +import com.gemstone.gemfire.internal.datasource.ConfigProperty; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -32,8 +34,6 @@ import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.internal.datasource.ConfigProperty; - /** * The JndiBindingsPropertyPlaceholderTest class is a test suite of test cases testing the configuration of a GemFire * Cache JNDI DataSource using property placeholders. diff --git a/src/test/java/org/springframework/data/gemfire/config/JndiBindingsTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsTest.java similarity index 97% rename from src/test/java/org/springframework/data/gemfire/config/JndiBindingsTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsTest.java index 087821ac..31a7f6c7 100644 --- a/src/test/java/org/springframework/data/gemfire/config/JndiBindingsTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/JndiBindingsTest.java @@ -14,20 +14,20 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.internal.datasource.GemFireBasicDataSource; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.internal.datasource.GemFireBasicDataSource; - /** * This test requires a real cache * diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceTest.java index 392f3fc5..cea1e7be 100644 --- a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -23,6 +23,14 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheListener; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.compression.Compressor; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -36,14 +44,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ObjectUtils; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheListener; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.compression.Compressor; - /** * The LocalRegionNamespaceTest class is a test suite of test cases testing the contract and functionality * of GemFire's Local Region support in SDG. @@ -52,7 +52,7 @@ import com.gemstone.gemfire.compression.Compressor; * @author David Turanski * @author John Blum * @see org.springframework.data.gemfire.LocalRegionFactoryBean - * @see org.springframework.data.gemfire.config.LocalRegionParser + * @see org.springframework.data.gemfire.config.xml.LocalRegionParser */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="local-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) @@ -60,7 +60,7 @@ public class LocalRegionNamespaceTest { @Autowired private ApplicationContext context; - + @Test public void testSimpleLocalRegion() throws Exception { @@ -150,7 +150,7 @@ public class LocalRegionNamespaceTest { assertEquals("existing", TestUtils.readField("name", localRegionFactoryBean)); assertSame(existing, context.getBean("lookup")); } - + @Test @SuppressWarnings("rawtypes") public void testLocalPersistent() { diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionWithEvictionPolicyActionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/LocalRegionWithEvictionPolicyActionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest.java index 4bb5704f..d6cf3acc 100644 --- a/src/test/java/org/springframework/data/gemfire/config/LocalRegionWithEvictionPolicyActionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest.java @@ -14,24 +14,24 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.Scope; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.EvictionAction; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.Scope; - /** * The LocalRegionWithEvictionPolicyActionNamespaceTest class is a test suite of tests cases testing the Eviction Policy * Actions on Local Regions defined in a Spring context configuration file. diff --git a/src/test/java/org/springframework/data/gemfire/config/MembershipAttributesTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesTest.java similarity index 93% rename from src/test/java/org/springframework/data/gemfire/config/MembershipAttributesTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesTest.java index c145c114..08f12861 100644 --- a/src/test/java/org/springframework/data/gemfire/config/MembershipAttributesTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/MembershipAttributesTest.java @@ -13,12 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.cache.LossAction; +import com.gemstone.gemfire.cache.MembershipAttributes; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.ResumptionAction; +import com.gemstone.gemfire.distributed.Role; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -27,18 +33,12 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.LossAction; -import com.gemstone.gemfire.cache.MembershipAttributes; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.ResumptionAction; -import com.gemstone.gemfire.distributed.Role; - /** * @author David Turanski - * + * */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="/org/springframework/data/gemfire/config/membership-attributes-ns.xml", +@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) public class MembershipAttributesTest { diff --git a/src/test/java/org/springframework/data/gemfire/config/MultipleCacheTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/MultipleCacheTest.java similarity index 94% rename from src/test/java/org/springframework/data/gemfire/config/MultipleCacheTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/MultipleCacheTest.java index b70847a0..506f5e85 100644 --- a/src/test/java/org/springframework/data/gemfire/config/MultipleCacheTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/MultipleCacheTest.java @@ -1,28 +1,28 @@ /* * Copyright 2002-2013 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; + import org.junit.Test; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.Region; - /** * @author David Turanski * @author John Blum @@ -31,7 +31,7 @@ public class MultipleCacheTest { @Test public void testMultipleCaches() { - String configLocation = "/org/springframework/data/gemfire/config/MultipleCacheTest-context.xml"; + String configLocation = "/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml"; ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext(configLocation); ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext(configLocation); diff --git a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceTest.java index 80b36761..54ef7131 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/PartitionedRegionNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -26,6 +26,16 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.List; +import com.gemstone.gemfire.cache.CacheListener; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.FixedPartitionAttributes; +import com.gemstone.gemfire.cache.PartitionAttributes; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.partition.PartitionListener; +import com.gemstone.gemfire.cache.partition.PartitionListenerAdapter; +import com.gemstone.gemfire.compression.Compressor; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -40,16 +50,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ObjectUtils; -import com.gemstone.gemfire.cache.CacheListener; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.FixedPartitionAttributes; -import com.gemstone.gemfire.cache.PartitionAttributes; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.cache.partition.PartitionListener; -import com.gemstone.gemfire.cache.partition.PartitionListenerAdapter; -import com.gemstone.gemfire.compression.Compressor; - /** * The PartitionRegionNamespaceTest class is a test suite of test cases testing the contract and functionality * of the GemFire Partition Region support in SDG. @@ -58,7 +58,7 @@ import com.gemstone.gemfire.compression.Compressor; * @author David Turanski * @author John Blum * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean - * @see org.springframework.data.gemfire.config.PartitionedRegionParser + * @see org.springframework.data.gemfire.config.xml.PartitionedRegionParser */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "partitioned-ns.xml", initializers = GemfireTestApplicationContextInitializer.class) diff --git a/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceTest.java index d1ae878c..668654da 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/PoolNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; @@ -43,7 +43,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @see org.junit.Test * @see org.springframework.data.gemfire.client.PoolAdapter * @see org.springframework.data.gemfire.client.PoolFactoryBean - * @see org.springframework.data.gemfire.config.PoolParser + * @see org.springframework.data.gemfire.config.xml.PoolParser * @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer * @see com.gemstone.gemfire.cache.client.Pool */ diff --git a/src/test/java/org/springframework/data/gemfire/config/PoolParserUnitTests.java b/src/test/java/org/springframework/data/gemfire/config/xml/PoolParserUnitTests.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/PoolParserUnitTests.java rename to src/test/java/org/springframework/data/gemfire/config/xml/PoolParserUnitTests.java index 69d8d5aa..177b16fb 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PoolParserUnitTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/PoolParserUnitTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -60,7 +60,7 @@ import org.w3c.dom.NodeList; * @see org.mockito.Mock * @see org.mockito.Mockito * @see org.mockito.runners.MockitoJUnitRunner - * @see org.springframework.data.gemfire.config.PoolParser + * @see org.springframework.data.gemfire.config.xml.PoolParser * @since 1.7.0 */ @RunWith(MockitoJUnitRunner.class) diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionDefinitionUsingBeansNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/RegionDefinitionUsingBeansNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest.java index 5ca14fb0..55637c2e 100644 --- a/src/test/java/org/springframework/data/gemfire/config/RegionDefinitionUsingBeansNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -22,6 +22,11 @@ import static org.junit.Assert.assertTrue; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.PartitionAttributes; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -32,11 +37,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.PartitionAttributes; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.RegionAttributes; - /** * The RawRegionBeanDefinitionTest class is a test suite of test cases testing the contract and functionality * of the SDG RegionFactoryBean class, and specifically the specification of the GemFire Region DataPolicy, diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest.java index 084d50b9..a0f8a75b 100644 --- a/src/test/java/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest.java @@ -14,25 +14,25 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import javax.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.EvictionAction; import com.gemstone.gemfire.cache.EvictionAlgorithm; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.internal.cache.lru.LRUCapacityController; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + /** * The RegionEvictionAttributesNamespaceTest class is a test suite of test cases testing the use of * Eviction configuration settings (EvictionAttributes) in the SDG XML namespace. diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionExpirationAttributesNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/RegionExpirationAttributesNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest.java index 41b38a55..f3e52db4 100644 --- a/src/test/java/org/springframework/data/gemfire/config/RegionExpirationAttributesNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -23,6 +23,12 @@ import static org.mockito.Mockito.mock; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.CustomExpiry; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.ExpirationAction; +import com.gemstone.gemfire.cache.ExpirationAttributes; +import com.gemstone.gemfire.cache.Region; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; @@ -30,12 +36,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; -import com.gemstone.gemfire.cache.CustomExpiry; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.ExpirationAction; -import com.gemstone.gemfire.cache.ExpirationAttributes; -import com.gemstone.gemfire.cache.Region; - /** * The RegionExpirationAttributesNamespaceTest class is a test suite of test cases testing the configuration of * ExpirationAttribute settings on Region Entries. diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionSubscriptionAttributesNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/RegionSubscriptionAttributesNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest.java index 51cd3913..6ba80d6f 100644 --- a/src/test/java/org/springframework/data/gemfire/config/RegionSubscriptionAttributesNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest.java @@ -14,23 +14,23 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.InterestPolicy; +import com.gemstone.gemfire.cache.Region; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.InterestPolicy; -import com.gemstone.gemfire.cache.Region; - /** * The RegionSubscriptionAttributesNamespaceTest class is a test suite of test cases testing the contract * and functionality of declaring and defining Subscription Attributes for a Region in the Spring Data GemFire diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionWithSubRegionBeanDefinitionHashCodeTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest.java similarity index 96% rename from src/test/java/org/springframework/data/gemfire/config/RegionWithSubRegionBeanDefinitionHashCodeTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest.java index 98926f2a..a53169b6 100644 --- a/src/test/java/org/springframework/data/gemfire/config/RegionWithSubRegionBeanDefinitionHashCodeTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -81,7 +81,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @link https://jira.springsource.org/browse/SGF-178 * @since 1.3.3 */ -@ContextConfiguration(locations="/org/springframework/data/gemfire/config/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml", +@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml", initializers=GemfireTestApplicationContextInitializer.class) @RunWith(SpringJUnit4ClassRunner.class) @SuppressWarnings("unused") diff --git a/src/test/java/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java index 74dc97fc..4748c184 100644 --- a/src/test/java/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -22,16 +22,16 @@ import static org.junit.Assert.assertNull; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.Region; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.EvictionAction; -import com.gemstone.gemfire.cache.Region; - /** * The RegionsWithDiskStoreAndPersistenceEvictionSettingsTest class is a test suite testing the functionality * of GemFire Cache Regions when persistent/non-persistent with and without Eviction settings when specifying a @@ -60,7 +60,7 @@ public class RegionsWithDiskStoreAndPersistenceEvictionSettingsTest { @Test public void testNotPersistentNoOverflowRegion() { - assertNotNull("The Not Persistent, No Overflow Region was not properly configured and initialized!", + assertNotNull("The Not Persistent, No Overflow Region was not properly configured and initialized!", notPersistentNoOverflowRegion); assertNotNull(notPersistentNoOverflowRegion.getAttributes()); diff --git a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceTest.java index 39fe6c6d..e82ab24e 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/ReplicatedRegionNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -24,6 +24,14 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheListener; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.compression.Compressor; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -38,14 +46,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ObjectUtils; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheListener; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.compression.Compressor; - /** * The ReplicatedRegionNamespaceTest class is a test suite of test cases testing the contract and functionality * of GemFire Replicated Region support in SDG. @@ -54,7 +54,7 @@ import com.gemstone.gemfire.compression.Compressor; * @author David Turanski * @author John Blum * @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean - * @see org.springframework.data.gemfire.config.ReplicatedRegionParser + * @see org.springframework.data.gemfire.config.xml.ReplicatedRegionParser */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="replicated-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) @@ -217,5 +217,4 @@ public class ReplicatedRegionNamespaceTest { return this.name; } } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceTest.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceTest.java index c1e5592f..85bb6ea8 100644 --- a/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionNamespaceTest.java @@ -14,12 +14,16 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheLoader; +import com.gemstone.gemfire.cache.Region; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -30,10 +34,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheLoader; -import com.gemstone.gemfire.cache.Region; - /** * The SubRegionNamespaceTest class is a test suite of test cases testing the contract and functionality of * Region/SubRegion creation in a GemFire Cache. diff --git a/src/test/java/org/springframework/data/gemfire/config/SubRegionSubElementNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/SubRegionSubElementNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceTest.java index f2033ad5..1d55b00d 100644 --- a/src/test/java/org/springframework/data/gemfire/config/SubRegionSubElementNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionSubElementNamespaceTest.java @@ -14,14 +14,21 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; + import javax.annotation.Resource; +import com.gemstone.gemfire.cache.CacheListener; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener; +import com.gemstone.gemfire.cache.util.CacheListenerAdapter; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -30,12 +37,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.CacheListener; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent; -import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener; -import com.gemstone.gemfire.cache.util.CacheListenerAdapter; - /** * The SubRegionSubElementNamespaceTest class... * @@ -114,5 +115,4 @@ public class SubRegionSubElementNamespaceTest { public void close() { } } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/SubRegionWithInvalidDataPolicyTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionWithInvalidDataPolicyTest.java similarity index 87% rename from src/test/java/org/springframework/data/gemfire/config/SubRegionWithInvalidDataPolicyTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/SubRegionWithInvalidDataPolicyTest.java index c7040542..13d30f8d 100644 --- a/src/test/java/org/springframework/data/gemfire/config/SubRegionWithInvalidDataPolicyTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/SubRegionWithInvalidDataPolicyTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -40,7 +40,8 @@ public class SubRegionWithInvalidDataPolicyTest { @Test(expected = XmlBeanDefinitionStoreException.class) public void testSubRegionBeanDefinitionWithInconsistentDataPolicy() { try { - new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/subregion-with-invalid-datapolicy.xml"); + new ClassPathXmlApplicationContext( + "/org/springframework/data/gemfire/config/xml/subregion-with-invalid-datapolicy.xml"); } catch (XmlBeanDefinitionStoreException expected) { //expected.printStackTrace(System.err); @@ -53,7 +54,8 @@ public class SubRegionWithInvalidDataPolicyTest { @Test(expected = BeanCreationException.class) public void testSubRegionBeanDefinitionWithInvalidDataPolicyPersistentSettings() { try { - new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/subregion-with-inconsistent-datapolicy-persistent-settings.xml"); + new ClassPathXmlApplicationContext( + "/org/springframework/data/gemfire/config/xml/subregion-with-inconsistent-datapolicy-persistent-settings.xml"); } catch (BeanCreationException expected) { //expected.printStackTrace(System.err); diff --git a/src/test/java/org/springframework/data/gemfire/config/TemplateClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/TemplateClientRegionNamespaceTest.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/TemplateClientRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/TemplateClientRegionNamespaceTest.java index 01f5c1e4..d322102d 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TemplateClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/TemplateClientRegionNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -24,13 +24,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeNotNull; import java.util.Arrays; -import javax.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.StringUtils; +import javax.annotation.Resource; import com.gemstone.gemfire.cache.CacheListener; import com.gemstone.gemfire.cache.CacheLoader; @@ -47,6 +42,12 @@ import com.gemstone.gemfire.cache.util.CacheListenerAdapter; import com.gemstone.gemfire.cache.util.CacheWriterAdapter; import com.gemstone.gemfire.cache.util.ObjectSizer; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.StringUtils; + /** * The TemplateClientRegionNamespaceTest class is a test suite of test cases testing the contract and functionality * of Client Region Templates using Spring Data GemFire XML namespace configuration meta-data. diff --git a/src/test/java/org/springframework/data/gemfire/config/TemplatePersistentPartitionRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest.java similarity index 98% rename from src/test/java/org/springframework/data/gemfire/config/TemplatePersistentPartitionRegionNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest.java index 8490f2a5..2414ad9b 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TemplatePersistentPartitionRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/TemplatePersistentPartitionRegionNamespaceTest.java @@ -14,14 +14,23 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.io.File; + import javax.annotation.Resource; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.DiskStore; +import com.gemstone.gemfire.cache.EntryOperation; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.EvictionAlgorithm; +import com.gemstone.gemfire.cache.PartitionResolver; +import com.gemstone.gemfire.cache.Region; + import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,14 +40,6 @@ import org.springframework.data.gemfire.test.support.FileSystemUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.DiskStore; -import com.gemstone.gemfire.cache.EntryOperation; -import com.gemstone.gemfire.cache.EvictionAction; -import com.gemstone.gemfire.cache.EvictionAlgorithm; -import com.gemstone.gemfire.cache.PartitionResolver; -import com.gemstone.gemfire.cache.Region; - /** * The PersistentPartitionRegionTemplateTest class is a test suite of test cases testing the functionality of * Spring Data GemFire's Region templates with a 'persistent', PARTITION Region configuration. diff --git a/src/test/java/org/springframework/data/gemfire/config/TemplateRegionDefinitionOrderErrorNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest.java similarity index 97% rename from src/test/java/org/springframework/data/gemfire/config/TemplateRegionDefinitionOrderErrorNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest.java index f7fc26cf..8cbf9bb2 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TemplateRegionDefinitionOrderErrorNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionDefinitionOrderErrorNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests.java b/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests.java similarity index 99% rename from src/test/java/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests.java rename to src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests.java index 54727cc1..67c03d8a 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TemplateRegionsNamespaceTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/TemplateRegionsNamespaceTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -27,19 +27,8 @@ import static org.junit.Assume.assumeNotNull; import java.util.Arrays; import java.util.Date; import java.util.List; -import javax.annotation.Resource; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanIsAbstractException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; +import javax.annotation.Resource; import com.gemstone.gemfire.cache.CacheListener; import com.gemstone.gemfire.cache.CacheLoader; @@ -69,6 +58,18 @@ import com.gemstone.gemfire.cache.util.CacheWriterAdapter; import com.gemstone.gemfire.cache.util.ObjectSizer; import com.gemstone.gemfire.distributed.Role; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanIsAbstractException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + /** * The TemplateRegionsNamespaceTests class is a test suite of test cases testing the functionality and support for * Region Templating in Spring Data GemFire. diff --git a/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersTest.java similarity index 86% rename from src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersTest.java index 7d151152..d4c38d39 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/TxEventHandlersTest.java @@ -13,13 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import javax.annotation.Resource; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.TransactionEvent; +import com.gemstone.gemfire.cache.TransactionListener; +import com.gemstone.gemfire.cache.TransactionWriter; +import com.gemstone.gemfire.cache.TransactionWriterException; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.BeanNameAware; @@ -28,20 +34,15 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.TransactionEvent; -import com.gemstone.gemfire.cache.TransactionListener; -import com.gemstone.gemfire.cache.TransactionWriter; -import com.gemstone.gemfire.cache.TransactionWriterException; - /** * @author David Turanski - * + * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="tx-listeners-and-writers.xml", - initializers=GemfireTestApplicationContextInitializer.class) + initializers=GemfireTestApplicationContextInitializer.class) public class TxEventHandlersTest { + @Autowired TestListener txListener1; @@ -54,16 +55,14 @@ public class TxEventHandlersTest { @Resource(name = "gemfireCache") Cache cache; - - @Test public void test() throws Exception { - TransactionListener[] listeners = cache.getCacheTransactionManager().getListeners(); - assertEquals(2,listeners.length); - assertSame(txListener1,listeners[0]); - assertSame(txListener2,listeners[1]); - assertSame(txWriter,cache.getCacheTransactionManager().getWriter()); + + assertEquals(2, listeners.length); + assertSame(txListener1, listeners[0]); + assertSame(txListener2, listeners[1]); + assertSame(txWriter, cache.getCacheTransactionManager().getWriter()); } public static class TestListener implements TransactionListener, BeanNameAware { @@ -90,14 +89,10 @@ public class TxEventHandlersTest { @Override public void afterFailedCommit(TransactionEvent arg0) { - // TODO Auto-generated method stub - } @Override public void afterRollback(TransactionEvent arg0) { - // TODO Auto-generated method stub - } @Override @@ -114,8 +109,6 @@ public class TxEventHandlersTest { @Override public void close() { - // TODO Auto-generated method stub - } @Override diff --git a/src/test/java/org/springframework/data/gemfire/config/TxManagerNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java similarity index 92% rename from src/test/java/org/springframework/data/gemfire/config/TxManagerNamespaceTest.java rename to src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java index cf11bbe5..60afb505 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TxManagerNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.data.gemfire.config; +package org.springframework.data.gemfire.config.xml; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -32,7 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Costin Leau */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="/org/springframework/data/gemfire/config/tx-ns.xml", +@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/tx-ns.xml", initializers=GemfireTestApplicationContextInitializer.class) public class TxManagerNamespaceTest { @@ -43,8 +43,8 @@ public class TxManagerNamespaceTest { assertTrue(ctx.containsBean("gemfireTransactionManager")); //Check old style alias also registered assertTrue(ctx.containsBean("gemfire-transaction-manager")); - + GemfireTransactionManager tx = ctx.getBean("gemfireTransactionManager", GemfireTransactionManager.class); assertFalse(tx.isCopyOnRead()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilderTest.java b/src/test/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilderTest.java index cb7d1fea..b7c11291 100644 --- a/src/test/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilderTest.java +++ b/src/test/java/org/springframework/data/gemfire/function/config/ServerBasedExecutionBeanDefinitionBuilderTest.java @@ -36,7 +36,7 @@ import org.mockito.stubbing.Answer; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; /** * The ServerBasedExecutionBeanDefinitionBuilderTest class is test suite of test cases testing the contract diff --git a/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java b/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java index 09015b06..4aa7e1c4 100644 --- a/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java +++ b/src/test/java/org/springframework/data/gemfire/listener/ContinuousQueryListenerContainerTest.java @@ -43,7 +43,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import com.gemstone.gemfire.cache.RegionService; import com.gemstone.gemfire.cache.client.Pool; diff --git a/src/test/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicyConverterTest.java b/src/test/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicyConverterTest.java deleted file mode 100644 index e79d9a02..00000000 --- a/src/test/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicyConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -/** - * The SubscriptionEvictionPolicyConverterTest class is a test suite of test cases testing the contract - * and functionality of the SubscriptionEvictionPolicyConverter class. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy - * @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter - * @since 1.6.0 - */ -public class SubscriptionEvictionPolicyConverterTest { - - private final SubscriptionEvictionPolicyConverter converter = new SubscriptionEvictionPolicyConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(SubscriptionEvictionPolicy.ENTRY, converter.convert("EnTry")); - assertEquals(SubscriptionEvictionPolicy.MEM, converter.convert("MEM")); - assertEquals(SubscriptionEvictionPolicy.NONE, converter.convert("nONE")); - assertEquals(SubscriptionEvictionPolicy.NONE, converter.convert("NOne")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.setAsText("memory"); - } - catch (IllegalArgumentException expected) { - assertEquals("(memory) is not a valid SubscriptionEvictionPolicy!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - assertNull(converter.getValue()); - converter.setAsText("enTRY"); - assertEquals(SubscriptionEvictionPolicy.ENTRY, converter.getValue()); - converter.setAsText("MEm"); - assertEquals(SubscriptionEvictionPolicy.MEM, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("KEYS"); - } - catch (IllegalArgumentException expected) { - assertEquals("(KEYS) is not a valid SubscriptionEvictionPolicy!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicyConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicyConverterUnitTests.java new file mode 100644 index 00000000..3a8afea3 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicyConverterUnitTests.java @@ -0,0 +1,83 @@ +/* + * Copyright 2010-2013 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 + * + * http://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.server; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link SubscriptionEvictionPolicyConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy + * @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter + * @since 1.6.0 + */ +public class SubscriptionEvictionPolicyConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final SubscriptionEvictionPolicyConverter converter = new SubscriptionEvictionPolicyConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("EnTry")).isEqualTo(SubscriptionEvictionPolicy.ENTRY); + assertThat(converter.convert("MEM")).isEqualTo(SubscriptionEvictionPolicy.MEM); + assertThat(converter.convert("nONE")).isEqualTo(SubscriptionEvictionPolicy.NONE); + assertThat(converter.convert("NOne")).isEqualTo(SubscriptionEvictionPolicy.NONE); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[memory] is not a valid SubscriptionEvictionPolicy"); + + converter.setAsText("memory"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("enTRY"); + assertThat(converter.getValue()).isEqualTo(SubscriptionEvictionPolicy.ENTRY); + converter.setAsText("MEm"); + assertThat(converter.getValue()).isEqualTo(SubscriptionEvictionPolicy.MEM); + } + + @Test + public void setAsTextWithIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[KEYS] is not a valid SubscriptionEvictionPolicy"); + + converter.setAsText("KEYS"); + } +} diff --git a/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTest.java index 3d058da9..071ca125 100644 --- a/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/support/SpringContextBootstrappingInitializerIntegrationTest.java @@ -40,7 +40,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.gemfire.LazyWiringDeclarableSupport; -import org.springframework.data.gemfire.config.GemfireConstants; +import org.springframework.data.gemfire.config.xml.GemfireConstants; import org.springframework.data.gemfire.repository.sample.User; import org.springframework.data.gemfire.support.sample.TestUserDao; import org.springframework.data.gemfire.support.sample.TestUserService; diff --git a/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java b/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java index fedf64ab..26652917 100644 --- a/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java +++ b/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java @@ -1,11 +1,11 @@ /* * Copyright 2002-2013 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 - * + * * http://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. @@ -20,25 +20,30 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.util.StringUtils; /** + * Spring {@link ApplicationContextInitializer} used to configure the Spring Data GemFire test suite + * with mocking enabled or disabled. + * * @author David Turanski * @author John Blum + * @see org.springframework.context.ApplicationContextInitializer + * @see org.springframework.context.ConfigurableApplicationContext */ public class GemfireTestApplicationContextInitializer implements ApplicationContextInitializer { - private static final Log LOG = LogFactory.getLog(GemfireTestApplicationContextInitializer.class); + public static final String GEMFIRE_TEST_RUNNER_DISABLED = + "org.springframework.data.gemfire.test.GemfireTestRunner.nomock"; - public static final String GEMFIRE_TEST_RUNNER_DISABLED = "org.springframework.data.gemfire.test.GemfireTestRunner.nomock"; + protected final Log log = LogFactory.getLog(getClass()); - /* - * (non-Javadoc) - * @see org.springframework.context.ApplicationContextInitializer#initialize(org.springframework.context.ConfigurableApplicationContext) + /** + * {@inheritDoc} */ @Override public void initialize(ConfigurableApplicationContext applicationContext) { String gemfireTestRunnerDisabled = System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED, Boolean.FALSE.toString()); - if (isGemFireTestRunnerDisable(gemfireTestRunnerDisabled)) { - LOG.warn(String.format("WARNING - Mocks disabled; Using real GemFire components (%1$s = %2$s)", + if (isGemFireTestRunnerDisabled(gemfireTestRunnerDisabled)) { + log.warn(String.format("WARNING - Mocks disabled; Using real GemFire components (%1$s = %2$s)", GEMFIRE_TEST_RUNNER_DISABLED, gemfireTestRunnerDisabled)); } else { @@ -46,10 +51,10 @@ public class GemfireTestApplicationContextInitializer implements ApplicationCont } } - private boolean isGemFireTestRunnerDisable(final String systemPropertyValue) { + /* (non-Javadoc) */ + private boolean isGemFireTestRunnerDisabled(String systemPropertyValue) { return (Boolean.valueOf(StringUtils.trimAllWhitespace(systemPropertyValue)) || "yes".equalsIgnoreCase(systemPropertyValue) || "y".equalsIgnoreCase(systemPropertyValue)); } - } diff --git a/src/test/java/org/springframework/data/gemfire/test/model/Gender.java b/src/test/java/org/springframework/data/gemfire/test/model/Gender.java new file mode 100644 index 00000000..93df759b --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/test/model/Gender.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012 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 + * + * http://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.test.model; + +/** + * The Gender enum is a enumeration of genders. + * + * @author John Blum + * @since 1.9.0 + */ +public enum Gender { + FEMALE, + MALE +} diff --git a/src/test/java/org/springframework/data/gemfire/test/model/Person.java b/src/test/java/org/springframework/data/gemfire/test/model/Person.java new file mode 100644 index 00000000..0c838a37 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/test/model/Person.java @@ -0,0 +1,164 @@ +/* + * Copyright 2012 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 + * + * http://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.test.model; + +import java.io.Serializable; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.PersistenceConstructor; +import org.springframework.data.gemfire.mapping.Region; +import org.springframework.data.gemfire.test.support.IdentifierSequence; +import org.springframework.data.gemfire.util.SpringUtils; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +/** + * The Person class... + * + * @author John Blum + * @since 1.0.0 + */ +@Region("People") +@SuppressWarnings("unused") +public class Person implements Serializable { + + protected static final String BIRTH_DATE_PATTERN = "yyyy/MM/dd"; + + private Date birthDate; + + private Gender gender; + + @Id + private Long id; + + private final String firstName; + private final String lastName; + + public static Date newBirthDate(int year, int month, int dayOfMonth) { + Calendar birthDate = Calendar.getInstance(); + birthDate.clear(); + birthDate.set(Calendar.YEAR, year); + birthDate.set(Calendar.MONTH, month); + birthDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); + return birthDate.getTime(); + } + + public static Person newPerson(String firstName, String lastName, Date birthDate, Gender gender) { + return newPerson(IdentifierSequence.nextId(), firstName, lastName, birthDate, gender); + } + + public static Person newPerson(Long id, String firstName, String lastName, Date birthDate, Gender gender) { + return new Person(id, firstName, lastName, birthDate, gender); + } + + @PersistenceConstructor + public Person(String firstName, String lastName, Date birthDate, Gender gender) { + Assert.hasText(firstName, "firstName must be specified"); + Assert.hasText(lastName, "lastName must be specified"); + + this.firstName = firstName; + this.lastName = lastName; + this.birthDate = (birthDate != null ? (Date) birthDate.clone() : null); + this.gender = gender; + } + + public Person(Long id, String firstName, String lastName, Date birthDate, Gender gender) { + this(firstName, lastName, birthDate, gender); + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getBirthDate() { + return birthDate; + } + + public void setBirthDate(Date birthDate) { + this.birthDate = (birthDate != null ? (Date) birthDate.clone() : null); + } + + public String getFirstName() { + return firstName; + } + + public Gender getGender() { + return gender; + } + + public void setGender(Gender gender) { + this.gender = gender; + } + + public String getLastName() { + return lastName; + } + + public String getName() { + return String.format("%1$s %2$s", getFirstName(), getLastName()); + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + + if (!(obj instanceof Person)) { + return false; + } + + Person that = (Person) obj; + + return SpringUtils.equalsIgnoreNull(this.getId(), that.getId()) + && (ObjectUtils.nullSafeEquals(this.getBirthDate(), that.getBirthDate())) + && (ObjectUtils.nullSafeEquals(this.getFirstName(), that.getFirstName()) + && (ObjectUtils.nullSafeEquals(this.getGender(), that.getGender())) + && (ObjectUtils.nullSafeEquals(this.getLastName(), that.getLastName()))); + } + + @Override + public int hashCode() { + int hashValue = 17; + hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getId()); + hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getBirthDate()); + hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getFirstName()); + hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getLastName()); + return hashValue; + } + + protected static String toString(Date dateTime, String DATE_FORMAT_PATTERN) { + return (dateTime == null ? null : new SimpleDateFormat(DATE_FORMAT_PATTERN).format(dateTime)); + } + + @Override + public String toString() { + return String.format( + "{ @type = %1$s, id = %2$d, firstName = %3$s, lastName = %4$s, birthDate = %5$s, gender = %6$s}", + getClass().getName(), getId(), getFirstName(), getLastName(), + toString(getBirthDate(), BIRTH_DATE_PATTERN), getGender()); + } +} diff --git a/src/test/java/org/springframework/data/gemfire/test/support/MockitoMatchers.java b/src/test/java/org/springframework/data/gemfire/test/support/MockitoMatchers.java new file mode 100644 index 00000000..e561ca33 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/test/support/MockitoMatchers.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012 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 + * + * http://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.test.support; + +import java.util.Arrays; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.mockito.internal.matchers.VarargMatcher; +import org.springframework.data.gemfire.util.ArrayUtils; + +/** + * MockitoMatchers is a utility class encapsulating customer Hamcrest {@link Matcher Matchers} used by Mockito + * in the Spring Data GemFire project test suite. + * + * @author John Blum + * @see org.hamcrest.Matcher + * @since 1.9.0 + */ +public abstract class MockitoMatchers { + + /* (non-Javadoc) */ + public static Matcher stringArrayMatcher(String... expected) { + return new ArrayMatcher(expected); + } + + /* (non-Javadoc) */ + protected static final class ArrayMatcher extends BaseMatcher implements VarargMatcher { + + private final T[] expected; + + protected ArrayMatcher(T... expected) { + this.expected = expected; + } + + @Override + public boolean matches(Object item) { + Object[] actual = (item instanceof Object[] ? (Object[]) item : ArrayUtils.asArray(item)); + + return Arrays.equals(actual, expected); + } + + @Override + public void describeTo(Description description) { + description.appendText(String.format("expected [%1$s]", this.expected)); + } + } +} diff --git a/src/test/java/org/springframework/data/gemfire/util/ArrayUtilsUnitTests.java b/src/test/java/org/springframework/data/gemfire/util/ArrayUtilsUnitTests.java index 0d0a8d83..0f7b7266 100644 --- a/src/test/java/org/springframework/data/gemfire/util/ArrayUtilsUnitTests.java +++ b/src/test/java/org/springframework/data/gemfire/util/ArrayUtilsUnitTests.java @@ -107,26 +107,26 @@ public class ArrayUtilsUnitTests { @Test public void isEmptyIsFalse() { - assertThat(ArrayUtils.isEmpty("test", "testing", "tested")).isFalse(); - assertThat(ArrayUtils.isEmpty("test")).isFalse(); - assertThat(ArrayUtils.isEmpty("")).isFalse(); - assertThat(ArrayUtils.isEmpty(null, null, null)).isFalse(); + assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray("test", "testing", "tested"))).isFalse(); + assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray("test"))).isFalse(); + assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray(""))).isFalse(); + assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray(null, null, null))).isFalse(); } @Test public void isEmptyIsTrue() { - assertThat(ArrayUtils.isEmpty()).isTrue(); - assertThat(ArrayUtils.isEmpty((Object[]) null)).isTrue(); + assertThat(ArrayUtils.isEmpty(new Object[0])).isTrue(); + assertThat(ArrayUtils.isEmpty(null)).isTrue(); } @Test public void length() { - assertThat(ArrayUtils.length("test", "testing", "tested")).isEqualTo(3); - assertThat(ArrayUtils.length("test")).isEqualTo(1); - assertThat(ArrayUtils.length("")).isEqualTo(1); - assertThat(ArrayUtils.length(null, null, null)).isEqualTo(3); - assertThat(ArrayUtils.length()).isEqualTo(0); - assertThat(ArrayUtils.length((Object[]) null)).isEqualTo(0); + assertThat(ArrayUtils.length(ArrayUtils.asArray("test", "testing", "tested"))).isEqualTo(3); + assertThat(ArrayUtils.length(ArrayUtils.asArray("test"))).isEqualTo(1); + assertThat(ArrayUtils.length(ArrayUtils.asArray(""))).isEqualTo(1); + assertThat(ArrayUtils.length(ArrayUtils.asArray(null, null, null))).isEqualTo(3); + assertThat(ArrayUtils.length(new Object[0])).isEqualTo(0); + assertThat(ArrayUtils.length(null)).isEqualTo(0); } @Test diff --git a/src/test/java/org/springframework/data/gemfire/util/SpringUtilsUnitTests.java b/src/test/java/org/springframework/data/gemfire/util/SpringUtilsUnitTests.java new file mode 100644 index 00000000..2c53a4d4 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/util/SpringUtilsUnitTests.java @@ -0,0 +1,129 @@ +/* + * Copyright 2012 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 + * + * http://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.util; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.data.gemfire.test.support.MockitoMatchers; + +/** + * Unit tests for {@link SpringUtils}. + * + * @author John Blum + * @see org.junit.Test + * @see org.mockito.Mock + * @see org.mockito.Mockito + * @see org.mockito.runners.MockitoJUnitRunner + * @see org.springframework.data.gemfire.util.SpringUtils + * @since 1.9.0 + */ +@RunWith(MockitoJUnitRunner.class) +public class SpringUtilsUnitTests { + + @Mock + private BeanDefinition mockBeanDefinition; + + @Test + public void addDependsOnToExistingDependencies() { + when(mockBeanDefinition.getDependsOn()).thenReturn(ArrayUtils.asArray("testBeanNameOne", "testBeanNameTwo")); + assertThat(SpringUtils.addDependsOn(mockBeanDefinition, "testBeanNameThree")).isSameAs(mockBeanDefinition); + verify(mockBeanDefinition, times(1)).getDependsOn(); + verify(mockBeanDefinition, times(1)).setDependsOn(argThat( + MockitoMatchers.stringArrayMatcher("testBeanNameOne", "testBeanNameTwo", "testBeanNameThree"))); + } + + @Test + public void addDependsOnToNonExistingDependencies() { + when(mockBeanDefinition.getDependsOn()).thenReturn(null); + assertThat(SpringUtils.addDependsOn(mockBeanDefinition, "testBeanName")).isSameAs(mockBeanDefinition); + verify(mockBeanDefinition, times(1)).getDependsOn(); + verify(mockBeanDefinition, times(1)).setDependsOn(argThat(MockitoMatchers.stringArrayMatcher("testBeanName"))); + } + + @Test + public void defaultIfEmptyReturnsValue() { + assertThat(SpringUtils.defaultIfEmpty("test", "DEFAULT")).isEqualTo("test"); + assertThat(SpringUtils.defaultIfEmpty("abc123", "DEFAULT")).isEqualTo("abc123"); + assertThat(SpringUtils.defaultIfEmpty("123", "DEFAULT")).isEqualTo("123"); + assertThat(SpringUtils.defaultIfEmpty("X", "DEFAULT")).isEqualTo("X"); + assertThat(SpringUtils.defaultIfEmpty("$", "DEFAULT")).isEqualTo("$"); + assertThat(SpringUtils.defaultIfEmpty("_", "DEFAULT")).isEqualTo("_"); + assertThat(SpringUtils.defaultIfEmpty("nil", "DEFAULT")).isEqualTo("nil"); + assertThat(SpringUtils.defaultIfEmpty("null", "DEFAULT")).isEqualTo("null"); + } + + @Test + public void defaultIfEmptyReturnsDefault() { + assertThat(SpringUtils.defaultIfEmpty(" ", "DEFAULT")).isEqualTo("DEFAULT"); + assertThat(SpringUtils.defaultIfEmpty("", "DEFAULT")).isEqualTo("DEFAULT"); + assertThat(SpringUtils.defaultIfEmpty(null, "DEFAULT")).isEqualTo("DEFAULT"); + } + + @Test + public void defaultIfNullReturnsValue() { + assertThat(SpringUtils.defaultIfNull(true, false)).isTrue(); + assertThat(SpringUtils.defaultIfNull('x', 'A')).isEqualTo('x'); + assertThat(SpringUtils.defaultIfNull(1, 2)).isEqualTo(1); + assertThat(SpringUtils.defaultIfNull(Math.PI, 2.0d)).isEqualTo(Math.PI); + assertThat(SpringUtils.defaultIfNull("test", "DEFAULT")).isEqualTo("test"); + } + + @Test + public void defaultIfNullReturnsDefault() { + assertThat(SpringUtils.defaultIfNull(null, false)).isFalse(); + assertThat(SpringUtils.defaultIfNull(null, 'A')).isEqualTo('A'); + assertThat(SpringUtils.defaultIfNull(null, 2)).isEqualTo(2); + assertThat(SpringUtils.defaultIfNull(null, 2.0d)).isEqualTo(2.0d); + assertThat(SpringUtils.defaultIfNull(null, "DEFAULT")).isEqualTo("DEFAULT"); + } + + @Test + public void equalsIgnoreNullIsTrue() { + assertThat(SpringUtils.equalsIgnoreNull(null, null)).isTrue(); + assertThat(SpringUtils.equalsIgnoreNull(true, true)).isTrue(); + assertThat(SpringUtils.equalsIgnoreNull('x', 'x')).isTrue(); + assertThat(SpringUtils.equalsIgnoreNull(1, 1)).isTrue(); + assertThat(SpringUtils.equalsIgnoreNull(Math.PI, Math.PI)).isTrue(); + assertThat(SpringUtils.equalsIgnoreNull("null", "null")).isTrue(); + assertThat(SpringUtils.equalsIgnoreNull("test", "test")).isTrue(); + } + + @Test + public void equalsIgnoreNullIsFalse() { + assertThat(SpringUtils.equalsIgnoreNull(null, "null")).isFalse(); + assertThat(SpringUtils.equalsIgnoreNull(true, false)).isFalse(); + assertThat(SpringUtils.equalsIgnoreNull('x', 'X')).isFalse(); + assertThat(SpringUtils.equalsIgnoreNull(1, 2)).isFalse(); + assertThat(SpringUtils.equalsIgnoreNull(3.14159d, Math.PI)).isFalse(); + assertThat(SpringUtils.equalsIgnoreNull("nil", "null")).isFalse(); + } + + @Test + public void dereferenceBean() { + assertThat(SpringUtils.dereferenceBean("example")).isEqualTo("&example"); + } +} diff --git a/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderFactoryBeanTest.java index e2416051..f32c66d0 100644 --- a/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/wan/GatewaySenderFactoryBeanTest.java @@ -26,13 +26,13 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.junit.Test; -import org.springframework.data.gemfire.TestUtils; - import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.wan.GatewaySender; import com.gemstone.gemfire.cache.wan.GatewaySenderFactory; +import org.junit.Test; +import org.springframework.data.gemfire.TestUtils; + /** * The GatewaySenderFactoryBeanTest class is a test suite of test cases testing the contract and functionality of the * GatewaySenderFactoryBean class. @@ -278,10 +278,9 @@ public class GatewaySenderFactoryBeanTest { .setOrderPolicy("invalid"); } catch (IllegalArgumentException expected) { - assertEquals(String.format("(invalid) is not a valid %1$s!", GatewaySender.OrderPolicy.class.getSimpleName()), + assertEquals(String.format("[invalid] is not a valid %s", GatewaySender.OrderPolicy.class.getSimpleName()), expected.getMessage()); throw expected; } } - } diff --git a/src/test/java/org/springframework/data/gemfire/wan/OrderPolicyConverterTest.java b/src/test/java/org/springframework/data/gemfire/wan/OrderPolicyConverterTest.java deleted file mode 100644 index 9c1a76cc..00000000 --- a/src/test/java/org/springframework/data/gemfire/wan/OrderPolicyConverterTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2010-2013 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 - * - * http://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.wan; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.After; -import org.junit.Test; - -import com.gemstone.gemfire.cache.wan.GatewaySender; - -/** - * The OrderPolicyConverterTest class is a test suite of test cases testing the contract and functionality - * of the OrderPolicyConverter. - * - * @author John Blum - * @see org.junit.Test - * @see org.springframework.data.gemfire.wan.OrderPolicyConverter - * @see com.gemstone.gemfire.cache.wan.GatewaySender.OrderPolicy - * @since 1.7.0 - */ -@SuppressWarnings("deprecation") -public class OrderPolicyConverterTest { - - private final OrderPolicyConverter converter = new OrderPolicyConverter(); - - @After - public void tearDown() { - converter.setValue(null); - } - - @Test - public void testConvert() { - assertEquals(GatewaySender.OrderPolicy.KEY, converter.convert("key")); - assertEquals(GatewaySender.OrderPolicy.PARTITION, converter.convert("Partition")); - assertEquals(GatewaySender.OrderPolicy.THREAD, converter.convert("THREAD")); - } - - @Test(expected = IllegalArgumentException.class) - public void testConvertIllegalValue() { - try { - converter.convert("process"); - } - catch (IllegalArgumentException expected) { - assertEquals("(process) is not a valid OrderPolicy!", expected.getMessage()); - throw expected; - } - } - - @Test - public void testSetAsText() { - converter.setAsText("PartItIOn"); - assertEquals(GatewaySender.OrderPolicy.PARTITION, converter.getValue()); - converter.setAsText("thREAD"); - assertEquals(GatewaySender.OrderPolicy.THREAD, converter.getValue()); - } - - @Test(expected = IllegalArgumentException.class) - public void testSetAsTextWithIllegalValue() { - try { - assertNull(converter.getValue()); - converter.setAsText("value"); - } - catch (IllegalArgumentException expected) { - assertEquals("(value) is not a valid OrderPolicy!", expected.getMessage()); - throw expected; - } - finally { - assertNull(converter.getValue()); - } - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/wan/OrderPolicyConverterUnitTests.java b/src/test/java/org/springframework/data/gemfire/wan/OrderPolicyConverterUnitTests.java new file mode 100644 index 00000000..509eca43 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/wan/OrderPolicyConverterUnitTests.java @@ -0,0 +1,84 @@ +/* + * Copyright 2010-2013 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 + * + * http://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.wan; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import com.gemstone.gemfire.cache.wan.GatewaySender; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Unit tests for {@link OrderPolicyConverter}. + * + * @author John Blum + * @see org.junit.Test + * @see org.springframework.data.gemfire.wan.OrderPolicyConverter + * @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy + * @since 1.7.0 + */ +public class OrderPolicyConverterUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + private final OrderPolicyConverter converter = new OrderPolicyConverter(); + + @After + public void tearDown() { + converter.setValue(null); + } + + @Test + public void convert() { + assertThat(converter.convert("key")).isEqualTo(GatewaySender.OrderPolicy.KEY); + assertThat(converter.convert("Partition")).isEqualTo(GatewaySender.OrderPolicy.PARTITION); + assertThat(converter.convert("THREAD")).isEqualTo(GatewaySender.OrderPolicy.THREAD); + } + + @Test + public void convertIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[process] is not a valid OrderPolicy"); + + converter.convert("process"); + } + + @Test + public void setAsText() { + assertThat(converter.getValue()).isNull(); + converter.setAsText("PartItIOn"); + assertThat(converter.getValue()).isEqualTo(GatewaySender.OrderPolicy.PARTITION); + converter.setAsText("thREAD"); + assertThat(converter.getValue()).isEqualTo(GatewaySender.OrderPolicy.THREAD); + } + + @Test + public void setAsTextWithIllegalValue() { + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("[value] is not a valid OrderPolicy"); + + converter.setAsText("value"); + } +} diff --git a/src/test/resources/org/springframework/data/gemfire/config/CreateDefinedIndexesIntegrationTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/CreateDefinedIndexesIntegrationTest-context.xml deleted file mode 100644 index 186523d2..00000000 --- a/src/test/resources/org/springframework/data/gemfire/config/CreateDefinedIndexesIntegrationTest-context.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - CreateDefinedIndexesIntegrationTest - 0 - warning - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessorTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessorTest-context.xml deleted file mode 100644 index 7d180319..00000000 --- a/src/test/resources/org/springframework/data/gemfire/config/DiskStoreBeanPostProcessorTest-context.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - DiskStoreBeanPostProcessorTest - 0 - warning - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/org/springframework/data/gemfire/config/ClientCacheNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/ClientCacheNamespaceTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/ClientCacheNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/ClientCacheNamespaceTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/ContinuousQueryListenerContainerNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/ContinuousQueryListenerContainerNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/ContinuousQueryListenerContainerNamespaceTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/GatewayReceiverNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/GatewayReceiverNamespaceTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/GatewayReceiverNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/GatewayReceiverNamespaceTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml similarity index 94% rename from src/test/resources/org/springframework/data/gemfire/config/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml index 2681cff5..99e5971b 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml @@ -20,7 +20,7 @@ - diff --git a/src/test/resources/org/springframework/data/gemfire/config/InvalidRegionExpirationAttributesNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml similarity index 84% rename from src/test/resources/org/springframework/data/gemfire/config/InvalidRegionExpirationAttributesNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml index 92d4c3e9..6b77781e 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/InvalidRegionExpirationAttributesNamespaceTest-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/xml/InvalidRegionExpirationAttributesNamespaceTest-context.xml @@ -20,9 +20,9 @@ - - diff --git a/src/test/resources/org/springframework/data/gemfire/config/LocalRegionWithEvictionPolicyActionNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/LocalRegionWithEvictionPolicyActionNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/LocalRegionWithEvictionPolicyActionNamespaceTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/MultipleCacheTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/MultipleCacheTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/RegionDefinitionUsingBeansNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml similarity index 92% rename from src/test/resources/org/springframework/data/gemfire/config/RegionDefinitionUsingBeansNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml index 397fe20e..4a9a996f 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/RegionDefinitionUsingBeansNamespaceTest-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionDefinitionUsingBeansNamespaceTest-context.xml @@ -18,7 +18,7 @@ - - diff --git a/src/test/resources/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/RegionEvictionAttributesNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/RegionEvictionAttributesNamespaceTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/RegionExpirationAttributesNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml similarity index 89% rename from src/test/resources/org/springframework/data/gemfire/config/RegionExpirationAttributesNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml index c703e633..fd95b177 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/RegionExpirationAttributesNamespaceTest-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionExpirationAttributesNamespaceTest-context.xml @@ -42,20 +42,20 @@ - - - + diff --git a/src/test/resources/org/springframework/data/gemfire/config/RegionSubscriptionAttributesNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/RegionSubscriptionAttributesNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/RegionSubscriptionAttributesNamespaceTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml similarity index 100% rename from src/test/resources/org/springframework/data/gemfire/config/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/RegionsWithDiskStoreAndPersistenceEvictionSettingsTest-context.xml diff --git a/src/test/resources/org/springframework/data/gemfire/config/TemplateClientRegionNamespaceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateClientRegionNamespaceTest-context.xml similarity index 76% rename from src/test/resources/org/springframework/data/gemfire/config/TemplateClientRegionNamespaceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/config/xml/TemplateClientRegionNamespaceTest-context.xml index 5de3eef3..c52fbde7 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/TemplateClientRegionNamespaceTest-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/xml/TemplateClientRegionNamespaceTest-context.xml @@ -28,9 +28,9 @@ disk-synchronous="false" initial-capacity="51" key-constraint="java.lang.Long" load-factor="0.85" persistent="false" statistics="true" value-constraint="java.lang.String"> - - - + + + @@ -38,10 +38,10 @@ - + - +