2 * Tests for the XML converter
4 * @author Graeme Rocher
12 package org
.codehaus
.groovy
.grails
.web
.converters
14 import org
.codehaus
.groovy
.grails
.web
.servlet
.mvc
.AbstractGrailsControllerTests
15 import net
.sf
.cglib
.proxy
.Enhancer
16 import java
.lang
.reflect
.Method
17 import net
.sf
.cglib
.proxy
.MethodProxy
18 import net
.sf
.cglib
.proxy
.MethodInterceptor
20 class XMLConverterTests
extends AbstractGrailsControllerTests
{
22 void testXMLConverter() {
23 def c
= ga
.getControllerClass("RestController").newInstance()
27 assertEquals( '''<?xml version="1.0" encoding="utf-8"?><book>
28 <author>Stephen King</author>
29 <title>The Stand</title>
30 </book>''', response
.contentAsString
)
33 void testProxiedDomainClassWithXMLConverter() {
34 Enhancer e
= new Enhancer();
36 e
.superclass
= ga
.getDomainClass("Book").clazz
37 e
.callback
= { obj
, Method method
, Object
[] args
,
39 proxy
.invokeSuper obj
, args
41 } as MethodInterceptor
43 def proxy
= e
.create()
44 proxy
.title
= "The Stand"
45 proxy
.author
= "Stephen King"
46 def c
= ga
.getControllerClass("RestController").newInstance()
51 // todo: Get Grails' Xstream stuff to deal with CGlib proxies
52 assertEquals( '''<?xml version="1.0" encoding="utf-8"?><CGLIB-enhanced-proxy>
53 <author>Stephen King</author>
54 <title>The Stand</title>
55 </CGLIB-enhanced-proxy>''', response
.contentAsString
)
60 import grails.converters.*
62 class RestController {
64 def b = new Book(title:'The Stand
', author:'Stephen King
')
69 render params.b as XML