Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GRAILS-3237 - Replace JUnit 3 with JUnit 4.

Our custom runner mimics JUnit 3 behaviours like the “test”, “setUp” and “tearDown” conventions for backwards compatibility.
  • Loading branch information...
commit 8a6d774ed31c556f143f67c8e0fb534ff83ac5f6 1 parent 041c47b
@alkemist alkemist authored
Showing with 658 additions and 479 deletions.
  1. +1 −1  build.properties
  2. +2 −2 dependencies.txt
  3. +1 −1  grails.ipr
  4. +2 −2 ivy.xml
  5. BIN  lib/junit-3.8.2.jar
  6. BIN  lib/junit-4.8.1.jar
  7. +1 −1  maven/grails-core.pom.in
  8. +1 −1  maven/grails-crud.pom.in
  9. +1 −1  maven/grails-gorm.pom.in
  10. +1 −1  maven/grails-scripts.pom.in
  11. +1 −1  maven/grails-spring.pom.in
  12. +2 −1  maven/grails-test.mf
  13. +1 −1  maven/grails-test.pom.in
  14. +1 −1  maven/grails-web.pom.in
  15. +1 −1  maven/grails-webflow.pom.in
  16. +5 −5 scripts/_GrailsTest.groovy
  17. +2 −2 src/java/org/codehaus/groovy/grails/resolve/IvyDependencyManager.groovy
  18. +0 −100 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsEnvironmentTestSuite.groovy
  19. +0 −140 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsTestType.java
  20. +0 −101 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsTestTypeRunner.java
  21. +0 −76 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3ListenerEventPublisherAdapter.java
  22. +116 −0 src/java/org/codehaus/groovy/grails/test/junit4/JUnit4GrailsTestType.groovy
  23. +118 −0 src/java/org/codehaus/groovy/grails/test/junit4/listener/PerTestRunListener.groovy
  24. +83 −0 src/java/org/codehaus/groovy/grails/test/junit4/listener/SuiteRunListener.groovy
  25. +20 −25 ...nit3/JUnit3GrailsTestTypeResult.groovy → junit4/result/JUnit4ResultGrailsTestTypeResultAdapter.groovy}
  26. +141 −0 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestCaseRunner.groovy
  27. +54 −0 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestCaseRunnerBuilder.groovy
  28. +75 −0 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestInvokeMethod.groovy
  29. +1 −1  src/java/org/codehaus/groovy/grails/test/support/ControllerNameExtractor.groovy
  30. +2 −2 ...g/codehaus/groovy/grails/test/{junit3/JUnit3GrailsTestTypeMode.groovy → support/GrailsTestMode.groovy}
  31. +13 −0 src/java/org/codehaus/groovy/grails/test/support/GrailsTestTypeSupport.groovy
  32. +12 −12 src/test/org/codehaus/groovy/grails/resolve/IvyDependencyManagerTests.groovy
