Skip to content

Commit fefca14

Browse files
GRAILS-6791 - rig up JSON and XML errors marshallers in GrailsUnitTestCase to simply unit testing code that renders validation errors as XML or JSON.
1 parent a9867d8 commit fefca14

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/java/grails/test/GrailsUnitTestCase.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import org.codehaus.groovy.grails.web.converters.ConverterUtil
2626
import org.codehaus.groovy.grails.web.converters.configuration.ConvertersConfigurationInitializer
2727

2828
import org.springframework.validation.Errors
29+
import org.codehaus.groovy.grails.web.converters.marshaller.json.ValidationErrorsMarshaller as JsonErrorsMarshaller
30+
import org.codehaus.groovy.grails.web.converters.marshaller.xml.ValidationErrorsMarshaller as XmlErrorsMarshaller
31+
32+
import grails.converters.XML
33+
import grails.converters.JSON
2934

3035
/**
3136
* Support class for writing unit tests in Grails. It mainly provides
@@ -59,6 +64,10 @@ class GrailsUnitTestCase extends GroovyTestCase {
5964
def convertersInit = new ConvertersConfigurationInitializer()
6065
convertersInit.initialize()
6166
[ List, Set, Map, Errors ].each { addConverters(it) }
67+
def xmlErrorMarshaller = new XmlErrorsMarshaller()
68+
XML.registerObjectMarshaller(xmlErrorMarshaller)
69+
def jsonErrorMarshaller = new JsonErrorsMarshaller()
70+
JSON.registerObjectMarshaller(jsonErrorMarshaller)
6271

6372
previousConfig = ConfigurationHolder.config
6473

0 commit comments

Comments
 (0)