diff --git a/gradle.properties b/gradle.properties index d9a7ce1a..31429bfa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,20 +5,20 @@ log4jVersion = 1.2.16 slf4jVersion = 1.6.4 # Common libraries -springVersion = 3.2.0.RELEASE +springVersion = 3.2.1.RELEASE springDataCommonsVersion = 1.5.0.BUILD-SNAPSHOT gemfireVersion = 7.0 # Testing junitVersion = 4.8.2 -mockitoVersion = 1.8.5 +mockitoVersion = 1.9.0 hamcrestVersion = 1.2.1 cglibVersion = 2.2 # Manifest properties ## OSGi ranges -spring.range = "[3.0.0, 4.0.0)" +spring.range = "[3.2.0, 4.0.0)" gemfire.range = "[6.5, 8.0)" # -------------------- diff --git a/src/main/java/org/springframework/data/gemfire/test/ContextLoaderUtils.java b/src/main/java/org/springframework/data/gemfire/test/ContextLoaderUtils.java deleted file mode 100644 index 711d53f4..00000000 --- a/src/main/java/org/springframework/data/gemfire/test/ContextLoaderUtils.java +++ /dev/null @@ -1,39 +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.test; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.util.StringUtils; - -/** - * @author David Turanski - * - */ -class ContextLoaderUtils { - /** - * - */ - static private Log logger = LogFactory.getLog(ContextLoaderUtils.class); - static void customizeBeanFactory(DefaultListableBeanFactory beanFactory) { - if (StringUtils.hasText(System.getProperty(GemfireTestRunner.GEMFIRE_TEST_RUNNER_DISABLED))) { - String value = System.getProperty(GemfireTestRunner.GEMFIRE_TEST_RUNNER_DISABLED); - if (!(value.equalsIgnoreCase("NO") || value.equalsIgnoreCase("FALSE"))) { - logger.warn("Mocks disabled using real GemFire components:" + GemfireTestRunner.GEMFIRE_TEST_RUNNER_DISABLED + " = " + System.getProperty(GemfireTestRunner.GEMFIRE_TEST_RUNNER_DISABLED)); - return; - } - } - beanFactory.addBeanPostProcessor(new GemfireTestBeanPostProcessor()); - } -} diff --git a/src/main/java/org/springframework/data/gemfire/test/GemfireAnnotationConfigContextLoader.java b/src/main/java/org/springframework/data/gemfire/test/GemfireAnnotationConfigContextLoader.java deleted file mode 100644 index fd840e66..00000000 --- a/src/main/java/org/springframework/data/gemfire/test/GemfireAnnotationConfigContextLoader.java +++ /dev/null @@ -1,27 +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.test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.test.context.support.AnnotationConfigContextLoader; - -/** - * @author David Turanski - * - */ -public class GemfireAnnotationConfigContextLoader extends AnnotationConfigContextLoader { - @Override - protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) { - ContextLoaderUtils.customizeBeanFactory(beanFactory); - } -} diff --git a/src/main/java/org/springframework/data/gemfire/test/GemfireSmartContextLoader.java b/src/main/java/org/springframework/data/gemfire/test/GemfireSmartContextLoader.java deleted file mode 100644 index 969c695c..00000000 --- a/src/main/java/org/springframework/data/gemfire/test/GemfireSmartContextLoader.java +++ /dev/null @@ -1,277 +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.test; - -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.ContextConfigurationAttributes; -import org.springframework.test.context.ContextLoader; -import org.springframework.test.context.MergedContextConfiguration; -import org.springframework.test.context.SmartContextLoader; -import org.springframework.test.context.support.AnnotationConfigContextLoader; -import org.springframework.test.context.support.DelegatingSmartContextLoader; -import org.springframework.test.context.support.GenericXmlContextLoader; -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; -/** - * @author David Turanski - * - */ -/* - * 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. - */ - -/** - * {@code DelegatingSmartContextLoader} is an implementation of the {@link SmartContextLoader} - * SPI that delegates to a set of candidate SmartContextLoaders (i.e., - * {@link GenericXmlContextLoader} and {@link AnnotationConfigContextLoader}) to - * determine which context loader is appropriate for a given test class's configuration. - * Each candidate is given a chance to {@link #processContextConfiguration process} the - * {@link ContextConfigurationAttributes} for each class in the test class hierarchy that - * is annotated with {@link ContextConfiguration @ContextConfiguration}, and the candidate - * that supports the merged, processed configuration will be used to actually - * {@link #loadContext load} the context. - * - *

