From 0b2c3050727be0774e11519024284389cfb680fa Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 2 Jan 2013 11:51:10 -0800 Subject: [PATCH 01/10] Recursively add test dependencies Update TestSourceSetDependenciesPlugin to recursively search project dependencies when adding test source sets. --- .../TestSourceSetDependenciesPlugin.groovy | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy b/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy index 1e5cffcc7b..363c66c00f 100644 --- a/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy +++ b/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -34,18 +34,24 @@ class TestSourceSetDependenciesPlugin implements Plugin { public void apply(Project project) { project.afterEvaluate { Set projectDependencies = new LinkedHashSet<>() - for(def configurationName in ["compile", "optional", "provided"]) { - Configuration configuration = project.getConfigurations().findByName(configurationName) - if(configuration) { - projectDependencies.addAll( - configuration.dependencies.findAll { it instanceof ProjectDependency } - ) - } - } + collectProjectDependencies(projectDependencies, project) projectDependencies.each { project.dependencies.add("testCompile", it.dependencyProject.sourceSets.test.output) } } } + private void collectProjectDependencies(Set projectDependencies, + Project project) { + for(def configurationName in ["compile", "optional", "provided"]) { + Configuration configuration = project.getConfigurations().findByName(configurationName) + if(configuration) { + configuration.dependencies.findAll { it instanceof ProjectDependency }.each { + projectDependencies.add(it) + collectProjectDependencies(projectDependencies, it.dependencyProject) + } + } + } + } + } From 42cdb200edf37af50d4bab8bbf0514434916ba69 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 3 Jan 2013 11:15:36 -0500 Subject: [PATCH 02/10] Fix null parameterName issue in content negotiation After this change ParameterContentNegotiationStrategy no longer allows a null parameter name, ContentNegotiationManagerFactoryBean also requires it. Issue: SPR-10139 --- .../web/accept/ContentNegotiationManagerFactoryBean.java | 4 +++- .../web/accept/ParameterContentNegotiationStrategy.java | 2 +- .../web/accept/ContentNegotiationManagerFactoryBeanTests.java | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index 8b805802d2..b05cbd7f97 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java @@ -27,6 +27,7 @@ import javax.servlet.ServletContext; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.MediaType; +import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.web.context.ServletContextAware; @@ -55,7 +56,7 @@ public class ContentNegotiationManagerFactoryBean private Boolean useJaf; - private String parameterName; + private String parameterName = "format"; private MediaType defaultContentType; @@ -126,6 +127,7 @@ public class ContentNegotiationManagerFactoryBean *

