Skip to content

Commit 22bcb54

Browse files
rwinchrstoyanchev
authored andcommitted
Add Spring MVC Test framework
This commit adds the spring-test-mvc project [1] to the Spring Framework as part of the spring-test module. The sources are added as a root-level project called "spring-test-mvc" instead of under "spring-test" because the new sources need to be compiled with Servlet 3 while the current "spring-test" sources require Servlet 2.5 and the Eclipse IDE does not support having different classpaths for the same project. The Gradle build produces a single spring-test jar that contains sources from both "spring-test" and "spring-test-mvc". This merge is made possible through merge-dist.gradle as follows: - jar tasks of the "from" project execute tasks of the "to" project - "to" project is added to the classpath of the "from" project - "to" project pom is updated with entries from the "from" project For further details see documentation in merge-dist.gradle. Special thanks to everyone who contributed to the initial development of the Spring MVC Test framework: Arjen Poutsma <poutsma@mac.com> Craig Walls <cwalls@vmware.com> Frans Flippo <fransflippo@utopia.orange11.nl> Harry Lascelles <harry@firstbanco.com> Irfan <mail.urfi@gmail.com> Jörg Rathlev <joerg.rathlev@s24.com> Keesun Baik <whiteship2000@gmail.com> Keesun Baik <whiteship@epril.com> Matthew Reid <matthew.reid@nakedwines.com> Nils-Helge Garli Hegvik <Nils-Helge.Hegvik@telenor.com> Rob Winch <rwinch@vmware.com> Scott Frederick <sfrederick@vmware.com> Sven Filatov <sven.filatov@gmail.com> Thomas Bruyelle <thomas.bruyelle@gmail.com> youngm <youngm@gmail.com> [1]: https://github.com/SpringSource/spring-test-mvc Issue: SPR-9859, SPR-7951
1 parent 4812c18 commit 22bcb54

File tree

132 files changed

+14278
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+14278
-0
lines changed

build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,48 @@ project('spring-test') {
548548
}
549549
}
550550