Placing an empty {@code @ContextConfiguration} annotation on a test class signals - * that default resource locations (i.e., XML configuration files) or default - * {@link org.springframework.context.annotation.Configuration configuration classes} - * should be detected. Furthermore, if a specific {@link ContextLoader} or - * {@link SmartContextLoader} is not explicitly declared via - * {@code @ContextConfiguration}, {@code DelegatingSmartContextLoader} will be used as - * the default loader, thus providing automatic support for either XML configuration - * files or configuration classes, but not both simultaneously. - * - * @author Sam Brannen - * @author David Turanski - * Replaces {@link DelegatingSmartContextLoader} - */ -public class GemfireSmartContextLoader implements SmartContextLoader { - - private static final Log logger = LogFactory.getLog(GemfireSmartContextLoader.class); - - private final SmartContextLoader xmlLoader = new GemfireXmlContextLoader(); - private final SmartContextLoader annotationConfigLoader = new GemfireAnnotationConfigContextLoader(); - - - // --- SmartContextLoader -------------------------------------------------- - - private static String name(SmartContextLoader loader) { - return loader.getClass().getSimpleName(); - } - - private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) { - if (logger.isDebugEnabled()) { - logger.debug(String.format("Delegating to %s to process context configuration %s.", name(loader), - configAttributes)); - } - loader.processContextConfiguration(configAttributes); - } - - private static boolean supports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) { - if (loader instanceof GemfireAnnotationConfigContextLoader) { - return ObjectUtils.isEmpty(mergedConfig.getLocations()) && !ObjectUtils.isEmpty(mergedConfig.getClasses()); - } - else { - return !ObjectUtils.isEmpty(mergedConfig.getLocations()) && ObjectUtils.isEmpty(mergedConfig.getClasses()); - } - } - - /** - * Delegates to candidate {@code SmartContextLoaders} to process the supplied - * {@link ContextConfigurationAttributes}. - * - *

Delegation is based on explicit knowledge of the implementations of - * {@link GenericXmlContextLoader} and {@link AnnotationConfigContextLoader}. - * Specifically, the delegation algorithm is as follows: - * - *

- * - * @param configAttributes the context configuration attributes to process - * @throws IllegalArgumentException if the supplied configuration attributes are - * null, or if the supplied configuration attributes include both - * resource locations and configuration classes - * @throws IllegalStateException if {@code GenericXmlContextLoader} detects default - * configuration classes; if {@code AnnotationConfigContextLoader} detects default - * resource locations; if neither candidate loader detects defaults for the supplied - * context configuration; or if both candidate loaders detect defaults for the - * supplied context configuration - */ - public void processContextConfiguration(final ContextConfigurationAttributes configAttributes) { - - Assert.notNull(configAttributes, "configAttributes must not be null"); - Assert.isTrue(!(configAttributes.hasLocations() && configAttributes.hasClasses()), String.format( - "Cannot process locations AND configuration classes for context " - + "configuration %s; configure one or the other, but not both.", configAttributes)); - - // If the original locations or classes were not empty, there's no - // need to bother with default detection checks; just let the - // appropriate loader process the configuration. - if (configAttributes.hasLocations()) { - delegateProcessing(xmlLoader, configAttributes); - } - else if (configAttributes.hasClasses()) { - delegateProcessing(annotationConfigLoader, configAttributes); - } - else { - // Else attempt to detect defaults... - - // Let the XML loader process the configuration. - delegateProcessing(xmlLoader, configAttributes); - boolean xmlLoaderDetectedDefaults = configAttributes.hasLocations(); - - if (xmlLoaderDetectedDefaults) { - if (logger.isInfoEnabled()) { - logger.info(String.format("%s detected default locations for context configuration %s.", - name(xmlLoader), configAttributes)); - } - } - - if (configAttributes.hasClasses()) { - throw new IllegalStateException(String.format( - "%s should NOT have detected default configuration classes for context configuration %s.", - name(xmlLoader), configAttributes)); - } - - // Now let the annotation config loader process the configuration. - delegateProcessing(annotationConfigLoader, configAttributes); - - if (configAttributes.hasClasses()) { - if (logger.isInfoEnabled()) { - logger.info(String.format( - "%s detected default configuration classes for context configuration %s.", - name(annotationConfigLoader), configAttributes)); - } - } - - if (!xmlLoaderDetectedDefaults && configAttributes.hasLocations()) { - throw new IllegalStateException(String.format( - "%s should NOT have detected default locations for context configuration %s.", - name(annotationConfigLoader), configAttributes)); - } - - // If neither loader detected defaults, throw an exception. - if (!configAttributes.hasResources()) { - throw new IllegalStateException(String.format( - "Neither %s nor %s was able to detect defaults for context configuration %s.", name(xmlLoader), - name(annotationConfigLoader), configAttributes)); - } - - if (configAttributes.hasLocations() && configAttributes.hasClasses()) { - String message = String.format( - "Configuration error: both default locations AND default configuration classes " - + "were detected for context configuration %s; configure one or the other, but not both.", - configAttributes); - logger.error(message); - throw new IllegalStateException(message); - } - } - } - - /** - * Delegates to an appropriate candidate {@code SmartContextLoader} to load - * an {@link ApplicationContext}. - * - *

Delegation is based on explicit knowledge of the implementations of - * {@link GenericXmlContextLoader} and {@link AnnotationConfigContextLoader}. - * Specifically, the delegation algorithm is as follows: - * - *

- * - * @param mergedConfig the merged context configuration to use to load the application context - * @throws IllegalArgumentException if the supplied merged configuration is null - * @throws IllegalStateException if neither candidate loader is capable of loading an - * {@code ApplicationContext} from the supplied merged context configuration - */ - public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { - Assert.notNull(mergedConfig, "mergedConfig must not be null"); - - List candidates = Arrays.asList(xmlLoader, annotationConfigLoader); - - for (SmartContextLoader loader : candidates) { - // Determine if each loader can load a context from the - // mergedConfig. If it can, let it; otherwise, keep iterating. - if (supports(loader, mergedConfig)) { - if (logger.isDebugEnabled()) { - logger.debug(String.format("Delegating to %s to load context from %s.", name(loader), mergedConfig)); - } - return loader.loadContext(mergedConfig); - } - } - - throw new IllegalStateException(String.format( - "Neither %s nor %s was able to load an ApplicationContext from %s.", name(xmlLoader), - name(annotationConfigLoader), mergedConfig)); - } - - // --- ContextLoader ------------------------------------------------------- - - /** - * {@code DelegatingSmartContextLoader} does not support the - * {@link ContextLoader#processLocations(Class, String...)} method. Call - * {@link #processContextConfiguration(ContextConfigurationAttributes)} instead. - * @throws UnsupportedOperationException - */ - public String[] processLocations(Class clazz, String... locations) { - throw new UnsupportedOperationException("DelegatingSmartContextLoader does not support the ContextLoader SPI. " - + "Call processContextConfiguration(ContextConfigurationAttributes) instead."); - } - - /** - * {@code DelegatingSmartContextLoader} does not support the - * {@link ContextLoader#loadContext(String...) } method. Call - * {@link #loadContext(MergedContextConfiguration)} instead. - * @throws UnsupportedOperationException - */ - public ApplicationContext loadContext(String... locations) throws Exception { - throw new UnsupportedOperationException("DelegatingSmartContextLoader does not support the ContextLoader SPI. " - + "Call loadContext(MergedContextConfiguration) instead."); - } - -} diff --git a/src/main/java/org/springframework/data/gemfire/test/GemfireTestContextManager.java b/src/main/java/org/springframework/data/gemfire/test/GemfireTestContextManager.java deleted file mode 100644 index 53cd424a..00000000 --- a/src/main/java/org/springframework/data/gemfire/test/GemfireTestContextManager.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.test; - -import org.springframework.test.context.TestContextManager; - -/** - * @author David Turanski - * - */ -public class GemfireTestContextManager extends TestContextManager { - - private final static String GEMFIRE_CONTEXT_LOADER_CLASSNAME = GemfireSmartContextLoader.class.getName(); - - /** - * @param testClass - * @param defaultContextLoaderClassName - */ - public GemfireTestContextManager(Class testClass, String defaultContextLoaderClassName) { - super(testClass, defaultContextLoaderClassName); - initializeTestContext(); - } - - /** - * - */ - private void initializeTestContext() { - registerTestExecutionListeners(new GemfireTestExecutionListener()); - } - - /** - * @param testClass - */ - public GemfireTestContextManager(Class testClass) { - super(testClass,GEMFIRE_CONTEXT_LOADER_CLASSNAME); - initializeTestContext(); - } - -} diff --git a/src/main/java/org/springframework/data/gemfire/test/GemfireTestExecutionListener.java b/src/main/java/org/springframework/data/gemfire/test/GemfireTestExecutionListener.java deleted file mode 100644 index 009ccf16..00000000 --- a/src/main/java/org/springframework/data/gemfire/test/GemfireTestExecutionListener.java +++ /dev/null @@ -1,96 +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.test; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.test.context.TestContext; -import org.springframework.test.context.TestExecutionListener; - -import com.gemstone.gemfire.cache.Cache; - -/** - * @author David Turanski - * - */ -public class GemfireTestExecutionListener implements TestExecutionListener { - private static Log logger = LogFactory.getLog(GemfireTestExecutionListener.class); - - /* (non-Javadoc) - * @see org.springframework.test.context.TestExecutionListener#beforeTestClass(org.springframework.test.context.TestContext) - */ - @Override - public void beforeTestClass(TestContext testContext) throws Exception { - - } - - /* (non-Javadoc) - * @see org.springframework.test.context.TestExecutionListener#prepareTestInstance(org.springframework.test.context.TestContext) - */ - @Override - public void prepareTestInstance(TestContext testContext) throws Exception { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.springframework.test.context.TestExecutionListener#beforeTestMethod(org.springframework.test.context.TestContext) - */ - @Override - public void beforeTestMethod(TestContext testContext) throws Exception { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.springframework.test.context.TestExecutionListener#afterTestMethod(org.springframework.test.context.TestContext) - */ - @Override - public void afterTestMethod(TestContext testContext) throws Exception { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.springframework.test.context.TestExecutionListener#afterTestClass(org.springframework.test.context.TestContext) - */ - @Override - public void afterTestClass(TestContext testContext) throws Exception { - // TODO Auto-generated method stub - - } - - public static class GemfireTestBeanPostProcessor implements BeanPostProcessor { - - /* (non-Javadoc) - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String) - */ - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - logger.debug("I have bean " + beanName); - return bean; - } - - /* (non-Javadoc) - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String) - */ - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - // TODO Auto-generated method stub - return null; - } - - } -} diff --git a/src/main/java/org/springframework/data/gemfire/test/GemfireTestRunner.java b/src/main/java/org/springframework/data/gemfire/test/GemfireTestRunner.java deleted file mode 100644 index 57b455a5..00000000 --- a/src/main/java/org/springframework/data/gemfire/test/GemfireTestRunner.java +++ /dev/null @@ -1,38 +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.test; - -import org.junit.runners.model.InitializationError; -import org.springframework.test.context.TestContextManager; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author David Turanski - * - */ -public class GemfireTestRunner extends SpringJUnit4ClassRunner { - public static final String GEMFIRE_TEST_RUNNER_DISABLED = "org.springframework.data.gemfire.test.GemfireTestRunner.nomock"; - - /** - * @param clazz - * @throws InitializationError - */ - public GemfireTestRunner(Class testClass) throws InitializationError { - super(testClass); - } - - protected TestContextManager createTestContextManager(Class testClass) { - return new GemfireTestContextManager(testClass); - } - -} diff --git a/src/main/java/org/springframework/data/gemfire/test/GemfireXmlContextLoader.java b/src/main/java/org/springframework/data/gemfire/test/GemfireXmlContextLoader.java deleted file mode 100644 index 8fc017ae..00000000 --- a/src/main/java/org/springframework/data/gemfire/test/GemfireXmlContextLoader.java +++ /dev/null @@ -1,28 +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.test; - -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.test.context.support.GenericXmlContextLoader; - -/** - * @author David Turanski - * - */ -public class GemfireXmlContextLoader extends GenericXmlContextLoader { - @Override - protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) { - ContextLoaderUtils.customizeBeanFactory(beanFactory); - } - -} diff --git a/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.java index dfd746c5..c4f785be 100644 --- a/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.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.test.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -37,8 +37,9 @@ import com.gemstone.gemfire.cache.Cache; * * @author Costin Leau */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/basic-cache.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/basic-cache.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class CacheIntegrationTest { @Autowired ApplicationContext ctx; diff --git a/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java b/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java index 13245256..f690ddeb 100644 --- a/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java +++ b/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java @@ -27,9 +27,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.data.gemfire.test.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.data.gemfire.test.MockRegionFactory; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.gemstone.gemfire.cache.query.FunctionDomainException; import com.gemstone.gemfire.cache.query.NameResolutionException; @@ -42,8 +43,9 @@ import com.gemstone.gemfire.cache.query.TypeMismatchException; /** * @author Costin Leau */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/basic-template.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/basic-template.xml", +initializers=GemfireTestApplicationContextInitializer.class) public class GemfireTemplateTest { private static final String MULTI_QUERY = "select * from /simple"; diff --git a/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java b/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java index f8a267c1..00d59483 100644 --- a/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/ClientCacheTest.java @@ -22,8 +22,9 @@ import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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.client.ClientCache; @@ -33,8 +34,9 @@ import com.gemstone.gemfire.cache.client.ClientCache; * @author David Turanski * */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("client-cache.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="client-cache.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class ClientCacheTest { @Resource(name="challengeQuestionsRegion") Region region; diff --git a/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java index d7a40720..b40d6628 100644 --- a/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java @@ -27,8 +27,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.context.ApplicationContext; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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.CacheListener; import com.gemstone.gemfire.cache.CacheLoader; @@ -44,8 +45,9 @@ import com.gemstone.gemfire.cache.util.CacheWriterAdapter; * @author Costin Leau * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration(locations = { "basic-region.xml" }) +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "basic-region.xml" }, + initializers=GemfireTestApplicationContextInitializer.class) public class RegionIntegrationTest { private static class CacheList extends CacheListenerAdapter { diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java index cd7d273b..2283054d 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java @@ -33,8 +33,9 @@ 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.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; 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; @@ -45,8 +46,9 @@ import com.gemstone.gemfire.cache.util.TimestampedEntryEvent; /** * @author Costin Leau */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/config/cache-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/config/cache-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class CacheNamespaceTest{ @Autowired ApplicationContext ctx; diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java index 1e174321..ca762245 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java @@ -23,8 +23,9 @@ 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.test.GemfireTestRunner; +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.server.CacheServer; @@ -33,8 +34,9 @@ import com.gemstone.gemfire.cache.server.CacheServer; * @author Costin Leau * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/config/server-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/config/server-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class CacheServerNamespaceTest { @Autowired ApplicationContext ctx; diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java index 356e9025..afbbd371 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java @@ -34,8 +34,9 @@ import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.ClientRegionFactoryBean; import org.springframework.data.gemfire.client.Interest; import org.springframework.data.gemfire.client.RegexInterest; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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 com.gemstone.gemfire.cache.CacheListener; @@ -52,8 +53,9 @@ import com.gemstone.gemfire.cache.util.ObjectSizer; * @author Costin Leau * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("client-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="client-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class ClientRegionNamespaceTest { @Autowired diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java b/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java index 315f1352..fbf35179 100644 --- a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java @@ -36,8 +36,10 @@ import org.springframework.data.gemfire.RegionFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.SimpleObjectSizer; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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.Cache; import com.gemstone.gemfire.cache.CustomExpiry; import com.gemstone.gemfire.cache.DiskStore; @@ -57,8 +59,9 @@ import com.gemstone.gemfire.cache.util.ObjectSizer; * @author Costin Leau * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("diskstore-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="diskstore-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class DiskStoreAndEvictionRegionParsingTest { @Autowired diff --git a/src/test/java/org/springframework/data/gemfire/config/DynamicRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/DynamicRegionNamespaceTest.java index b69e351e..1ec13a2d 100644 --- a/src/test/java/org/springframework/data/gemfire/config/DynamicRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/DynamicRegionNamespaceTest.java @@ -27,7 +27,6 @@ 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.test.GemfireTestRunner; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; diff --git a/src/test/java/org/springframework/data/gemfire/config/FunctionServiceNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/FunctionServiceNamespaceTest.java index 86e759ce..de690450 100644 --- a/src/test/java/org/springframework/data/gemfire/config/FunctionServiceNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/FunctionServiceNamespaceTest.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.data.gemfire.RecreatingContextTest; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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; @@ -31,9 +31,11 @@ import com.gemstone.gemfire.cache.execute.FunctionService; /** * @author Costin Leau + * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/config/function-service-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/config/function-service-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class FunctionServiceNamespaceTest { @Test public void testFunctionsRegistered() throws Exception { diff --git a/src/test/java/org/springframework/data/gemfire/config/GemfireAsyncEventQueueNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/GemfireAsyncEventQueueNamespaceTest.java new file mode 100644 index 00000000..b39da2bb --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/GemfireAsyncEventQueueNamespaceTest.java @@ -0,0 +1,105 @@ +/* + * 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.File; +import java.io.FilenameFilter; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; +import org.springframework.data.gemfire.RecreatingContextTest; + +import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue; + +/** + * This test is only valid for GF 7.0 and above + * + * @author David Turanski + * + */ + +public class GemfireAsyncEventQueueNamespaceTest extends RecreatingContextTest { + + /* (non-Javadoc) + * @see org.springframework.data.gemfire.RecreatingContextTest#location() + */ + @Override + protected String location() { + return "/org/springframework/data/gemfire/config/async-event-queue-ns.xml"; + } + + @Override + protected void configureContext() { + //ctx.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor()); + } + + @Before + @Override + public void createCtx() { + if (ParsingUtils.GEMFIRE_VERSION.startsWith("7")) { + super.createCtx(); + } + } + + @AfterClass + public static void tearDown() { + for (String name : new File(".").list(new FilenameFilter() { + + @Override + public boolean accept(File dir, String name) { + return name.startsWith("BACKUP"); + } + })) { + new File(name).delete(); + } + } + + /** + * + */ + @Test + public void testAsyncEventQueue() { + AsyncEventQueue aseq = ctx.getBean("async-event-queue", AsyncEventQueue.class); + assertEquals(10, aseq.getBatchSize()); + assertTrue(aseq.isPersistent()); + assertEquals("diskstore", aseq.getDiskStoreName()); + assertEquals(50, aseq.getMaximumQueueMemory()); + } + + @SuppressWarnings("rawtypes") + public static class TestAsyncEventListener implements AsyncEventListener { + + @Override + public void close() { + // TODO Auto-generated method stub + } + + @Override + public boolean processEvents(List arg0) { + // TODO Auto-generated method stub + return false; + } + + } + +} diff --git a/src/test/java/org/springframework/data/gemfire/config/GemfireV6GatewayNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/GemfireV6GatewayNamespaceTest.java index 017ffc8b..42d98048 100644 --- a/src/test/java/org/springframework/data/gemfire/config/GemfireV6GatewayNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/GemfireV6GatewayNamespaceTest.java @@ -25,13 +25,12 @@ 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.RecreatingContextTest; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.data.gemfire.wan.GatewayHubFactoryBean; import org.springframework.data.gemfire.wan.GatewayProxy; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.Region; @@ -43,8 +42,9 @@ import com.gemstone.gemfire.cache.util.GatewayHub; * @author David Turanski * */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/config/gateway-v6-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/config/gateway-v6-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class GemfireV6GatewayNamespaceTest { @Autowired ApplicationContext ctx; diff --git a/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java index af766982..ab46efe2 100644 --- a/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java @@ -28,19 +28,11 @@ import java.util.List; import org.junit.AfterClass; 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.config.BeanPostProcessor; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.gemfire.RecreatingContextTest; import org.springframework.data.gemfire.RegionFactoryBean; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor; -import org.springframework.data.gemfire.test.GemfireTestRunner; import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.Region; diff --git a/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java index e683ccbc..a607e97e 100644 --- a/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java @@ -23,8 +23,10 @@ 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.test.GemfireTestRunner; +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.Cache; import com.gemstone.gemfire.cache.query.Index; import com.gemstone.gemfire.cache.query.IndexType; @@ -32,9 +34,11 @@ import com.gemstone.gemfire.cache.query.IndexType; /** * * @author Costin Leau + * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("index-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="index-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class IndexNamespaceTest { private final String name = "test-index"; diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java index 75d55b7b..ad17c7ec 100644 --- a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java @@ -29,8 +29,9 @@ import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.RegionFactoryBean; import org.springframework.data.gemfire.RegionLookupFactoryBean; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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 com.gemstone.gemfire.cache.Cache; @@ -41,9 +42,11 @@ import com.gemstone.gemfire.cache.Scope; /** * @author Costin Leau + * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("local-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="local-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class LocalRegionNamespaceTest { @Autowired diff --git a/src/test/java/org/springframework/data/gemfire/config/MembershipAttributesTest.java b/src/test/java/org/springframework/data/gemfire/config/MembershipAttributesTest.java index 298fff3d..c145c114 100644 --- a/src/test/java/org/springframework/data/gemfire/config/MembershipAttributesTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/MembershipAttributesTest.java @@ -23,9 +23,9 @@ 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.RecreatingContextTest; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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.LossAction; import com.gemstone.gemfire.cache.MembershipAttributes; @@ -37,8 +37,9 @@ import com.gemstone.gemfire.distributed.Role; * @author David Turanski * */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/config/membership-attributes-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/config/membership-attributes-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class MembershipAttributesTest { @Autowired ApplicationContext ctx; diff --git a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java index ee275fd7..195785a9 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java @@ -30,8 +30,9 @@ import org.springframework.data.gemfire.PartitionedRegionFactoryBean; import org.springframework.data.gemfire.RegionFactoryBean; import org.springframework.data.gemfire.SimplePartitionResolver; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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 com.gemstone.gemfire.cache.CacheListener; @@ -45,8 +46,9 @@ import com.gemstone.gemfire.cache.partition.PartitionListener; * @author Costin Leau * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("partitioned-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="partitioned-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class PartitionedRegionNamespaceTest { @Autowired diff --git a/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java index 283b76da..cea18ad5 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java @@ -30,7 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.client.PoolFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,8 +39,9 @@ import com.gemstone.gemfire.cache.client.PoolManager; /** * @author Costin Leau */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("pool-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="pool-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class PoolNamespaceTest { @Autowired diff --git a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java index f21f1758..d94362ff 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java @@ -29,8 +29,9 @@ import org.springframework.data.gemfire.RegionFactoryBean; import org.springframework.data.gemfire.RegionLookupFactoryBean; import org.springframework.data.gemfire.ReplicatedRegionFactoryBean; import org.springframework.data.gemfire.TestUtils; -import org.springframework.data.gemfire.test.GemfireTestRunner; +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 com.gemstone.gemfire.cache.Cache; @@ -43,8 +44,9 @@ import com.gemstone.gemfire.cache.Scope; * @author Costin Leau * @author David Turanski */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("replicated-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="replicated-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class ReplicatedRegionNamespaceTest { @Autowired diff --git a/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java index 9be5d408..db530dc0 100644 --- a/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.gemfire.SubRegionFactoryBean; -import org.springframework.data.gemfire.test.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,8 +39,9 @@ import com.gemstone.gemfire.cache.RegionAttributes; * @author David Turanski */ @SuppressWarnings("deprecation") -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("subregion-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="subregion-ns.xml", +initializers=GemfireTestApplicationContextInitializer.class) public class SubRegionNamespaceTest { @Autowired diff --git a/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java b/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java index 6055a245..7d151152 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java @@ -15,8 +15,8 @@ */ package org.springframework.data.gemfire.config; -import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import javax.annotation.Resource; @@ -24,12 +24,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.data.gemfire.test.GemfireTestRunner; import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.TransactionEvent; import com.gemstone.gemfire.cache.TransactionListener; import com.gemstone.gemfire.cache.TransactionWriter; @@ -39,8 +38,9 @@ import com.gemstone.gemfire.cache.TransactionWriterException; * @author David Turanski * */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("tx-listeners-and-writers.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="tx-listeners-and-writers.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class TxEventHandlersTest { @Autowired TestListener txListener1; diff --git a/src/test/java/org/springframework/data/gemfire/config/TxManagerNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/TxManagerNamespaceTest.java index 0f9227f7..cf11bbe5 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TxManagerNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/TxManagerNamespaceTest.java @@ -24,15 +24,16 @@ 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.RecreatingContextTest; -import org.springframework.data.gemfire.test.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Costin Leau */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration("/org/springframework/data/gemfire/config/tx-ns.xml") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="/org/springframework/data/gemfire/config/tx-ns.xml", + initializers=GemfireTestApplicationContextInitializer.class) public class TxManagerNamespaceTest { @Autowired ApplicationContext ctx; diff --git a/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java index 57570822..afda9bf8 100644 --- a/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/function/config/FunctionExecutionIntegrationTests.java @@ -25,17 +25,18 @@ import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.function.config.two.TestOnRegionFunction; import org.springframework.data.gemfire.function.execution.GemfireOnRegionFunctionTemplate; import org.springframework.data.gemfire.function.execution.OnRegionFunctionProxyFactoryBean; +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 org.springframework.data.gemfire.test.GemfireTestRunner; /** * @author David Turanski * */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration(classes={TestConfig.class}) +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes={TestConfig.class}, + initializers=GemfireTestApplicationContextInitializer.class) public class FunctionExecutionIntegrationTests { @Autowired ApplicationContext context; diff --git a/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java index aba8cdcc..b58804c9 100644 --- a/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/function/config/XmlConfiguredFunctionExecutionIntegrationTests.java @@ -23,16 +23,18 @@ import org.springframework.data.gemfire.TestUtils; import org.springframework.data.gemfire.function.config.two.TestOnRegionFunction; import org.springframework.data.gemfire.function.execution.GemfireOnRegionFunctionTemplate; import org.springframework.data.gemfire.function.execution.OnRegionFunctionProxyFactoryBean; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.test.context.ContextConfiguration; -import org.springframework.data.gemfire.test.GemfireTestRunner; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + import com.gemstone.gemfire.cache.Region; /** * @author David Turanski * */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(initializers=GemfireTestApplicationContextInitializer.class) public class XmlConfiguredFunctionExecutionIntegrationTests { @Autowired ApplicationContext context; diff --git a/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTest.java index 5775de00..dfb17a95 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/config/GemfireRepositoriesRegistrarIntegrationTest.java @@ -25,7 +25,7 @@ import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.LocalRegionFactoryBean; import org.springframework.data.gemfire.repository.sample.Person; import org.springframework.data.gemfire.repository.sample.PersonRepository; -import org.springframework.data.gemfire.test.GemfireTestRunner; +import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer; import org.springframework.data.gemfire.test.MockCacheFactoryBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,8 +39,8 @@ import com.gemstone.gemfire.cache.Region; * * @author Oliver Gierke */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(initializers=GemfireTestApplicationContextInitializer.class) public class GemfireRepositoriesRegistrarIntegrationTest { @Configuration diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java index e27d2068..89f889a7 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java @@ -35,7 +35,6 @@ import org.springframework.data.gemfire.repository.sample.PersonRepository; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.gemstone.gemfire.cache.Region; -import org.springframework.data.gemfire.test.GemfireTestRunner; /** * Integration test for {@link GemfireRepositoryFactory}. * diff --git a/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java b/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java new file mode 100644 index 00000000..29f4e067 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/test/GemfireTestApplicationContextInitializer.java @@ -0,0 +1,43 @@ +/* + * 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.test; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.util.StringUtils; + +/** + * @author David Turanski + * + */ +public class GemfireTestApplicationContextInitializer implements ApplicationContextInitializer { + private static Log logger = LogFactory.getLog(GemfireTestApplicationContextInitializer.class); + public static final String GEMFIRE_TEST_RUNNER_DISABLED = "org.springframework.data.gemfire.test.GemfireTestRunner.nomock"; + + /* (non-Javadoc) + * @see org.springframework.context.ApplicationContextInitializer#initialize(org.springframework.context.ConfigurableApplicationContext) + */ + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + if (StringUtils.hasText(System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED))) { + String value = System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED); + if (!(value.equalsIgnoreCase("NO") || value.equalsIgnoreCase("FALSE"))) { + logger.warn("Mocks disabled. Using real GemFire components:" + GEMFIRE_TEST_RUNNER_DISABLED + " = " + value); + return; + } + } + applicationContext.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor()); + } + +} diff --git a/src/main/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java b/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java similarity index 95% rename from src/main/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java rename to src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java index 871e7fae..592b22c3 100644 --- a/src/main/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java +++ b/src/test/java/org/springframework/data/gemfire/test/GemfireTestBeanPostProcessor.java @@ -34,12 +34,12 @@ public class GemfireTestBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof CacheFactoryBean) { - logger.info("replacing " + beanName+ " definition to mock GemFire components" ); bean = (bean instanceof ClientCacheFactoryBean)? new MockClientCacheFactoryBean((ClientCacheFactoryBean)bean): new MockCacheFactoryBean((CacheFactoryBean)bean); - + logger.info(String.format("replacing '%s' definition with type %s", + beanName, bean.getClass().getName())); } else if (bean instanceof CacheServerFactoryBean) { ((CacheServerFactoryBean)bean).setCache(new StubCache()); diff --git a/src/test/java/org/springframework/data/gemfire/test/GemfireTestRunnerTest.java b/src/test/java/org/springframework/data/gemfire/test/GemfireTestRunnerTest.java deleted file mode 100644 index 68a23a3a..00000000 --- a/src/test/java/org/springframework/data/gemfire/test/GemfireTestRunnerTest.java +++ /dev/null @@ -1,37 +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.test; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.model.InitializationError; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; - -/** - * @author David Turanski - * - */ -@RunWith(GemfireTestRunner.class) -@ContextConfiguration -public class GemfireTestRunnerTest { - - @Test - public void test() { - - } -} - - diff --git a/src/main/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java b/src/test/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java rename to src/test/java/org/springframework/data/gemfire/test/MockCacheFactoryBean.java diff --git a/src/main/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java b/src/test/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java rename to src/test/java/org/springframework/data/gemfire/test/MockClientCacheFactoryBean.java diff --git a/src/main/java/org/springframework/data/gemfire/test/MockRegionFactory.java b/src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/MockRegionFactory.java rename to src/test/java/org/springframework/data/gemfire/test/MockRegionFactory.java diff --git a/src/main/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java b/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java rename to src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java diff --git a/src/main/java/org/springframework/data/gemfire/test/StubCache.java b/src/test/java/org/springframework/data/gemfire/test/StubCache.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/StubCache.java rename to src/test/java/org/springframework/data/gemfire/test/StubCache.java diff --git a/src/main/java/org/springframework/data/gemfire/test/StubCacheServer.java b/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/StubCacheServer.java rename to src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java diff --git a/src/main/java/org/springframework/data/gemfire/test/StubCacheTransactionMananger.java b/src/test/java/org/springframework/data/gemfire/test/StubCacheTransactionMananger.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/StubCacheTransactionMananger.java rename to src/test/java/org/springframework/data/gemfire/test/StubCacheTransactionMananger.java diff --git a/src/main/java/org/springframework/data/gemfire/test/StubDiskStore.java b/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/StubDiskStore.java rename to src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java diff --git a/src/main/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java b/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java rename to src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java diff --git a/src/main/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java b/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java similarity index 100% rename from src/main/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java rename to src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java diff --git a/src/test/resources/org/springframework/data/gemfire/config/async-event-queue-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/async-event-queue-ns.xml new file mode 100644 index 00000000..dd22f36d --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/async-event-queue-ns.xml @@ -0,0 +1,27 @@ + + + + + 81083-4WY42-48948-0YM00-8J425,Y10AA-N0JDJ-J8R8T-07CFK-34RPC + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/test/GemfireTestRunnerTest-context.xml b/src/test/resources/org/springframework/data/gemfire/test/GemfireTestRunnerTest-context.xml deleted file mode 100644 index 2494e1b4..00000000 --- a/src/test/resources/org/springframework/data/gemfire/test/GemfireTestRunnerTest-context.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - -