diff --git a/gradle/idea.gradle b/gradle/idea.gradle index 4925722d8b9..cbfb0441ea2 100644 --- a/gradle/idea.gradle +++ b/gradle/idea.gradle @@ -1,5 +1,3 @@ -import groovy.xml.XmlParser - idea { project { jdkName "1.7" diff --git a/grails-bootstrap/src/main/groovy/grails/codegen/model/ModelBuilder.groovy b/grails-bootstrap/src/main/groovy/grails/codegen/model/ModelBuilder.groovy index 7cec3d20d8d..8fedc4d1a85 100644 --- a/grails-bootstrap/src/main/groovy/grails/codegen/model/ModelBuilder.groovy +++ b/grails-bootstrap/src/main/groovy/grails/codegen/model/ModelBuilder.groovy @@ -17,7 +17,7 @@ package grails.codegen.model import grails.util.GrailsNameUtils import groovy.transform.CompileStatic -import org.apache.groovy.util.BeanUtils +import org.codehaus.groovy.runtime.MetaClassHelper import org.grails.io.support.FileSystemResource import org.grails.io.support.GrailsResourceUtils import org.grails.io.support.Resource @@ -89,7 +89,7 @@ trait ModelBuilder { final String packagePath ModelImpl(String className) { - this.className = BeanUtils.capitalize(GrailsNameUtils.getShortName(className)) + this.className = MetaClassHelper.capitalize(GrailsNameUtils.getShortName(className)) this.fullName = className this.propertyName = GrailsNameUtils.getPropertyName(className) this.packageName = GrailsNameUtils.getPackageName(className) @@ -111,14 +111,7 @@ trait ModelBuilder { @Override Map asMap() { - [className: className, - fullName: fullName, - propertyName: propertyName, - modelName: propertyName, - packageName: packageName, - packagePath: packagePath, - simpleName: simpleName, - lowerCaseName: lowerCaseName] as Map + (Map) [ className: className, fullName: fullName, propertyName: propertyName, modelName: propertyName, packageName: packageName, packagePath: packagePath, simpleName: simpleName, lowerCaseName: lowerCaseName] } } diff --git a/grails-bootstrap/src/main/groovy/org/grails/io/support/SpringIOUtils.java b/grails-bootstrap/src/main/groovy/org/grails/io/support/SpringIOUtils.java index 20256781d31..2346198ccd6 100644 --- a/grails-bootstrap/src/main/groovy/org/grails/io/support/SpringIOUtils.java +++ b/grails-bootstrap/src/main/groovy/org/grails/io/support/SpringIOUtils.java @@ -15,7 +15,7 @@ */ package org.grails.io.support; -import groovy.xml.XmlSlurper; +import groovy.util.XmlSlurper; import groovy.xml.FactorySupport; import org.xml.sax.SAXException; import javax.xml.XMLConstants; diff --git a/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshApplicationContext.groovy b/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshApplicationContext.groovy index 46eff357a5d..1dd2123802a 100644 --- a/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshApplicationContext.groovy +++ b/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshApplicationContext.groovy @@ -16,10 +16,12 @@ package grails.ui.shell.support import grails.core.GrailsApplication -import org.apache.groovy.groovysh.Groovysh +import grails.ui.support.DevelopmentWebApplicationContext +import org.codehaus.groovy.tools.shell.Groovysh import org.codehaus.groovy.tools.shell.IO import org.springframework.context.support.GenericApplicationContext + /** * @author Graeme Rocher * @since 3.0 diff --git a/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshWebApplicationContext.groovy b/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshWebApplicationContext.groovy index b31e3d5efae..a3a2774af09 100644 --- a/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshWebApplicationContext.groovy +++ b/grails-console/src/main/groovy/grails/ui/shell/support/GroovyshWebApplicationContext.groovy @@ -19,9 +19,10 @@ import grails.core.GrailsApplication import grails.ui.support.DevelopmentWebApplicationContext import groovy.transform.CompileStatic import groovy.transform.InheritConstructors -import org.apache.groovy.groovysh.Groovysh +import org.codehaus.groovy.tools.shell.Groovysh import org.codehaus.groovy.tools.shell.IO + /** * @author Graeme Rocher * @since 3.0 diff --git a/grails-core/src/main/groovy/grails/util/AbstractTypeConvertingMap.java b/grails-core/src/main/groovy/grails/util/AbstractTypeConvertingMap.java index 3c370ea52a7..c348f1ad0fe 100644 --- a/grails-core/src/main/groovy/grails/util/AbstractTypeConvertingMap.java +++ b/grails-core/src/main/groovy/grails/util/AbstractTypeConvertingMap.java @@ -15,6 +15,7 @@ */ package grails.util; +import grails.util.GrailsStringUtils; import groovy.lang.GroovyObjectSupport; import org.codehaus.groovy.runtime.DefaultGroovyMethods; import org.codehaus.groovy.util.HashCodeHelper; diff --git a/grails-core/src/main/groovy/grails/util/GrailsStringUtils.groovy b/grails-core/src/main/groovy/grails/util/GrailsStringUtils.groovy index 85cb80188d7..08926a26bb5 100644 --- a/grails-core/src/main/groovy/grails/util/GrailsStringUtils.groovy +++ b/grails-core/src/main/groovy/grails/util/GrailsStringUtils.groovy @@ -165,7 +165,7 @@ abstract class GrailsStringUtils extends StringUtils{ * Same as {@link StringUtils#isEmpty(java.lang.Object)} but trims the string for surrounding whitespace */ static boolean isBlank(String str) { - !hasText(str?.trim()) + isEmpty(str?.trim()) } /** @@ -179,7 +179,7 @@ abstract class GrailsStringUtils extends StringUtils{ * Opposite of {@link GrailsStringUtils#isEmpty(java.lang.Object)} */ static boolean isNotEmpty(String str) { - hasText(str) + !isEmpty(str) } /** diff --git a/grails-core/src/main/groovy/grails/util/GrailsUtil.java b/grails-core/src/main/groovy/grails/util/GrailsUtil.java index 588bd48886a..a186f4e124e 100644 --- a/grails-core/src/main/groovy/grails/util/GrailsUtil.java +++ b/grails-core/src/main/groovy/grails/util/GrailsUtil.java @@ -15,12 +15,27 @@ */ package grails.util; +import grails.io.IOUtils; +import groovy.lang.Binding; +import groovy.lang.GroovyShell; +import groovy.lang.Writable; +import groovy.util.slurpersupport.GPathResult; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.grails.core.io.CachingPathMatchingResourcePatternResolver; import org.grails.exceptions.reporting.DefaultStackTraceFilterer; import org.grails.exceptions.reporting.StackTraceFilterer; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import java.io.IOException; +import java.io.InputStream; import java.io.PrintWriter; +import java.io.Writer; +import java.net.URL; +import java.util.jar.Attributes; +import java.util.jar.Manifest; /** * Grails utility methods for command line and GUI applications. diff --git a/grails-core/src/main/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformation.groovy b/grails-core/src/main/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformation.groovy index 6bc924337e9..7b5f6a50c78 100644 --- a/grails-core/src/main/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformation.groovy +++ b/grails-core/src/main/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformation.groovy @@ -9,10 +9,9 @@ import grails.util.GrailsNameUtils import groovy.transform.CompilationUnitAware import groovy.transform.CompileDynamic import groovy.transform.CompileStatic +import groovy.util.slurpersupport.GPathResult import groovy.xml.MarkupBuilder import groovy.xml.StreamingMarkupBuilder -import groovy.xml.XmlSlurper -import groovy.xml.slurpersupport.GPathResult import org.codehaus.groovy.ast.* import org.codehaus.groovy.ast.expr.ConstantExpression import org.codehaus.groovy.control.CompilationUnit diff --git a/grails-core/src/main/groovy/org/grails/core/io/support/GrailsFactoriesLoader.groovy b/grails-core/src/main/groovy/org/grails/core/io/support/GrailsFactoriesLoader.groovy index 8c9aea8e1e3..6eb416e43d5 100644 --- a/grails-core/src/main/groovy/org/grails/core/io/support/GrailsFactoriesLoader.groovy +++ b/grails-core/src/main/groovy/org/grails/core/io/support/GrailsFactoriesLoader.groovy @@ -62,7 +62,7 @@ class GrailsFactoriesLoader extends FactoriesLoaderSupport { boolean hasArguments = !(arguments != null && arguments.length==0) List results = new ArrayList() for(Class clazz : loadFactoryClasses(factoryClass, classLoader)) { - results.add(hasArguments ? clazz.newInstance(arguments) : clazz.getDeclaredConstructor().newInstance()) + results.add(hasArguments ? clazz.newInstance(arguments) : clazz.newInstance()) } OrderComparator.sort((List) results) results diff --git a/grails-core/src/main/groovy/org/grails/plugins/BinaryGrailsPluginDescriptor.java b/grails-core/src/main/groovy/org/grails/plugins/BinaryGrailsPluginDescriptor.java index 08d47f78638..87e29ceb942 100644 --- a/grails-core/src/main/groovy/org/grails/plugins/BinaryGrailsPluginDescriptor.java +++ b/grails-core/src/main/groovy/org/grails/plugins/BinaryGrailsPluginDescriptor.java @@ -15,7 +15,7 @@ */ package org.grails.plugins; -import groovy.xml.slurpersupport.GPathResult; +import groovy.util.slurpersupport.GPathResult; import org.grails.core.exceptions.GrailsConfigurationException; import org.grails.io.support.SpringIOUtils; import org.springframework.core.io.Resource; diff --git a/grails-core/src/test/groovy/grails/artefact/EnhancesSpec.groovy b/grails-core/src/test/groovy/grails/artefact/EnhancesSpec.groovy index 81002b0357c..1f91c650b5c 100644 --- a/grails-core/src/test/groovy/grails/artefact/EnhancesSpec.groovy +++ b/grails-core/src/test/groovy/grails/artefact/EnhancesSpec.groovy @@ -27,7 +27,7 @@ class EnhancesSpec extends Specification{ void "Test that the enhances trait transform works as expected"() { when:"The generated transformer is loaded" - def traitInjector = getClass().classLoader.loadClass("grails.artefact.FooTraitInjector").getDeclaredConstructor().newInstance() + def traitInjector = getClass().classLoader.loadClass("grails.artefact.FooTraitInjector").newInstance() then:"It is a valid trait injector" traitInjector instanceof TraitInjector diff --git a/grails-core/src/test/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformationSpec.groovy b/grails-core/src/test/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformationSpec.groovy index e1a1474c6e2..5befbb06777 100644 --- a/grails-core/src/test/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformationSpec.groovy +++ b/grails-core/src/test/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformationSpec.groovy @@ -1,7 +1,6 @@ package org.grails.compiler.injection import groovy.xml.MarkupBuilder -import groovy.xml.XmlSlurper import org.codehaus.groovy.ast.ClassNode import org.codehaus.groovy.classgen.GeneratorContext import org.codehaus.groovy.control.CompilationFailedException diff --git a/grails-core/src/test/groovy/org/grails/core/io/ResourceLocatorSpec.groovy b/grails-core/src/test/groovy/org/grails/core/io/ResourceLocatorSpec.groovy index 2b3f71309fb..e835cdad804 100644 --- a/grails-core/src/test/groovy/org/grails/core/io/ResourceLocatorSpec.groovy +++ b/grails-core/src/test/groovy/org/grails/core/io/ResourceLocatorSpec.groovy @@ -1,10 +1,14 @@ package org.grails.core.io import grails.core.DefaultGrailsApplication -import groovy.xml.XmlSlurper -import org.grails.plugins.* +import org.grails.plugins.BinaryGrailsPlugin +import org.grails.plugins.BinaryGrailsPluginDescriptor +import org.grails.plugins.MockBinaryPluginResource +import org.grails.plugins.MockGrailsPluginManager +import org.grails.plugins.TestBinaryGrailsPlugin import org.springframework.core.io.ByteArrayResource import org.springframework.core.io.ResourceLoader + import spock.lang.Specification class ResourceLocatorSpec extends Specification { diff --git a/grails-core/src/test/groovy/org/grails/exception/reporting/StackTraceFiltererSpec.groovy b/grails-core/src/test/groovy/org/grails/exception/reporting/StackTraceFiltererSpec.groovy index 34b669e71fd..114c2bba810 100644 --- a/grails-core/src/test/groovy/org/grails/exception/reporting/StackTraceFiltererSpec.groovy +++ b/grails-core/src/test/groovy/org/grails/exception/reporting/StackTraceFiltererSpec.groovy @@ -28,7 +28,7 @@ class FooController { filterer.setCutOffPackage("org.spockframework.util") Throwable exception try { - cls.getDeclaredConstructor().newInstance().show() + cls.newInstance().show() } catch (e) { filterer.filter(e) exception = e @@ -77,7 +77,7 @@ class FooService { filterer.setCutOffPackage("org.spockframework.util") Throwable exception try { - cls.getDeclaredConstructor().newInstance().show() + cls.newInstance().show() } catch (e) { filterer.filter(e, true) println getExceptionContents(e) diff --git a/grails-core/src/test/groovy/org/grails/exception/reporting/StackTracePrinterSpec.groovy b/grails-core/src/test/groovy/org/grails/exception/reporting/StackTracePrinterSpec.groovy index 2c34781682f..f69120a4bc4 100644 --- a/grails-core/src/test/groovy/org/grails/exception/reporting/StackTracePrinterSpec.groovy +++ b/grails-core/src/test/groovy/org/grails/exception/reporting/StackTracePrinterSpec.groovy @@ -15,8 +15,8 @@ class StackTracePrinterSpec extends Specification { void "Test pretty print simple stack trace"() { given: "a controller that throws an exception" final gcl = new GroovyClassLoader() - gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename) - def controller = gcl.parseClass(new BufferedReader(new InputStreamReader(getControllerResource().inputStream)), getControllerResource().filename).getDeclaredConstructor().newInstance() + gcl.parseClass(getServiceResource().inputStream, serviceResource.filename) + def controller = gcl.parseClass(getControllerResource().inputStream, controllerResource.filename).newInstance() when:"An exception is pretty printed" def printer = new DefaultErrorsPrinter() def result = null @@ -36,8 +36,8 @@ class StackTracePrinterSpec extends Specification { void "Test pretty print nested stack trace"() { given: "a controller that throws an exception" final gcl = new GroovyClassLoader() - gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename) - def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance() + gcl.parseClass(getServiceResource().inputStream, serviceResource.filename) + def controller = gcl.parseClass(getControllerResource().inputStream, controllerResource.filename).newInstance() when:"An exception is pretty printed" def printer = new DefaultErrorsPrinter() def result = null @@ -58,8 +58,8 @@ class StackTracePrinterSpec extends Specification { void "Test pretty print nested stack trace for JDK 11"() { given: "a controller that throws an exception" final gcl = new GroovyClassLoader() - gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename) - def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance() + gcl.parseClass(getServiceResource().inputStream, serviceResource.filename) + def controller = gcl.parseClass(getControllerResource().inputStream, controllerResource.filename).newInstance() when:"An exception is pretty printed" def printer = new DefaultErrorsPrinter() def result = null @@ -79,8 +79,8 @@ class StackTracePrinterSpec extends Specification { void "Test pretty print code snippet"() { given: "a controller that throws an exception" final gcl = new GroovyClassLoader() - gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename) - def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance() + gcl.parseClass(getServiceResource().inputStream, serviceResource.filename) + def controller = gcl.parseClass(getControllerResource().inputStream, getControllerResource().filename).newInstance() when: "A code snippet is pretty printed" final locator = new StaticResourceLocator() @@ -118,8 +118,8 @@ Around line 5 of FooController.groovy void "Test pretty print nested exception code snippet"() { given:"a service that throws an exception that is caught and rethrown" final gcl = new GroovyClassLoader() - gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename) - def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance() + gcl.parseClass(getServiceResource().inputStream, serviceResource.filename) + def controller = gcl.parseClass(controllerResource.inputStream, controllerResource.filename).newInstance() final locator = new StaticResourceLocator() locator.addClassResource("test.FooController", controllerResource) locator.addClassResource("test.FooService", serviceResource) @@ -198,8 +198,4 @@ class FooService { } } } - - private BufferedReader toBufferedReader(InputStream inputStream) { - new BufferedReader(new InputStreamReader(inputStream)) - } } diff --git a/grails-databinding/src/main/groovy/grails/databinding/DataBinder.java b/grails-databinding/src/main/groovy/grails/databinding/DataBinder.java index b10010e42dc..21d274dadbd 100644 --- a/grails-databinding/src/main/groovy/grails/databinding/DataBinder.java +++ b/grails-databinding/src/main/groovy/grails/databinding/DataBinder.java @@ -16,7 +16,7 @@ package grails.databinding; import grails.databinding.events.DataBindingListener; -import groovy.xml.slurpersupport.GPathResult; +import groovy.util.slurpersupport.GPathResult; import java.util.List; diff --git a/grails-databinding/src/main/groovy/grails/databinding/SimpleDataBinder.groovy b/grails-databinding/src/main/groovy/grails/databinding/SimpleDataBinder.groovy index 78c1f594c29..bf4c58f4cfa 100755 --- a/grails-databinding/src/main/groovy/grails/databinding/SimpleDataBinder.groovy +++ b/grails-databinding/src/main/groovy/grails/databinding/SimpleDataBinder.groovy @@ -21,7 +21,7 @@ import grails.databinding.events.DataBindingListener import grails.databinding.initializers.ValueInitializer import groovy.transform.CompileStatic import groovy.transform.TypeCheckingMode -import groovy.xml.slurpersupport.GPathResult +import groovy.util.slurpersupport.GPathResult import org.codehaus.groovy.reflection.CachedMethod import org.grails.databinding.ClosureValueConverter import org.grails.databinding.ClosureValueInitializer @@ -344,11 +344,11 @@ class SimpleDataBinder implements DataBinder { } else if (isBasicType(genericType)) { addElementToCollectionAt obj, propName, collectionInstance, index, convert(genericType, val) } else if (val instanceof Map){ - indexedInstance = genericType.getDeclaredConstructor().newInstance() + indexedInstance = genericType.newInstance() bind indexedInstance, new SimpleMapDataBindingSource(val), listener addElementToCollectionAt obj, propName, collectionInstance, index, indexedInstance } else if (val instanceof DataBindingSource) { - indexedInstance = genericType.getDeclaredConstructor().newInstance() + indexedInstance = genericType.newInstance() bind indexedInstance, val, listener addElementToCollectionAt obj, propName, collectionInstance, index, indexedInstance } else if(genericType.isEnum() && val instanceof CharSequence) { @@ -752,7 +752,7 @@ class SimpleDataBinder implements DataBinder { obj[propName] = initializer.initialize() } else{ - obj[propName] = propertyType.getDeclaredConstructor().newInstance() + obj[propName] = propertyType.newInstance() } } @@ -815,7 +815,7 @@ class SimpleDataBinder implements DataBinder { } else if (typeToConvertTo.isPrimitive() || typeToConvertTo.isArray()) { return value } else if (value instanceof Map) { - def obj = typeToConvertTo.getDeclaredConstructor().newInstance() + def obj = typeToConvertTo.newInstance() bind obj, new SimpleMapDataBindingSource(value) return obj } else if (Enum.isAssignableFrom(typeToConvertTo) && value instanceof String) { diff --git a/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultCollectionDataBindingSource.groovy b/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultCollectionDataBindingSource.groovy index 9f17a932980..af021abf3ac 100644 --- a/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultCollectionDataBindingSource.groovy +++ b/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultCollectionDataBindingSource.groovy @@ -19,7 +19,7 @@ import grails.databinding.CollectionDataBindingSource; import grails.databinding.DataBindingSource; import grails.databinding.SimpleMapDataBindingSource; import groovy.transform.CompileStatic -import groovy.xml.slurpersupport.GPathResult +import groovy.util.slurpersupport.GPathResult @CompileStatic class GPathResultCollectionDataBindingSource implements CollectionDataBindingSource { diff --git a/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultMap.groovy b/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultMap.groovy index 96477c9b637..cee3a6716da 100755 --- a/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultMap.groovy +++ b/grails-databinding/src/main/groovy/org/grails/databinding/xml/GPathResultMap.groovy @@ -15,9 +15,9 @@ */ package org.grails.databinding.xml -import groovy.xml.slurpersupport.GPathResult -import groovy.xml.slurpersupport.Node -import groovy.xml.slurpersupport.NodeChild +import groovy.util.slurpersupport.GPathResult +import groovy.util.slurpersupport.Node +import groovy.util.slurpersupport.NodeChild /** * @author Jeff Brown diff --git a/grails-databinding/src/test/groovy/grails/databinding/XMLBindingSpec.groovy b/grails-databinding/src/test/groovy/grails/databinding/XMLBindingSpec.groovy index 5caae09bf62..f038b15f988 100755 --- a/grails-databinding/src/test/groovy/grails/databinding/XMLBindingSpec.groovy +++ b/grails-databinding/src/test/groovy/grails/databinding/XMLBindingSpec.groovy @@ -14,8 +14,7 @@ */ package grails.databinding - -import groovy.xml.XmlSlurper +import grails.databinding.SimpleDataBinder; import spock.lang.Specification class XMLBindingSpec extends Specification { diff --git a/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathCollectionDataBindingSourceSpec.groovy b/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathCollectionDataBindingSourceSpec.groovy index a036c54be67..cd415375f04 100644 --- a/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathCollectionDataBindingSourceSpec.groovy +++ b/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathCollectionDataBindingSourceSpec.groovy @@ -1,7 +1,6 @@ package org.grails.databinding.xml -import grails.databinding.DataBindingSource -import groovy.xml.XmlSlurper +import grails.databinding.DataBindingSource; import spock.lang.Specification class GPathCollectionDataBindingSourceSpec extends Specification { diff --git a/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathResultMapSpec.groovy b/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathResultMapSpec.groovy index ecbd0b84193..9992a995884 100755 --- a/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathResultMapSpec.groovy +++ b/grails-databinding/src/test/groovy/org/grails/databinding/xml/GPathResultMapSpec.groovy @@ -14,7 +14,6 @@ */ package org.grails.databinding.xml -import groovy.xml.XmlSlurper import spock.lang.Specification class GPathResultMapSpec extends Specification { diff --git a/grails-docs/src/main/groovy/grails/doc/DocEngine.groovy b/grails-docs/src/main/groovy/grails/doc/DocEngine.groovy index 2952708b347..41ea67fc0ef 100644 --- a/grails-docs/src/main/groovy/grails/doc/DocEngine.groovy +++ b/grails-docs/src/main/groovy/grails/doc/DocEngine.groovy @@ -167,7 +167,7 @@ class DocEngine extends BaseRenderEngine implements WikiRenderEngine { EscapeFilter] for (f in filters) { - RegexFilter filter = f.getDeclaredConstructor().newInstance() + RegexFilter filter = f.newInstance() fp.addFilter(filter) if (filter instanceof MacroFilter) { diff --git a/grails-encoder/src/main/groovy/org/grails/encoder/impl/StandaloneCodecLookup.groovy b/grails-encoder/src/main/groovy/org/grails/encoder/impl/StandaloneCodecLookup.groovy index 7f24ca2730c..e92fb7e0579 100644 --- a/grails-encoder/src/main/groovy/org/grails/encoder/impl/StandaloneCodecLookup.groovy +++ b/grails-encoder/src/main/groovy/org/grails/encoder/impl/StandaloneCodecLookup.groovy @@ -25,14 +25,14 @@ import org.grails.encoder.CodecMetaClassSupport class StandaloneCodecLookup extends BasicCodecLookup { boolean registerMetaMethods = true boolean cacheLookupsInMetaMethods = true - Collection> targetClassesForMetaMethods = [ + Collection targetClassesForMetaMethods = [ String, GStringImpl, StringBuffer, StringBuilder, Object ] - Collection> codecFactoryClasses = [ + Collection codecFactoryClasses = [ XMLCodecFactory, HTMLCodecFactory, JSONCodecFactory, @@ -45,7 +45,7 @@ class StandaloneCodecLookup extends BasicCodecLookup { @Override protected void registerCodecs() { codecFactoryClasses.each { Class clazz -> - registerCodecFactory((CodecFactory)clazz.getDeclaredConstructor().newInstance()) + registerCodecFactory((CodecFactory)clazz.newInstance()) } } diff --git a/grails-logging/src/test/groovy/org/grails/compiler/logging/LoggingTransformerSpec.groovy b/grails-logging/src/test/groovy/org/grails/compiler/logging/LoggingTransformerSpec.groovy index c485f3235a5..aab4567cc28 100644 --- a/grails-logging/src/test/groovy/org/grails/compiler/logging/LoggingTransformerSpec.groovy +++ b/grails-logging/src/test/groovy/org/grails/compiler/logging/LoggingTransformerSpec.groovy @@ -30,7 +30,7 @@ class LoggingController extends BaseController{ } } ''', "foo/grails-app/controllers/LoggingController.groovy") - def controller = cls.getDeclaredConstructor().newInstance() + def controller = cls.newInstance() Logger log = controller.index() then: @@ -56,7 +56,7 @@ class LoggingController extends BaseController{ } } ''', "foo/grails-app/controllers/LoggingController.groovy") - def controller = cls.getDeclaredConstructor().newInstance() + def controller = cls.newInstance() Logger log = controller.index() then: @@ -77,7 +77,7 @@ class LoggingController { } } ''', "foo/grails-app/controllers/LoggingController.groovy") - def controller = cls.getDeclaredConstructor().newInstance() + def controller = cls.newInstance() Logger log = controller.index() then: @@ -98,7 +98,7 @@ class LoggingController { } } ''', "foo/grails-app/controllers/LoggingController.groovy") - def controller = cls.getDeclaredConstructor().newInstance() + def controller = cls.newInstance() Logger log = controller.index() then: @@ -117,7 +117,7 @@ class LoggingController extends grails.boot.config.GrailsAutoConfiguration { } } ''', "foo/src/main/groovy/LoggingController.groovy") - def controller = cls.getDeclaredConstructor().newInstance() + def controller = cls.newInstance() controller.index() then: diff --git a/grails-plugin-controllers/src/main/groovy/grails/artefact/Controller.groovy b/grails-plugin-controllers/src/main/groovy/grails/artefact/Controller.groovy index 866e6d845d8..2bc68060ed8 100644 --- a/grails-plugin-controllers/src/main/groovy/grails/artefact/Controller.groovy +++ b/grails-plugin-controllers/src/main/groovy/grails/artefact/Controller.groovy @@ -410,7 +410,7 @@ trait Controller implements ResponseRenderer, ResponseRedirector, RequestForward } } } else if (requestMethod == HttpMethod.POST || !isDomainClass) { - commandObjectInstance = type.getDeclaredConstructor().newInstance() + commandObjectInstance = type.newInstance() } if (commandObjectInstance != null @@ -440,7 +440,7 @@ trait Controller implements ResponseRenderer, ResponseRedirector, RequestForward if(exceptionHandlerMethodFor != null) { throw e } - commandObjectInstance = type.getDeclaredConstructor().newInstance() + commandObjectInstance = type.newInstance() final o = GrailsMetaClassUtils.invokeMethodIfExists(commandObjectInstance, "getErrors") if(o instanceof BindingResult) { final BindingResult errors = (BindingResult)o diff --git a/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy b/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy index 134ba08d0f9..2ece247ccee 100644 --- a/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy +++ b/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy @@ -27,7 +27,7 @@ import grails.web.mime.MimeUtility import groovy.json.StreamingJsonBuilder import groovy.transform.CompileStatic import groovy.transform.Generated -import groovy.xml.slurpersupport.GPathResult +import groovy.util.slurpersupport.GPathResult import groovy.xml.StreamingMarkupBuilder import org.grails.gsp.GroovyPageTemplate import org.grails.io.support.SpringIOUtils diff --git a/grails-plugin-mimetypes/src/test/groovy/grails/web/mime/MimeUtilitySpec.groovy b/grails-plugin-mimetypes/src/test/groovy/grails/web/mime/MimeUtilitySpec.groovy index 59c5aaca810..a99fd378b86 100644 --- a/grails-plugin-mimetypes/src/test/groovy/grails/web/mime/MimeUtilitySpec.groovy +++ b/grails-plugin-mimetypes/src/test/groovy/grails/web/mime/MimeUtilitySpec.groovy @@ -1,11 +1,9 @@ package grails.web.mime +import grails.web.mime.MimeUtility import grails.core.DefaultGrailsApplication -import grails.spring.BeanBuilder -import org.grails.plugins.web.mime.MimeTypesConfiguration +import org.grails.plugins.web.mime.MimeTypesFactoryBean import org.grails.web.mime.DefaultMimeUtility -import org.springframework.context.ApplicationContext -import org.springframework.context.support.GenericApplicationContext import spock.lang.Specification /** @@ -14,8 +12,8 @@ import spock.lang.Specification class MimeUtilitySpec extends Specification { MimeUtility getMimeUtility() { - def application = new DefaultGrailsApplication() - application.config.grails.mime.types = [ html: ['text/html','application/xhtml+xml'], + def ga = new DefaultGrailsApplication() + ga.config.grails.mime.types = [ html: ['text/html','application/xhtml+xml'], xml: ['text/xml', 'application/xml'], text: 'text/plain', js: 'text/javascript', @@ -29,18 +27,10 @@ class MimeUtilitySpec extends Specification { multipartForm: 'multipart/form-data' ] - final def mainContext = new GenericApplicationContext() - mainContext.refresh() - application.setApplicationContext(mainContext) + final factory = new MimeTypesFactoryBean(grailsApplication: ga) - def bb = new BeanBuilder() - bb.beans { - grailsApplication = application - mimeConfiguration(MimeTypesConfiguration, application, []) - } - final ApplicationContext context = bb.createApplicationContext() - final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration) - return new DefaultMimeUtility(mimeTypesConfiguration.mimeTypes()) + def mimeTypes = factory.getObject() + return new DefaultMimeUtility(mimeTypes) } void "Test get mime by extension method"() { diff --git a/grails-plugin-mimetypes/src/test/groovy/org/grails/web/mime/AcceptHeaderParserSpec.groovy b/grails-plugin-mimetypes/src/test/groovy/org/grails/web/mime/AcceptHeaderParserTests.groovy similarity index 54% rename from grails-plugin-mimetypes/src/test/groovy/org/grails/web/mime/AcceptHeaderParserSpec.groovy rename to grails-plugin-mimetypes/src/test/groovy/org/grails/web/mime/AcceptHeaderParserTests.groovy index d05baf5489d..c72fccee58c 100644 --- a/grails-plugin-mimetypes/src/test/groovy/org/grails/web/mime/AcceptHeaderParserSpec.groovy +++ b/grails-plugin-mimetypes/src/test/groovy/org/grails/web/mime/AcceptHeaderParserTests.groovy @@ -1,15 +1,15 @@ package org.grails.web.mime import grails.core.DefaultGrailsApplication -import grails.spring.BeanBuilder import grails.util.Holders import org.grails.config.PropertySourcesConfig -import org.grails.plugins.web.mime.MimeTypesConfiguration -import org.springframework.context.ApplicationContext -import org.springframework.context.support.GenericApplicationContext +import org.grails.plugins.web.mime.MimeTypesFactoryBean +import org.grails.web.mime.DefaultAcceptHeaderParser +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import org.springframework.core.env.MapPropertySource import org.springframework.core.env.MutablePropertySources -import spock.lang.Specification import static org.junit.jupiter.api.Assertions.assertEquals @@ -17,13 +17,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals * @author Graeme Rocher * @since 1.0 */ -class AcceptHeaderParserSpec extends Specification { +class AcceptHeaderParserTests { def config - void setup() { - def configObject = new ConfigSlurper() - .parse(""" + @BeforeEach + protected void setUp() { + def configObject = new ConfigSlurper().parse(""" grails.mime.types = [ xml: ['text/xml', 'application/xml'], text: 'text/plain', js: 'text/javascript', @@ -41,160 +41,140 @@ grails.mime.types = [ xml: ['text/xml', 'application/xml'], def ps = new MutablePropertySources() ps.addLast(new MapPropertySource("grails", configObject)) config = new PropertySourcesConfig(ps) + } - void cleanup() { + @AfterEach + protected void tearDown() { config = null Holders.setConfig null } + @Test void testXmlContentTypeWithCharset() { - when: DefaultAcceptHeaderParser parser = getAcceptHeaderParser() def mimes = parser.parse("text/xml; charset=UTF-8") - then: - 1 == mimes.size() - "application/xml" == mimes[0].name - "xml" == mimes[0].extension - 'UTF-8' == mimes[0].parameters.charset - '1.0' == mimes[0].parameters.q - '1.0' == mimes[0].quality + assertEquals 1, mimes.size() + assertEquals "application/xml", mimes[0].name + assertEquals "xml", mimes[0].extension + assertEquals('UTF-8', mimes[0].parameters.charset) + assertEquals('1.0', mimes[0].parameters.q) + assertEquals('1.0', mimes[0].quality) } protected DefaultAcceptHeaderParser getAcceptHeaderParser() { - final application = new DefaultGrailsApplication() - application.setConfig(config) - final def mainContext = new GenericApplicationContext() - mainContext.refresh() - application.setApplicationContext(mainContext) - - def bb = new BeanBuilder() - bb.beans { - grailsApplication = application - mimeConfiguration(MimeTypesConfiguration, application, []) - } - final ApplicationContext context = bb.createApplicationContext() - final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration) - final parser = new DefaultAcceptHeaderParser(mimeTypesConfiguration.mimeTypes()) + final application = new DefaultGrailsApplication(config: config) + final factoryBean = new MimeTypesFactoryBean(grailsApplication: application) + final parser = new DefaultAcceptHeaderParser(factoryBean.getObject()) parser } - - void testXmlContentTypeWithCharsetAndVersion() { - when: + @Test + void testXmlContentTypeWithCharsetAndVersion() { def mimes = getAcceptHeaderParser().parse("text/xml; charset=UTF-8; v=1.1") - then: - 1 == mimes.size() - "application/xml" == mimes[0].name - "xml" == mimes[0].extension - 'UTF-8' == mimes[0].parameters.charset - '1.0' == mimes[0].parameters.q - '1.0' == mimes[0].quality - '1.1' == mimes[0].version + assertEquals 1, mimes.size() + assertEquals "application/xml", mimes[0].name + assertEquals "xml", mimes[0].extension + assertEquals('UTF-8', mimes[0].parameters.charset) + assertEquals('1.0', mimes[0].parameters.q) + assertEquals('1.0', mimes[0].quality) + assertEquals('1.1', mimes[0].version) } + @Test void testGRAILS10678() { - - when: def mimes = getAcceptHeaderParser().parse("application/json;") - then: - 1 == mimes.size() - "application/json" == mimes[0].name - "json" == mimes[0].extension + assertEquals 1, mimes.size() + assertEquals "application/json", mimes[0].name + assertEquals "json", mimes[0].extension } + @Test void testFirefox2AcceptHeaderOrdering() { - when: def mimes = getAcceptHeaderParser().parse("text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5") - then: assertEquals 5, mimes.size() - ['application/xhtml+xml','application/xml', 'text/html', 'text/plain', '*/*'] == mimes.name - ['html', 'xml', 'html', 'text', 'all'] == mimes.extension + assertEquals(['application/xhtml+xml','application/xml', 'text/html', 'text/plain', '*/*'], mimes.name) + assertEquals(['html', 'xml', 'html', 'text', 'all'], mimes.extension) } + @Test void testFirefox3AcceptHeaderOrdering() { - when: def mimes = getAcceptHeaderParser().parse("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") - then: - 4 == mimes.size() - ['html','html','xml', 'all'] == mimes.extension + assertEquals 4, mimes.size() + + assertEquals(['html','html','xml', 'all'], mimes.extension) } + @Test void testParseAcceptHeaderWithNonNumericQualityValue() { - when: def mimes = getAcceptHeaderParser().parse("text/html,application/xhtml+xml,application/xml;q=blah,*/*;q=0.8") - then: - 4 == mimes.size() - ['html','html','xml', 'all'] == mimes.extension + assertEquals 4, mimes.size() + + assertEquals(['html','html','xml', 'all'], mimes.extension) } + @Test void testAcceptHeaderWithQNumberOrdering() { - - when: def mimes = getAcceptHeaderParser().parse("text/html,application/xhtml+xml,application/xml;q=1.1,*/*;q=0.8") - then: - 4 == mimes.size() - ['xml','html','html', 'all'] == mimes.extension + assertEquals 4, mimes.size() + + assertEquals(['xml','html','html', 'all'], mimes.extension) } + @Test void testPrototypeHeaderOrdering() { - when: def mimes = getAcceptHeaderParser().parse("text/javascript, text/html, application/xml, text/xml, */*") - then: - 4 == mimes.size() - ["js",'html', 'xml', 'all'] == mimes.extension - ["text/javascript",'text/html', 'application/xml', '*/*'] == mimes.name + assertEquals 4, mimes.size() + + assertEquals(["js",'html', 'xml', 'all'], mimes.extension) + assertEquals(["text/javascript",'text/html', 'application/xml', '*/*'], mimes.name) } + @Test void testOldBrowserHeader() { - when: def mimes = getAcceptHeaderParser().parse("*/*") - then: - 1 == mimes.size() - ['all'] == mimes.extension + assertEquals 1, mimes.size() + assertEquals(['all'], mimes.extension) } + @Test // test for GRAILS-3389 void testAcceptExtensionWithTokenNoValue() { - when: def mimes = getAcceptHeaderParser().parse("text/html,application/xhtml+xml,application/xml;token,*/*;q=0.8") - then: - 4 == mimes.size() - ['html','html', 'xml','all'] == mimes.extension + assertEquals 4, mimes.size() + + assertEquals(['html','html', 'xml','all'], mimes.extension) } + @Test // test for GRAILS-3493 void testAcceptHeaderWithNoQValue() { - when: def mimes = getAcceptHeaderParser().parse("application/xml; charset=UTF-8") - then: - 1 == mimes.size() + assertEquals 1, mimes.size() } + @Test void testAcceptExtensionWithCustomVndTypeAndVersion() { - - when: def mimesV1 = getAcceptHeaderParser().parse("application/vnd.foo+json;v=1.0; charset=UTF-8") def mimesV2 = getAcceptHeaderParser().parse("application/vnd.foo+json;v=2.0; charset=UTF-8") - then: - ['foov1'] == mimesV1.extension - ['foov2'] == mimesV2.extension + assertEquals(['foov1'], mimesV1.extension) + assertEquals(['foov2'], mimesV2.extension) } } diff --git a/grails-plugin-mimetypes/src/test/groovy/org/grails/web/servlet/mvc/RequestAndResponseMimeTypesApiSpec.groovy b/grails-plugin-mimetypes/src/test/groovy/org/grails/web/servlet/mvc/RequestAndResponseMimeTypesApiSpec.groovy index e42fb4ca2bb..af826e41f0c 100644 --- a/grails-plugin-mimetypes/src/test/groovy/org/grails/web/servlet/mvc/RequestAndResponseMimeTypesApiSpec.groovy +++ b/grails-plugin-mimetypes/src/test/groovy/org/grails/web/servlet/mvc/RequestAndResponseMimeTypesApiSpec.groovy @@ -1,18 +1,14 @@ package org.grails.web.servlet.mvc - import grails.config.Config import grails.core.DefaultGrailsApplication import grails.core.GrailsApplication -import grails.spring.BeanBuilder import grails.util.GrailsWebMockUtil import grails.web.mime.MimeType import org.grails.config.PropertySourcesConfig import org.grails.core.lifecycle.ShutdownOperations -import org.grails.plugins.web.mime.MimeTypesConfiguration import org.grails.plugins.web.mime.MimeTypesFactoryBean import org.grails.web.mime.DefaultMimeUtility -import org.springframework.context.ApplicationContext -import org.springframework.context.support.GenericApplicationContext +import org.grails.web.servlet.mvc.GrailsWebRequest import org.springframework.core.env.MapPropertySource import org.springframework.core.env.MutablePropertySources import org.springframework.mock.web.MockHttpServletRequest @@ -22,7 +18,6 @@ import org.springframework.web.context.support.GenericWebApplicationContext import spock.lang.Issue import spock.lang.Specification import spock.lang.Unroll - /** * Tests for mime type resolution */ @@ -283,18 +278,10 @@ class RequestAndResponseMimeTypesApiSpec extends Specification{ private MimeType[] buildMimeTypes() { - final def mainContext = new GenericApplicationContext() - mainContext.refresh() - application.setApplicationContext(mainContext) - - def bb = new BeanBuilder() - bb.beans { - grailsApplication = application - mimeConfiguration(MimeTypesConfiguration, application, []) - } - final ApplicationContext context = bb.createApplicationContext() - final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration) - mimeTypesConfiguration.mimeTypes() + def mimeTypesFactory = new MimeTypesFactoryBean() + mimeTypesFactory.grailsApplication = application + def mimeTypes = mimeTypesFactory.getObject() + mimeTypes } String applicationConfigText = ''' diff --git a/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy b/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy index d4738bee3e8..821f52c6882 100644 --- a/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy +++ b/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy @@ -254,7 +254,7 @@ class RestfulController { * @return The resource instance */ protected T createResource() { - T instance = resource.getDeclaredConstructor().newInstance() + T instance = resource.newInstance() bindData instance, getObjectToBind() instance } diff --git a/grails-plugin-rest/src/main/groovy/grails/rest/render/Renderer.groovy b/grails-plugin-rest/src/main/groovy/grails/rest/render/Renderer.groovy index 96419d4aed5..e8a20fe8b77 100644 --- a/grails-plugin-rest/src/main/groovy/grails/rest/render/Renderer.groovy +++ b/grails-plugin-rest/src/main/groovy/grails/rest/render/Renderer.groovy @@ -38,5 +38,5 @@ interface Renderer extends MimeTypeProvider { * * @return Optional return value, those to that directly write typically return null */ - void render(T object, RenderContext context) + void render(Object object, RenderContext context) } diff --git a/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorJsonRenderer.groovy b/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorJsonRenderer.groovy index b275c040c29..33b3db55dbd 100644 --- a/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorJsonRenderer.groovy +++ b/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorJsonRenderer.groovy @@ -42,7 +42,7 @@ class VndErrorJsonRenderer extends AbstractVndErrorRenderer { MimeType[] mimeTypes = [MIME_TYPE, MimeType.HAL_JSON, MimeType.JSON, MimeType.TEXT_JSON] as MimeType[] @Override - void render(Errors object, RenderContext context) { + void render(Object object, RenderContext context) { if (messageSource == null) throw new IllegalStateException("messageSource property null") if (object instanceof BeanPropertyBindingResult) { diff --git a/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorXmlRenderer.groovy b/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorXmlRenderer.groovy index 93f55c848b9..a2b5c8e0e5d 100644 --- a/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorXmlRenderer.groovy +++ b/grails-plugin-rest/src/main/groovy/grails/rest/render/errors/VndErrorXmlRenderer.groovy @@ -44,7 +44,7 @@ class VndErrorXmlRenderer extends AbstractVndErrorRenderer { MimeType[] mimeTypes = [MIME_TYPE, MimeType.HAL_XML, MimeType.XML, MimeType.TEXT_XML] as MimeType[] @Override - void render(Errors object, RenderContext context) { + void render(Object object, RenderContext context) { if (object instanceof BeanPropertyBindingResult) { def errors = object as BeanPropertyBindingResult context.setContentType(GrailsWebUtil.getContentType(MIME_TYPE.name, encoding)) diff --git a/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/render/json/DefaultJsonRenderer.groovy b/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/render/json/DefaultJsonRenderer.groovy index e6f7d078e70..c956d773ad1 100644 --- a/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/render/json/DefaultJsonRenderer.groovy +++ b/grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/render/json/DefaultJsonRenderer.groovy @@ -20,10 +20,10 @@ import grails.rest.render.RenderContext import grails.rest.render.Renderer import grails.rest.render.RendererRegistry import grails.util.GrailsWebUtil -import grails.web.mime.MimeType import groovy.transform.CompileStatic -import org.grails.plugins.web.rest.render.html.DefaultHtmlRenderer +import grails.web.mime.MimeType import org.grails.web.gsp.io.GrailsConventionGroovyPageLocator +import org.grails.plugins.web.rest.render.html.DefaultHtmlRenderer import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.HttpStatus import org.springframework.validation.Errors diff --git a/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalJsonRendererSpec.groovy b/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalJsonRendererSpec.groovy index 7ee698a4817..6d465561428 100644 --- a/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalJsonRendererSpec.groovy +++ b/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalJsonRendererSpec.groovy @@ -23,21 +23,20 @@ import grails.persistence.Entity import grails.rest.render.Renderer import grails.rest.render.hal.HalJsonCollectionRenderer import grails.rest.render.hal.HalJsonRenderer -import grails.spring.BeanBuilder import grails.util.GrailsWebMockUtil import grails.util.GrailsWebUtil import grails.web.CamelCaseUrlConverter import grails.web.mapping.LinkGenerator import grails.web.mapping.UrlMappingsHolder import grails.web.mime.MimeType -import groovy.test.NotYetImplemented +import groovy.transform.NotYetImplemented import org.grails.config.PropertySourcesConfig import org.grails.core.lifecycle.ShutdownOperations import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext import org.grails.datastore.mapping.model.AbstractPersistentProperty import org.grails.datastore.mapping.model.MappingContext import org.grails.datastore.mapping.model.PropertyMapping -import org.grails.plugins.web.mime.MimeTypesConfiguration +import org.grails.plugins.web.mime.MimeTypesFactoryBean import org.grails.plugins.web.rest.render.ServletRenderContext import org.grails.support.MockApplicationContext import org.grails.web.mapping.DefaultLinkGenerator @@ -46,8 +45,6 @@ import org.grails.web.mapping.DefaultUrlMappingsHolder import org.grails.web.mime.DefaultMimeUtility import org.grails.web.servlet.mvc.GrailsWebRequest import org.grails.web.servlet.mvc.MockHibernateProxyHandler -import org.springframework.context.ApplicationContext -import org.springframework.context.support.GenericApplicationContext import org.springframework.context.support.StaticMessageSource import org.springframework.core.convert.converter.Converter import org.springframework.core.env.MapPropertySource @@ -691,9 +688,7 @@ class HalJsonRendererSpec extends Specification{ webRequest.request.addHeader("ACCEPT", "application/hal+json") def response = webRequest.response def renderContext = new ServletRenderContext(webRequest) - Calendar calendar = Calendar.getInstance() - calendar.set(2013, 10, 8, 13, 12, 30) - def event = new Event(name: "Lollapalooza", date: calendar.getTime(), state: Event.State.OPEN) + def event = new Event(name: "Lollapalooza", date: new Date(113, 10, 8, 13, 12, 30), state: Event.State.OPEN) renderer.render(event, renderContext) @@ -959,18 +954,10 @@ grails.mime.types = [ } private MimeType[] buildMimeTypes(application) { - final def mainContext = new GenericApplicationContext() - mainContext.refresh() - application.setApplicationContext(mainContext) - - def bb = new BeanBuilder() - bb.beans { - grailsApplication = application - mimeConfiguration(MimeTypesConfiguration, application, []) - } - final ApplicationContext context = bb.createApplicationContext() - final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration) - mimeTypesConfiguration.mimeTypes() + def mimeTypesFactory = new MimeTypesFactoryBean() + mimeTypesFactory.grailsApplication = application + def mimeTypes = mimeTypesFactory.getObject() + mimeTypes } } diff --git a/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/LinkableTransformSpec.groovy b/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/LinkableTransformSpec.groovy index 7194dee3e6b..5a13456f2e5 100644 --- a/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/LinkableTransformSpec.groovy +++ b/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/LinkableTransformSpec.groovy @@ -25,7 +25,7 @@ class LinkableTransformSpec extends Specification { when:"A link is added" def domain = gcl.loadClass("Book") - def book = domain.getDeclaredConstructor().newInstance() + def book = domain.newInstance() book.link(rel:'foos', href:"/foo") def links = book.links() diff --git a/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/ResourceTransformSpec.groovy b/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/ResourceTransformSpec.groovy index d09226ec2c1..bc4b8976ee9 100644 --- a/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/ResourceTransformSpec.groovy +++ b/grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/transform/ResourceTransformSpec.groovy @@ -69,7 +69,7 @@ class Book { ctrl.getSuperclass() == superClazz when:"A link is added" - def book = domain.getDeclaredConstructor().newInstance() + def book = domain.newInstance() book.link(rel:'foos', href:"/foo") def links = book.links() @@ -152,7 +152,7 @@ class Book { ctrl.getSuperclass() == superClazz when:"A link is added" - def book = domain.getDeclaredConstructor().newInstance() + def book = domain.newInstance() book.link(rel:'foos', href:"/foo") def links = book.links() diff --git a/grails-shell/src/main/groovy/org/grails/cli/boot/GrailsDependencyVersions.groovy b/grails-shell/src/main/groovy/org/grails/cli/boot/GrailsDependencyVersions.groovy index 1aa456bcf4e..f0704d4589c 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/boot/GrailsDependencyVersions.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/boot/GrailsDependencyVersions.groovy @@ -19,8 +19,7 @@ import groovy.grape.Grape import groovy.grape.GrapeEngine import groovy.transform.CompileDynamic import groovy.transform.CompileStatic -import groovy.xml.XmlSlurper -import groovy.xml.slurpersupport.GPathResult +import groovy.util.slurpersupport.GPathResult import org.springframework.boot.cli.compiler.dependencies.Dependency import org.springframework.boot.cli.compiler.dependencies.DependencyManagement diff --git a/grails-shell/src/main/groovy/org/grails/cli/profile/CommandDescription.groovy b/grails-shell/src/main/groovy/org/grails/cli/profile/CommandDescription.groovy index cb638cb9b76..2f3b2edea9d 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/profile/CommandDescription.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/profile/CommandDescription.groovy @@ -104,7 +104,7 @@ class CommandDescription { * @return The description instance */ CommandDescription completer(Class completer) { - this.completer = completer.getDeclaredConstructor().newInstance() + this.completer = completer.newInstance() return this } diff --git a/grails-shell/src/main/groovy/org/grails/cli/profile/commands/DefaultMultiStepCommand.groovy b/grails-shell/src/main/groovy/org/grails/cli/profile/commands/DefaultMultiStepCommand.groovy index 38de3bc8d1e..bea967a0343 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/profile/commands/DefaultMultiStepCommand.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/profile/commands/DefaultMultiStepCommand.groovy @@ -55,7 +55,7 @@ class DefaultMultiStepCommand extends MultiStepCommand { def completerClass = map.get('completer') if(completerClass) { try { - this.description.completer = (Completer)Thread.currentThread().contextClassLoader.loadClass(completerClass.toString()).getDeclaredConstructor().newInstance() + this.description.completer = (Completer)Thread.currentThread().contextClassLoader.loadClass(completerClass.toString()).newInstance() } catch (e) { // ignore } diff --git a/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/GroovyScriptCommandFactory.groovy b/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/GroovyScriptCommandFactory.groovy index c6b2c04f4c7..1b9aba68469 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/GroovyScriptCommandFactory.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/GroovyScriptCommandFactory.groovy @@ -47,7 +47,7 @@ class GroovyScriptCommandFactory extends ResourceResolvingCommandFactory results = ['one', 'two', 'three'] - def result - - when: - result = new JsonBuilder({ - List> books = [] - for (t in results) { - books << [title: t] - } - return books - }()) - - then: - '[{"title":"one"},{"title":"two"},{"title":"three"}]' == result.toString() - - when: - result = new JsonBuilder({ - books results.collect { [title: it] } - }) - - then: - '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}' == result.toString() - - when: - new JsonBuilder({ - List> array = [] - for (b in results) { - array.add(title: b) - } - books array - }) - - - then: - '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}' == result.toString() - } - - - @Ignore("This isn't supported with the new JsonBuilder. This test is not supported.") - void testAppendToArray() { - def builder = new JSONBuilder() - - def results = ['one', 'two', 'three'] - - def result = builder.build { - books = array { list -> - for (b in results) { - list << [title: b] - } - } - } - - assertEquals '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}', result.toString() - } -} diff --git a/grails-test-suite-uber/src/test/groovy/grails/web/JSONBuilderTests.groovy b/grails-test-suite-uber/src/test/groovy/grails/web/JSONBuilderTests.groovy new file mode 100644 index 00000000000..f7dde788ff5 --- /dev/null +++ b/grails-test-suite-uber/src/test/groovy/grails/web/JSONBuilderTests.groovy @@ -0,0 +1,170 @@ +package grails.web + +import grails.core.DefaultGrailsApplication +import org.grails.web.converters.configuration.ConvertersConfigurationInitializer +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test + +import static org.junit.jupiter.api.Assertions.assertEquals + +/** + * @author Graeme Rocher + * @since 1.2 + */ +class JSONBuilderTests { + + @BeforeEach + void setUp() { + def initializer = new ConvertersConfigurationInitializer(grailsApplication: new DefaultGrailsApplication()) + initializer.initialize() + } + + @Test + void testSimple() { + def builder = new JSONBuilder() + + def result = builder.build { + rootprop ="something" + } + + assertEquals '{"rootprop":"something"}', result.toString() + } + + @Test + void testArrays() { + def builder = new JSONBuilder() + + def result = builder.build { + categories = ['a', 'b', 'c'] + rootprop ="something" + } + + assertEquals '{"categories":["a","b","c"],"rootprop":"something"}', result.toString() + } + + @Test + void testSubObjects() { + def builder = new JSONBuilder() + + def result = builder.build { + categories = ['a', 'b', 'c'] + rootprop ="something" + test { + subprop = 10 + } + } + + assertEquals '{"categories":["a","b","c"],"rootprop":"something","test":{"subprop":10}}', result.toString() + } + + @Test + void testAssignedObjects() { + + def builder = new JSONBuilder() + + def result = builder.build { + categories = ['a', 'b', 'c'] + rootprop ="something" + test = { + subprop = 10 + } + } + + assertEquals '{"categories":["a","b","c"],"rootprop":"something","test":{"subprop":10}}', result.toString() + } + + @Test + void testNamedArgumentHandling() { + def builder = new JSONBuilder() + + def result = builder.build { + categories = ['a', 'b', 'c'] + rootprop ="something" + test subprop:10, three:[1,2,3] + } + + assertEquals '{"categories":["a","b","c"],"rootprop":"something","test":{"subprop":10,"three":[1,2,3]}}', result.toString() + } + + @Test + void testArrayOfClosures() { + def builder = new JSONBuilder() + + def result = builder.build { + foo = [ { bar = "hello" } ] + } + + assertEquals '{"foo":[{"bar":"hello"}]}', result.toString() + } + + @Test + void testRootElementList() { + def builder = new JSONBuilder() + + def results = ['one', 'two', 'three'] + + def result = builder.build { + for (b in results) { + element b + } + } + + assertEquals '["one","two","three"]', result.toString() + + result = builder.build { + results + } + + assertEquals '["one","two","three"]', result.toString() + } + + @Test + void testExampleFromReferenceGuide() { + def builder = new JSONBuilder() + + def results = ['one', 'two', 'three'] + + def result = builder.build { + for (b in results) { + element title:b + } + } + + assertEquals '[{"title":"one"},{"title":"two"},{"title":"three"}]', result.toString() + + result = builder.build { + books = results.collect { + [title:it] + } + } + + assertEquals '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}', result.toString() + + result = builder.build { + books = array { + for (b in results) { + book title:b + } + } + } + + assertEquals '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}', result.toString() + } + + @Test + void testAppendToArray() { + def builder = new JSONBuilder() + + def results = ['one', 'two', 'three'] + + def result = builder.build { + books = array { list -> + for (b in results) { + list << [title:b] + } + } + } + + assertEquals '{"books":[{"title":"one"},{"title":"two"},{"title":"three"}]}', result.toString() + } +} diff --git a/grails-test-suite-uber/src/test/groovy/org/grails/commons/MultipleClassesPerFileTests.groovy b/grails-test-suite-uber/src/test/groovy/org/grails/commons/MultipleClassesPerFileTests.groovy index cccf49a8d9c..75cbddc59d2 100644 --- a/grails-test-suite-uber/src/test/groovy/org/grails/commons/MultipleClassesPerFileTests.groovy +++ b/grails-test-suite-uber/src/test/groovy/org/grails/commons/MultipleClassesPerFileTests.groovy @@ -28,7 +28,7 @@ class MultipleClassesPerFileTests { @Test void testMultipleClassesPerFile() { GroovyClassLoader cl = new GroovyClassLoader() - cl.parseClass(new BufferedReader(new InputStreamReader(getClass().classLoader.getResourceAsStream('org/grails/commons/classes.groovy'))), 'classes.groovy') + cl.parseClass(getClass().classLoader.getResourceAsStream('org/grails/commons/classes.groovy'), 'classes.groovy') assertNotNull cl.loadClass('TestClass1') assertNotNull cl.loadClass('TestClass2') diff --git a/grails-test-suite-uber/src/test/groovy/org/grails/commons/UrlMappingsArtefactHandlerTests.groovy b/grails-test-suite-uber/src/test/groovy/org/grails/commons/UrlMappingsArtefactHandlerTests.groovy index 272eb0ad0d4..555df600f1f 100644 --- a/grails-test-suite-uber/src/test/groovy/org/grails/commons/UrlMappingsArtefactHandlerTests.groovy +++ b/grails-test-suite-uber/src/test/groovy/org/grails/commons/UrlMappingsArtefactHandlerTests.groovy @@ -36,7 +36,7 @@ mappings { @Test void testUrlMappingsArtefactHandler() { def gcl = new GroovyClassLoader() - Class mappings = gcl.parseClass(new BufferedReader(new InputStreamReader(new ByteArrayResource(mappingScript.bytes).inputStream)), "MyUrlMappings") + Class mappings = gcl.parseClass(new ByteArrayResource(mappingScript.bytes).inputStream, "MyUrlMappings") def handler = new UrlMappingsArtefactHandler() assertTrue handler.isArtefactClass(mappings) diff --git a/grails-test-suite-uber/src/test/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequestTests.groovy b/grails-test-suite-uber/src/test/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequestTests.groovy index ea3c61a5aa8..f33d788bb9d 100644 --- a/grails-test-suite-uber/src/test/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequestTests.groovy +++ b/grails-test-suite-uber/src/test/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequestTests.groovy @@ -14,7 +14,7 @@ */ package org.grails.plugins.testing - +import org.grails.plugins.testing.GrailsMockHttpServletRequest import org.junit.jupiter.api.Test import static org.junit.jupiter.api.Assertions.* diff --git a/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassJsonRendererSpec.groovy b/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassJsonRendererSpec.groovy index 7b2ae27dcba..1ba46e7a9cd 100644 --- a/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassJsonRendererSpec.groovy +++ b/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassJsonRendererSpec.groovy @@ -7,7 +7,6 @@ import grails.persistence.Entity import grails.rest.Linkable import grails.rest.Resource import grails.rest.render.hal.HalJsonRenderer -import grails.spring.BeanBuilder import grails.util.GrailsWebMockUtil import grails.util.GrailsWebUtil import grails.web.CamelCaseUrlConverter @@ -17,7 +16,7 @@ import grails.web.mime.MimeType import org.grails.config.PropertySourcesConfig import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext import org.grails.datastore.mapping.model.MappingContext -import org.grails.plugins.web.mime.MimeTypesConfiguration +import org.grails.plugins.web.mime.MimeTypesFactoryBean import org.grails.plugins.web.rest.render.ServletRenderContext import org.grails.support.MockApplicationContext import org.grails.web.mapping.DefaultLinkGenerator @@ -25,8 +24,6 @@ import org.grails.web.mapping.DefaultUrlMappingEvaluator import org.grails.web.mapping.DefaultUrlMappingsHolder import org.grails.web.mime.DefaultMimeUtility import org.grails.web.servlet.mvc.GrailsWebRequest -import org.springframework.context.ApplicationContext -import org.springframework.context.support.GenericApplicationContext import org.springframework.context.support.StaticMessageSource import org.springframework.core.env.MapPropertySource import org.springframework.core.env.MutablePropertySources @@ -35,6 +32,7 @@ import org.springframework.web.context.WebApplicationContext import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.support.GenericWebApplicationContext import org.springframework.web.util.WebUtils + import spock.lang.Specification /** @@ -201,18 +199,10 @@ grails.mime.types = [ } private MimeType[] buildMimeTypes(application) { - final def mainContext = new GenericApplicationContext() - mainContext.refresh() - application.setApplicationContext(mainContext) - - def bb = new BeanBuilder() - bb.beans { - grailsApplication = application - mimeConfiguration(MimeTypesConfiguration, application, []) - } - final ApplicationContext context = bb.createApplicationContext() - final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration) - mimeTypesConfiguration.mimeTypes() + def mimeTypesFactory = new MimeTypesFactoryBean() + mimeTypesFactory.grailsApplication = application + def mimeTypes = mimeTypesFactory.getObject() + mimeTypes } } diff --git a/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassXmlRendererSpec.groovy b/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassXmlRendererSpec.groovy index 73c361a0038..6ab98b9dc2e 100644 --- a/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassXmlRendererSpec.groovy +++ b/grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassXmlRendererSpec.groovy @@ -4,7 +4,6 @@ import grails.config.Config import grails.core.DefaultGrailsApplication import grails.core.GrailsApplication import grails.rest.render.hal.HalXmlRenderer -import grails.spring.BeanBuilder import grails.util.GrailsWebMockUtil import grails.util.GrailsWebUtil import grails.web.CamelCaseUrlConverter @@ -14,7 +13,7 @@ import grails.web.mime.MimeType import org.grails.config.PropertySourcesConfig import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext import org.grails.datastore.mapping.model.MappingContext -import org.grails.plugins.web.mime.MimeTypesConfiguration +import org.grails.plugins.web.mime.MimeTypesFactoryBean import org.grails.plugins.web.rest.render.ServletRenderContext import org.grails.support.MockApplicationContext import org.grails.web.converters.configuration.ConvertersConfigurationHolder @@ -24,8 +23,6 @@ import org.grails.web.mapping.DefaultUrlMappingEvaluator import org.grails.web.mapping.DefaultUrlMappingsHolder import org.grails.web.mime.DefaultMimeUtility import org.grails.web.servlet.mvc.GrailsWebRequest -import org.springframework.context.ApplicationContext -import org.springframework.context.support.GenericApplicationContext import org.springframework.context.support.StaticMessageSource import org.springframework.core.env.MapPropertySource import org.springframework.core.env.MutablePropertySources @@ -34,6 +31,7 @@ import org.springframework.web.context.WebApplicationContext import org.springframework.web.context.request.RequestContextHolder import org.springframework.web.context.support.GenericWebApplicationContext import org.springframework.web.util.WebUtils + import spock.lang.Specification /** @@ -205,17 +203,9 @@ grails.mime.types = [ } private MimeType[] buildMimeTypes(application) { - final def mainContext = new GenericApplicationContext() - mainContext.refresh() - application.setApplicationContext(mainContext) - - def bb = new BeanBuilder() - bb.beans { - grailsApplication = application - mimeConfiguration(MimeTypesConfiguration, application, []) - } - final ApplicationContext context = bb.createApplicationContext() - final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration) - mimeTypesConfiguration.mimeTypes() + def mimeTypesFactory = new MimeTypesFactoryBean() + mimeTypesFactory.grailsApplication = application + def mimeTypes = mimeTypesFactory.getObject() + mimeTypes } } diff --git a/grails-test-suite-uber/src/test/groovy/org/grails/web/util/WebUtilsTests.groovy b/grails-test-suite-uber/src/test/groovy/org/grails/web/util/WebUtilsTests.groovy index 7a938184aa6..66695be4d40 100644 --- a/grails-test-suite-uber/src/test/groovy/org/grails/web/util/WebUtilsTests.groovy +++ b/grails-test-suite-uber/src/test/groovy/org/grails/web/util/WebUtilsTests.groovy @@ -2,17 +2,14 @@ package org.grails.web.util import grails.core.DefaultGrailsApplication import grails.core.GrailsApplication -import grails.spring.BeanBuilder import grails.web.mime.MimeType import org.grails.config.PropertySourcesConfig -import org.grails.plugins.web.mime.MimeTypesConfiguration +import org.grails.plugins.web.mime.MimeTypesFactoryBean import org.grails.support.MockApplicationContext import org.grails.web.servlet.mvc.GrailsWebRequest import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.springframework.context.ApplicationContext -import org.springframework.context.support.GenericApplicationContext import org.springframework.mock.web.MockHttpServletRequest import org.springframework.mock.web.MockHttpServletResponse import org.springframework.mock.web.MockServletContext @@ -72,19 +69,10 @@ grails.mime.file.extensions=true private def bindMockRequest(DefaultGrailsApplication ga) { def ctx = new MockApplicationContext() ctx.registerMockBean(GrailsApplication.APPLICATION_ID, ga) + def factory = new MimeTypesFactoryBean(grailsApplication: ga) - final def mainContext = new GenericApplicationContext() - mainContext.refresh() - ga.setApplicationContext(mainContext) + ctx.registerMockBean(MimeType.BEAN_NAME, factory.getObject()) - def bb = new BeanBuilder() - bb.beans { - grailsApplication = ga - mimeConfiguration(MimeTypesConfiguration, ga, []) - } - final ApplicationContext context = bb.createApplicationContext() - final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration) - ctx.registerMockBean(MimeType.BEAN_NAME, mimeTypesConfiguration.mimeTypes()) def servletContext = new MockServletContext() servletContext.setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT, ctx) def webRequest = new GrailsWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse(), servletContext) diff --git a/grails-test-suite-web/src/test/groovy/org/grails/plugins/web/rest/render/xml/DefaultXmlRendererSpec.groovy b/grails-test-suite-web/src/test/groovy/org/grails/plugins/web/rest/render/xml/DefaultXmlRendererSpec.groovy index df3a587d4a8..0631bede51d 100644 --- a/grails-test-suite-web/src/test/groovy/org/grails/plugins/web/rest/render/xml/DefaultXmlRendererSpec.groovy +++ b/grails-test-suite-web/src/test/groovy/org/grails/plugins/web/rest/render/xml/DefaultXmlRendererSpec.groovy @@ -7,7 +7,7 @@ import grails.testing.gorm.DomainUnitTest import grails.util.GrailsWebUtil import grails.validation.ValidationErrors import grails.web.mime.MimeType -import groovy.xml.XmlSlurper + import org.grails.plugins.web.rest.render.ServletRenderContext import org.grails.web.converters.configuration.ConvertersConfigurationHolder import org.grails.web.converters.configuration.ConvertersConfigurationInitializer @@ -16,6 +16,7 @@ import org.grails.web.servlet.mvc.GrailsWebRequest import org.springframework.mock.web.MockHttpServletRequest import org.springframework.mock.web.MockHttpServletResponse import org.springframework.mock.web.MockServletContext + import spock.lang.Specification /** diff --git a/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONBindingToNullSpec.groovy b/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONBindingToNullTests.groovy similarity index 52% rename from grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONBindingToNullSpec.groovy rename to grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONBindingToNullTests.groovy index be6b1b4ab78..8c19717ced6 100644 --- a/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONBindingToNullSpec.groovy +++ b/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONBindingToNullTests.groovy @@ -6,37 +6,35 @@ import grails.converters.XML import grails.persistence.Entity import grails.testing.gorm.DomainUnitTest import grails.testing.web.controllers.ControllerUnitTest -import groovy.json.JsonBuilder +import grails.web.JSONBuilder import spock.lang.Specification -class JSONBindingToNullSpec extends Specification implements ControllerUnitTest, DomainUnitTest { - - Closure doWithConfig() { - { config -> - config.grails.mime.types = [html : ['text/html', 'application/xhtml+xml'], - xml : ['text/xml', 'application/xml'], - text : 'text/plain', - js : 'text/javascript', - rss : 'application/rss+xml', - atom : 'application/atom+xml', - css : 'text/css', - csv : 'text/csv', - all : '*/*', - json : ['application/json', 'text/json'], - form : 'application/x-www-form-urlencoded', - multipartForm: 'multipart/form-data' - ] - - } - } +class JSONBindingToNullTests extends Specification implements ControllerUnitTest, DomainUnitTest { + + Closure doWithConfig() {{ config -> + config.grails.mime.types = [ html: ['text/html','application/xhtml+xml'], + xml: ['text/xml', 'application/xml'], + text: 'text/plain', + js: 'text/javascript', + rss: 'application/rss+xml', + atom: 'application/atom+xml', + css: 'text/css', + csv: 'text/csv', + all: '*/*', + json: ['application/json','text/json'], + form: 'application/x-www-form-urlencoded', + multipartForm: 'multipart/form-data' + ] + + }} void testJsonBindingToNull() { when: - def pebbles = new User(username: "pebbles", password: "letmein", firstName: "Pebbles", lastName: "Flintstone", middleName: "T", phone: "555-555-5555", email: 'pebbles@flintstone.com', activationDate: new Date(), logonFailureCount: 0, deactivationDate: null).save(flush: true) + def pebbles = new User(username:"pebbles", password:"letmein", firstName:"Pebbles", lastName:"Flintstone", middleName:"T", phone:"555-555-5555", email:'pebbles@flintstone.com', activationDate:new Date(), logonFailureCount:0, deactivationDate:null).save(flush:true) - def builder = new JsonBuilder() + def builder = new JSONBuilder() request.method = 'PUT' - request.json = [user: pebbles] + request.json = builder.build { user = pebbles } response.format = "json" params.id = pebbles.id @@ -49,7 +47,7 @@ class JSONBindingToNullSpec extends Specification implements ControllerUnitTest< void testXmlBindingToNull() { when: - def pebbles = new User(username: "pebbles", password: "letmein", firstName: "Pebbles", lastName: "Flintstone", middleName: "T", phone: "555-555-5555", email: 'pebbles@flintstone.com', activationDate: new Date(), logonFailureCount: 0, deactivationDate: null).save(flush: true) + def pebbles = new User(username:"pebbles", password:"letmein", firstName:"Pebbles", lastName:"Flintstone", middleName:"T", phone:"555-555-5555", email:'pebbles@flintstone.com', activationDate:new Date(), logonFailureCount:0, deactivationDate:null).save(flush:true) request.method = 'PUT' request.xml = pebbles @@ -116,15 +114,15 @@ class User { Date lastAccessDate static constraints = { - middleName(nullable: true) - phone(nullable: true) - email(nullable: true, email: true) - activeDirectoryUsername(nullable: true) - createdBy(nullable: true) - lastUpdatedBy(nullable: true) - logonFailureCount(nullable: false) - deactivationDate(nullable: true) - lastUpdatedDate(nullable: true) - lastAccessDate(nullable: true) + middleName(nullable:true) + phone(nullable:true) + email(nullable:true, email:true) + activeDirectoryUsername(nullable:true) + createdBy(nullable:true) + lastUpdatedBy(nullable:true) + logonFailureCount(nullable:false) + deactivationDate(nullable:true) + lastUpdatedDate(nullable:true) + lastAccessDate(nullable:true) } } diff --git a/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONRequestToResponseRenderingSpec.groovy b/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONRequestToResponseRenderingSpec.groovy index 7a9adac1c9b..3296fc6d618 100644 --- a/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONRequestToResponseRenderingSpec.groovy +++ b/grails-test-suite-web/src/test/groovy/org/grails/web/binding/JSONRequestToResponseRenderingSpec.groovy @@ -44,6 +44,7 @@ class JSONRequestToResponseRenderingSpec extends Specification implements Contro class ArrayController { def list() { def json = request.JSON + render json } } diff --git a/grails-test-suite-web/src/test/groovy/org/grails/web/controllers/ControllerExceptionHandlerSpec.groovy b/grails-test-suite-web/src/test/groovy/org/grails/web/controllers/ControllerExceptionHandlerSpec.groovy index 1f56178e29f..052a17bfc8f 100644 --- a/grails-test-suite-web/src/test/groovy/org/grails/web/controllers/ControllerExceptionHandlerSpec.groovy +++ b/grails-test-suite-web/src/test/groovy/org/grails/web/controllers/ControllerExceptionHandlerSpec.groovy @@ -186,18 +186,18 @@ class ErrorHandlersController extends SomeAbstractController implements Database def testAction() { def exceptionClass = Class.forName(params.exceptionToThrow) - throw exceptionClass.getDeclaredConstructor().newInstance() + throw exceptionClass.newInstance() } def testActionWithCommandObject(MyCommand co) { def exceptionClass = Class.forName(co.exceptionToThrow) - throw exceptionClass.getDeclaredConstructor().newInstance() + throw exceptionClass.newInstance() } def testActionWithNonCommandObjectParameter(String exceptionToThrow) { def exceptionClass = Class.forName(exceptionToThrow) - throw exceptionClass.getDeclaredConstructor().newInstance() + throw exceptionClass.newInstance() } def handleNumberFormatException(NumberFormatException nfe) { diff --git a/grails-test/src/main/groovy/org/grails/plugins/testing/AbstractGrailsMockHttpServletResponse.groovy b/grails-test/src/main/groovy/org/grails/plugins/testing/AbstractGrailsMockHttpServletResponse.groovy index cfcd603a8cf..5bb2b802ac3 100644 --- a/grails-test/src/main/groovy/org/grails/plugins/testing/AbstractGrailsMockHttpServletResponse.groovy +++ b/grails-test/src/main/groovy/org/grails/plugins/testing/AbstractGrailsMockHttpServletResponse.groovy @@ -16,15 +16,16 @@ package org.grails.plugins.testing import grails.converters.JSON -import groovy.xml.slurpersupport.GPathResult -import org.grails.io.support.SpringIOUtils +import groovy.util.slurpersupport.GPathResult + +import javax.servlet.http.HttpServletRequest + import org.grails.web.json.JSONElement -import org.grails.web.servlet.mvc.GrailsWebRequest import org.grails.web.util.GrailsApplicationAttributes +import org.grails.web.servlet.mvc.GrailsWebRequest import org.springframework.mock.web.MockHttpServletResponse import org.springframework.util.ReflectionUtils - -import javax.servlet.http.HttpServletRequest +import org.grails.io.support.SpringIOUtils /** * Simple sub-class of Spring's MockHttpServletResponse that adds the diff --git a/grails-test/src/main/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequest.groovy b/grails-test/src/main/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequest.groovy index 2d2f39c8dbc..61f7f081215 100644 --- a/grails-test/src/main/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequest.groovy +++ b/grails-test/src/main/groovy/org/grails/plugins/testing/GrailsMockHttpServletRequest.groovy @@ -82,15 +82,15 @@ class GrailsMockHttpServletRequest extends MockHttpServletRequest implements Mul void setFormat(String format) { setAttribute(GrailsApplicationAttributes.CONTENT_FORMAT, format) } - + @Override void setContentType(String newContentType) { super.setContentType(newContentType) def webRequest = getAttribute(GrailsApplicationAttributes.WEB_REQUEST) def mimeType = MimeType.configuredMimeTypes?.find { mt -> mt?.name == newContentType - } - + } + if(!mimeType) { mimeType = new MimeType(newContentType) } @@ -223,10 +223,10 @@ class GrailsMockHttpServletRequest extends MockHttpServletRequest implements Mul boolean isPost() { method == "POST" } /** - * Parses the request content as XML using XmlSlurper and returns - * the GPath result object. Throws an exception if there is no - * content or the content is not valid XML. - */ + * Parses the request content as XML using XmlSlurper and returns + * the GPath result object. Throws an exception if there is no + * content or the content is not valid XML. + */ def getXML() { if (!cachedXml) { cachedXml = GrailsMockHttpServletRequest.classLoader.loadClass("grails.converters.XML").parse(this) @@ -566,6 +566,6 @@ class MockAsyncContext implements AsyncContext { } def T createListener(Class clazz) { - return clazz.getDeclaredConstructor().newInstance() + return clazz.newInstance() } } diff --git a/grails-test/src/main/groovy/org/grails/test/spock/IntegrationSpecConfigurerExtension.groovy b/grails-test/src/main/groovy/org/grails/test/spock/IntegrationSpecConfigurerExtension.groovy index 0b71ab89a21..1deec991d73 100644 --- a/grails-test/src/main/groovy/org/grails/test/spock/IntegrationSpecConfigurerExtension.groovy +++ b/grails-test/src/main/groovy/org/grails/test/spock/IntegrationSpecConfigurerExtension.groovy @@ -16,18 +16,17 @@ package org.grails.test.spock -import grails.util.Holders -import groovy.transform.CompileStatic -import org.grails.test.support.GrailsTestInterceptor -import org.grails.test.support.GrailsTestMode -import org.spockframework.runtime.extension.IAnnotationDrivenExtension +import org.spockframework.runtime.model.SpecInfo import org.spockframework.runtime.extension.IMethodInterceptor import org.spockframework.runtime.extension.IMethodInvocation -import org.spockframework.runtime.model.FeatureInfo -import org.spockframework.runtime.model.SpecInfo +import grails.util.Holders import org.springframework.context.ApplicationContext - +import org.grails.test.support.GrailsTestMode +import org.grails.test.support.GrailsTestInterceptor +import groovy.transform.CompileStatic +import org.spockframework.runtime.extension.AbstractAnnotationDrivenExtension import java.lang.annotation.Annotation +import org.spockframework.runtime.model.FeatureInfo /** * Spock extension that can be applied to Integration tests to make them Grails aware @@ -37,7 +36,7 @@ import java.lang.annotation.Annotation * */ @CompileStatic -class IntegrationSpecConfigurerExtension implements IAnnotationDrivenExtension { +class IntegrationSpecConfigurerExtension extends AbstractAnnotationDrivenExtension { void visitSpecAnnotation(Annotation annotation, SpecInfo spec) { final context = Holders.getApplicationContext() diff --git a/grails-web-common/src/test/groovy/grails/web/servlet/mvc/GrailsParameterMapTests.groovy b/grails-web-common/src/test/groovy/grails/web/servlet/mvc/GrailsParameterMapTests.groovy index 654844682a3..0b88a694857 100644 --- a/grails-web-common/src/test/groovy/grails/web/servlet/mvc/GrailsParameterMapTests.groovy +++ b/grails-web-common/src/test/groovy/grails/web/servlet/mvc/GrailsParameterMapTests.groovy @@ -337,11 +337,9 @@ class GrailsParameterMapTests { mockRequest.addParameter("foo_month", "07") theMap = new GrailsParameterMap(mockRequest) - final Calendar calendar = Calendar.getInstance() assert theMap.getDate("foo").getClass() == java.util.Date - calendar.setTime(theMap.getDate("foo")) - assert calendar.get(Calendar.YEAR) == 2007 - assert calendar.get(Calendar.MONTH) == Calendar.JULY + assert theMap.getDate("foo").year == 107 + assert theMap.getDate("foo").month == Calendar.JULY } @Test diff --git a/grails-web-databinding/src/main/groovy/grails/web/databinding/GrailsWebDataBinder.groovy b/grails-web-databinding/src/main/groovy/grails/web/databinding/GrailsWebDataBinder.groovy index e7d564361d1..09063e35a0f 100644 --- a/grails-web-databinding/src/main/groovy/grails/web/databinding/GrailsWebDataBinder.groovy +++ b/grails-web-databinding/src/main/groovy/grails/web/databinding/GrailsWebDataBinder.groovy @@ -20,6 +20,7 @@ import grails.databinding.* import grails.databinding.converters.FormattedValueConverter import grails.databinding.converters.ValueConverter import grails.databinding.events.DataBindingListener +import grails.util.Environment import grails.util.GrailsClassUtils import grails.util.GrailsMetaClassUtils import grails.util.GrailsNameUtils @@ -27,7 +28,7 @@ import grails.validation.DeferredBindingActions import grails.validation.ValidationErrors import groovy.transform.CompileStatic import groovy.transform.TypeCheckingMode -import groovy.xml.slurpersupport.GPathResult +import groovy.util.slurpersupport.GPathResult import org.codehaus.groovy.runtime.InvokerHelper import org.codehaus.groovy.runtime.MetaClassHelper import org.codehaus.groovy.runtime.metaclass.ThreadManagedMetaBeanProperty @@ -38,8 +39,14 @@ import org.grails.databinding.IndexedPropertyReferenceDescriptor import org.grails.databinding.xml.GPathResultMap import org.grails.datastore.mapping.model.PersistentEntity import org.grails.datastore.mapping.model.PersistentProperty -import org.grails.datastore.mapping.model.types.* +import org.grails.datastore.mapping.model.types.Association +import org.grails.datastore.mapping.model.types.Basic +import org.grails.datastore.mapping.model.types.ManyToOne +import org.grails.datastore.mapping.model.types.OneToMany +import org.grails.datastore.mapping.model.types.OneToOne +import org.grails.datastore.mapping.model.types.Simple import org.grails.web.databinding.DataBindingEventMulticastListener +import org.grails.web.databinding.DefaultASTDatabindingHelper import org.grails.web.databinding.GrailsWebDataBindingListener import org.grails.web.databinding.SpringConversionServiceAdapter import org.grails.web.databinding.converters.ByteArrayMultipartFileValueConverter @@ -52,8 +59,10 @@ import org.springframework.validation.FieldError import org.springframework.validation.ObjectError import java.lang.annotation.Annotation +import java.lang.reflect.Modifier +import java.util.concurrent.ConcurrentHashMap -import static grails.web.databinding.DataBindingUtils.getBindingIncludeList +import static grails.web.databinding.DataBindingUtils.* @CompileStatic class GrailsWebDataBinder extends SimpleDataBinder { diff --git a/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMap.groovy b/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMap.groovy index 1dc2c7af203..d4295242cf2 100644 --- a/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMap.groovy +++ b/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMap.groovy @@ -15,9 +15,9 @@ */ package org.grails.web.databinding.bindingsource -import groovy.xml.slurpersupport.GPathResult -import groovy.xml.slurpersupport.Node -import groovy.xml.slurpersupport.NodeChild +import groovy.util.slurpersupport.GPathResult +import groovy.util.slurpersupport.Node +import groovy.util.slurpersupport.NodeChild import org.grails.databinding.xml.GPathResultMap diff --git a/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/XmlDataBindingSourceCreator.groovy b/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/XmlDataBindingSourceCreator.groovy index 73995ec137b..7d4259f749e 100644 --- a/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/XmlDataBindingSourceCreator.groovy +++ b/grails-web-databinding/src/main/groovy/org/grails/web/databinding/bindingsource/XmlDataBindingSourceCreator.groovy @@ -19,7 +19,7 @@ import grails.databinding.CollectionDataBindingSource; import grails.databinding.DataBindingSource; import grails.databinding.SimpleMapDataBindingSource; import groovy.transform.CompileStatic -import groovy.xml.slurpersupport.GPathResult +import groovy.util.slurpersupport.GPathResult import grails.web.mime.MimeType import org.grails.databinding.bindingsource.DataBindingSourceCreationException diff --git a/grails-web-databinding/src/test/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMapSpec.groovy b/grails-web-databinding/src/test/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMapSpec.groovy index d59c635e405..106ddda0557 100644 --- a/grails-web-databinding/src/test/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMapSpec.groovy +++ b/grails-web-databinding/src/test/groovy/org/grails/web/databinding/bindingsource/HalGPathResultMapSpec.groovy @@ -1,6 +1,8 @@ package org.grails.web.databinding.bindingsource -import groovy.xml.XmlSlurper +import org.grails.databinding.xml.GPathResultMap +import org.grails.web.databinding.bindingsource.HalGPathResultMap; + import spock.lang.Specification class HalGPathResultMapSpec extends Specification {