View
2  build.properties
@@ -19,7 +19,7 @@ bundlor.spring.version=3.0.0.RELEASE
bundlor.ant.version=1.7.1
bundlor.ivy.version=2.0.0
bundlor.gant.version=1.9.1
-bundlor.junit.version=3.8.2
+bundlor.junit.version=4.8.1
bundlor.commons.logging.version=1.1.0
bundlor.commons.beanutils.version=1.8.0
bundlor.commons.lang.version=2.4.0
View
4 dependencies.txt
@@ -120,8 +120,8 @@ The following libraries are included in Grails because they are required either
- Java Transaction API
- required for running Grails applications
-* junit-3.8.2.jar
-- JUnit 3.8.2 (http://junit.org) CPL 1.0 License
+* junit-4.8.1.jar
+- JUnit 4.8.1 (http://junit.org) CPL 1.0 License
- required for building Grails core
- required for the command line tools (Gant)
View
2  grails.ipr
@@ -624,7 +624,7 @@
</library>
<library name="JUnit">
<CLASSES>
- <root url="jar://$PROJECT_DIR$/lib/junit-3.8.2.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/junit-4.8.1.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/ant-junit-1.7.1.jar!/" />
</CLASSES>
<JAVADOC />
View
4 ivy.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="codehaus" module="grails"/>
<dependencies>
@@ -16,7 +16,7 @@
<dependency org="apache" name="commons-pool" rev="1.2"/>
<dependency org="apache" name="commons-validator" rev="1.3.0"/>
<dependency org="dom4j" name="dom4j" rev="1.6.1"/>
- <dependency org="junit" name="junit" rev="3.8.1"/>
+ <dependency org="junit" name="junit" rev="4.8.1"/>
<!--<dependency org="rhino" name="js" rev="1.6R2"/> -->
<dependency org="log4j" name="log4j" rev="1.2.8"/>
<!--<dependency org="ognl" name="ognl" rev="2.6.9"/>
View
BIN  lib/junit-3.8.2.jar
Binary file not shown
View
BIN  lib/junit-4.8.1.jar
Binary file not shown
View
2  maven/grails-core.pom.in
@@ -231,7 +231,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
2  maven/grails-crud.pom.in
@@ -81,7 +81,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
2  maven/grails-gorm.pom.in
@@ -184,7 +184,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
2  maven/grails-scripts.pom.in
@@ -77,7 +77,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
</dependency>
<dependency>
View
2  maven/grails-spring.pom.in
@@ -65,7 +65,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
3  maven/grails-test.mf
@@ -19,4 +19,5 @@ Import-Template:
org.codehaus.groovy.ant.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.tools.*;version="${groovy.version:[=.=.=, =.+1.0)}",
org.codehaus.groovy.grails.*;version="${grails.version:[=.=.=, +1.0.0)}",
- org.springframework.*;version="${spring.version:[=.=.=, +1.0.0)}"
+ org.springframework.*;version="${spring.version:[=.=.=, +1.0.0)}",
+ org.junit.*;version="${junit.version:[=.=.=, +1.0.0)}"
View
2  maven/grails-test.pom.in
@@ -64,7 +64,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>runtime</scope>
</dependency>
View
2  maven/grails-web.pom.in
@@ -121,7 +121,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
2  maven/grails-webflow.pom.in
@@ -142,7 +142,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
View
10 scripts/_GrailsTest.groovy
@@ -20,8 +20,8 @@ import org.codehaus.groovy.grails.support.PersistenceContextInterceptor
import org.codehaus.groovy.grails.web.context.GrailsConfigUtils
import grails.util.GrailsUtil
-import org.codehaus.groovy.grails.test.junit3.JUnit3GrailsTestType
-import org.codehaus.groovy.grails.test.junit3.JUnit3GrailsTestTypeMode
+import org.codehaus.groovy.grails.test.junit4.JUnit4GrailsTestType
+import org.codehaus.groovy.grails.test.support.GrailsTestMode
import org.codehaus.groovy.grails.test.report.junit.JUnitReportsFactory
import org.codehaus.groovy.grails.test.report.junit.JUnitReportProcessor
@@ -128,14 +128,14 @@ target(allTests: "Runs the project's tests.") {
if (rawType instanceof CharSequence) {
def rawTypeString = rawType.toString()
if (phaseName in ['integration', 'functional']) {
- def mode = new JUnit3GrailsTestTypeMode(
+ def mode = new GrailsTestMode(
autowire: true,
wrapInTransaction: phaseName == "integration",
wrapInRequestEnvironment: phaseName == "integration"
)
- new JUnit3GrailsTestType(rawTypeString, rawTypeString, mode)
+ new JUnit4GrailsTestType(rawTypeString, rawTypeString, mode)
} else {
- new JUnit3GrailsTestType(rawTypeString, rawTypeString)
+ new JUnit4GrailsTestType(rawTypeString, rawTypeString)
}
} else {
rawType
View
4 src/java/org/codehaus/groovy/grails/resolve/IvyDependencyManager.groovy
@@ -294,7 +294,7 @@ public class IvyDependencyManager extends AbstractIvyDependencyManager implement
// dependencies needed for running tests
- test "junit:junit:3.8.2",
+ test "junit:junit:4.8.1",
"org.grails:grails-test:$grailsVersion",
"org.springframework:org.springframework.test:3.0.0.RELEASE"
@@ -359,7 +359,7 @@ public class IvyDependencyManager extends AbstractIvyDependencyManager implement
}
/**
- * For usages such as addPluginDependency("foo", [group:"junit", name:"junit", version:"3.8.2"])
+ * For usages such as addPluginDependency("foo", [group:"junit", name:"junit", version:"4.8.1"])
*
* This method is designed to be used by the internal framework and plugins and not be end users.
* The idea is that plugins can provide dependencies at runtime which are then inherited by
View
100 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsEnvironmentTestSuite.groovy
@@ -1,100 +0,0 @@
-/*
- * Copyright 2009 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.codehaus.groovy.grails.test.junit3
-
-import junit.framework.Test
-import junit.framework.TestResult
-import junit.framework.TestSuite
-
-import org.springframework.context.ApplicationContext
-
-import java.util.regex.Matcher
-import java.util.regex.Pattern
-
-import org.codehaus.groovy.grails.test.support.GrailsTestAutowirer
-import org.codehaus.groovy.grails.test.support.GrailsTestRequestEnvironmentInterceptor
-import org.codehaus.groovy.grails.test.support.GrailsTestTransactionInterceptor
-import org.codehaus.groovy.grails.test.support.ControllerNameExtractor
-
-import grails.util.GrailsNameUtils
-
-/**
- * A Grails specific test suite that runs tests in a “Grails” environment. That is,
- * subjects the tests to autowiring of dependencies (by name), establishes a request like environment,
- * and inside a rollback only transaction (unless the test is not transactional).
- *
- * @see GrailsTestAutowirer
- * @see GrailsTestRequestEnvironmentInterceptor
- * @see GrailsTestTransactionInterceptor
- */
-class JUnit3GrailsEnvironmentTestSuite extends TestSuite {
-
- GrailsTestAutowirer autowirer
- GrailsTestRequestEnvironmentInterceptor requestEnvironmentInterceptor
- GrailsTestTransactionInterceptor transactionInterceptor
-
- final JUnit3GrailsTestTypeMode mode
-
- /**
- * @see TestSuite(Class)
- */
- JUnit3GrailsEnvironmentTestSuite(Class test, ApplicationContext applicationContext, JUnit3GrailsTestTypeMode mode) {
- super(test)
- init(applicationContext, mode)
- }
-
- JUnit3GrailsEnvironmentTestSuite(ApplicationContext applicationContext, JUnit3GrailsTestTypeMode mode) {
- init(applicationContext, mode)
- }
-
- protected init(ApplicationContext applicationContext, JUnit3GrailsTestTypeMode mode) {
- this.mode = mode
- autowirer = new GrailsTestAutowirer(applicationContext)
- requestEnvironmentInterceptor = new GrailsTestRequestEnvironmentInterceptor(applicationContext)
- transactionInterceptor = new GrailsTestTransactionInterceptor(applicationContext)
- }
-
- void runTest(Test test, TestResult result) {
- if (mode.autowire) {
- autowirer.autowire(test)
- }
-
- def rawRunner = { test.run(result) }
-
- def inTransactionRunner
- if (mode.wrapInTransaction && transactionInterceptor.isTransactional(test)) {
- inTransactionRunner = { transactionInterceptor.doInTransaction(rawRunner) }
- } else {
- inTransactionRunner = rawRunner
- }
-
- def inRequestRunner
- if (mode.wrapInRequestEnvironment) {
- def controllerName = ControllerNameExtractor.extractControllerNameFromTestClassName(test.class.name, JUnit3GrailsTestType.TESTS_SUFFIX)
- if (controllerName) {
- controllerName = GrailsNameUtils.getPropertyName(controllerName)
- inRequestRunner = { requestEnvironmentInterceptor.doInRequestEnvironment(controllerName, inTransactionRunner) }
- } else {
- inRequestRunner = { requestEnvironmentInterceptor.doInRequestEnvironment(inTransactionRunner) }
- }
- } else {
- inRequestRunner = inTransactionRunner
- }
-
- inRequestRunner()
- }
-}
View
140 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsTestType.java
@@ -1,140 +0,0 @@
-/*
- * Copyright 2009 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.codehaus.groovy.grails.test.junit3;
-
-import org.codehaus.groovy.grails.test.GrailsTestTypeResult;
-import org.codehaus.groovy.grails.test.GrailsTestTargetPattern;
-import org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport;
-
-import junit.framework.TestSuite;
-import junit.framework.TestCase;
-
-import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher;
-
-import org.codehaus.groovy.grails.test.report.junit.JUnitReportsFactory;
-
-import java.lang.reflect.Modifier;
-import java.io.IOException;
-import java.io.File;
-
-import org.springframework.context.ApplicationContext;
-
-import java.util.List;
-import java.util.LinkedList;
-
-import groovy.lang.Binding;
-
-/**
- * An {@code GrailsTestType} for JUnit3 tests.
- */
-public class JUnit3GrailsTestType extends GrailsTestTypeSupport {
-
- public static final String TESTS_SUFFIX = "Tests";
- public static final String TEST_SUFFIX = "Test";
-
- protected TestSuite wholeTestSuite;
- protected JUnit3GrailsTestTypeMode mode;
-
- public JUnit3GrailsTestType(String name, String sourceDirectory) {
- this(name, sourceDirectory, null);
- }
-
- public JUnit3GrailsTestType(String name, String sourceDirectory, JUnit3GrailsTestTypeMode mode) {
- super(name, sourceDirectory);
- this.mode = mode;
- }
-
- protected List<String> getTestSuffixes() {
- List<String> testSuffixes = new LinkedList<String>();
- testSuffixes.add(TESTS_SUFFIX);
- testSuffixes.add(TEST_SUFFIX);
- return testSuffixes;
- }
-
- protected int doPrepare() {
- wholeTestSuite = createWholeTestSuite();
- return wholeTestSuite.testCount();
- }
-
- protected TestSuite createWholeTestSuite() {
- TestSuite theWholeTestSuite = new TestSuite("Grails Test Suite");
-
- for (GrailsTestTargetPattern targetPattern : this.getTestTargetPatterns()) {
- for (File sourceFile : findSourceFiles(targetPattern)) {
-
- String className = sourceFileToClassName(sourceFile);
- Class clazz = sourceFileToClass(sourceFile);
-
- if (TestCase.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
- TestSuite testSuite = null;
-
- String targetMethodName = targetPattern.getMethodName();
- if (targetMethodName != null) {
- try {
- clazz.getMethod(targetMethodName); // make sure that the method exists
- testSuite = createTestSuite();
- testSuite.setName(className);
- testSuite.addTest(TestSuite.createTest(clazz, targetMethodName));
- } catch (NoSuchMethodException e) {}
- } else {
- testSuite = createTestSuite(clazz);
- }
-
- if (testSuite != null) {
- theWholeTestSuite.addTest(testSuite);
- }
- }
- }
- }
-
- return theWholeTestSuite;
- }
-
- protected ApplicationContext getApplicationContext() {
- Binding buildBinding = getBuildBinding();
- if (buildBinding.getVariables().containsKey("appCtx")) {
- return (ApplicationContext)buildBinding.getProperty("appCtx");
- } else {
- throw new IllegalStateException("ApplicationContext requested, but is not present in the build binding");
- }
- }
-
- protected TestSuite createTestSuite(Class clazz) {
- if (mode == null) {
- return new TestSuite(clazz);
- } else {
- return new JUnit3GrailsEnvironmentTestSuite(clazz, getApplicationContext(), mode);
- }
- }
-
- protected TestSuite createTestSuite() {
- if (mode == null) {
- return new TestSuite();
- } else {
- return new JUnit3GrailsEnvironmentTestSuite(getApplicationContext(), mode);
- }
- }
-
- protected JUnit3GrailsTestTypeRunner createRunner(GrailsTestEventPublisher eventPublisher) {
- return new JUnit3GrailsTestTypeRunner(JUnitReportsFactory.createFromBuildBinding(getBuildBinding()), eventPublisher, createSystemOutAndErrSwapper());
- }
-
- protected GrailsTestTypeResult doRun(GrailsTestEventPublisher eventPublisher) {
- return new JUnit3GrailsTestTypeResult(createRunner(eventPublisher).runTests(wholeTestSuite));
- }
-
-}
View
101 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3GrailsTestTypeRunner.java
@@ -1,101 +0,0 @@
-/*
- * Copyright 2009 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.codehaus.groovy.grails.test.junit3;
-
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
-import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher;
-import org.codehaus.groovy.grails.test.io.SystemOutAndErrSwapper;
-import org.codehaus.groovy.grails.test.report.junit.JUnitReports;
-import org.codehaus.groovy.grails.test.report.junit.JUnitReportsFactory;
-
-import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.List;
-
-public class JUnit3GrailsTestTypeRunner {
-
- private SystemOutAndErrSwapper outAndErrSwapper;
- private JUnitReportsFactory reportsFactory;
- private GrailsTestEventPublisher eventPublisher;
-
- public JUnit3GrailsTestTypeRunner(JUnitReportsFactory reportsFactory, GrailsTestEventPublisher eventPublisher, SystemOutAndErrSwapper outAndErrSwapper) {
- this.reportsFactory = reportsFactory;
- this.eventPublisher = eventPublisher;
- this.outAndErrSwapper = outAndErrSwapper;
- }
-
- public TestResult runTests(TestSuite suite) {
- TestResult result = new TestResult();
-
- JUnit3ListenerEventPublisherAdapter eventPublisherAdapter = new JUnit3ListenerEventPublisherAdapter(eventPublisher);
- result.addListener(eventPublisherAdapter);
-
- for (Enumeration tests = suite.tests(); tests.hasMoreElements();) {
- TestSuite test = (TestSuite) tests.nextElement();
-
- JUnitTest junitTest = new JUnitTest(test.getName());
- JUnitReports reports = reportsFactory.createReports(test.getName());
-
- try {
- outAndErrSwapper.swapIn();
-
- result.addListener(reports);
-
- reports.startTestSuite(junitTest);
- eventPublisherAdapter.startTestSuite(junitTest);
-
- // Starting...now!
- long start = System.currentTimeMillis();
- int runCount = result.runCount();
- int failureCount = result.failureCount();
- int errorCount = result.errorCount();
-
- for (int i = 0; i < test.testCount(); i++) {
- TestCase t = (TestCase) test.testAt(i);
- System.out.println("--Output from " + t.getName() + "--");
- System.err.println("--Output from " + t.getName() + "--");
-
- test.runTest(t, result);
- }
-
- junitTest.setCounts(
- result.runCount() - runCount,
- result.failureCount() - failureCount,
- result.errorCount() - errorCount);
- junitTest.setRunTime(System.currentTimeMillis() - start);
- }
- finally {
- List<OutputStream> outAndErr = outAndErrSwapper.swapOut();
- String out = outAndErr.get(0).toString();
- String err = outAndErr.get(1).toString();
-
- reports.setSystemOutput(out);
- reports.setSystemError(err);
- reports.endTestSuite(junitTest);
-
- eventPublisherAdapter.endTestSuite(junitTest, out, err);
- }
-
- result.removeListener(reports);
- }
-
- return result;
- }
-}
View
76 src/java/org/codehaus/groovy/grails/test/junit3/JUnit3ListenerEventPublisherAdapter.java
@@ -1,76 +0,0 @@
-/*
- * Copyright 2009 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.codehaus.groovy.grails.test.junit3;
-
-import java.io.OutputStream;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.AssertionFailedError;
-
-import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
-import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter;
-
-import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher;
-
-public class JUnit3ListenerEventPublisherAdapter implements JUnitResultFormatter {
-
- protected GrailsTestEventPublisher eventPublisher;
- protected String out;
- protected String err;
-
- public JUnit3ListenerEventPublisherAdapter(GrailsTestEventPublisher eventPublisher) {
- this.eventPublisher = eventPublisher;
- }
-
- public void setOutput(OutputStream outputStream) {}
-
- public void setSystemOutput(String out) {}
-
- public void setSystemError(String err) {}
-
- public void startTestSuite(JUnitTest test) {
- eventPublisher.testCaseStart(test.getName());
- }
-
- public void startTest(Test test) {
- eventPublisher.testStart(((TestCase)test).getName());
- }
-
- public void addError(Test test, Throwable throwable) {
- eventPublisher.testFailure(((TestCase)test).getName(), throwable, true);
- }
-
- public void addFailure(Test test, AssertionFailedError assertionFailedError) {
- eventPublisher.testFailure(((TestCase)test).getName(), assertionFailedError);
- }
-
- public void endTest(Test test) {
- eventPublisher.testEnd(((TestCase)test).getName());
- }
-
- public void endTestSuite(JUnitTest test, String out, String err) {
- eventPublisher.testCaseEnd(test.getName(), out, err);
- out = null;
- err = null;
- }
-
- public void endTestSuite(JUnitTest test) {
- throw new IllegalStateException("should not be called, use endTestSuite(JUnitTest, String, String) instead");
- }
-
-}
View
116 src/java/org/codehaus/groovy/grails/test/junit4/JUnit4GrailsTestType.groovy
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2009 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.codehaus.groovy.grails.test.junit4
+
+import org.codehaus.groovy.grails.test.junit4.listener.SuiteRunListener
+import org.codehaus.groovy.grails.test.junit4.runner.GrailsTestCaseRunnerBuilder
+import org.codehaus.groovy.grails.test.junit4.result.JUnit4ResultGrailsTestTypeResultAdapter
+
+import org.codehaus.groovy.grails.test.GrailsTestTypeResult
+import org.codehaus.groovy.grails.test.GrailsTestTargetPattern
+import org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport
+import org.codehaus.groovy.grails.test.support.GrailsTestMode
+import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher
+import org.codehaus.groovy.grails.test.report.junit.JUnitReportsFactory
+
+import org.junit.runners.Suite
+import org.junit.runner.Result
+import org.junit.runner.notification.RunNotifier
+
+import java.lang.reflect.Modifier
+
+/**
+ * An {@code GrailsTestType} for JUnit4 tests.
+ */
+public class JUnit4GrailsTestType extends GrailsTestTypeSupport {
+
+ public static final SUFFIXES = ["Test", "Tests"].asImmutable()
+
+ protected suite
+ protected mode
+
+ public JUnit4GrailsTestType(String name, String sourceDirectory) {
+ this(name, sourceDirectory, null)
+ }
+
+ public JUnit4GrailsTestType(String name, String sourceDirectory, GrailsTestMode mode) {
+ super(name, sourceDirectory)
+ this.mode = mode
+ }
+
+ protected List<String> getTestSuffixes() {
+ SUFFIXES
+ }
+
+ protected int doPrepare() {
+ def testClasses = getTestClasses()
+ if (testClasses) {
+ suite = createSuite(testClasses)
+ suite.testCount()
+ } else {
+ 0
+ }
+ }
+
+ protected getTestClasses() {
+ def classes = []
+ eachSourceFile { testTargetPattern, sourceFile ->
+ def testClass = sourceFileToClass(sourceFile)
+ if (!Modifier.isAbstract(testClass.modifiers)) {
+ classes << testClass
+ }
+ }
+ classes
+ }
+
+ protected createRunnerBuilder() {
+ if (mode) {
+ new GrailsTestCaseRunnerBuilder(mode, getApplicationContext())
+ } else {
+ new GrailsTestCaseRunnerBuilder()
+ }
+ }
+
+ protected createSuite(classes) {
+ new Suite(createRunnerBuilder(), classes as Class[])
+ }
+
+ protected createJUnitReportsFactory() {
+ JUnitReportsFactory.createFromBuildBinding(buildBinding)
+ }
+
+ protected createListener(eventPublisher) {
+ new SuiteRunListener(eventPublisher, createJUnitReportsFactory(), createSystemOutAndErrSwapper())
+ }
+
+ protected createNotifier(eventPublisher) {
+ def notifier = new RunNotifier()
+ notifier.addListener(createListener(eventPublisher))
+ notifier
+ }
+
+ protected GrailsTestTypeResult doRun(GrailsTestEventPublisher eventPublisher) {
+ def notifier = createNotifier(eventPublisher)
+ def result = new Result()
+ notifier.addListener(result.createListener())
+ suite.run(notifier)
+
+ notifier.fireTestRunFinished(result)
+ new JUnit4ResultGrailsTestTypeResultAdapter(result)
+ }
+
+}
View
118 src/java/org/codehaus/groovy/grails/test/junit4/listener/PerTestRunListener.groovy
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2009 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.codehaus.groovy.grails.test.junit4.listener
+
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest
+import org.junit.runner.Description
+import org.junit.runner.notification.Failure
+
+import junit.framework.JUnit4TestCaseFacade
+import junit.framework.AssertionFailedError
+
+class PerTestRunListener {
+ final name
+
+ private final eventPublisher
+ private final reports
+ private final outAndErrSwapper
+ private final testSuite
+
+ private startTime
+ private runCount = 0
+ private failureCount = 0
+ private errorCount = 0
+
+ private testsByDescription = [:]
+
+ PerTestRunListener(name, eventPublisher, reports, outAndErrSwapper) {
+ this.name = name
+ this.eventPublisher = eventPublisher
+ this.reports = reports
+ this.outAndErrSwapper = outAndErrSwapper
+ this.testSuite = new JUnitTest(name)
+ }
+
+ void start() {
+ eventPublisher.testCaseStart(name)
+ outAndErrSwapper.swapIn()
+ reports.startTestSuite(testSuite)
+ startTime = System.currentTimeMillis()
+ }
+
+ void finish() {
+ testSuite.runTime = System.currentTimeMillis() - startTime
+ testSuite.setCounts(runCount, failureCount, errorCount)
+ def (out, err) = outAndErrSwapper.swapOut()*.toString()
+ reports.systemOutput = out
+ reports.systemError = err
+ reports.endTestSuite(testSuite)
+ eventPublisher.testCaseEnd(name)
+ }
+
+ void testStarted(Description description) {
+ def testName = description.methodName
+ eventPublisher.testStart(testName)
+ runCount++
+ [System.out, System.err]*.println("--Output from ${testName}--")
+ reports.startTest(getTest(description))
+ }
+
+ void testFailure(Failure failure) {
+ def testName = failure.description.methodName
+ def testCase = getTest(failure.description)
+ def exception = failure.exception
+
+ if (exception instanceof AssertionError) {
+ eventPublisher.testFailure(testName, exception)
+ failureCount++
+ reports.addFailure(testCase, toAssertionFailedError(exception))
+ } else {
+ eventPublisher.testFailure(testName, exception, true)
+ errorCount++
+ reports.addError(testCase, exception)
+ }
+ }
+
+ void testFinished(Description description) {
+ reports.endTest(getTest(description))
+ eventPublisher.testEnd(description.methodName)
+ }
+
+ // JUnitReports requires us to always pass the same Test instance
+ // for a test, so we cache it; this scheme also works for the case
+ // where testFailure() is invoked without a prior call to testStarted()
+ private getTest(description) {
+ def test = testsByDescription.get(description)
+ if (test == null) {
+ test = createJUnit4TestCaseFacade(description)
+ testsByDescription.put(description, test)
+ }
+ test
+ }
+
+ private toAssertionFailedError(assertionError) {
+ def result = new AssertionFailedError(assertionError.toString())
+ result.stackTrace = assertionError.stackTrace
+ result
+ }
+
+ static createJUnit4TestCaseFacade(Description description) {
+ def ctor = JUnit4TestCaseFacade.getDeclaredConstructor(Description)
+ ctor.accessible = true
+ ctor.newInstance(description)
+ }
+}
View
83 src/java/org/codehaus/groovy/grails/test/junit4/listener/SuiteRunListener.groovy
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2009 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.codehaus.groovy.grails.test.junit4.listener
+
+import org.codehaus.groovy.grails.test.io.SystemOutAndErrSwapper
+import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher
+import org.codehaus.groovy.grails.test.report.junit.JUnitReportsFactory
+
+import org.junit.runner.Description
+import org.junit.runner.Result
+import org.junit.runner.notification.Failure
+import org.junit.runner.notification.RunListener
+
+/**
+ * Listens in on the execution of an entire test suite (or test "type" in Grails) and creates
+ * new TestRunListeners for each actual test class.
+ */
+class SuiteRunListener extends RunListener {
+
+ private final GrailsTestEventPublisher eventPublisher
+ private final JUnitReportsFactory reportsFactory
+ private final SystemOutAndErrSwapper outAndErrSwapper
+
+ private PerTestRunListener perTestListener
+
+ SuiteRunListener(GrailsTestEventPublisher eventPublisher, JUnitReportsFactory reportsFactory, SystemOutAndErrSwapper outAndErrSwapper) {
+ this.eventPublisher = eventPublisher
+ this.reportsFactory = reportsFactory
+ this.outAndErrSwapper = outAndErrSwapper
+ }
+
+ void testRunStarted(Description description) {
+ // nothing to do
+ }
+
+ void testStarted(Description description) {
+ if (perTestListener?.name != description.className) {
+ perTestListener?.finish()
+
+ def testName = description.className
+ perTestListener = new PerTestRunListener(testName, eventPublisher, reportsFactory.createReports(testName), outAndErrSwapper)
+ perTestListener.start()
+ }
+
+ perTestListener.testStarted(description)
+ }
+
+ void testFailure(Failure failure) {
+ perTestListener.testFailure(failure)
+ }
+
+ void testAssumptionFailure(Failure failure) {
+ // assumptions (and AssumptionViolatedException) are specific to JUnit,
+ // and are treated as ordinary failures
+ perTestListener.testFailure(failure)
+ }
+
+ void testFinished(Description description) {
+ perTestListener.testFinished(description)
+ }
+
+ void testRunFinished(Result result) {
+ perTestListener.finish()
+ }
+
+ void testIgnored(Description description) {
+ // nothing to do
+ }
+}
View
45 ...ils/test/junit3/JUnit3GrailsTestTypeResult.groovy → ...lt/JUnit4ResultGrailsTestTypeResultAdapter.groovy
@@ -1,41 +1,36 @@
/*
* Copyright 2009 the original author or authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package org.codehaus.groovy.grails.test.junit3
-import junit.framework.TestResult
+package org.codehaus.groovy.grails.test.junit4.result
+
import org.codehaus.groovy.grails.test.GrailsTestTypeResult
+import org.junit.runner.Result
-/**
- * Adapts the new GrailsTestTypeResult to the pre Grails 1.2 test running API.
- */
-class JUnit3GrailsTestTypeResult implements GrailsTestTypeResult {
+class JUnit4ResultGrailsTestTypeResultAdapter implements GrailsTestTypeResult {
+ private final Result result
+
+ JUnit4ResultGrailsTestTypeResultAdapter(Result result) {
+ this.result = result
+ }
- protected result
-
- JUnit3GrailsTestTypeResult(TestResult result) {
- this.result = result
- }
-
- int getPassCount() {
- result.runCount() - failCount
- }
-
- int getFailCount() {
- result.errorCount() + result.failureCount()
- }
-
+ int getPassCount() {
+ result.runCount - failCount
+ }
+
+ int getFailCount() {
+ result.failureCount
+ }
}
View
141 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestCaseRunner.groovy
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2009 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.codehaus.groovy.grails.test.junit4.runner
+
+import org.junit.runners.BlockJUnit4ClassRunner
+import org.junit.runners.model.FrameworkMethod
+import org.junit.runners.model.Statement
+import org.junit.runner.notification.RunNotifier
+import org.junit.internal.runners.statements.InvokeMethod
+
+import org.springframework.context.ApplicationContext
+
+import org.codehaus.groovy.grails.test.support.GrailsTestMode
+import org.codehaus.groovy.grails.test.support.GrailsTestAutowirer
+import org.codehaus.groovy.grails.test.support.GrailsTestRequestEnvironmentInterceptor
+import org.codehaus.groovy.grails.test.support.GrailsTestTransactionInterceptor
+
+import org.junit.internal.runners.statements.RunAfters
+import org.junit.internal.runners.statements.RunBefores
+
+class GrailsTestCaseRunner extends BlockJUnit4ClassRunner {
+
+ final mode
+ final appCtx
+
+ private autowirer
+ private requestEnvironmentInterceptor
+ private transactionInterceptor
+
+ private transactional = false
+ private controllerName = null
+
+ GrailsTestCaseRunner(Class testClass) {
+ this(testClass, null, null)
+ }
+
+ GrailsTestCaseRunner(Class testClass, GrailsTestMode mode, ApplicationContext appCtx) {
+ super(testClass)
+ this.mode = mode
+ this.appCtx = appCtx
+ validateMode()
+ }
+
+ protected validateMode() {
+ if (mode && appCtx == null) {
+ throw new IllegalStateException("mode $mode requires an application context")
+ }
+ }
+
+ protected Statement methodInvoker(FrameworkMethod method, Object test) {
+ if (mode) {
+ new GrailsTestInvokeMethod(method, test, mode, getAutowirer(), getRequestEnvironmentInterceptor(), getTransactionInterceptor())
+ } else {
+ new InvokeMethod(method, test)
+ }
+ }
+
+ protected autowireIfNecessary(test) {
+ if (mode?.autowire) {
+ getAutowirer().autowire(test)
+ }
+ test
+ }
+
+ protected getAutowirer() {
+ ifHasApplicationContext {
+ autowirer = this.@autowirer ?: new GrailsTestAutowirer(appCtx)
+ }
+ }
+
+ protected getTransactionInterceptor() {
+ ifHasApplicationContext {
+ transactionInterceptor = this.@transactionInterceptor ?: new GrailsTestTransactionInterceptor(appCtx)
+ }
+ }
+
+ protected getRequestEnvironmentInterceptor() {
+ ifHasApplicationContext {
+ requestEnvironmentInterceptor = this.@requestEnvironmentInterceptor ?: new GrailsTestRequestEnvironmentInterceptor(appCtx)
+ }
+ }
+
+ protected ifHasApplicationContext(body) {
+ appCtx ? body() : null
+ }
+
+ protected List<FrameworkMethod> computeTestMethods() {
+ def annotated = super.computeTestMethods()
+ testClass.javaClass.methods.each { method ->
+ if (method.name.size() > 4 && method.name[0..3] == "test" && method.parameterTypes.size() == 0) {
+ def existing = annotated.find { it.method == method }
+ if (!existing) {
+ annotated << new FrameworkMethod(method)
+ }
+ }
+ }
+ annotated
+ }
+
+ protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
+ def superResult = super.withBefores(method, target, statement)
+ if (superResult.is(statement)) {
+ try {
+ def setUp = new FrameworkMethod(testClass.javaClass.getMethod('setUp'))
+ new RunAfters(statement, [setUp], target)
+ } catch (NoSuchMethodException e) {
+ superResult
+ }
+ } else {
+ superResult
+ }
+ }
+
+ protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) {
+ def superResult = super.withAfters(method, target, statement)
+ if (superResult.is(statement)) {
+ try {
+ def tearDown = new FrameworkMethod(testClass.javaClass.getMethod('tearDown'))
+ new RunAfters(statement, [tearDown], target)
+ } catch (NoSuchMethodException e) {
+ superResult
+ }
+ } else {
+ superResult
+ }
+ }
+}
View
54 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestCaseRunnerBuilder.groovy
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2009 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.codehaus.groovy.grails.test.junit4.runner
+
+import org.junit.runner.Runner
+import org.junit.runners.model.RunnerBuilder
+
+import org.codehaus.groovy.grails.test.support.GrailsTestMode
+import org.springframework.context.ApplicationContext
+
+class GrailsTestCaseRunnerBuilder extends RunnerBuilder {
+
+ final mode
+ final appCtx
+
+ GrailsTestCaseRunnerBuilder() {
+ this(null, null)
+ }
+
+ GrailsTestCaseRunnerBuilder(GrailsTestMode mode, ApplicationContext appCtx) {
+ this.mode = mode
+ this.appCtx = appCtx
+ validateMode()
+ }
+
+ protected validateMode() {
+ if (mode && appCtx == null) {
+ throw new IllegalStateException("mode $mode requires an application context")
+ }
+ }
+
+ Runner runnerForClass(Class testClass) {
+ if (mode) {
+ new GrailsTestCaseRunner(testClass, mode, appCtx)
+ } else {
+ new GrailsTestCaseRunner(testClass)
+ }
+ }
+
+}
View
75 src/java/org/codehaus/groovy/grails/test/junit4/runner/GrailsTestInvokeMethod.groovy
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2009 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.codehaus.groovy.grails.test.junit4.runner
+
+import org.junit.runners.model.FrameworkMethod
+import org.junit.runners.model.Statement
+
+import org.codehaus.groovy.grails.test.support.GrailsTestMode
+import org.codehaus.groovy.grails.test.support.ControllerNameExtractor
+import org.codehaus.groovy.grails.test.junit4.JUnit4GrailsTestType
+import org.springframework.context.ApplicationContext
+
+class GrailsTestInvokeMethod extends Statement {
+
+ private testMethod
+ private target
+ private mode
+ private autowirer
+ private requestEnvironmentInterceptor
+ private transactionInterceptor
+
+ GrailsTestInvokeMethod(FrameworkMethod testMethod, Object target, GrailsTestMode mode, autowirer, requestEnvironmentInterceptor, transactionInterceptor) {
+ this.testMethod = testMethod
+ this.target = target
+ this.mode = mode
+ this.autowirer = autowirer
+ this.requestEnvironmentInterceptor = requestEnvironmentInterceptor
+ this.transactionInterceptor = transactionInterceptor
+ }
+
+ void evaluate() throws Throwable {
+ if (mode.autowire) {
+ autowirer.autowire(target)
+ }
+
+ def runner = { testMethod.invokeExplosively(target) }
+
+ def inTransactionRunner
+ if (mode.wrapInTransaction && transactionInterceptor.isTransactional(target)) {
+ inTransactionRunner = { transactionInterceptor.doInTransaction(runner) }
+ } else {
+ inTransactionRunner = runner
+ }
+
+ def inRequestRunner
+ if (mode.wrapInRequestEnvironment) {
+ def controllerName = ControllerNameExtractor.extractControllerNameFromTestClassName(target.class.name, JUnit4GrailsTestType.SUFFIXES as String[])
+ if (controllerName) {
+ inRequestRunner = { requestEnvironmentInterceptor.doInRequestEnvironment(controllerName, inTransactionRunner) }
+ } else {
+ inRequestRunner = { requestEnvironmentInterceptor.doInRequestEnvironment(inTransactionRunner) }
+ }
+ } else {
+ inRequestRunner = inTransactionRunner
+ }
+
+ inRequestRunner()
+ }
+
+
+}
View
2  src/java/org/codehaus/groovy/grails/test/support/ControllerNameExtractor.groovy
@@ -29,7 +29,7 @@ class ControllerNameExtractor {
if (testClassName.endsWith(tail)) matchingTail = tail }
if (matchingTail) {
- testClassName[0..(testClassName.size() - matchingTail.size() - 1)]
+ GrailsNameUtils.getPropertyName(testClassName[0..(testClassName.size() - matchingTail.size() - 1)])
} else {
null
}
View
4 ...rails/test/junit3/JUnit3GrailsTestTypeMode.groovy → .../groovy/grails/test/support/GrailsTestMode.groovy
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package org.codehaus.groovy.grails.test.junit3
+package org.codehaus.groovy.grails.test.support
-class JUnit3GrailsTestTypeMode {
+class GrailsTestMode {
boolean autowire = false
boolean wrapInRequestEnvironment = false
boolean wrapInTransaction = false
View
13 src/java/org/codehaus/groovy/grails/test/support/GrailsTestTypeSupport.groovy
@@ -23,6 +23,7 @@ import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher
import org.codehaus.groovy.grails.test.io.SystemOutAndErrSwapper
import org.springframework.core.io.Resource
+import org.springframework.context.ApplicationContext
/**
* Provides a convenient base for {@link GrailsTestType} implementations.
@@ -236,5 +237,17 @@ abstract class GrailsTestTypeSupport implements GrailsTestType {
throw new RuntimeException("Could not load class in test type '$name'", e)
}
}
+
+ /**
+ * Will return the application context if it is present, but will throw an IllegalStateException
+ * if it is not. This should only be called when Grails is bootstrapped up (i.e. not for unit tests)
+ */
+ protected ApplicationContext getApplicationContext() {
+ if (buildBinding.variables.containsKey("appCtx")) {
+ buildBinding.getProperty("appCtx")
+ } else {
+ throw new IllegalStateException("ApplicationContext requested, but is not present in the build binding")
+ }
+ }
}
View
24 src/test/org/codehaus/groovy/grails/resolve/IvyDependencyManagerTests.groovy
@@ -250,12 +250,12 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
excludes "junit"
}
}
- build "junit:junit:3.8.4"
+ build "junit:junit:4.8.1"
}
manager.parseDependencies("foo") {
build "org.grails:grails-test:1.2"
- build "junit:junit:3.8.3"
+ build "junit:junit:4.8.1"
}
final IvyNode[] buildDeps = manager.listDependencies("build")
@@ -264,7 +264,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
def junit = buildDeps.find { it.moduleId.name == "junit" }
assertEquals "junit", junit.moduleId.name
- assertEquals "3.8.4", junit.id.revision
+ assertEquals "4.8.1", junit.id.revision
def dd = manager.dependencyDescriptors.find { DependencyDescriptor dd -> dd.dependencyRevisionId.name == 'junit' }
@@ -287,7 +287,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
manager.parseDependencies("foo") {
build "org.grails:grails-test:1.2"
- build "junit:junit:3.8.3"
+ build "junit:junit:4.8.1"
}
final IvyNode[] buildDeps = manager.listDependencies("build")
@@ -323,7 +323,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
manager.parseDependencies {
inherits "test"
runtime( [group:"opensymphony", name:"oscache", version:"2.4.1", transitive:false] )
- test( [group:"junit", name:"junit", version:"3.8.2", transitive:true] )
+ test( [group:"junit", name:"junit", version:"4.8.1", transitive:true] )
}
manager.resolveApplicationDependencies()
@@ -340,7 +340,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
manager.parseDependencies {
inherits "test"
runtime( [group:"opensymphony", name:"oscache", version:"2.4.1", transitive:false] )
- test( [group:"junit", name:"junit", version:"3.8.2", transitive:true] )
+ test( [group:"junit", name:"junit", version:"4.8.1", transitive:true] )
}
assertEquals 2, manager.getApplicationDependencyDescriptors().size()
@@ -420,7 +420,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
mavenRepo "http://snapshots.repository.codehaus.org"
}
runtime( [group:"opensymphony", name:"oscache", version:"2.4.1", transitive:false],
- [group:"junit", name:"junit", version:"3.8.2", transitive:true] )
+ [group:"junit", name:"junit", version:"4.8.1", transitive:true] )
runtime("opensymphony:foocache:2.4.1") {
excludes 'jms'
@@ -470,7 +470,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
// test simple exclude
manager.parseDependencies {
runtime( [group:"opensymphony", name:"oscache", version:"2.4.1", transitive:false],
- [group:"junit", name:"junit", version:"3.8.2", transitive:true] )
+ [group:"junit", name:"junit", version:"4.8.1", transitive:true] )
}
@@ -511,7 +511,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
def settings = new BuildSettings()
def manager = new IvyDependencyManager("test", "0.1",settings)
settings.config.grails.test.dependency.resolution = {
- test "junit:junit:3.8.2"
+ test "junit:junit:4.8.1"
}
// test simple exclude
manager.parseDependencies {
@@ -534,7 +534,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
def settings = new BuildSettings()
def manager = new IvyDependencyManager("test", "0.1",settings)
settings.config.grails.test.dependency.resolution = {
- test "junit:junit:3.8.2"
+ test "junit:junit:4.8.1"
}
// test simple exclude
manager.parseDependencies {
@@ -688,7 +688,7 @@ public class IvyDependencyManagerTests extends GroovyTestCase{
"javax.servlet:jstl:1.1.2",
"xalan:serializer:2.7.1"
- test "junit:junit:3.8.2"
+ test "junit:junit:4.8.1"
runtime "apache-taglibs:standard:1.1.2",
"org.aspectj:aspectjweaver:1.6.2",
@@ -725,7 +725,7 @@ class DummyMavenAwareDependencyManager extends IvyDependencyManager {
public List readDependenciesFromPOM() {
return [
- [getExcludedModules:{[]}, getGroupId:{"junit"}, getArtifactId:{"junit"}, getVersion:{"3.8.3"}, getScope:{"test"}] as PomDependencyMgt
+ [getExcludedModules:{[]}, getGroupId:{"junit"}, getArtifactId:{"junit"}, getVersion:{"4.8.1"}, getScope:{"test"}] as PomDependencyMgt
]
}
Please sign in to comment.
Something went wrong with that request. Please try again.