551+
project('spring-test-mvc') {
552+
description = 'Spring Test MVC Framework'
553+
apply from: 'test-mvc.gradle'
554+
dependencies {
555+
compile project(":spring-context")
556+
compile project(":spring-webmvc")
557+
compile project(":spring-test").sourceSets.main.output
558+
compile("org.apache.tomcat:tomcat-servlet-api:7.0.8", provided)
559+
compile "org.hamcrest:hamcrest-all:1.1"
560+
compile("com.jayway.jsonpath:json-path:0.8.1", optional)
561+
compile("xmlunit:xmlunit:1.2", optional)
562+
testCompile("org.slf4j:jcl-over-slf4j:1.6.1")
563+
testCompile("org.slf4j:slf4j-log4j12:1.6.1") {
564+
exclude group: 'log4j', module: 'log4j'
565+
}
566+
testCompile("log4j:log4j:1.2.15") {
567+
exclude group: 'javax.mail', module: 'mail'
568+
exclude group: 'javax.jms', module: 'jms'
569+
exclude group: 'com.sun.jdmk', module: 'jmxtools'
570+
exclude group: 'com.sun.jmx', module: 'jmxri'
571+
}
572+
testCompile "javax.servlet:jstl:1.2"
573+
testCompile "org.apache.tiles:tiles-jsp:2.2.2"
574+
testCompile "org.hibernate:hibernate-validator:4.2.0.Final"
575+
testCompile "org.codehaus.jackson:jackson-mapper-asl:1.4.2"
576+
testCompile project(":spring-oxm")
577+
testCompile "com.thoughtworks.xstream:xstream:1.3.1"
578+
testCompile "cglib:cglib-nodep:2.2"
579+
testCompile "rome:rome:1.0"
580+
testCompile "javax.xml.bind:jaxb-api:2.2.6"
581+
testCompile("org.springframework.security:spring-security-core:3.1.2.RELEASE") {
582+
exclude group: 'org.springframework'
583+
}
584+
testCompile("org.springframework.security:spring-security-web:3.1.2.RELEASE") {
585+
exclude group: 'org.springframework'
586+
}
587+
testCompile("org.springframework.security:spring-security-config:3.1.2.RELEASE") {
588+
exclude group: 'org.springframework'
589+
}
590+
}
591+
}
592+
551593
project('spring-struts') {
552594
description = 'Spring Struts'
553595
dependencies {

merge-dist.gradle

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
2+
3+
/**
4+
* Will merge the distributions of the current project into mergeIntoProject. For
5+
* example, to bundle spring-test-mvc in spring-test's jars. This script will perform the
6+
* following steps:
7+
* <ul>
8+
* <li>Ensure that jar tasks of the project being merged from will execute the tasks of
9+
* the project being merged into</li>
10+
* <li>Add the project being merged into to the classpath of the project being merged
11+
* from</li>
12+
* <li>Update the pom.xml of the project being merged into to contain the entries from
13+
* the project being merged from</li>
14+
* </ul>
15+
*
16+
* Example Usage:
17+
*
18+
* ext.mergeIntoProject = project(':spring-test')
19+
* apply from: "${rootProject.projectDir}/merge-dist.gradle"
20+
*/
21+
22+
def mergeFromProject = project
23+
24+
// invoking a task on mergeFromProject will invoke the task with the same name on mergeIntoProject
25+
def taskNamesToMerge = ['sourcesJar','jar','javadocJar','javadoc','install']
26+
taskNamesToMerge.each { taskName ->
27+
def taskToRemove = tasks.getByPath(taskName)
28+
taskToRemove.enabled = false
29+
taskToRemove.dependsOn mergeIntoProject."$taskName"
30+
}
31+
32+
// update mergeIntoProject artifacts to contain the mergeFromProject artifact contents
33+
mergeIntoProject."sourcesJar" {
34+
from mergeFromProject.sourcesJar.source
35+
}
36+
mergeIntoProject."jar" {
37+
from mergeFromProject.jar.source
38+
}
39+
mergeIntoProject."javadoc" {
40+
source += mergeFromProject.javadoc.source
41+
classpath += mergeFromProject.javadoc.classpath
42+
}
43+
44+
// GRADLE-1116
45+
mergeFromProject.eclipse.classpath.file.whenMerged { classpath ->
46+
classpath.entries.removeAll { entry -> entry.path.contains("/${mergeIntoProject.name}/build/") }
47+
def dependency = new ProjectDependency("/${mergeIntoProject.name}", mergeIntoProject.path)
48+
dependency.exported = true
49+
classpath.entries.add(dependency)
50+
}
51+
52+
// Update mergeIntoProject to contain additional configurations that contains all the dependencies from mergeFromProject
53+
// so that Maven pom generation works
54+
gradle.taskGraph.whenReady {
55+
mergeFromProject.configurations.archives.artifacts.clear()
56+
57+
mergeFromProject.configurations.each { config->
58+
def mapping = mergeFromProject.conf2ScopeMappings.getMapping([config])
59+
if(mapping.scope) {
60+
def newConfigName = mergeFromProject.name + "-"+ config.name
61+
mergeIntoProject.configurations.add(newConfigName)
62+
config.dependencies.each { dependency ->
63+
mergeIntoProject.dependencies.add(newConfigName, dependency)
64+
}
65+
configure(mergeIntoProject.install.repositories.mavenInstaller.pom.scopeMappings) {
66+
addMapping(mapping.priority + 100, mergeIntoProject.configurations."$newConfigName", mapping.scope)
67+
}
68+
mergeIntoProject.optionalDeps += mergeFromProject.optionalDeps
69+
mergeIntoProject.providedDeps += mergeFromProject.providedDeps
70+
}
71+
}
72+
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include 'spring-orm'
1515
include 'spring-oxm'
1616
include 'spring-struts'
1717
include 'spring-test'
18+
include 'spring-test-mvc'
1819
include 'spring-tx'
1920
include 'spring-web'
2021
include 'spring-webmvc'
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2002-2012 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.test.web.mock;
17+
18+
/**
19+
* JUnit independent assertion class.
20+
*
21+
* @author Lukas Krecan
22+
* @author Arjen Poutsma
23+
* @since 3.2
24+
*/
25+
public abstract class AssertionErrors {
26+
27+
private AssertionErrors() {
28+
}
29+
30+
/**
31+
* Fails a test with the given message.
32+
*
33+
* @param message the message
34+
*/
35+
public static void fail(String message) {
36+
throw new AssertionError(message);
37+
}
38+
39+
/**
40+
* Fails a test with the given message passing along expected and actual values to be added to the message.
41+
*
42+
* @param message the message
43+
* @param expected the expected value
44+
* @param actual the actual value
45+
*/
46+
public static void fail(String message, Object expected, Object actual) {
47+
throw new AssertionError(message + " expected:<" + expected + "> but was:<" + actual + ">");
48+
}
49+
50+
/**
51+
* Asserts that a condition is {@code true}. If not, throws an {@link AssertionError} with the given message.
52+
*
53+
* @param message the message
54+
* @param condition the condition to test for
55+
*/
56+
public static void assertTrue(String message, boolean condition) {
57+
if (!condition) {
58+
fail(message);
59+
}
60+
}
61+
62+
/**
63+
* Asserts that two objects are equal. If not, an {@link AssertionError} is thrown with the given message.
64+
*
65+
* @param message the message
66+
* @param expected the expected value
67+
* @param actual the actual value
68+
*/
69+
public static void assertEquals(String message, Object expected, Object actual) {
70+
if (expected == null && actual == null) {
71+
return;
72+
}
73+
if (expected != null && expected.equals(actual)) {
74+
return;
75+
}
76+
fail(message, expected, actual);
77+
}
78+
79+
}

0 commit comments

Comments
 (0)