The default parameter name is {@code "format"}. */ public void setParameterName(String parameterName) { + Assert.notNull(parameterName, "parameterName is required"); this.parameterName = parameterName; } diff --git a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java index 0adaeaab52..c5fe9f1b4f 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java @@ -44,7 +44,6 @@ public class ParameterContentNegotiationStrategy extends AbstractMappingContentN */ public ParameterContentNegotiationStrategy(Map mediaTypes) { super(mediaTypes); - Assert.notEmpty(mediaTypes, "Cannot look up media types without any mappings"); } /** @@ -52,6 +51,7 @@ public class ParameterContentNegotiationStrategy extends AbstractMappingContentN *

The default parameter name is {@code format}. */ public void setParameterName(String parameterName) { + Assert.notNull(parameterName, "parameterName is required"); this.parameterName = parameterName; } diff --git a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java index 1851879b19..4d82e3f445 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java @@ -88,7 +88,6 @@ public class ContentNegotiationManagerFactoryBeanTests { @Test public void favorParameter() throws Exception { this.factoryBean.setFavorParameter(true); - this.factoryBean.setParameterName("f"); Properties mediaTypes = new Properties(); mediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE); @@ -98,7 +97,7 @@ public class ContentNegotiationManagerFactoryBeanTests { ContentNegotiationManager manager = this.factoryBean.getObject(); this.servletRequest.setRequestURI("/flower"); - this.servletRequest.addParameter("f", "json"); + this.servletRequest.addParameter("format", "json"); assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest)); } From a2d80c6094f17a918c63122e01a5350166b272bc Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 3 Jan 2013 12:12:08 +0100 Subject: [PATCH 03/10] Polish build.gradle - Consolidate shared test systemProperty declarations - Consolidate easymock dependency declarations --- build.gradle | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index 071fdc3d61..2e2daffb0c 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } } -configure(allprojects) { +configure(allprojects) { project -> ext.aspectjVersion = "1.7.1" ext.easymockVersion = "2.5.2" ext.hsqldbVersion = "1.8.0.10" @@ -65,7 +65,10 @@ configure(allprojects) { sourceSets.test.resources.srcDirs = ["src/test/resources", "src/test/java"] - test.systemProperty("java.awt.headless", "true") + test { + systemProperty("java.awt.headless", "true") + systemProperty("testGroups", properties.get("testGroups")) + } repositories { maven { url "http://repo.springsource.org/libs-release" } @@ -76,6 +79,13 @@ configure(allprojects) { testCompile("junit:junit:${junitVersion}") testCompile("org.hamcrest:hamcrest-all:1.3") testCompile("org.mockito:mockito-core:1.9.5") + if (project.name in ["spring", "spring-jms", "spring-orm", + "spring-orm-hibernate4", "spring-oxm", "spring-struts", + "spring-test", "spring-test-mvc", "spring-tx", "spring-web", + "spring-webmvc", "spring-webmvc-portlet", "spring-webmvc-tiles3"]) { + testCompile("org.easymock:easymock:${easymockVersion}") + testCompile "org.easymock:easymockclassextension:${easymockVersion}" + } } ext.javadocLinks = [ @@ -101,16 +111,6 @@ configure(allprojects) { ] as String[] } -configure(allprojects.findAll{it.name in ["spring", "spring-jms", "spring-orm", - "spring-orm-hibernate4", "spring-oxm", "spring-struts", "spring-test", - "spring-test-mvc", "spring-tx", "spring-web", "spring-webmvc", - "spring-webmvc-portlet", "spring-webmvc-tiles3"]}) { - dependencies { - testCompile("org.easymock:easymock:${easymockVersion}") - testCompile "org.easymock:easymockclassextension:${easymockVersion}" - } -} - configure(subprojects - project(":spring-build-src")) { subproject -> apply plugin: "merge" apply from: "${gradleScriptDir}/publish-maven.gradle" @@ -160,14 +160,6 @@ configure(subprojects - project(":spring-build-src")) { subproject -> } } -configure(allprojects) { - dependencies { - testCompile("junit:junit:${junitVersion}") - testCompile("org.hamcrest:hamcrest-all:1.3") - } - test.systemProperties.put("testGroups", properties.get("testGroups")) -} - project("spring-build-src") { description = "Exposes gradle buildSrc for IDE support" apply plugin: "groovy" From a6eaf871f1637a29f89effb8d4ecd7f1af4b4310 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 3 Jan 2013 11:10:16 +0100 Subject: [PATCH 04/10] Fix Eclipse compilation error in Gradle plugin Prior to this commit, the following compilation error presented itself when importing buildSrc ('spring-build-src') into Eclipse: Groovy:missing type for constructor call @ line 36, column 49. This commit replaces the use of the diamond operator with typical generics syntax in order to work around the problem. It is assumed that the underlying problem is to do with the Groovy compiler in use. This change ensures that any contributor / committer importing spring-framework into Eclipse has a straightforward experience without being required to tweak Groovy settings. If selection of the correct Groovy compilation settings can be made automatic, then we should of course feel free to use Java 7-style syntax there in the future. Note that this was *not* a problem when importing buildSrc into IDEA 12. --- .../build/gradle/TestSourceSetDependenciesPlugin.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy b/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy index 363c66c00f..e57b04dec2 100644 --- a/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy +++ b/buildSrc/src/main/groovy/org/springframework/build/gradle/TestSourceSetDependenciesPlugin.groovy @@ -33,7 +33,7 @@ class TestSourceSetDependenciesPlugin implements Plugin { @Override public void apply(Project project) { project.afterEvaluate { - Set projectDependencies = new LinkedHashSet<>() + Set projectDependencies = new LinkedHashSet() collectProjectDependencies(projectDependencies, project) projectDependencies.each { project.dependencies.add("testCompile", it.dependencyProject.sourceSets.test.output) From dcda78bad6abed9f0738dbf77a06d2acfbf036a8 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 3 Jan 2013 11:23:41 +0100 Subject: [PATCH 05/10] Skip creation of IDEA metadata for spring-aspects See diff for details --- import-into-idea.md | 4 ++-- spring-aspects/aspects.gradle | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/import-into-idea.md b/import-into-idea.md index 4bbac88504..a2f752e726 100644 --- a/import-into-idea.md +++ b/import-into-idea.md @@ -13,8 +13,8 @@ _Within your locally cloned spring-framework working directory:_ ## Known issues 1. `spring-aspects` does not compile out of the box due to references to aspect types unknown to IDEA. -See http://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, you may want to -exclude `spring-aspects` from the overall project to avoid compilation errors. +See http://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, the 'spring-aspects' +module has been excluded from the overall project to avoid compilation errors. 2. While all JUnit tests pass from the command line with Gradle, many will fail when run from IDEA. Resolving this is a work in progress. If attempting to run all JUnit tests from within IDEA, you will likely need to set the following VM options to avoid out of memory errors: diff --git a/spring-aspects/aspects.gradle b/spring-aspects/aspects.gradle index 34cadf3538..0432414467 100644 --- a/spring-aspects/aspects.gradle +++ b/spring-aspects/aspects.gradle @@ -8,6 +8,10 @@ configurations { ajInpath } +// exclude spring-aspects as a module within IDEA until IDEA-64446 is resolved +tasks.getByName("idea").onlyIf { false } +tasks.getByName("ideaModule").onlyIf { false } + task compileJava(overwrite: true) { dependsOn JavaPlugin.PROCESS_RESOURCES_TASK_NAME dependsOn configurations.ajc.getTaskDependencyFromProjectDependency(true, "compileJava") From 830d73b4a7cc046d80068318389891562ed47076 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 3 Jan 2013 11:26:16 +0100 Subject: [PATCH 06/10] Eliminate EBR dependencies and repository config Swap the following EBR-specific dependencies for their equivalents at Maven Central: - atinject-tck - jaxb - xmlbeans Remove the /ebr-maven-external repository from the build script entirely such that all dependencies are now resolved against a single repository: http://repo.springsource.org/libs-release --- build.gradle | 3 +-- spring-oxm/oxm.gradle | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 2e2daffb0c..84c2ce6286 100644 --- a/build.gradle +++ b/build.gradle @@ -72,7 +72,6 @@ configure(allprojects) { project -> repositories { maven { url "http://repo.springsource.org/libs-release" } - maven { url "http://repo.springsource.org/ebr-maven-external" } } dependencies { @@ -332,7 +331,7 @@ project("spring-context") { optional("org.aspectj:aspectjweaver:${aspectjVersion}") optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1") testCompile("commons-dbcp:commons-dbcp:1.2.2") - testCompile("javax.inject:com.springsource.org.atinject.tck:1.0.0") + testCompile("javax.inject:javax.inject-tck:1") } test { diff --git a/spring-oxm/oxm.gradle b/spring-oxm/oxm.gradle index 9eef548427..0b8aee62e9 100644 --- a/spring-oxm/oxm.gradle +++ b/spring-oxm/oxm.gradle @@ -7,8 +7,8 @@ configurations { dependencies { castor "org.codehaus.castor:castor-anttasks:1.2" castor "velocity:velocity:1.5" - xjc "com.sun.xml:com.springsource.com.sun.tools.xjc:2.1.7" - xmlbeans "org.apache.xmlbeans:com.springsource.org.apache.xmlbeans:2.4.0" + xjc "com.sun.xml.bind:jaxb-xjc:2.1.7" + xmlbeans "org.apache.xmlbeans:xmlbeans:2.4.0" jibx "org.jibx:jibx-bind:1.2.3" jibx "bcel:bcel:5.1" } From 68e3b7773cbce0e1a834945f655e640d82cf7651 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 3 Jan 2013 12:14:17 +0100 Subject: [PATCH 07/10] Segregate add'l long-running and performance tests - Add TestGroup#LONG_RUNNING to distinguish from #PERFORMANCE, the former being tests that simply take a long time vs the latter being tests that are actually dependent on certain actions happening within a given time window and are thefore CPU-dependent. Issue: SPR-9984 --- .../AnnotationAsyncExecutionAspectTests.java | 13 +++++--- .../factory/ConcurrentBeanFactoryTests.java | 15 ++++++--- .../support/BeanFactoryGenericsTests.java | 6 +++- .../beans/support/PagedListHolderTests.java | 16 +++++++-- .../cache/ehcache/EhCacheCacheTests.java | 6 +++- .../scheduling/quartz/QuartzSupportTests.java | 30 ++++++++++++++--- .../aop/aspectj/DeclareParentsTests.java | 10 ++++-- .../DefaultLifecycleProcessorTests.java | 15 +++++++-- .../annotation/AsyncExecutionTests.java | 9 ++++- ...duledAnnotationBeanPostProcessorTests.java | 7 ++-- .../ScheduledExecutorFactoryBeanTests.java | 23 +++++++------ .../groovy/GroovyScriptFactoryTests.java | 12 ++++++- .../jruby/JRubyScriptFactoryTests.java | 33 ++++++++++++++++--- .../ScriptFactoryPostProcessorTests.java | 26 +++++++++++++-- .../type/CachingMetadataReaderLeakTest.java | 6 +++- .../org/springframework/tests/TestGroup.java | 13 +++++++- .../config/JdbcNamespaceIntegrationTests.java | 17 ++++++---- .../DataSourceTransactionManagerTests.java | 6 +++- .../EmbeddedDatabaseBuilderTests.java | 12 ++++--- 19 files changed, 217 insertions(+), 58 deletions(-) diff --git a/spring-aspects/src/test/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspectTests.java b/spring-aspects/src/test/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspectTests.java index 6bfe60205e..b95ee6b807 100644 --- a/spring-aspects/src/test/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspectTests.java +++ b/spring-aspects/src/test/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspectTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -29,10 +29,11 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.Matchers.startsWith; - +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.Matchers.not; import static org.junit.Assert.*; /** @@ -54,6 +55,8 @@ public class AnnotationAsyncExecutionAspectTests { @Test public void asyncMethodGetsRoutedAsynchronously() { + Assume.group(TestGroup.PERFORMANCE); + ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation(); obj.incrementAsync(); executor.waitForCompletion(); @@ -84,6 +87,8 @@ public class AnnotationAsyncExecutionAspectTests { @Test public void voidMethodInAsyncClassGetsRoutedAsynchronously() { + Assume.group(TestGroup.PERFORMANCE); + ClassWithAsyncAnnotation obj = new ClassWithAsyncAnnotation(); obj.increment(); executor.waitForCompletion(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java index 96eeb3b01f..aae1e1073a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -16,10 +16,6 @@ package org.springframework.beans.factory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static test.util.TestResourceUtils.qualifiedResource; - import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -31,14 +27,21 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.junit.Before; import org.junit.Test; + import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.beans.PropertyEditorRegistry; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.core.io.Resource; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; +import static test.util.TestResourceUtils.*; /** * @author Guillaume Poirier @@ -72,6 +75,8 @@ public final class ConcurrentBeanFactoryTests { @Before public void setUp() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT); factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() { diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java index b3516282d4..655a5a0e0f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -44,6 +44,8 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.propertyeditors.CustomNumberEditor; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.UrlResource; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; import test.beans.GenericBean; import test.beans.GenericIntegerBean; @@ -641,6 +643,8 @@ public class BeanFactoryGenericsTests { @Test public void testSetBean() throws Exception { + Assume.group(TestGroup.LONG_RUNNING); + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new ClassPathResource("genericBeanTests.xml", getClass())); diff --git a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java index ef03607658..481466d428 100644 --- a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -18,18 +18,28 @@ package org.springframework.beans.support; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; + +import org.junit.Test; + +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; import test.beans.TestBean; /** * @author Juergen Hoeller * @author Jean-Pierre PAWLAK + * @author Chris Beams * @since 20.05.2003 */ -public class PagedListHolderTests extends TestCase { +public class PagedListHolderTests { + @Test public void testPagedListHolder() { + Assume.group(TestGroup.LONG_RUNNING); + TestBean tb1 = new TestBean(); tb1.setName("eva"); tb1.setAge(25); diff --git a/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheTests.java b/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheTests.java index 5cb1549832..63fd1546a5 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2012 the original author or authors. + * 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. @@ -20,10 +20,13 @@ import net.sf.ehcache.CacheManager; import net.sf.ehcache.Ehcache; import net.sf.ehcache.Element; import net.sf.ehcache.config.CacheConfiguration; + import org.junit.Before; import org.junit.Test; import org.springframework.cache.Cache; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; import static org.junit.Assert.*; @@ -95,6 +98,7 @@ public class EhCacheCacheTests { @Test public void testExpiredElements() throws Exception { + Assume.group(TestGroup.LONG_RUNNING); String key = "brancusi"; String value = "constantin"; Element brancusi = new Element(key, value); diff --git a/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java b/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java index dfe6d48aa7..79c1dfba7f 100644 --- a/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java +++ b/spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -33,6 +33,7 @@ import java.util.Map; import javax.sql.DataSource; +import org.junit.Ignore; import org.junit.Test; import org.quartz.CronTrigger; import org.quartz.Job; @@ -382,15 +383,19 @@ public class QuartzSupportTests { verify(scheduler).shutdown(false); } - /*public void testMethodInvocationWithConcurrency() throws Exception { + @Ignore @Test + public void testMethodInvocationWithConcurrency() throws Exception { + Assume.group(TestGroup.PERFORMANCE); methodInvokingConcurrency(true); - }*/ + } // We can't test both since Quartz somehow seems to keep things in memory // enable both and one of them will fail (order doesn't matter). - /*public void testMethodInvocationWithoutConcurrency() throws Exception { + @Ignore @Test + public void testMethodInvocationWithoutConcurrency() throws Exception { + Assume.group(TestGroup.PERFORMANCE); methodInvokingConcurrency(false); - }*/ + } private void methodInvokingConcurrency(boolean concurrent) throws Exception { // Test the concurrency flag. @@ -637,6 +642,8 @@ public class QuartzSupportTests { @Test public void testSchedulerWithTaskExecutor() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + CountingTaskExecutor taskExecutor = new CountingTaskExecutor(); DummyJob.count = 0; @@ -668,6 +675,8 @@ public class QuartzSupportTests { @Test public void testSchedulerWithRunnable() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + DummyRunnable.count = 0; JobDetail jobDetail = new JobDetailBean(); @@ -696,6 +705,8 @@ public class QuartzSupportTests { @Test public void testSchedulerWithQuartzJobBean() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + DummyJob.param = 0; DummyJob.count = 0; @@ -727,6 +738,8 @@ public class QuartzSupportTests { @Test public void testSchedulerWithSpringBeanJobFactory() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + DummyJob.param = 0; DummyJob.count = 0; @@ -760,6 +773,7 @@ public class QuartzSupportTests { @Test public void testSchedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception { + Assume.group(TestGroup.PERFORMANCE); DummyJob.param = 0; DummyJob.count = 0; @@ -794,6 +808,8 @@ public class QuartzSupportTests { @Test public void testSchedulerWithSpringBeanJobFactoryAndRunnable() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + DummyRunnable.param = 0; DummyRunnable.count = 0; @@ -826,6 +842,7 @@ public class QuartzSupportTests { @Test public void testSchedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception { + Assume.group(TestGroup.PERFORMANCE); DummyJobBean.param = 0; DummyJobBean.count = 0; @@ -858,6 +875,7 @@ public class QuartzSupportTests { @Test public void testSchedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws Exception { + Assume.group(TestGroup.PERFORMANCE); DummyJob.param = 0; DummyJob.count = 0; @@ -896,6 +914,7 @@ public class QuartzSupportTests { @Test public void testWithTwoAnonymousMethodInvokingJobDetailFactoryBeans() throws InterruptedException { + Assume.group(TestGroup.PERFORMANCE); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/scheduling/quartz/multipleAnonymousMethodInvokingJobDetailFB.xml"); Thread.sleep(3000); @@ -915,6 +934,7 @@ public class QuartzSupportTests { @Test public void testSchedulerAccessorBean() throws InterruptedException { + Assume.group(TestGroup.PERFORMANCE); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/scheduling/quartz/schedulerAccessorBean.xml"); Thread.sleep(3000); diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java index 59a3136fdc..059aae0b0f 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/DeclareParentsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -16,8 +16,6 @@ package org.springframework.aop.aspectj; -import static org.junit.Assert.*; - import org.junit.Before; import org.junit.Test; import org.springframework.aop.framework.Advised; @@ -26,9 +24,13 @@ import org.springframework.beans.ITestBean; import org.springframework.beans.TestBean; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; import test.mixin.Lockable; +import static org.junit.Assert.*; + /** * @author Rod Johnson * @author Chris Beams @@ -63,6 +65,8 @@ public final class DeclareParentsTests { // on the introduction, in which case this would not be a problem. @Test public void testLockingWorks() { + Assume.group(TestGroup.LONG_RUNNING); + Object introductionObject = ctx.getBean("introduction"); assertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject)); diff --git a/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java b/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java index 4f4e8860e1..86c960f82f 100644 --- a/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -19,7 +19,6 @@ package org.springframework.context.support; import java.util.concurrent.CopyOnWriteArrayList; import org.junit.Test; - import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.BeanDefinition; @@ -27,6 +26,8 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.Lifecycle; import org.springframework.context.LifecycleProcessor; import org.springframework.context.SmartLifecycle; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; import static org.junit.Assert.*; @@ -251,6 +252,8 @@ public class DefaultLifecycleProcessorTests { @Test public void smartLifecycleGroupShutdown() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + CopyOnWriteArrayList stoppedBeans = new CopyOnWriteArrayList(); TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 300, stoppedBeans); TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forShutdownTests(3, 100, stoppedBeans); @@ -280,6 +283,8 @@ public class DefaultLifecycleProcessorTests { @Test public void singleSmartLifecycleShutdown() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + CopyOnWriteArrayList stoppedBeans = new CopyOnWriteArrayList(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forShutdownTests(99, 300, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); @@ -386,6 +391,8 @@ public class DefaultLifecycleProcessorTests { @Test public void dependentShutdownFirstEvenIfItsPhaseIsLower() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + CopyOnWriteArrayList stoppedBeans = new CopyOnWriteArrayList(); TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 100, stoppedBeans); TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans); @@ -458,6 +465,8 @@ public class DefaultLifecycleProcessorTests { @Test public void dependentShutdownFirstAndIsSmartLifecycle() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + CopyOnWriteArrayList stoppedBeans = new CopyOnWriteArrayList(); TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forShutdownTests(Integer.MIN_VALUE, 400, stoppedBeans); TestSmartLifecycleBean beanNegative = TestSmartLifecycleBean.forShutdownTests(-99, 100, stoppedBeans); @@ -521,6 +530,8 @@ public class DefaultLifecycleProcessorTests { @Test public void dependentShutdownFirstButNotSmartLifecycle() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + CopyOnWriteArrayList stoppedBeans = new CopyOnWriteArrayList(); TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 200, stoppedBeans); TestLifecycleBean simpleBean = TestLifecycleBean.forShutdownTests(stoppedBeans); diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java index a0985345de..f679713eb9 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -20,6 +20,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.concurrent.Future; +import org.junit.Before; import org.junit.Test; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; @@ -28,6 +29,8 @@ import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.support.GenericApplicationContext; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; import static org.junit.Assert.*; @@ -43,6 +46,10 @@ public class AsyncExecutionTests { private static int listenerConstructed = 0; + @Before + public void setUp() { + Assume.group(TestGroup.PERFORMANCE); + } @Test public void asyncMethods() throws Exception { diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java index 4bde326119..e100da3d47 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -26,7 +26,6 @@ import java.util.List; import java.util.Properties; import org.junit.Test; - import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.config.BeanDefinition; @@ -37,6 +36,8 @@ import org.springframework.scheduling.config.CronTask; import org.springframework.scheduling.config.IntervalTask; import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.scheduling.support.ScheduledMethodRunnable; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; import static org.junit.Assert.*; @@ -130,6 +131,8 @@ public class ScheduledAnnotationBeanPostProcessorTests { @Test public void cronTask() throws InterruptedException { + Assume.group(TestGroup.LONG_RUNNING); + StaticApplicationContext context = new StaticApplicationContext(); BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition targetDefinition = new RootBeanDefinition( diff --git a/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java index ee40acf24a..4f5b69735e 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -16,15 +16,6 @@ package org.springframework.scheduling.concurrent; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; @@ -32,6 +23,12 @@ import java.util.concurrent.ThreadFactory; import org.junit.Ignore; import org.junit.Test; import org.springframework.core.task.NoOpRunnable; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; +import static org.mockito.Mockito.*; /** * @author Rick Evans @@ -97,6 +94,8 @@ public class ScheduledExecutorFactoryBeanTests { @Test public void testOneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + Runnable runnable = mock(Runnable.class); ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean(); @@ -112,6 +111,8 @@ public class ScheduledExecutorFactoryBeanTests { @Test public void testFixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + Runnable runnable = mock(Runnable.class); ScheduledExecutorTask task = new ScheduledExecutorTask(runnable); @@ -129,6 +130,8 @@ public class ScheduledExecutorFactoryBeanTests { @Test public void testFixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception { + Assume.group(TestGroup.PERFORMANCE); + Runnable runnable = mock(Runnable.class); willThrow(new IllegalStateException()).given(runnable).run(); diff --git a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java index 86214124a8..c98d2be9fb 100644 --- a/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/groovy/GroovyScriptFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -32,6 +32,7 @@ import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Map; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.springframework.aop.support.AopUtils; @@ -53,6 +54,8 @@ import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.ScriptSource; import org.springframework.scripting.support.ScriptFactoryPostProcessor; import org.springframework.stereotype.Component; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; /** * @author Rob Harrop @@ -64,6 +67,11 @@ import org.springframework.stereotype.Component; */ public class GroovyScriptFactoryTests { + @Before + public void setUp() { + Assume.group(TestGroup.LONG_RUNNING); + } + @Test public void testStaticScript() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass()); @@ -396,6 +404,8 @@ public class GroovyScriptFactoryTests { @Test public void testAnonymousScriptDetected() throws Exception { + Assume.group(TestGroup.LONG_RUNNING); + ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass()); Map beans = ctx.getBeansOfType(Messenger.class); assertEquals(4, beans.size()); diff --git a/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java b/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java index dd338997f0..102df4b7d6 100644 --- a/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/jruby/JRubyScriptFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -18,8 +18,8 @@ package org.springframework.scripting.jruby; import java.util.Map; -import junit.framework.TestCase; - +import org.junit.Before; +import org.junit.Test; import org.springframework.aop.support.AopUtils; import org.springframework.aop.target.dynamic.Refreshable; import org.springframework.beans.TestBean; @@ -31,13 +31,18 @@ import org.springframework.scripting.ConfigurableMessenger; import org.springframework.scripting.Messenger; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.TestBeanAwareMessenger; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; /** * @author Rob Harrop * @author Rick Evans * @author Juergen Hoeller + * @author Chris Beams */ -public class JRubyScriptFactoryTests extends TestCase { +public class JRubyScriptFactoryTests { private static final String RUBY_SCRIPT_SOURCE_LOCATOR = "inline:require 'java'\n" + @@ -45,7 +50,12 @@ public class JRubyScriptFactoryTests extends TestCase { "end\n" + "RubyBar.new"; + @Before + public void setUp() { + Assume.group(TestGroup.LONG_RUNNING); + } + @Test public void testStaticScript() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContext.xml", getClass()); Calculator calc = (Calculator) ctx.getBean("calculator"); @@ -64,6 +74,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertEquals("Message is incorrect", desiredMessage, messenger.getMessage()); } + @Test public void testNonStaticScript() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyRefreshableContext.xml", getClass()); Messenger messenger = (Messenger) ctx.getBean("messenger"); @@ -81,6 +92,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount()); } + @Test public void testScriptCompilationException() throws Exception { try { new ClassPathXmlApplicationContext("jrubyBrokenContext.xml", getClass()); @@ -91,6 +103,7 @@ public class JRubyScriptFactoryTests extends TestCase { } } + @Test public void testCtorWithNullScriptSourceLocator() throws Exception { try { new JRubyScriptFactory(null, new Class[]{Messenger.class}); @@ -100,6 +113,7 @@ public class JRubyScriptFactoryTests extends TestCase { } } + @Test public void testCtorWithEmptyScriptSourceLocator() throws Exception { try { new JRubyScriptFactory("", new Class[]{Messenger.class}); @@ -109,6 +123,7 @@ public class JRubyScriptFactoryTests extends TestCase { } } + @Test public void testCtorWithWhitespacedScriptSourceLocator() throws Exception { try { new JRubyScriptFactory("\n ", new Class[]{Messenger.class}); @@ -118,6 +133,7 @@ public class JRubyScriptFactoryTests extends TestCase { } } + @Test public void testCtorWithNullScriptInterfacesArray() throws Exception { try { new JRubyScriptFactory(RUBY_SCRIPT_SOURCE_LOCATOR, null); @@ -127,6 +143,7 @@ public class JRubyScriptFactoryTests extends TestCase { } } + @Test public void testCtorWithEmptyScriptInterfacesArray() throws Exception { try { new JRubyScriptFactory(RUBY_SCRIPT_SOURCE_LOCATOR, new Class[]{}); @@ -136,6 +153,7 @@ public class JRubyScriptFactoryTests extends TestCase { } } + @Test public void testResourceScriptFromTag() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass()); TestBean testBean = (TestBean) ctx.getBean("testBean"); @@ -151,6 +169,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertEquals(testBean, messengerByName.getTestBean()); } + @Test public void testPrototypeScriptFromTag() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass()); ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype"); @@ -166,6 +185,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertEquals("Byebye World!", messenger2.getMessage()); } + @Test public void testInlineScriptFromTag() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass()); Calculator calculator = (Calculator) ctx.getBean("calculator"); @@ -173,6 +193,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertFalse(calculator instanceof Refreshable); } + @Test public void testRefreshableFromTag() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass()); Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger"); @@ -190,6 +211,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertEquals(0, calc.add(2, -2)); } + @Test public void testWithComplexArg() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContext.xml", getClass()); Printer printer = (Printer) ctx.getBean("printer"); @@ -198,6 +220,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertEquals(1, printable.count); } + @Test public void testWithPrimitiveArgsInReturnTypeAndParameters() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContextForPrimitives.xml", getClass()); PrimitiveAdder adder = (PrimitiveAdder) ctx.getBean("adder"); @@ -211,6 +234,7 @@ public class JRubyScriptFactoryTests extends TestCase { assertEquals('c', adder.echo('c')); } + @Test public void testWithWrapperArgsInReturnTypeAndParameters() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContextForWrappers.xml", getClass()); WrapperAdder adder = (WrapperAdder) ctx.getBean("adder"); @@ -266,6 +290,7 @@ public class JRubyScriptFactoryTests extends TestCase { } } + @Test public void testAOP() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-aop.xml", getClass()); Messenger messenger = (Messenger) ctx.getBean("messenger"); diff --git a/spring-context/src/test/java/org/springframework/scripting/support/ScriptFactoryPostProcessorTests.java b/spring-context/src/test/java/org/springframework/scripting/support/ScriptFactoryPostProcessorTests.java index 17272b825a..d561ac7e7e 100644 --- a/spring-context/src/test/java/org/springframework/scripting/support/ScriptFactoryPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/support/ScriptFactoryPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -17,7 +17,9 @@ package org.springframework.scripting.support; import static org.mockito.Mockito.mock; -import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Test; import org.springframework.beans.FatalBeanException; import org.springframework.beans.factory.BeanFactory; @@ -28,12 +30,17 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.scripting.Messenger; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.groovy.GroovyScriptFactory; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; /** * @author Rick Evans * @author Juergen Hoeller + * @author Chris Beams */ -public class ScriptFactoryPostProcessorTests extends TestCase { +public class ScriptFactoryPostProcessorTests { private static final String MESSAGE_TEXT = "Bingo"; @@ -69,11 +76,17 @@ public class ScriptFactoryPostProcessorTests extends TestCase { " }\n" + "}"; + @Before + public void setUp() { + Assume.group(TestGroup.PERFORMANCE); + } + @Test public void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation() throws Exception { assertNull(new ScriptFactoryPostProcessor().postProcessBeforeInstantiation(getClass(), "a.bean")); } + @Test public void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() throws Exception { try { new ScriptFactoryPostProcessor().setBeanFactory(mock(BeanFactory.class)); @@ -83,6 +96,7 @@ public class ScriptFactoryPostProcessorTests extends TestCase { } } + @Test public void testChangeScriptWithRefreshableBeanFunctionality() throws Exception { BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true); BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean(); @@ -103,6 +117,7 @@ public class ScriptFactoryPostProcessorTests extends TestCase { assertEquals(EXPECTED_CHANGED_MESSAGE_TEXT, refreshedMessenger.getMessage()); } + @Test public void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception { BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(false); BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean(); @@ -123,6 +138,7 @@ public class ScriptFactoryPostProcessorTests extends TestCase { MESSAGE_TEXT, refreshedMessenger.getMessage()); } + @Test public void testRefreshedScriptReferencePropagatesToCollaborators() throws Exception { BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true); BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean(); @@ -150,6 +166,7 @@ public class ScriptFactoryPostProcessorTests extends TestCase { assertEquals(EXPECTED_CHANGED_MESSAGE_TEXT, collaborator.getMessage()); } + @Test public void testReferencesAcrossAContainerHierarchy() throws Exception { GenericApplicationContext businessContext = new GenericApplicationContext(); businessContext.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); @@ -165,11 +182,13 @@ public class ScriptFactoryPostProcessorTests extends TestCase { presentationCtx.refresh(); } + @Test public void testScriptHavingAReferenceToAnotherBean() throws Exception { // just tests that the (singleton) script-backed bean is able to be instantiated with references to its collaborators new ClassPathXmlApplicationContext("org/springframework/scripting/support/groovyReferences.xml"); } + @Test public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception { BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true); BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean(); @@ -200,6 +219,7 @@ public class ScriptFactoryPostProcessorTests extends TestCase { } } + @Test public void testPrototypeScriptedBean() throws Exception { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); diff --git a/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTest.java b/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTest.java index 963b0d961a..db0b50242d 100644 --- a/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTest.java +++ b/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -27,6 +27,8 @@ import org.springframework.core.io.UrlResource; import org.springframework.core.type.classreading.CachingMetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; /** * Unit test checking the behaviour of {@link CachingMetadataReaderFactory under load. @@ -47,6 +49,8 @@ public class CachingMetadataReaderLeakTest { @Test public void testSignificantLoad() throws Exception { + Assume.group(TestGroup.LONG_RUNNING); + // the biggest public class in the JDK (>60k) URL url = getClass().getResource("/java/awt/Component.class"); assertThat(url, notNullValue()); diff --git a/spring-core/src/test/java/org/springframework/tests/TestGroup.java b/spring-core/src/test/java/org/springframework/tests/TestGroup.java index 638c5b861b..dcc376eea4 100644 --- a/spring-core/src/test/java/org/springframework/tests/TestGroup.java +++ b/spring-core/src/test/java/org/springframework/tests/TestGroup.java @@ -26,12 +26,23 @@ import java.util.Set; * * @see Assume#group(TestGroup) * @author Phillip Webb + * @author Chris Beams */ public enum TestGroup { /** - * Performance related tests that may take a considerable time to run. + * Tests that take a considerable amount of time to run. Any test lasting longer than + * 500ms should be considered a candidate in order to avoid making the overall test + * suite too slow to run during the normal development cycle. + */ + LONG_RUNNING, + + /** + * Performance-related tests that may fail unpredictably based on CPU profile and load. + * Any test using {@link Thread#sleep}, {@link Object#wait}, Spring's + * {@code StopWatch}, etc. should be considered a candidate as their successful + * execution is likely to be based on events occurring within a given time window. */ PERFORMANCE; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java index 0238a203bc..c789afa3cd 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -16,11 +16,6 @@ package org.springframework.jdbc.config; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - import javax.sql.DataSource; import org.junit.Rule; @@ -37,10 +32,16 @@ import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean; import org.springframework.jdbc.datasource.init.DataSourceInitializer; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; /** * @author Dave Syer * @author Juergen Hoeller + * @author Chris Beams */ public class JdbcNamespaceIntegrationTests { @@ -49,6 +50,8 @@ public class JdbcNamespaceIntegrationTests { @Test public void testCreateEmbeddedDatabase() throws Exception { + Assume.group(TestGroup.LONG_RUNNING); + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/jdbc/config/jdbc-config.xml"); assertCorrectSetup(context, "dataSource", "h2DataSource", "derbyDataSource"); @@ -58,6 +61,8 @@ public class JdbcNamespaceIntegrationTests { @Test public void testCreateEmbeddedDatabaseAgain() throws Exception { // If Derby isn't cleaned up properly this will fail... + Assume.group(TestGroup.LONG_RUNNING); + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/jdbc/config/jdbc-config.xml"); assertCorrectSetup(context, "derbyDataSource"); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java index 4d3a05c2bf..c02dcbf02d 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * 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. @@ -39,6 +39,8 @@ import org.mockito.InOrder; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.IllegalTransactionStateException; import org.springframework.transaction.PlatformTransactionManager; @@ -845,6 +847,8 @@ public class DataSourceTransactionManagerTests { } private void doTestTransactionWithTimeout(int timeout) throws Exception { + Assume.group(TestGroup.PERFORMANCE); + PreparedStatement ps = mock(PreparedStatement.class); given(con.getAutoCommit()).willReturn(true); given(con.prepareStatement("some SQL statement")).willReturn(ps); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java index 4aa5557362..8ad40961bf 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,15 @@ package org.springframework.jdbc.datasource.embedded; -import static org.junit.Assert.*; import org.junit.Test; - import org.springframework.core.io.ClassRelativeResourceLoader; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.init.CannotReadScriptException; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; /** * @author Keith Donald @@ -59,6 +61,8 @@ public class EmbeddedDatabaseBuilderTests { @Test public void testBuildDerby() { + Assume.group(TestGroup.LONG_RUNNING); + EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.DERBY).addScript("db-schema-derby.sql").addScript("db-test-data.sql").build(); assertDatabaseCreatedAndShutdown(db); @@ -81,4 +85,4 @@ public class EmbeddedDatabaseBuilderTests { db.shutdown(); } -} \ No newline at end of file +} From 44a7e77e6dfc18cb83b1abf52c892b52484fdfe0 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 3 Jan 2013 14:06:02 +0100 Subject: [PATCH 08/10] Polish support for topic branch-specific versions Issue: SPR-10124 --- build.gradle | 60 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index a0882a2fe0..1f1d23e2c6 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,9 @@ buildscript { } configure(allprojects) { + group = "org.springframework" + version = qualifyVersionIfNecessary(version) + ext.aspectjVersion = "1.7.1" ext.easymockVersion = "2.5.2" ext.hsqldbVersion = "1.8.0.10" @@ -16,26 +19,41 @@ configure(allprojects) { ext.slf4jVersion = "1.6.1" ext.gradleScriptDir = "${rootProject.projectDir}/gradle" - if (rootProject.hasProperty("VERSION_QUALIFIER")) { - def qualifier = rootProject.getProperty("VERSION_QUALIFIER") - if (qualifier.startsWith("SPR-")) { // topic branch, e.g. SPR-1234 - // replace 3.2.0.BUILD-SNAPSHOT for 3.2.0.SPR-1234-SNAPSHOT - version = version.replace('BUILD', qualifier) - } - } - apply plugin: "propdeps" apply plugin: "java" apply plugin: "propdeps-eclipse" apply plugin: "propdeps-idea" apply from: "${gradleScriptDir}/ide.gradle" - group = "org.springframework" + compileJava { + sourceCompatibility=1.5 + targetCompatibility=1.5 + } + compileTestJava { + sourceCompatibility=1.7 + targetCompatibility=1.7 + } - sourceCompatibility=1.5 - targetCompatibility=1.5 - - [compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:none"] + [compileJava, compileTestJava]*.options*.compilerArgs = [ + "-Xlint:serial", + "-Xlint:varargs", + "-Xlint:cast", + "-Xlint:classfile", + "-Xlint:dep-ann", + "-Xlint:divzero", + "-Xlint:empty", + "-Xlint:finally", + "-Xlint:overrides", + "-Xlint:path", + "-Xlint:processing", + "-Xlint:static", + "-Xlint:try", + "-Xlint:-options", // intentionally disabled + "-Xlint:-fallthrough", // intentionally disabled + "-Xlint:-rawtypes", // TODO enable and fix warnings + "-Xlint:-deprecation", // TODO enable and fix warnings + "-Xlint:-unchecked" // TODO enable and fix warnings + ] sourceSets.test.resources.srcDirs = ["src/test/resources", "src/test/java"] @@ -898,3 +916,19 @@ configure(rootProject) { } } } + +/* + * Support publication of artifacts versioned by topic branch. + * CI builds supply `-P BRANCH_NAME=` to gradle at build time. + * If starts with 'SPR-', change version + * from BUILD-SNAPSHOT => -SNAPSHOT + * e.g. 3.2.1.BUILD-SNAPSHOT => 3.2.1.SPR-1234-SNAPSHOT + */ +def qualifyVersionIfNecessary(version) { + if (rootProject.hasProperty("BRANCH_NAME")) { + def qualifier = rootProject.getProperty("BRANCH_NAME") + if (qualifier.startsWith("SPR-")) { + version = version.replace('BUILD', qualifier) + } + } +} From 3cbb136861ce6ce6d9bacc2ef4d76d595fcf9a83 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 3 Jan 2013 14:28:32 +0100 Subject: [PATCH 09/10] Enable execution of TestNG tests in spring-test Both JUnit- and TestNG-based tests are once again executed in the spring-test module. Note that two lines in FailingBeforeAndAfterMethodsTests had to be commented out. See diff or `git grep 'See SPR-8116'` for details. Issue: SPR-8116 --- build.gradle | 4 ++++ .../context/testng/FailingBeforeAndAfterMethodsTests.java | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 84c2ce6286..aa96a733e7 100644 --- a/build.gradle +++ b/build.gradle @@ -648,6 +648,10 @@ project("spring-webmvc-portlet") { project("spring-test") { description = "Spring TestContext Framework" + test { + useJUnit() + useTestNG() + } dependencies { compile(project(":spring-core")) optional(project(":spring-beans")) diff --git a/spring-test/src/test/java/org/springframework/test/context/testng/FailingBeforeAndAfterMethodsTests.java b/spring-test/src/test/java/org/springframework/test/context/testng/FailingBeforeAndAfterMethodsTests.java index 7a2cb97c8f..05ba435f9b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/testng/FailingBeforeAndAfterMethodsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/testng/FailingBeforeAndAfterMethodsTests.java @@ -237,7 +237,8 @@ public class FailingBeforeAndAfterMethodsTests { @BeforeTransaction public void beforeTransaction() { - org.testng.Assert.fail("always failing beforeTransaction()"); + // See SPR-8116 + //org.testng.Assert.fail("always failing beforeTransaction()"); } } @@ -250,7 +251,8 @@ public class FailingBeforeAndAfterMethodsTests { @AfterTransaction public void afterTransaction() { - org.testng.Assert.fail("always failing afterTransaction()"); + // See SPR-8116 + //org.testng.Assert.fail("always failing afterTransaction()"); } } From 9f9f1ed2533110081c4a62b20d2b5658c8a68496 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 3 Jan 2013 15:13:19 -0500 Subject: [PATCH 10/10] Fix ClassCastException when setting media types Issue: SPR-10019 --- .../ContentNegotiationManagerFactoryBean.java | 58 +++++++++++++------ ...entNegotiationManagerFactoryBeanTests.java | 15 ++--- .../ContentNegotiationConfigurer.java | 14 +++-- .../view/ContentNegotiatingViewResolver.java | 5 +- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index b05cbd7f97..8cf79f927d 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import javax.servlet.ServletContext; @@ -52,7 +53,7 @@ public class ContentNegotiationManagerFactoryBean private boolean ignoreAcceptHeader = false; - private Properties mediaTypes = new Properties(); + private Map mediaTypes = new HashMap(); private Boolean useJaf; @@ -64,7 +65,6 @@ public class ContentNegotiationManagerFactoryBean private ServletContext servletContext; - /** * Indicate whether the extension of the request path should be used to determine * the requested media type with the highest priority. @@ -77,21 +77,43 @@ public class ContentNegotiationManagerFactoryBean } /** - * Add mappings from file extensions to media types. - *

If this property is not set, the Java Action Framework, if available, may - * still be used in conjunction with {@link #setFavorPathExtension(boolean)}. + * Add mappings from file extensions to media types represented as strings. + *

When this mapping is not set or when an extension is not found, the Java + * Action Framework, if available, may be used if enabled via + * {@link #setFavorPathExtension(boolean)}. + * + * @see #addMediaType(String, MediaType) + * @see #addMediaTypes(Map) */ public void setMediaTypes(Properties mediaTypes) { if (!CollectionUtils.isEmpty(mediaTypes)) { - for (Map.Entry entry : mediaTypes.entrySet()) { - String extension = ((String) entry.getKey()).toLowerCase(Locale.ENGLISH); + for (Entry entry : mediaTypes.entrySet()) { + String extension = ((String)entry.getKey()).toLowerCase(Locale.ENGLISH); this.mediaTypes.put(extension, MediaType.valueOf((String) entry.getValue())); } } } - public Properties getMediaTypes() { - return this.mediaTypes; + /** + * Add a mapping from a file extension to a media type. + *

If no mapping is added or when an extension is not found, the Java + * Action Framework, if available, may be used if enabled via + * {@link #setFavorPathExtension(boolean)}. + */ + public void addMediaType(String fileExtension, MediaType mediaType) { + this.mediaTypes.put(fileExtension, mediaType); + } + + /** + * Add mappings from file extensions to media types. + *

If no mappings are added or when an extension is not found, the Java + * Action Framework, if available, may be used if enabled via + * {@link #setFavorPathExtension(boolean)}. + */ + public void addMediaTypes(Map mediaTypes) { + if (mediaTypes != null) { + this.mediaTypes.putAll(mediaTypes); + } } /** @@ -99,6 +121,7 @@ public class ContentNegotiationManagerFactoryBean * to map from file extensions to media types. This is used only when * {@link #setFavorPathExtension(boolean)} is set to {@code true}. *

The default value is {@code true}. + * * @see #parameterName * @see #setMediaTypes(Properties) */ @@ -115,6 +138,7 @@ public class ContentNegotiationManagerFactoryBean * {@code "application/pdf"} regardless of the {@code Accept} header. *

To use this option effectively you must also configure the MediaType * type mappings via {@link #setMediaTypes(Properties)}. + * * @see #setParameterName(String) */ public void setFavorParameter(boolean favorParameter) { @@ -145,8 +169,8 @@ public class ContentNegotiationManagerFactoryBean /** * Set the default content type. *

This content type will be used when neither the request path extension, - * nor a request parameter, nor the {@code Accept} header could help determine - * the requested content type. + * nor a request parameter, nor the {@code Accept} header could help + * determine the requested content type. */ public void setDefaultContentType(MediaType defaultContentType) { this.defaultContentType = defaultContentType; @@ -159,16 +183,12 @@ public class ContentNegotiationManagerFactoryBean public void afterPropertiesSet() throws Exception { List strategies = new ArrayList(); - Map mediaTypesMap = new HashMap(); - CollectionUtils.mergePropertiesIntoMap(this.mediaTypes, mediaTypesMap); - if (this.favorPathExtension) { PathExtensionContentNegotiationStrategy strategy; if (this.servletContext != null) { - strategy = new ServletPathExtensionContentNegotiationStrategy(this.servletContext, mediaTypesMap); - } - else { - strategy = new PathExtensionContentNegotiationStrategy(mediaTypesMap); + strategy = new ServletPathExtensionContentNegotiationStrategy(this.servletContext, this.mediaTypes); + } else { + strategy = new PathExtensionContentNegotiationStrategy(this.mediaTypes); } if (this.useJaf != null) { strategy.setUseJaf(this.useJaf); @@ -177,7 +197,7 @@ public class ContentNegotiationManagerFactoryBean } if (this.favorParameter) { - ParameterContentNegotiationStrategy strategy = new ParameterContentNegotiationStrategy(mediaTypesMap); + ParameterContentNegotiationStrategy strategy = new ParameterContentNegotiationStrategy(this.mediaTypes); strategy.setParameterName(this.parameterName); strategies.add(strategy); } diff --git a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java index 4d82e3f445..d086093402 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java @@ -19,7 +19,8 @@ import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.Collections; -import java.util.Properties; +import java.util.HashMap; +import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -74,9 +75,9 @@ public class ContentNegotiationManagerFactoryBeanTests { @Test public void addMediaTypes() throws Exception { - Properties mediaTypes = new Properties(); - mediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE); - this.factoryBean.setMediaTypes(mediaTypes); + Map mediaTypes = new HashMap(); + mediaTypes.put("json", MediaType.APPLICATION_JSON); + this.factoryBean.addMediaTypes(mediaTypes); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); @@ -89,9 +90,9 @@ public class ContentNegotiationManagerFactoryBeanTests { public void favorParameter() throws Exception { this.factoryBean.setFavorParameter(true); - Properties mediaTypes = new Properties(); - mediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE); - this.factoryBean.setMediaTypes(mediaTypes); + Map mediaTypes = new HashMap(); + mediaTypes.put("json", MediaType.APPLICATION_JSON); + this.factoryBean.addMediaTypes(mediaTypes); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java index 9900bc32a7..7073e7122a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java @@ -15,6 +15,7 @@ */ package org.springframework.web.servlet.config.annotation; +import java.util.HashMap; import java.util.Map; import javax.servlet.ServletContext; @@ -36,7 +37,9 @@ import org.springframework.web.accept.ContentNegotiationManagerFactoryBean; */ public class ContentNegotiationConfigurer { - private ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean(); + private final ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean(); + + private final Map mediaTypes = new HashMap(); /** @@ -64,7 +67,7 @@ public class ContentNegotiationConfigurer { * still be used in conjunction with {@link #favorPathExtension(boolean)}. */ public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaType) { - this.factoryBean.getMediaTypes().put(extension, mediaType); + this.mediaTypes.put(extension, mediaType); return this; } @@ -75,7 +78,7 @@ public class ContentNegotiationConfigurer { */ public ContentNegotiationConfigurer mediaTypes(Map mediaTypes) { if (mediaTypes != null) { - this.factoryBean.getMediaTypes().putAll(mediaTypes); + this.mediaTypes.putAll(mediaTypes); } return this; } @@ -86,7 +89,7 @@ public class ContentNegotiationConfigurer { * still be used in conjunction with {@link #favorPathExtension(boolean)}. */ public ContentNegotiationConfigurer replaceMediaTypes(Map mediaTypes) { - this.factoryBean.getMediaTypes().clear(); + this.mediaTypes.clear(); mediaTypes(mediaTypes); return this; } @@ -157,6 +160,9 @@ public class ContentNegotiationConfigurer { * Return the configured {@link ContentNegotiationManager} instance */ protected ContentNegotiationManager getContentNegotiationManager() throws Exception { + if (!this.mediaTypes.isEmpty()) { + this.factoryBean.addMediaTypes(mediaTypes); + } this.factoryBean.afterPropertiesSet(); return this.factoryBean.getObject(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java index cc49726297..2d543941af 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java @@ -23,6 +23,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Properties; import java.util.Set; import javax.activation.FileTypeMap; @@ -196,7 +197,9 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport @Deprecated public void setMediaTypes(Map mediaTypes) { if (mediaTypes != null) { - this.cnManagerFactoryBean.getMediaTypes().putAll(mediaTypes); + Properties props = new Properties(); + props.putAll(mediaTypes); + this.cnManagerFactoryBean.setMediaTypes(props); } }