From 1997b0da5bdcf665802c624d1f5716719f0688e8 Mon Sep 17 00:00:00 2001 From: Peter Niederwieser Date: Thu, 23 Feb 2012 10:48:30 +0100 Subject: [PATCH] removed obsolete spock-grails-support project from build and version control --- settings.gradle | 1 - spock-grails-support/build.gradle | 16 -- spock-grails-support/pom.xml | 180 -------------- .../grails/plugin/spock/ControllerSpec.groovy | 89 ------- .../plugin/spock/GroovyPagesSpec.groovy | 50 ---- .../plugin/spock/IntegrationSpec.groovy | 86 ------- .../groovy/grails/plugin/spock/MvcSpec.groovy | 99 -------- .../grails/plugin/spock/TagLibSpec.groovy | 52 ---- .../grails/plugin/spock/UnitSpec.groovy | 228 ------------------ .../spock/test/GrailsSpecTestType.groovy | 87 ------- .../test/GrailsSpecTestTypeResult.groovy | 28 --- .../test/listener/OverallRunListener.groovy | 92 ------- .../test/listener/PerSpecRunListener.groovy | 164 ------------- .../JUnit4TestCaseFacadeFactory.groovy | 27 --- 14 files changed, 1199 deletions(-) delete mode 100644 spock-grails-support/build.gradle delete mode 100644 spock-grails-support/pom.xml delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/ControllerSpec.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/GroovyPagesSpec.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/IntegrationSpec.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/MvcSpec.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/TagLibSpec.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/UnitSpec.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestType.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestTypeResult.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/OverallRunListener.groovy delete mode 100644 spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/PerSpecRunListener.groovy delete mode 100644 spock-grails-support/src/main/groovy/junit/framework/JUnit4TestCaseFacadeFactory.groovy diff --git a/settings.gradle b/settings.gradle index 6a325869ce..2779da5d53 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,4 @@ include "spock-core" -include "spock-grails-support" include "spock-guice" include "spock-maven" include "spock-specs" diff --git a/spock-grails-support/build.gradle b/spock-grails-support/build.gradle deleted file mode 100644 index e5d6634862..0000000000 --- a/spock-grails-support/build.gradle +++ /dev/null @@ -1,16 +0,0 @@ -apply from: profile("publishMaven") - -description = "Spock Framework - Grails Plugin Support" - -dependencies { - compile "org.grails:grails-core:${grailsVersion}" - compile "org.grails:grails-test:${grailsVersion}" - compile "org.grails:grails-web:${grailsVersion}" - compile "org.apache.ant:ant-junit:1.7.1" - compile "org.apache.tomcat:servlet-api:6.0.29" - compile libs.slf4j - - compile(project(":spock-core")) { - exclude module: "ant" // Grails build uses different Ant version (1.7.1) - } -} diff --git a/spock-grails-support/pom.xml b/spock-grails-support/pom.xml deleted file mode 100644 index 4b34302049..0000000000 --- a/spock-grails-support/pom.xml +++ /dev/null @@ -1,180 +0,0 @@ - - - - org.spockframework - spock-parent - 0.6-groovy-1.7-SNAPSHOT - - - 4.0.0 - org.spockframework - spock-grails-support - jar - Spock Framework - Grails Plugin Support Classes - http://grails.org/plugin/spock - - - - - org.codehaus.gmaven - gmaven-plugin - - - - - - - org.spockframework - spock-core - ${project.version} - - - junit - junit-dep - provided - - - org.apache.ant - ant-junit - 1.7.1 - provided - - - org.apache.ant - ant - 1.7.1 - provided - - - - org.grails - grails-crud - ${grails.version} - provided - - - org.grails - grails-gorm - ${grails.version} - provided - - - org.grails - grails-test - ${grails.version} - provided - - - junit - junit - - - - - org.grails - grails-webflow - ${grails.version} - provided - - - org.apache.commons - com.springsource.org.apache.commons.logging - - - org.aopalliance - com.springsource.org.aopalliance - - - org.springframework.webflow - org.springframework.webflow - - - - - - org.springframework.webflow - spring-webflow - 2.1.1.RELEASE - provided - - - - javassist - javassist - 3.4.GA - provided - true - - - - - opensymphony - oscache - 2.4 - provided - - - commons-logging - commons-logging - - - javax.jms - jms - - - javax.servlet - servlet-api - - - - - - - org.slf4j - slf4j-log4j12 - 1.5.5 - provided - - - - javax.servlet - jstl - 1.2 - provided - - - - org.apache.tomcat - servlet-api - 6.0.29 - provided - - - - org.tmatesoft.svnkit - svnkit - 1.3.1 - provided - - - - - - codehaus - http://repository.codehaus.org - - - springsource - http://maven.springframework.org/release - - - - - - codehaus - http://repository.codehaus.org - - - - diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/ControllerSpec.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/ControllerSpec.groovy deleted file mode 100644 index d8b7caa133..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/ControllerSpec.groovy +++ /dev/null @@ -1,89 +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 grails.plugin.spock - -import grails.test.MockUtils -import grails.util.GrailsNameUtils -import groovy.xml.StreamingMarkupBuilder - -/** - * Support class for writing unit tests for controllers. Its main job - * is to mock the various properties and methods that Grails injects - * into controllers. By default it determines what controller to mock - * based on the name of the test, but this can be overridden by one - * of the constructors. - * - * @author Graeme Rocher - * @author Peter Ledbrook - */ -class ControllerSpec extends MvcSpec { - def setup() { - webRequest.controllerName = GrailsNameUtils.getLogicalPropertyName(controllerClass.name, "Controller") - } - - def provideMvcClassUnderTest() { - findClassUnderTestConventiallyBySuffix('Controller') - } - - def initializeMvcMocking(Class classUnderTest) { - mockController(classUnderTest) - } - - def getControllerClass() { - classUnderTest - } - - def getController() { - instanceUnderTest - } - - def getForwardArgs() { instanceUnderTest.forwardArgs } - - def getRedirectArgs() { instanceUnderTest.redirectArgs } - - def getChainArgs() { instanceUnderTest.chainArgs } - - void reset() { - super.reset() - redirectArgs.clear() - forwardArgs.clear() - chainArgs.clear() - } - - protected mockCommandObject(Class clazz) { - registerMetaClass(clazz) - MockUtils.mockCommandObject(clazz, errorsMap) - } - - protected void setXmlRequestContent(content) { - setXmlRequestContent("UTF-8", content) - } - - protected void setXmlRequestContent(String encoding, content) { - mockRequest.contentType = "application/xml; charset=$encoding" - - if (content instanceof Closure) { - def xml = new StreamingMarkupBuilder(encoding: encoding).bind(content) - def out = new ByteArrayOutputStream() - out << xml - - mockRequest.contentType = "application/xml; charset=$encoding" - mockRequest.content = out.toByteArray() - } else { - mockRequest.content = content.getBytes(encoding) - } - } -} diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/GroovyPagesSpec.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/GroovyPagesSpec.groovy deleted file mode 100644 index d49dd61220..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/GroovyPagesSpec.groovy +++ /dev/null @@ -1,50 +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 grails.plugin.spock - -import org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine -import org.codehaus.groovy.grails.web.util.GrailsPrintWriter -import org.springframework.web.context.request.RequestContextHolder - -class GroovyPagesSpec extends IntegrationSpec { - GroovyPagesTemplateEngine groovyPagesTemplateEngine // autowired - - String template = '' - Map params = [:] - - def getRequest() { - RequestContextHolder.currentRequestAttributes() - } - - void setControllerName(String name) { - getRequest().controllerName = name - } - - def getOutput() { - assert groovyPagesTemplateEngine - - def webRequest = getRequest() - - def t = groovyPagesTemplateEngine.createTemplate(template, "test_"+ System.currentTimeMillis()) - def w = t.make(params) - - def sw = new StringWriter() - def out = new GrailsPrintWriter(sw) - webRequest.out = out - w.writeTo(out) - sw.toString() - } -} \ No newline at end of file diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/IntegrationSpec.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/IntegrationSpec.groovy deleted file mode 100644 index 5a8b5f3130..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/IntegrationSpec.groovy +++ /dev/null @@ -1,86 +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 grails.plugin.spock - -import org.codehaus.groovy.grails.commons.ApplicationHolder -import org.codehaus.groovy.grails.test.support.GrailsTestAutowirer -import org.codehaus.groovy.grails.test.support.GrailsTestTransactionInterceptor -import org.codehaus.groovy.grails.test.support.GrailsTestRequestEnvironmentInterceptor -import org.codehaus.groovy.grails.test.support.ControllerNameExtractor - -import grails.plugin.spock.test.GrailsSpecTestType - -import spock.lang.Specification -import spock.lang.Shared -import spock.lang.Stepwise - -class IntegrationSpec extends Specification { - @Shared private applicationContext = ApplicationHolder.application.mainContext - @Shared private autowirer = new GrailsTestAutowirer(applicationContext) - - @Shared private perSpecTransactionInterceptor - @Shared private perSpecRequestEnvironmentInterceptor - - private perMethodTransactionInterceptor = null - private perMethodRequestEnvironmentInterceptor = null - - def setupSpec() { - if (isStepwiseSpec()) { - perSpecTransactionInterceptor = initTransaction() - perSpecRequestEnvironmentInterceptor = initRequestEnv() - } - - autowirer.autowire(this) - } - - def setup() { - if (!isStepwiseSpec()) { - perMethodTransactionInterceptor = initTransaction() - perMethodRequestEnvironmentInterceptor = initRequestEnv() - } - - autowirer.autowire(this) - } - - def cleanup() { - perMethodRequestEnvironmentInterceptor?.destroy() - perMethodTransactionInterceptor?.destroy() - } - - def cleanupSpec() { - perSpecRequestEnvironmentInterceptor?.destroy() - perSpecTransactionInterceptor?.destroy() - } - - private boolean isStepwiseSpec() { - getClass().isAnnotationPresent(Stepwise) - } - - private initTransaction() { - def interceptor = new GrailsTestTransactionInterceptor(applicationContext) - if (interceptor.isTransactional(this)) interceptor.init() - interceptor - } - - private initRequestEnv() { - def interceptor = new GrailsTestRequestEnvironmentInterceptor(applicationContext) - def controllerName = ControllerNameExtractor.extractControllerNameFromTestClassName( - this.class.name, GrailsSpecTestType.TEST_SUFFIXES as String[]) - interceptor.init(controllerName ?: GrailsTestRequestEnvironmentInterceptor.DEFAULT_CONTROLLER_NAME) - interceptor - } -} \ No newline at end of file diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/MvcSpec.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/MvcSpec.groovy deleted file mode 100644 index d0556988f8..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/MvcSpec.groovy +++ /dev/null @@ -1,99 +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 grails.plugin.spock - -import org.codehaus.groovy.grails.commons.ApplicationAttributes -import org.codehaus.groovy.grails.support.MockApplicationContext -import org.codehaus.groovy.grails.web.pages.DefaultGroovyPagesUriService -import org.codehaus.groovy.grails.web.pages.GroovyPagesUriService -import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes -import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest -import org.springframework.web.context.request.RequestContextHolder -import spock.lang.Shared - -/** - * Support class for writing unit tests for controllers. Its main job - * is to mock the various properties and methods that Grails injects - * into controllers. By default it determines what controller to mock - * based on the name of the test, but this can be overridden by one - * of the constructors. - * - * @author Graeme Rocher - * @author Peter Ledbrook - */ -abstract class MvcSpec extends UnitSpec { - @Shared classUnderTest - def instanceUnderTest - - protected webRequest - - abstract provideMvcClassUnderTest() - abstract initializeMvcMocking(Class classUnderTest) - - def setupSpec() { - classUnderTest = provideMvcClassUnderTest() - } - - def findClassUnderTestConventiallyBySuffix(suffix) { - def matcher = getClass().name =~ /^([\w\.]*?[A-Z]\w*?${suffix})\w+/ - if (matcher) { - def classUnderTestName = matcher[0][1] - classUnderTest = Thread.currentThread().contextClassLoader.loadClass(classUnderTestName) - } else { - throw new RuntimeException("Can not find classUnderTest conventionally for ${this.class.name} as it doesn't contain $suffix".toString()) - } - } - - def getMockRequest() { instanceUnderTest.request } - def getMockResponse() { instanceUnderTest.response } - def getMockSession() { instanceUnderTest.session } - - def getRenderArgs() { instanceUnderTest.renderArgs } - - def getMockParams() { instanceUnderTest.params } - def getMockFlash() { instanceUnderTest.flash } - - def setup() { - initializeMvcMocking(classUnderTest) - instanceUnderTest = classUnderTest.newInstance() - - MockApplicationContext ctx = new MockApplicationContext() - ctx.registerMockBean(GroovyPagesUriService.BEAN_ID, new DefaultGroovyPagesUriService()) - mockRequest.servletContext.setAttribute(ApplicationAttributes.APPLICATION_CONTEXT, ctx) - - webRequest = new GrailsWebRequest( - mockRequest, - mockResponse, - mockRequest.servletContext - ) - - mockRequest.setAttribute(GrailsApplicationAttributes.WEB_REQUEST, webRequest) - RequestContextHolder.setRequestAttributes(webRequest) - } - - void reset() { - mockRequest.clearAttributes() - mockRequest.removeAllParameters() - mockResponse.committed = false - mockSession.clearAttributes() - mockSession.setNew(true) - - renderArgs.clear() - - mockParams.clear() - mockFlash.clear() - } -} diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/TagLibSpec.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/TagLibSpec.groovy deleted file mode 100644 index d0015ba3bd..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/TagLibSpec.groovy +++ /dev/null @@ -1,52 +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 grails.plugin.spock - -class TagLibSpec extends MvcSpec { - def provideMvcClassUnderTest() { - findClassUnderTestConventiallyBySuffix('TagLib') - } - - def initializeMvcMocking(Class classUnderTest) { - mockTagLib(classUnderTest) - } - - def getTagLib() { - instanceUnderTest - } - - Class getTagLibClass() { - classUnderTest - } - - void reset() { - super.reset() - tagLib.out.buffer.delete(0, tagLib.out.buffer.size()) - } - - - def methodMissing(String name, args) { - if (args.size() > 2) throw new IllegalArgumentException("tags take a maximum of 2 arguments") - invokeTag(name, *args) - } - - def invokeTag(String name, Map params = [:], Closure body = null) { - def tag = tagLib."$name" - def out = (tag.maximumNumberOfParameters == 1 ? tag(params) : tag(params, body)).toString() - reset() - out - } -} diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/UnitSpec.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/UnitSpec.groovy deleted file mode 100644 index 6188ff35e6..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/UnitSpec.groovy +++ /dev/null @@ -1,228 +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 grails.plugin.spock - -import org.codehaus.groovy.grails.commons.* -import org.codehaus.groovy.grails.support.MockApplicationContext -import org.codehaus.groovy.grails.web.converters.ConverterUtil -import org.codehaus.groovy.grails.web.converters.configuration.ConvertersConfigurationInitializer -import org.springframework.validation.Errors -import org.codehaus.groovy.grails.plugins.GrailsPluginManager -import org.codehaus.groovy.grails.plugins.PluginManagerHolder - -import grails.test.GrailsMock -import grails.test.MockUtils -import grails.util.GrailsNameUtils - -import spock.lang.Specification - -/** - * Support class for writing unit tests in Grails. It mainly provides - * access to various mocking options, while making sure that the meta- - * class magic does not leak outside of a single test. - */ -class UnitSpec extends Specification { - private loadedCodecs - private applicationContext - private savedMetaClasses - protected errorsMap - - /** - * Keeps track of the domain classes mocked within a single test - * so that the relationships can be configured for cascading - * validation. - */ - DefaultArtefactInfo domainClassesInfo - - def setupSpec() { - PluginManagerHolder.pluginManager = [hasGrailsPlugin: { String name -> true }] as GrailsPluginManager - } - - def setup() { - loadedCodecs = [] as Set - applicationContext = new MockApplicationContext() - savedMetaClasses = [:] - domainClassesInfo = new DefaultArtefactInfo() - errorsMap = new IdentityHashMap() - - // Register some common classes so that they can be converted - // to XML, JSON, etc. - def convertersInit = new ConvertersConfigurationInitializer() - convertersInit.initialize() - [List, Set, Map, Errors].each { addConverters(it) } - } - - def cleanup() { - ConfigurationHolder.config = null - // Restore all the saved meta classes. - savedMetaClasses.each {clazz, metaClass -> - GroovySystem.metaClassRegistry.removeMetaClass(clazz) - GroovySystem.metaClassRegistry.setMetaClass(clazz, metaClass) - } - } - - def cleanupSpec() { - PluginManagerHolder.pluginManager = null - } - - /** - * Use this method when you plan to perform some meta-programming - * on a class. It ensures that any modifications you make will be - * cleared at the end of the test. - * @param clazz The class to register. - */ - protected void registerMetaClass(Class clazz) { - // If the class has already been registered, then there's - // nothing to do. - if (savedMetaClasses.containsKey(clazz)) return - - // Save the class's current meta class. - savedMetaClasses[clazz] = clazz.metaClass - - // Create a new EMC for the class and attach it. - def emc = new ExpandoMetaClass(clazz, true, true) - emc.initialize() - GroovySystem.metaClassRegistry.setMetaClass(clazz, emc) - } - - /** - * Creates a new Grails mock for the given class. Use it as you - * would use MockFor and StubFor. - * @param clazz The class to mock. - * @param loose If true, the method returns a loose- - * expectation mock, otherwise it returns a strict one. The default - * is a strict mock. - */ - protected GrailsMock mockFor(Class clazz, boolean loose = false) { - registerMetaClass(clazz) - return new GrailsMock(clazz, loose) - } - - /** - * Mocks the given class (either a domain class or a command object) - * so that a "validate()" method is added. This can then be used - * to test the constraints on the class. - */ - protected void mockForConstraintsTests(Class clazz, List instances = []) { - registerMetaClass(clazz) - MockUtils.prepareForConstraintsTests(clazz, errorsMap, instances) - } - - /** - * Mocks a domain class, providing working implementations of the - * standard dynamic methods. A list of domain instances can be - * provided as a source of data for the methods, in particular - * the queries. - * @param domainClass The class to mock. - * @param instances An optional list of domain instances to use - * as the data backing the dynamic methods. - */ - protected void mockDomain(Class domainClass, List instances = []) { - registerMetaClass(domainClass) - def dc = MockUtils.mockDomain(domainClass, errorsMap, instances) - - domainClassesInfo.addGrailsClass(dc) - addConverters(domainClass) - } - - /** - * Enables the cascading validation support for domain classes. - * This should be called after all the relevant domain - * classes have been mocked. - */ - protected void enableCascadingValidation() { - // We need to call this before we access the "grailsClasses" - // property, otherwise that property will be null. - domainClassesInfo.updateComplete() - - // This method is required to enable cascading validation - // because it populates some important relationship information. - GrailsDomainConfigurationUtil.configureDomainClassRelationships( - domainClassesInfo.grailsClasses, - domainClassesInfo.grailsClassesByName) - } - - /** - * Mocks a controller class, providing implementations of standard methods - * like render and redirect - */ - protected void mockController(Class controllerClass) { - registerMetaClass(controllerClass) - MockUtils.mockController(controllerClass) - } - - /** - * Mocks a tag library, providing the common web properties as - * well as "out", "throwTagError()", and an implementation of - * the "render" tag. - */ - protected void mockTagLib(Class tagLibClass) { - registerMetaClass(tagLibClass) - MockUtils.mockTagLib(tagLibClass) - } - - /** - * Provides a mock implementation of the "log" property for the - * given class. By default, debug and trace levels are ignored - * but you can enable printing of debug statements via the - * enableDebug argument. - * @param clazz The class to add the log method to. - * @param enableDebug An optional flag to switch on printing of - * debug statements. - */ - protected void mockLogging(Class clazz, boolean enableDebug = false) { - registerMetaClass(clazz) - MockUtils.mockLogging(clazz, enableDebug) - } - - protected void mockConfig(String config) { - def c = new ConfigSlurper().parse(config) - ConfigurationHolder.config = c - } - - /** - * Loads the given codec, adding the "encodeAs...()" and "decode...()" - * methods to objects. - * @param codecClass The codec to load, e.g. HTMLCodec. - */ - protected void loadCodec(Class codecClass) { - registerMetaClass(Object) - - if (!loadedCodecs.contains(codecClass)) { - loadedCodecs << codecClass - - // Instantiate the codec so we can use it. - final codec = codecClass.newInstance() - - // Add the encode and decode methods. - def codecName = GrailsNameUtils.getLogicalName(codecClass, "Codec") - Object.metaClass."encodeAs$codecName" = {-> return codec.encode(delegate) } - Object.metaClass."decode$codecName" = {-> return codec.decode(delegate) } - } - } - - protected void addConverters(Class clazz) { - registerMetaClass(clazz) - clazz.metaClass.asType = {Class asClass -> - if (ConverterUtil.isConverterClass(asClass)) { - return ConverterUtil.createConverter(asClass, delegate, applicationContext) - } - else { - return ConverterUtil.invokeOriginalAsTypeMethod(delegate, asClass) - } - } - } -} diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestType.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestType.groovy deleted file mode 100644 index 35c06388b7..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestType.groovy +++ /dev/null @@ -1,87 +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 grails.plugin.spock.test - -import grails.plugin.spock.test.listener.OverallRunListener - -import org.junit.runner.JUnitCore -import org.codehaus.groovy.grails.test.GrailsTestTypeResult -import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher -import org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport -import org.codehaus.groovy.grails.test.report.junit.JUnitReportsFactory - -import org.spockframework.runtime.SpecUtil - -import spock.config.RunnerConfiguration - -class GrailsSpecTestType extends GrailsTestTypeSupport { - public static final TEST_SUFFIXES = ["Spec", "Specification"].asImmutable() - - private final List specClasses = [] - - GrailsSpecTestType(String name, String relativeSourcePath) { - super(name, relativeSourcePath) - } - - protected List getTestExtensions() { - ["groovy"] - } - - protected List getTestSuffixes() { - TEST_SUFFIXES - } - - JUnitReportsFactory createJUnitReportsFactory() { - JUnitReportsFactory.createFromBuildBinding(buildBinding) - } - - protected int doPrepare() { - eachSourceFile { testTargetPattern, specSourceFile -> - def specClass = sourceFileToClass(specSourceFile) - if (SpecUtil.isRunnableSpec(specClass)) specClasses << specClass - } - - optimizeSpecRunOrderIfEnabled() - - specClasses.sum 0, { SpecUtil.getFeatureCount(it) } - } - - protected GrailsTestTypeResult doRun(GrailsTestEventPublisher eventPublisher) { - def junit = new JUnitCore() - def result = new GrailsSpecTestTypeResult() - junit.addListener(new OverallRunListener(eventPublisher, - createJUnitReportsFactory(), createSystemOutAndErrSwapper(), result)) - junit.run(specClasses as Class[]) - result - } - - private void optimizeSpecRunOrderIfEnabled() { - if (!SpecUtil.getConfiguration(RunnerConfiguration).optimizeRunOrder) return - - def specNames = specClasses.collect { it.name } - def reordered = SpecUtil.optimizeRunOrder(specNames) - def reordedPositions = [:] - reordered.eachWithIndex { name, idx -> reordedPositions[name] = idx } - specClasses.sort { reordedPositions[it.name] } - } - - // Override to workaround GRAILS-7296 - protected File getSourceDir() { - new File(buildBinding.grailsSettings.testSourceDir, relativeSourcePath) - } - -} \ No newline at end of file diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestTypeResult.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestTypeResult.groovy deleted file mode 100644 index 86a5e1cb3b..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/GrailsSpecTestTypeResult.groovy +++ /dev/null @@ -1,28 +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 grails.plugin.spock.test - -import org.codehaus.groovy.grails.test.GrailsTestTypeResult - -class GrailsSpecTestTypeResult implements GrailsTestTypeResult { - int runCount = 0 - int failCount = 0 - - int getPassCount() { - runCount - failCount - } -} diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/OverallRunListener.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/OverallRunListener.groovy deleted file mode 100644 index 8ff64dfcbd..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/OverallRunListener.groovy +++ /dev/null @@ -1,92 +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 grails.plugin.spock.test.listener - -import grails.plugin.spock.test.GrailsSpecTestTypeResult - -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 - -class OverallRunListener extends RunListener { - private final GrailsTestEventPublisher eventPublisher - private final JUnitReportsFactory reportsFactory - private final SystemOutAndErrSwapper outAndErrSwapper - private final GrailsSpecTestTypeResult result - - private PerSpecRunListener perSpecListener - - OverallRunListener(GrailsTestEventPublisher eventPublisher, JUnitReportsFactory reportsFactory, SystemOutAndErrSwapper outAndErrSwapper, GrailsSpecTestTypeResult result) { - this.eventPublisher = eventPublisher - this.reportsFactory = reportsFactory - this.outAndErrSwapper = outAndErrSwapper - this.result = result - } - - void testRunStarted(Description description) { - // nothing to do - } - - void testStarted(Description description) { - getPerSpecRunListener(description).testStarted(description) - } - - void testFailure(Failure failure) { - getPerSpecRunListener(failure.description).testFailure(failure) - } - - void testAssumptionFailure(Failure failure) { - // assumptions (and AssumptionViolatedException) are specific to JUnit, - // and are treated as ordinary failures - getPerSpecRunListener(failure.description).testFailure(failure) - } - - void testFinished(Description description) { - getPerSpecRunListener(description).testFinished(description) - } - - void testRunFinished(Result result) { - // I can't think of a situation where this would be called without - // a perSpecListener being available, even if it does happen - // our handling options are very limited at this point in execution. - getPerSpecRunListener()?.finish() - } - - void testIgnored(Description description) { - // nothing to do - } - - private getPerSpecRunListener(description = null) { - if (description && perSpecListener?.name != description.className) { - perSpecListener?.finish() - - def specName = description.className - perSpecListener = new PerSpecRunListener(specName, eventPublisher, - reportsFactory.createReports(specName), outAndErrSwapper, result) - - perSpecListener.start() - } - - perSpecListener - } -} - diff --git a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/PerSpecRunListener.groovy b/spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/PerSpecRunListener.groovy deleted file mode 100644 index 22a20c5e21..0000000000 --- a/spock-grails-support/src/main/groovy/grails/plugin/spock/test/listener/PerSpecRunListener.groovy +++ /dev/null @@ -1,164 +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 grails.plugin.spock.test.listener - -import grails.plugin.spock.test.GrailsSpecTestTypeResult - -import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest -import org.junit.runner.Description -import org.junit.runner.notification.Failure -import org.codehaus.groovy.grails.test.event.GrailsTestEventPublisher -import org.codehaus.groovy.grails.test.report.junit.JUnitReports -import org.codehaus.groovy.grails.test.io.SystemOutAndErrSwapper - -import junit.framework.AssertionFailedError -import junit.framework.JUnit4TestCaseFacadeFactory -import junit.framework.JUnit4TestCaseFacade - -class PerSpecRunListener { - final String name - - private final GrailsTestEventPublisher eventPublisher - private final JUnitReports reports - private final SystemOutAndErrSwapper outAndErrSwapper - private final GrailsSpecTestTypeResult result - private final JUnitTest testSuite - - private long startTime - - // number of tests that have run - private int runCount = 0 - - // number of tests that have failed; note that number of failures reported to - // eventPublisher/reports may be higher, for example when both feature method - // and cleanup method fail - private int failureCount = 0 - - // number of tests that have erred; note that number of errors reported to - // eventPublisher/reports may be higher, for example when both feature method - // and cleanup method erred - private int errorCount = 0 - - // tells whether testFailure() has been called for the current test - private boolean testFailed = false - - // tells whether the setupSpec() method has failed - private boolean setupSpecFailed = false - - private final Map testsByDescription = [:] - - PerSpecRunListener(String name, GrailsTestEventPublisher eventPublisher, JUnitReports reports, - SystemOutAndErrSwapper outAndErrSwapper, GrailsSpecTestTypeResult result) { - this.name = name - this.eventPublisher = eventPublisher - this.reports = reports - this.outAndErrSwapper = outAndErrSwapper - this.result = result - - testSuite = new JUnitTest(name) - } - - void start() { - eventPublisher.testCaseStart(name) - reports.startTestSuite(testSuite) - - outAndErrSwapper.swapIn() - startTime = System.currentTimeMillis() - } - - void finish() { - result.runCount += runCount - result.failCount += failureCount + errorCount - - testSuite.runTime = System.currentTimeMillis() - startTime - testSuite.setCounts(runCount, failureCount, errorCount) - - def (out, err) = outAndErrSwapper.swapOut()*.toString() - reports.systemOutput = out - reports.systemError = err - - eventPublisher.testCaseEnd(name) - reports.endTestSuite(testSuite) - } - - void testStarted(Description description) { - def testName = description.methodName - - eventPublisher.testStart(testName) - reports.startTest(getTest(description)) - - [System.out, System.err]*.println("--Output from ${testName}--") - testFailed = false - runCount++ - } - - void testFailure(Failure failure) { - def testName = failure.description.methodName - - if (testName == null) { - // in the following we assume that setupSpec() can only fail once - if (runCount == 0 && !setupSpecFailed) { - testName = "setupSpec" - setupSpecFailed = true - } else { - testName = "cleanupSpec" - } - - // prevent increase of failureCount/errorCount because the error doesn't stem from a "test" - testFailed = true - } - - def testCase = getTest(failure.description) - def exception = failure.exception - - if (exception instanceof AssertionError) { - eventPublisher.testFailure(testName, exception) - reports.addFailure(testCase, toAssertionFailedError(exception)) - if (!testFailed) failureCount++ - } else { - eventPublisher.testFailure(testName, exception, true) - reports.addError(testCase, exception) - if (!testFailed) errorCount++ - } - - testFailed = true - } - - void testFinished(Description description) { - reports.endTest(getTest(description)) - eventPublisher.testEnd(description.methodName) - testFailed = false - } - - // 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 = JUnit4TestCaseFacadeFactory.createFacade(description) - testsByDescription.put(description, test) - } - test - } - - private toAssertionFailedError(assertionError) { - def result = new AssertionFailedError(assertionError.toString()) - result.stackTrace = assertionError.stackTrace - result - } -} \ No newline at end of file diff --git a/spock-grails-support/src/main/groovy/junit/framework/JUnit4TestCaseFacadeFactory.groovy b/spock-grails-support/src/main/groovy/junit/framework/JUnit4TestCaseFacadeFactory.groovy deleted file mode 100644 index b64e1d0e68..0000000000 --- a/spock-grails-support/src/main/groovy/junit/framework/JUnit4TestCaseFacadeFactory.groovy +++ /dev/null @@ -1,27 +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 junit.framework - -import org.junit.runner.Description - -/** - * {@code JUnit4TestCaseFacade}'s constructor is package scoped. This just exposes it. - */ -class JUnit4TestCaseFacadeFactory { - static JUnit4TestCaseFacade createFacade(Description description) { - new JUnit4TestCaseFacade(description) - } -} \ No newline at end of file