From 2dbc60854bc77fead46db05e219adeffd552ba4b Mon Sep 17 00:00:00 2001 From: John Blum Date: Fri, 20 Jan 2017 22:32:56 -0800 Subject: [PATCH] SGF-588 - Reorganize and repackage additional classes in the SDG API. --- .../CallableCacheLoaderAdapter.java | 15 ++- .../GemfireDataSourcePostProcessor.java | 4 +- .../ListRegionsOnServerFunction.java | 23 ++-- .../xml/GemfireRegionAutoProxyParser.java | 4 +- .../config/xml/TransactionManagerParser.java | 4 +- .../{support => dao}/GemfireDaoSupport.java | 53 ++++----- .../json}/JSONRegionAdvice.java | 29 +++-- .../support/GemfireBeanFactoryLocator.java | 18 ++- .../support/LazyWiringDeclarableSupport.java | 8 +- .../GemfireTransactionCommitException.java | 7 +- .../GemfireTransactionManager.java | 19 ++-- .../gemfire/LocalRegionFactoryBeanTest.java | 5 +- .../data/gemfire/RegionFactoryBeanTest.java | 5 +- .../CallableCacheLoaderAdapterTest.java | 65 ++++++----- .../cache/GemfireCacheIntegrationTests.java | 2 +- .../gemfire/client/ClientCachePoolTests.java | 2 +- .../DurableClientCacheIntegrationTest.java | 4 +- .../GemfireDataSourcePostProcessorTest.java | 2 +- .../ListRegionsOnServerFunctionTest.java | 18 +-- .../config/xml/TxManagerNamespaceTest.java | 2 +- .../dao/GemfireDaoSupportUnitTests.java | 106 ++++++++++++++++++ .../json}/JSONRegionAdviceTest.java | 36 +++--- .../support/GemfireDaoSupportTests.java | 60 ---------- ...ringDeclarableSupportIntegrationTests.java | 1 + ...actGemFireClientServerIntegrationTest.java | 9 +- .../support/AbstractNativeCacheTests.java | 5 +- .../AbstractRegionFactoryBeanTests.java} | 16 +-- .../data/gemfire/basic-tx-config.xml | 8 +- .../json}/JSONRegionAdviceTest-context.xml | 2 +- 29 files changed, 302 insertions(+), 230 deletions(-) rename src/main/java/org/springframework/data/gemfire/{support => cache}/CallableCacheLoaderAdapter.java (93%) rename src/main/java/org/springframework/data/gemfire/{support => client/function}/ListRegionsOnServerFunction.java (76%) rename src/main/java/org/springframework/data/gemfire/{support => dao}/GemfireDaoSupport.java (74%) rename src/main/java/org/springframework/data/gemfire/{support => serialization/json}/JSONRegionAdvice.java (91%) rename src/main/java/org/springframework/data/gemfire/{ => transaction}/GemfireTransactionCommitException.java (90%) rename src/main/java/org/springframework/data/gemfire/{ => transaction}/GemfireTransactionManager.java (97%) rename src/test/java/org/springframework/data/gemfire/{support => cache}/CallableCacheLoaderAdapterTest.java (70%) rename src/test/java/org/springframework/data/gemfire/{support => client/function}/ListRegionsOnServerFunctionTest.java (92%) create mode 100644 src/test/java/org/springframework/data/gemfire/dao/GemfireDaoSupportUnitTests.java rename src/test/java/org/springframework/data/gemfire/{support => serialization/json}/JSONRegionAdviceTest.java (76%) delete mode 100644 src/test/java/org/springframework/data/gemfire/support/GemfireDaoSupportTests.java rename src/test/java/org/springframework/data/gemfire/test/{ => support}/AbstractGemFireClientServerIntegrationTest.java (94%) rename src/test/java/org/springframework/data/gemfire/{ => test}/support/AbstractNativeCacheTests.java (96%) rename src/test/java/org/springframework/data/gemfire/{support/AbstractRegionFactoryBeanTest.java => test/support/AbstractRegionFactoryBeanTests.java} (87%) rename src/test/resources/org/springframework/data/gemfire/{support => serialization/json}/JSONRegionAdviceTest-context.xml (94%) diff --git a/src/main/java/org/springframework/data/gemfire/support/CallableCacheLoaderAdapter.java b/src/main/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapter.java similarity index 93% rename from src/main/java/org/springframework/data/gemfire/support/CallableCacheLoaderAdapter.java rename to src/main/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapter.java index 0e184fae..825ddd33 100644 --- a/src/main/java/org/springframework/data/gemfire/support/CallableCacheLoaderAdapter.java +++ b/src/main/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2016 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. @@ -15,7 +15,7 @@ * */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.cache; import java.util.concurrent.Callable; @@ -27,17 +27,17 @@ import org.apache.geode.cache.TimeoutException; import org.springframework.util.Assert; /** - * The CallableCacheLoaderAdapter class is a {@link Callable} and GemFire {@link CacheLoader} implementation that - * adapts the {@link Callable} interface into an instance of the {@link CacheLoader} interface. This class is useful - * in situations where GemFire developers have several {@link CacheLoader} implementations that they wish to use - * with Spring's Cache Abstraction. + * The {@link CallableCacheLoaderAdapter} class is a {@link Callable} and GemFire {@link CacheLoader} implementation + * that adapts the {@link Callable} interface into an instance of the {@link CacheLoader} interface. This class is + * useful in situations where GemFire developers have several {@link CacheLoader} implementations that they wish to + * use with Spring's Cache Abstraction. * * @author John Blum * @see java.util.concurrent.Callable * @see org.apache.geode.cache.CacheLoader * @see org.apache.geode.cache.LoaderHelper * @see org.apache.geode.cache.Region - * @since 1.0.0 + * @since 1.9.0 */ @SuppressWarnings("unused") public class CallableCacheLoaderAdapter implements Callable, CacheLoader { @@ -196,5 +196,4 @@ public class CallableCacheLoaderAdapter implements Callable, CacheLoade public V load(LoaderHelper loaderHelper) throws CacheLoaderException { return getCacheLoader().load(loaderHelper); } - } diff --git a/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java index ac572161..dde4bb4b 100644 --- a/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java +++ b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java @@ -29,7 +29,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.data.gemfire.function.execution.GemfireOnServersFunctionTemplate; -import org.springframework.data.gemfire.support.ListRegionsOnServerFunction; +import org.springframework.data.gemfire.client.function.ListRegionsOnServerFunction; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -42,7 +42,7 @@ import org.springframework.util.ObjectUtils; * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory * @see org.springframework.data.gemfire.function.execution.GemfireOnServersFunctionTemplate - * @see org.springframework.data.gemfire.support.ListRegionsOnServerFunction + * @see ListRegionsOnServerFunction * @see org.apache.geode.cache.Region * @see org.apache.geode.cache.client.ClientCache * @see org.apache.geode.cache.client.ClientRegionFactory diff --git a/src/main/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunction.java b/src/main/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunction.java similarity index 76% rename from src/main/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunction.java rename to src/main/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunction.java index ad3e06b9..5a83146b 100644 --- a/src/main/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunction.java +++ b/src/main/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunction.java @@ -1,16 +1,20 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2016 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 + * 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 + * 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. * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.client.function; import java.util.ArrayList; import java.util.List; @@ -32,7 +36,7 @@ import org.apache.geode.cache.execute.FunctionContext; @SuppressWarnings("serial") public class ListRegionsOnServerFunction implements Function { - private static final long serialVersionUID = 867530169l; + private static final long serialVersionUID = 867530169L; public static final String ID = ListRegionsOnServerFunction.class.getName(); @@ -91,5 +95,4 @@ public class ListRegionsOnServerFunction implements Function { public boolean optimizeForWrite() { return false; } - } diff --git a/src/main/java/org/springframework/data/gemfire/config/xml/GemfireRegionAutoProxyParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireRegionAutoProxyParser.java index 1f27e351..3b45cffa 100644 --- a/src/main/java/org/springframework/data/gemfire/config/xml/GemfireRegionAutoProxyParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/GemfireRegionAutoProxyParser.java @@ -22,7 +22,7 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.data.gemfire.support.JSONRegionAdvice; +import org.springframework.data.gemfire.serialization.json.JSONRegionAdvice; import org.springframework.util.StringUtils; import org.w3c.dom.Element; @@ -32,7 +32,7 @@ import org.w3c.dom.Element; * @author David Turanski * @author John Blum * @see org.springframework.beans.factory.xml.BeanDefinitionParser - * @see org.springframework.data.gemfire.support.JSONRegionAdvice + * @see JSONRegionAdvice */ class GemfireRegionAutoProxyParser implements BeanDefinitionParser { diff --git a/src/main/java/org/springframework/data/gemfire/config/xml/TransactionManagerParser.java b/src/main/java/org/springframework/data/gemfire/config/xml/TransactionManagerParser.java index 7cb8753e..41057a68 100644 --- a/src/main/java/org/springframework/data/gemfire/config/xml/TransactionManagerParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/xml/TransactionManagerParser.java @@ -21,7 +21,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; 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.GemfireTransactionManager; +import org.springframework.data.gemfire.transaction.GemfireTransactionManager; import org.springframework.util.StringUtils; import org.w3c.dom.Element; @@ -31,7 +31,7 @@ import org.w3c.dom.Element; * @author Costin Leau * @author John Blum * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser - * @see org.springframework.data.gemfire.GemfireTransactionManager + * @see GemfireTransactionManager */ class TransactionManagerParser extends AbstractSingleBeanDefinitionParser { diff --git a/src/main/java/org/springframework/data/gemfire/support/GemfireDaoSupport.java b/src/main/java/org/springframework/data/gemfire/dao/GemfireDaoSupport.java similarity index 74% rename from src/main/java/org/springframework/data/gemfire/support/GemfireDaoSupport.java rename to src/main/java/org/springframework/data/gemfire/dao/GemfireDaoSupport.java index df0aeae9..9306190e 100644 --- a/src/main/java/org/springframework/data/gemfire/support/GemfireDaoSupport.java +++ b/src/main/java/org/springframework/data/gemfire/dao/GemfireDaoSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2016 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. @@ -12,9 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.dao; import org.apache.geode.cache.Region; import org.springframework.dao.support.DaoSupport; @@ -23,36 +24,25 @@ import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.util.Assert; /** - * Convenient super class for GemFire data access objects. Intended for - * GemfireTemplate usage. + * Convenient super class for GemFire Data Access Objects (DAO) implementing the Spring + * {@link DaoSupport} abstract class. Intended for use with {@link GemfireTemplate}. * - *

Requires a Region to be set, providing a GemfireTemplate based on it to subclasses. - * Can alternatively be initialized directly via a GemfireTemplate, to reuse the latter's - * settings. + * Requires a GemFire {@link Region} to be set, providing a {@link GemfireTemplate} based on it to subclasses. + * Can alternatively be initialized directly via a {@link GemfireTemplate} reusing the template's settings. * - *

This class will create its own GemfireTemplate if an Region reference is passed in. - * A custom GemfireTemplate instance can be used through overriding createGemfireTemplate. + * This class will create its own {@link GemfireTemplate} if a GemFire {@link Region} reference is passed in. + * A custom {@link GemfireTemplate} instance can be used through overriding createGemfireTemplate. * * @author Costin Leau * @author John Blum + * @see org.apache.geode.cache.Region * @see org.springframework.dao.support.DaoSupport + * @see org.springframework.data.gemfire.GemfireTemplate */ -public class GemfireDaoSupport extends DaoSupport { +public abstract class GemfireDaoSupport extends DaoSupport { private GemfireOperations gemfireTemplate; - /** - * Sets the GemFire Cache Region to be used by this DAO. Will automatically create - * an instance of the GemfireTemplate for the given Region. - * - * @param region the GemFire Cache Region upon which this DAO operates. - * @see org.apache.geode.cache.Region - * @see #createGemfireTemplate(org.apache.geode.cache.Region) - */ - public void setRegion(Region region) { - this.gemfireTemplate = createGemfireTemplate(region); - } - /** * Set the GemfireTemplate for this DAO explicitly as an alternative to specifying a GemFire Cache {@link Region}. * @@ -73,7 +63,19 @@ public class GemfireDaoSupport extends DaoSupport { * @see org.springframework.data.gemfire.GemfireTemplate */ public final GemfireOperations getGemfireTemplate() { - return gemfireTemplate; + return this.gemfireTemplate; + } + + /** + * Sets the GemFire Cache Region to be used by this DAO. Will automatically create + * an instance of the GemfireTemplate for the given Region. + * + * @param region the GemFire Cache Region upon which this DAO operates. + * @see org.apache.geode.cache.Region + * @see #createGemfireTemplate(org.apache.geode.cache.Region) + */ + public void setRegion(Region region) { + this.gemfireTemplate = createGemfireTemplate(region); } /** @@ -86,7 +88,7 @@ public class GemfireDaoSupport extends DaoSupport { * @see org.apache.geode.cache.Region * @see #setRegion */ - protected GemfireOperations createGemfireTemplate(Region region) { + protected GemfireTemplate createGemfireTemplate(Region region) { return new GemfireTemplate(region); } @@ -95,7 +97,6 @@ public class GemfireDaoSupport extends DaoSupport { */ @Override protected final void checkDaoConfig() { - Assert.state(gemfireTemplate != null, "A GemFire Cache Region or an instance of the GemfireTemplate is required."); + Assert.state(gemfireTemplate != null, "A GemFire Cache Region or instance of GemfireTemplate is required"); } - } diff --git a/src/main/java/org/springframework/data/gemfire/support/JSONRegionAdvice.java b/src/main/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdvice.java similarity index 91% rename from src/main/java/org/springframework/data/gemfire/support/JSONRegionAdvice.java rename to src/main/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdvice.java index 3944cace..b7305b2c 100644 --- a/src/main/java/org/springframework/data/gemfire/support/JSONRegionAdvice.java +++ b/src/main/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdvice.java @@ -1,17 +1,21 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2016 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 + * 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 + * 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. * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.serialization.json; import java.util.ArrayList; import java.util.Arrays; @@ -37,7 +41,15 @@ import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.util.CollectionUtils; /** + * Spring/AspectJ AOP Aspect to adapt a GemFire {@link Region} to handle JSON data. + * * @author David Turanski + * @author John Blum + * @see org.apache.geode.cache.Region + * @see org.apache.geode.pdx.JSONFormatter + * @see org.apache.geode.pdx.PdxInstance + * @see org.aspectj.lang.annotation.Aspect + * @see org.aspectj.lang.annotation.Around */ @Aspect @SuppressWarnings("unused") @@ -320,5 +332,4 @@ public class JSONRegionAdvice { } } - } diff --git a/src/main/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocator.java b/src/main/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocator.java index 31d752bd..09563d1f 100644 --- a/src/main/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocator.java +++ b/src/main/java/org/springframework/data/gemfire/support/GemfireBeanFactoryLocator.java @@ -248,6 +248,7 @@ public class GemfireBeanFactoryLocator implements BeanFactoryAware, BeanNameAwar * the {@link #setBeanName(String)} beanName} property. * * @return the single Spring {@link BeanFactory} from the registry. + * @throws IllegalArgumentException if more than Spring {@link BeanFactory} is registered. * @throws IllegalStateException if the {@link BeanFactory} with the associated * {@link #setBeanName(String) beanName} is not found. * @see org.springframework.beans.factory.BeanFactory @@ -259,9 +260,16 @@ public class GemfireBeanFactoryLocator implements BeanFactoryAware, BeanNameAwar } /** + * Attempts to use the Spring {@link BeanFactory} idenified by the given {@code beanFactoryKey}. * - * @param beanFactoryKey - * @return + * @param beanFactoryKey {@link String} containing the key used to lookup the Spring {@link BeanFactory}. + * @return the Spring {@link BeanFactory} for the given {@code beanFactoryKey}. + * @throws IllegalArgumentException if a Spring {@link BeanFactory} could not be found for {@code beanFactoryKey}. + * @throws IllegalStateException if {@literal useBeanFactoryLocator} was not configured. + * @see org.springframework.beans.factory.BeanFactory + * @see BeanFactoryReference#newBeanFactoryReference(BeanFactory) + * @see #resolveBeanFactory(String) + * @see #resolveSingleBeanFactory() */ public BeanFactory useBeanFactory(String beanFactoryKey) { return newBeanFactoryReference(StringUtils.hasText(beanFactoryKey) ? resolveBeanFactory(beanFactoryKey) @@ -349,9 +357,9 @@ public class GemfireBeanFactoryLocator implements BeanFactoryAware, BeanNameAwar * @param beanFactory {@link BeanFactory} reference to store. * @return a new instance of {@link BeanFactoryReference} initialized with the given {@link BeanFactory}. * @see org.springframework.beans.factory.BeanFactory - * @see #BeanFactoryReference(BeanFactory) + * @see #GemfireBeanFactoryLocator.BeanFactoryReference(BeanFactory) */ - public static BeanFactoryReference newBeanFactoryReference(BeanFactory beanFactory) { + protected static BeanFactoryReference newBeanFactoryReference(BeanFactory beanFactory) { return new BeanFactoryReference(beanFactory); } @@ -361,7 +369,7 @@ public class GemfireBeanFactoryLocator implements BeanFactoryAware, BeanNameAwar * @param beanFactory {@link BeanFactory} reference to store; may be {@literal null}. * @see org.springframework.beans.factory.BeanFactory */ - public BeanFactoryReference(BeanFactory beanFactory) { + protected BeanFactoryReference(BeanFactory beanFactory) { this.beanFactory.set(beanFactory); } diff --git a/src/main/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupport.java b/src/main/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupport.java index 3a406926..0d91c831 100644 --- a/src/main/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupport.java +++ b/src/main/java/org/springframework/data/gemfire/support/LazyWiringDeclarableSupport.java @@ -117,7 +117,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor * * @return a boolean value indicating whether this {@link Declarable} object has been properly configured * and initialized by the Spring container. - * @see #doInit(Properties) + * @see #doInit(BeanFactory, Properties) * @see #assertInitialized() */ protected boolean isInitialized() { @@ -130,7 +130,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor * * @return a boolean value indicating whether this {@link Declarable} object has been properly configured * and initialized by the Spring container. - * @see #doInit(Properties) + * @see #doInit(BeanFactory, Properties) * @see #isInitialized() */ protected boolean isNotInitialized() { @@ -144,7 +144,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor * * @param parameters {@link Properties} containing the configured parameters parsed from GemFire's * configuration meta-data (e.g. {@literal cache.xml}) and passed to this {@link Declarable} object. - * @see #doInit(Properties) + * @see #doInit(BeanFactory, Properties) * @see java.util.Properties */ @Override @@ -188,7 +188,7 @@ public abstract class LazyWiringDeclarableSupport extends WiringDeclarableSuppor * * @param parameters {@link Properties} containing the configured parameters parsed from GemFire's * configuration meta-data (e.g. {@literal cache.xml}) and passed to this {@link Declarable} object. - * @see #doInit(Properties) + * @see #doInit(BeanFactory, Properties) * @see java.util.Properties */ protected void doPostInit(Properties parameters) { diff --git a/src/main/java/org/springframework/data/gemfire/GemfireTransactionCommitException.java b/src/main/java/org/springframework/data/gemfire/transaction/GemfireTransactionCommitException.java similarity index 90% rename from src/main/java/org/springframework/data/gemfire/GemfireTransactionCommitException.java rename to src/main/java/org/springframework/data/gemfire/transaction/GemfireTransactionCommitException.java index 89fbe432..2ffbb7cf 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireTransactionCommitException.java +++ b/src/main/java/org/springframework/data/gemfire/transaction/GemfireTransactionCommitException.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2016 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. @@ -12,15 +12,16 @@ * 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; +package org.springframework.data.gemfire.transaction; import org.springframework.transaction.TransactionException; /** * Gemfire-specific subclass of {@link org.springframework.transaction.TransactionException}, indicating a transaction failure at commit time. - * + * * @author Costin Leau */ @SuppressWarnings("serial") diff --git a/src/main/java/org/springframework/data/gemfire/GemfireTransactionManager.java b/src/main/java/org/springframework/data/gemfire/transaction/GemfireTransactionManager.java similarity index 97% rename from src/main/java/org/springframework/data/gemfire/GemfireTransactionManager.java rename to src/main/java/org/springframework/data/gemfire/transaction/GemfireTransactionManager.java index 9cb0a818..98568daa 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireTransactionManager.java +++ b/src/main/java/org/springframework/data/gemfire/transaction/GemfireTransactionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2016 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. @@ -12,9 +12,10 @@ * 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; +package org.springframework.data.gemfire.transaction; import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheTransactionManager; @@ -52,20 +53,20 @@ import org.springframework.util.Assert; * workaround, one could use explicitly deep copy objects before making changes * to them to avoid unnecessary copying on every fetch. * - * @see org.apache.geode.cache.CacheTransactionManager + * @author Costin Leau + * @author John Blum * @see org.apache.geode.cache.Cache#setCopyOnRead(boolean) + * @see org.apache.geode.cache.CacheTransactionManager * @see org.apache.geode.cache.Region#get(Object) * @see org.apache.geode.CopyHelper#copy(Object) - * @see #setCopyOnRead(boolean) * @see org.springframework.transaction.support.AbstractPlatformTransactionManager - * - * @author Costin Leau + * @see #setCopyOnRead(boolean) */ // TODO add lenient behavior if a transaction is already started on the current // thread (what should happen then) @SuppressWarnings("serial") -public class GemfireTransactionManager extends AbstractPlatformTransactionManager implements InitializingBean, - ResourceTransactionManager { +public class GemfireTransactionManager extends AbstractPlatformTransactionManager + implements InitializingBean, ResourceTransactionManager { private Cache cache; @@ -112,7 +113,7 @@ public class GemfireTransactionManager extends AbstractPlatformTransactionManage protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException { CacheTransactionObject txObject = (CacheTransactionObject) transaction; - Cache cache = null; + Cache cache; try { cache = getCache(); diff --git a/src/test/java/org/springframework/data/gemfire/LocalRegionFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/LocalRegionFactoryBeanTest.java index 93fc6f28..46db57df 100644 --- a/src/test/java/org/springframework/data/gemfire/LocalRegionFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/LocalRegionFactoryBeanTest.java @@ -28,7 +28,7 @@ import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionFactory; import org.apache.geode.cache.RegionShortcut; import org.junit.Test; -import org.springframework.data.gemfire.support.AbstractRegionFactoryBeanTest; +import org.springframework.data.gemfire.test.support.AbstractRegionFactoryBeanTests; /** * The PartitionedRegionFactoryBeanTest class is a test suite of test cases testing the component functionality @@ -42,7 +42,7 @@ import org.springframework.data.gemfire.support.AbstractRegionFactoryBeanTest; * @since 1.3.x */ @SuppressWarnings("unchecked") -public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTest { +public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTests { private final LocalRegionFactoryBean factoryBean = new LocalRegionFactoryBean(); @@ -283,5 +283,4 @@ public class LocalRegionFactoryBeanTest extends AbstractRegionFactoryBeanTest { factoryBean.resolveDataPolicy(mockRegionFactory, false, DataPolicy.PERSISTENT_REPLICATE); verify(mockRegionFactory).setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); } - } diff --git a/src/test/java/org/springframework/data/gemfire/RegionFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/RegionFactoryBeanTest.java index 163ac1d2..933fd597 100644 --- a/src/test/java/org/springframework/data/gemfire/RegionFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/RegionFactoryBeanTest.java @@ -50,7 +50,7 @@ import org.apache.geode.cache.SubscriptionAttributes; import org.apache.geode.internal.cache.GemFireCacheImpl; import org.junit.After; import org.junit.Test; -import org.springframework.data.gemfire.support.AbstractRegionFactoryBeanTest; +import org.springframework.data.gemfire.test.support.AbstractRegionFactoryBeanTests; import org.springframework.data.gemfire.util.ArrayUtils; /** @@ -69,7 +69,7 @@ import org.springframework.data.gemfire.util.ArrayUtils; * @see org.apache.geode.cache.RegionShortcut */ @SuppressWarnings("unchecked") -public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest { +public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests { private final RegionFactoryBean factoryBean = new TestRegionFactoryBean(); @@ -1053,5 +1053,4 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTest { protected static class TestRegionFactoryBean extends RegionFactoryBean { } - } diff --git a/src/test/java/org/springframework/data/gemfire/support/CallableCacheLoaderAdapterTest.java b/src/test/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapterTest.java similarity index 70% rename from src/test/java/org/springframework/data/gemfire/support/CallableCacheLoaderAdapterTest.java rename to src/test/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapterTest.java index 83795512..3cd363ef 100644 --- a/src/test/java/org/springframework/data/gemfire/support/CallableCacheLoaderAdapterTest.java +++ b/src/test/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2016 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. @@ -15,7 +15,7 @@ * */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.cache; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -43,7 +43,8 @@ import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; /** - * Tests the adaption of the {@link java.util.concurrent.Callable} in to GemFire's {@link org.apache.geode.cache.CacheLoader} interface. + * Unit tests to test the adaption of the {@link java.util.concurrent.Callable} + * into GemFire's {@link org.apache.geode.cache.CacheLoader} interface. * * @author John Blum * @see org.junit.Rule @@ -57,7 +58,7 @@ import org.mockito.stubbing.Answer; * @see org.apache.geode.cache.CacheLoader * @see org.apache.geode.cache.LoaderHelper * @see org.apache.geode.cache.Region - * @since 1.0.0 + * @since 1.9.0 */ @RunWith(MockitoJUnitRunner.class) public class CallableCacheLoaderAdapterTest { @@ -66,7 +67,7 @@ public class CallableCacheLoaderAdapterTest { private CacheLoader mockCacheLoader; @Rule - public ExpectedException expectedException = ExpectedException.none(); + public ExpectedException exception = ExpectedException.none(); @Mock private LoaderHelper mockLoaderHelper; @@ -76,8 +77,8 @@ public class CallableCacheLoaderAdapterTest { @Test public void constructCallableCacheLoaderAdapterWithArgumentKeyAndRegion() { - CallableCacheLoaderAdapter instance = new CallableCacheLoaderAdapter( - mockCacheLoader, "key", mockRegion, "test"); + CallableCacheLoaderAdapter instance = + new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", mockRegion, "test"); assertThat(instance, is(notNullValue())); assertThat(instance.getCacheLoader(), is(sameInstance(mockCacheLoader))); @@ -88,8 +89,8 @@ public class CallableCacheLoaderAdapterTest { @Test public void constructCallableCacheLoaderAdapterWithKeyRegionAndNoArgument() { - CallableCacheLoaderAdapter instance = new CallableCacheLoaderAdapter( - mockCacheLoader, "key", mockRegion); + CallableCacheLoaderAdapter instance = + new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", mockRegion); assertThat(instance, is(notNullValue())); assertThat(instance.getCacheLoader(), is(sameInstance(mockCacheLoader))); @@ -101,7 +102,7 @@ public class CallableCacheLoaderAdapterTest { @Test public void constructCallableCacheLoaderAdapterWithNoArgumentKeyOrRegion() { CallableCacheLoaderAdapter instance = - new CallableCacheLoaderAdapter(mockCacheLoader); + new CallableCacheLoaderAdapter<>(mockCacheLoader); assertThat(instance, is(notNullValue())); assertThat(instance.getCacheLoader(), is(sameInstance(mockCacheLoader))); @@ -112,25 +113,25 @@ public class CallableCacheLoaderAdapterTest { @Test public void constructCallableCacheLoaderAdapterWithNullCacheLoader() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectCause(is(nullValue(Throwable.class))); - expectedException.expectMessage("CacheLoader must not be null"); + exception.expect(IllegalArgumentException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("CacheLoader must not be null"); - new CallableCacheLoaderAdapter(null); + new CallableCacheLoaderAdapter<>(null); } @Test @SuppressWarnings("unchecked") public void callDelegatesToLoad() throws Exception { - CallableCacheLoaderAdapter instance = new CallableCacheLoaderAdapter( - mockCacheLoader, "key", mockRegion, "test"); + CallableCacheLoaderAdapter instance = + new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", mockRegion, "test"); when(mockCacheLoader.load(any(LoaderHelper.class))).thenAnswer(new Answer() { public String answer(final InvocationOnMock invocation) throws Throwable { LoaderHelper loaderHelper = invocation.getArgumentAt(0, LoaderHelper.class); assertThat(loaderHelper, is(notNullValue())); - assertThat((String) loaderHelper.getArgument(), is(equalTo("test"))); + assertThat(loaderHelper.getArgument(), is(equalTo("test"))); assertThat(loaderHelper.getKey(), is(equalTo("key"))); assertThat(loaderHelper.getRegion(), is(sameInstance(mockRegion))); @@ -138,57 +139,55 @@ public class CallableCacheLoaderAdapterTest { } }); - assertThat((String) instance.call(), is(equalTo("mockValue"))); + assertThat(instance.call(), is(equalTo("mockValue"))); verify(mockCacheLoader, times(1)).load(isA(LoaderHelper.class)); } @Test public void callThrowsIllegalStateExceptionForNullKey() throws Exception { - CallableCacheLoaderAdapter instance = new CallableCacheLoaderAdapter( - mockCacheLoader, null, mockRegion); + CallableCacheLoaderAdapter instance = + new CallableCacheLoaderAdapter<>(mockCacheLoader, null, mockRegion); assertThat(instance.getKey(), is(nullValue())); assertThat(instance.getRegion(), is(sameInstance(mockRegion))); - expectedException.expect(IllegalStateException.class); - expectedException.expectCause(is(nullValue(Throwable.class))); - expectedException.expectMessage("The key for which the value is loaded for cannot be null"); + exception.expect(IllegalStateException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("The key for which the value is loaded for cannot be null"); instance.call(); } @Test public void callThrowsIllegalStateExceptionForNullRegion() throws Exception { - CallableCacheLoaderAdapter instance = new CallableCacheLoaderAdapter( - mockCacheLoader, "key", null); + CallableCacheLoaderAdapter instance = + new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", null); assertThat(instance.getKey(), is(equalTo("key"))); assertThat(instance.getRegion(), is(nullValue())); - expectedException.expect(IllegalStateException.class); - expectedException.expectCause(is(nullValue(Throwable.class))); - expectedException.expectMessage("The Region to load cannot be null"); + exception.expect(IllegalStateException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("The Region to load cannot be null"); instance.call(); } @Test public void closeDelegatesToCacheLoaderClose() { - new CallableCacheLoaderAdapter(mockCacheLoader).close(); + new CallableCacheLoaderAdapter<>(mockCacheLoader).close(); verify(mockCacheLoader, times(1)).close(); } @Test public void loadDelegatesToCacheLoaderLoad() { - CallableCacheLoaderAdapter instance = - new CallableCacheLoaderAdapter(mockCacheLoader); + CallableCacheLoaderAdapter instance = new CallableCacheLoaderAdapter<>(mockCacheLoader); when(mockCacheLoader.load(eq(mockLoaderHelper))).thenReturn("test"); - assertThat((String) instance.load(mockLoaderHelper), is(equalTo("test"))); + assertThat(instance.load(mockLoaderHelper), is(equalTo("test"))); verify(mockCacheLoader, times(1)).load(eq(mockLoaderHelper)); } - } diff --git a/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java index 632d9d49..63df08f6 100644 --- a/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheIntegrationTests.java @@ -33,7 +33,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.cache.Cache; import org.springframework.data.gemfire.GemfireUtils; -import org.springframework.data.gemfire.support.AbstractNativeCacheTests; +import org.springframework.data.gemfire.test.support.AbstractNativeCacheTests; /** * Integration Tests for {@link GemfireCache}. diff --git a/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolTests.java b/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolTests.java index 5752e171..6d3a1d1f 100644 --- a/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolTests.java +++ b/src/test/java/org/springframework/data/gemfire/client/ClientCachePoolTests.java @@ -32,7 +32,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.AbstractGemFireClientServerIntegrationTest; +import org.springframework.data.gemfire.test.support.AbstractGemFireClientServerIntegrationTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; diff --git a/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java index 686e259d..163097a4 100644 --- a/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/DurableClientCacheIntegrationTest.java @@ -55,7 +55,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.gemfire.GemfireUtils; import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.AbstractGemFireClientServerIntegrationTest; +import org.springframework.data.gemfire.test.support.AbstractGemFireClientServerIntegrationTest; import org.springframework.data.gemfire.test.support.ThreadUtils; import org.springframework.data.gemfire.util.DistributedSystemUtils; import org.springframework.test.annotation.DirtiesContext; @@ -74,7 +74,7 @@ import org.springframework.util.SocketUtils; * @see org.springframework.beans.factory.config.BeanPostProcessor * @see org.springframework.context.ConfigurableApplicationContext * @see org.springframework.data.gemfire.process.ProcessWrapper - * @see org.springframework.data.gemfire.test.AbstractGemFireClientServerIntegrationTest + * @see AbstractGemFireClientServerIntegrationTest * @see org.springframework.test.context.ContextConfiguration * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @see org.apache.geode.cache.client.ClientCache diff --git a/src/test/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessorTest.java b/src/test/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessorTest.java index 0323d666..52db1d3e 100644 --- a/src/test/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessorTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessorTest.java @@ -58,7 +58,7 @@ import org.junit.rules.ExpectedException; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.data.gemfire.support.ListRegionsOnServerFunction; +import org.springframework.data.gemfire.client.function.ListRegionsOnServerFunction; /** * The GemfireDataSourcePostProcessor class is a test suite of test cases testing the contract and functionality diff --git a/src/test/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunctionTest.java b/src/test/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunctionTest.java similarity index 92% rename from src/test/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunctionTest.java rename to src/test/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunctionTest.java index 7d87c6ba..e54fc5a8 100644 --- a/src/test/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunctionTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/function/ListRegionsOnServerFunctionTest.java @@ -1,20 +1,21 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2016 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 + * 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.support; +package org.springframework.data.gemfire.client.function; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -49,7 +50,7 @@ import org.mockito.stubbing.Answer; * @author John Blum * @see org.junit.Test * @see org.mockito.Mockito - * @see org.springframework.data.gemfire.support.ListRegionsOnServerFunction + * @see ListRegionsOnServerFunction * @since 1.7.0 */ public class ListRegionsOnServerFunctionTest { @@ -69,14 +70,14 @@ public class ListRegionsOnServerFunctionTest { ResultSender mockResultSender = mock(ResultSender.class, "MockGemFireResultSender"); - when(mockCache.rootRegions()).thenReturn(new HashSet>( + when(mockCache.rootRegions()).thenReturn(new HashSet<>( Arrays.>asList(mockRegionOne, mockRegionTwo, mockRegionThree))); when(mockRegionOne.getName()).thenReturn("One"); when(mockRegionTwo.getName()).thenReturn("Two"); when(mockRegionThree.getName()).thenReturn("Three"); when(mockFunctionContext.getResultSender()).thenReturn(mockResultSender); - final AtomicReference> regionNames = new AtomicReference>(null); + final AtomicReference> regionNames = new AtomicReference<>(null); doAnswer(new Answer() { @Override @@ -118,10 +119,10 @@ public class ListRegionsOnServerFunctionTest { ResultSender mockResultSender = mock(ResultSender.class, "MockGemFireResultSender"); - when(mockCache.rootRegions()).thenReturn(Collections.>emptySet()); + when(mockCache.rootRegions()).thenReturn(Collections.emptySet()); when(mockFunctionContext.getResultSender()).thenReturn(mockResultSender); - final AtomicReference> regionNames = new AtomicReference>(null); + final AtomicReference> regionNames = new AtomicReference<>(null); doAnswer(new Answer() { @Override @@ -164,5 +165,4 @@ public class ListRegionsOnServerFunctionTest { assertThat(function.isHA(), is(false)); assertThat(function.optimizeForWrite(), is(false)); } - } diff --git a/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java index 60afb505..9c7124d2 100644 --- a/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/xml/TxManagerNamespaceTest.java @@ -23,7 +23,7 @@ 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.GemfireTransactionManager; +import org.springframework.data.gemfire.transaction.GemfireTransactionManager; import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; diff --git a/src/test/java/org/springframework/data/gemfire/dao/GemfireDaoSupportUnitTests.java b/src/test/java/org/springframework/data/gemfire/dao/GemfireDaoSupportUnitTests.java new file mode 100644 index 00000000..32172f48 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/dao/GemfireDaoSupportUnitTests.java @@ -0,0 +1,106 @@ +/* + * Copyright 2016 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.dao; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import org.apache.geode.cache.Region; +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.data.gemfire.GemfireOperations; +import org.springframework.data.gemfire.GemfireTemplate; + +/** + * Unit tests for {@link GemfireDaoSupport}. + * + * @author Costin Leau + * @author John Blum + * @see org.junit.Rule + * @see org.junit.Test + * @see org.mockito.Mock + * @see org.mockito.Mockito + * @see org.mockito.runners.MockitoJUnitRunner + */ +@RunWith(MockitoJUnitRunner.class) +public class GemfireDaoSupportUnitTests { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Mock + public Region mockRegion; + + @Test + public void setAndGetGemfireTemplate() { + GemfireTemplate expectedGemfireTemplate = new GemfireTemplate(mockRegion); + GemfireDaoSupport dao = new TestGemfireDaoSupport(); + + assertThat(dao.getGemfireTemplate()).isNull(); + + dao.setGemfireTemplate(expectedGemfireTemplate); + + assertThat(dao.getGemfireTemplate()).isSameAs(expectedGemfireTemplate); + + dao.setGemfireTemplate(null); + + assertThat(dao.getGemfireTemplate()).isNull(); + } + + @Test + public void setRegion() { + GemfireDaoSupport dao = new TestGemfireDaoSupport(); + + dao.setRegion(mockRegion); + + GemfireOperations gemfireTemplate = dao.getGemfireTemplate(); + + assertThat(gemfireTemplate).isNotNull(); + assertThat(gemfireTemplate).isInstanceOf(GemfireTemplate.class); + assertThat(((GemfireTemplate) gemfireTemplate).getRegion()).isSameAs(mockRegion); + } + + @Test + @SuppressWarnings("rawtypes") + public void createProperlyInitializedGemfireDaoSupportWithTemplate() throws Exception { + GemfireTemplate expectedGemfireTemplate = new GemfireTemplate(); + GemfireDaoSupport dao = new TestGemfireDaoSupport(); + + dao.setGemfireTemplate(expectedGemfireTemplate); + dao.afterPropertiesSet(); + + assertThat(dao.getGemfireTemplate()).isNotNull(); + assertThat(dao.getGemfireTemplate()).isEqualTo(expectedGemfireTemplate); + } + + @Test + public void invalidGemfireDaoSupportInstanceThrowsIllegalStateException() throws Exception { + exception.expect(IllegalStateException.class); + exception.expectCause(is(nullValue(Throwable.class))); + exception.expectMessage("A GemFire Cache Region or instance of GemfireTemplate is required"); + + new TestGemfireDaoSupport().afterPropertiesSet(); + } + + private static final class TestGemfireDaoSupport extends GemfireDaoSupport { + } +} diff --git a/src/test/java/org/springframework/data/gemfire/support/JSONRegionAdviceTest.java b/src/test/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceTest.java similarity index 76% rename from src/test/java/org/springframework/data/gemfire/support/JSONRegionAdviceTest.java rename to src/test/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceTest.java index 4cf65e08..6ef7dab2 100644 --- a/src/test/java/org/springframework/data/gemfire/support/JSONRegionAdviceTest.java +++ b/src/test/java/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceTest.java @@ -1,17 +1,21 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2016 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 + * 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 + * 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. * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.serialization.json; import static org.junit.Assert.assertEquals; @@ -34,23 +38,28 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.GemfireOperations; import org.springframework.data.gemfire.repository.sample.Person; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * JSONRegionAdviceTest is a test suite of test cases testing SDG's support for storing and retrieving JSON data - * in GemFire Cache Regions (un)marshalled using Jackson. + * Integration test to test SDG support for storing and reading JSON data to/from + * a GemFire Cache {@link Region} by (un)marshalled JSON data using Jackson. * * @author David Turanski * @author John Blum + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.GemfireOperations + * @see org.springframework.data.gemfire.serialization.json.JSONRegionAdvice + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings({ "unchecked", "unused" }) public class JSONRegionAdviceTest { // TODO figure out why auto-proxying the Region for JSON support prevents the GemfireTemplate from being "auto-wired", // as a GemfireTemplate rather than GemfireOperations, resulting in a NoSuchBeanDefinitionException thrown by the - // Spring container!?!?!?!? + // Spring container? @Autowired private GemfireOperations template; @@ -132,5 +141,4 @@ public class JSONRegionAdviceTest { SelectResults results = template.query("firstname='Dave'"); assertEquals(toJson(daveTuranski), results.iterator().next()); } - } diff --git a/src/test/java/org/springframework/data/gemfire/support/GemfireDaoSupportTests.java b/src/test/java/org/springframework/data/gemfire/support/GemfireDaoSupportTests.java deleted file mode 100644 index 88fe602a..00000000 --- a/src/test/java/org/springframework/data/gemfire/support/GemfireDaoSupportTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2011-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.support; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.junit.Test; -import org.springframework.data.gemfire.GemfireOperations; -import org.springframework.data.gemfire.GemfireTemplate; - -/** - * @author Costin Leau - * @author John Blum - */ -public class GemfireDaoSupportTests { - - @Test - @SuppressWarnings("rawtypes") - public void testGemfireDaoSupportWithTemplate() throws Exception { - final AtomicBoolean flag = new AtomicBoolean(false); - - GemfireDaoSupport dao = new GemfireDaoSupport() { - protected void initDao() { - flag.set(true); - } - }; - - GemfireOperations expectedTemplate = new GemfireTemplate(); - - dao.setGemfireTemplate(expectedTemplate); - dao.afterPropertiesSet(); - - assertNotNull("template not created", dao.getGemfireTemplate()); - assertEquals("incorrect template", expectedTemplate, dao.getGemfireTemplate()); - assertTrue("initDao not called", flag.get()); - } - - @Test(expected = IllegalStateException.class) - public void testInvalidDaoTemplate() throws Exception { - new GemfireDaoSupport().afterPropertiesSet(); - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java index ce52b8ee..e7f615a4 100644 --- a/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/support/WiringDeclarableSupportIntegrationTests.java @@ -92,6 +92,7 @@ public class WiringDeclarableSupportIntegrationTests { @Data @NoArgsConstructor + @SuppressWarnings("all") public static class TestCacheLoader extends WiringDeclarableSupport implements CacheLoader { private Object propertyOne; diff --git a/src/test/java/org/springframework/data/gemfire/test/AbstractGemFireClientServerIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/test/support/AbstractGemFireClientServerIntegrationTest.java similarity index 94% rename from src/test/java/org/springframework/data/gemfire/test/AbstractGemFireClientServerIntegrationTest.java rename to src/test/java/org/springframework/data/gemfire/test/support/AbstractGemFireClientServerIntegrationTest.java index 2b49eb09..e510f907 100644 --- a/src/test/java/org/springframework/data/gemfire/test/AbstractGemFireClientServerIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/test/support/AbstractGemFireClientServerIntegrationTest.java @@ -1,20 +1,21 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2016 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 + * 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; +package org.springframework.data.gemfire.test.support; import java.io.File; import java.io.IOException; @@ -25,8 +26,6 @@ import java.util.concurrent.TimeUnit; import org.springframework.data.gemfire.fork.ServerProcess; import org.springframework.data.gemfire.process.ProcessExecutor; import org.springframework.data.gemfire.process.ProcessWrapper; -import org.springframework.data.gemfire.test.support.FileSystemUtils; -import org.springframework.data.gemfire.test.support.ThreadUtils; import org.springframework.util.Assert; /** diff --git a/src/test/java/org/springframework/data/gemfire/support/AbstractNativeCacheTests.java b/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java similarity index 96% rename from src/test/java/org/springframework/data/gemfire/support/AbstractNativeCacheTests.java rename to src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java index fe173605..481e78b1 100644 --- a/src/test/java/org/springframework/data/gemfire/support/AbstractNativeCacheTests.java +++ b/src/test/java/org/springframework/data/gemfire/test/support/AbstractNativeCacheTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010 the original author or authors. + * Copyright 2016 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. @@ -12,9 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.test.support; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/org/springframework/data/gemfire/support/AbstractRegionFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/test/support/AbstractRegionFactoryBeanTests.java similarity index 87% rename from src/test/java/org/springframework/data/gemfire/support/AbstractRegionFactoryBeanTest.java rename to src/test/java/org/springframework/data/gemfire/test/support/AbstractRegionFactoryBeanTests.java index e0d7abca..c912abcf 100644 --- a/src/test/java/org/springframework/data/gemfire/support/AbstractRegionFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/test/support/AbstractRegionFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2016 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. @@ -12,9 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * */ -package org.springframework.data.gemfire.support; +package org.springframework.data.gemfire.test.support; import java.io.File; import java.io.FilenameFilter; @@ -33,19 +34,15 @@ import org.springframework.data.gemfire.test.StubCache; * @author David Turanski * @author John Blum */ -public abstract class AbstractRegionFactoryBeanTest { +public abstract class AbstractRegionFactoryBeanTests { private GemFireCache cache; - private Map regionFactoryBeanConfigs = new HashMap(); + private Map regionFactoryBeanConfigs = new HashMap<>(); @AfterClass public static void cleanUp() { - for (String name : new File(".").list(new FilenameFilter() { - @Override public boolean accept(File dir, String name) { - return name.startsWith("BACKUP"); - } - })) { + for (String name : new File(".").list((dir, name1) -> name1.startsWith("BACKUP"))) { new File(name).delete(); } } @@ -114,5 +111,4 @@ public abstract class AbstractRegionFactoryBeanTest { public abstract void verify(); } - } diff --git a/src/test/resources/org/springframework/data/gemfire/basic-tx-config.xml b/src/test/resources/org/springframework/data/gemfire/basic-tx-config.xml index 40b89dc3..77de8cb9 100644 --- a/src/test/resources/org/springframework/data/gemfire/basic-tx-config.xml +++ b/src/test/resources/org/springframework/data/gemfire/basic-tx-config.xml @@ -17,10 +17,10 @@ - - - + + + - + diff --git a/src/test/resources/org/springframework/data/gemfire/support/JSONRegionAdviceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceTest-context.xml similarity index 94% rename from src/test/resources/org/springframework/data/gemfire/support/JSONRegionAdviceTest-context.xml rename to src/test/resources/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceTest-context.xml index d72299b5..8e3ee90c 100644 --- a/src/test/resources/org/springframework/data/gemfire/support/JSONRegionAdviceTest-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/serialization/json/JSONRegionAdviceTest-context.xml @@ -26,7 +26,7 @@