grails-plugins / grails-rest-client-builder

REST client plugin that uses Spring's RestTemplate
http://grails.org/plugin/rest-client-builder
Apache License 2.0
65 stars 32 forks source link

ConverterException on functional -war test #1

Open bluesliverx opened 12 years ago

bluesliverx commented 12 years ago

(No JIRA project yet, so I thought I would enter it here) I'm using the plugin in functional testing, and it works great with a typical test-app functional: run, but fails when doing test-app functional: -war. The reason:

org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Unconvertable Object of class: java.util.LinkedHashMap
org.apache.commons.lang.UnhandledException: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Unconvertable Object of class: java.util.LinkedHashMap
    at grails.plugins.rest.client.RequestCustomizer.json(RestBuilder.groovy:182)
    at com.ace.mws.policies.MyFunctionalSpec.test rest client_closure5(MyFunctionalSpec.groovy:83)
    at grails.plugins.rest.client.RestBuilder.doRequestInternal(RestBuilder.groovy:90)
    at grails.plugins.rest.client.RestBuilder.put(RestBuilder.groovy:63)
    at com.ace.mws.policies.MyFunctionalSpec.test rest client(MyFunctionalSpec.groovy:80)
Caused by: org.codehaus.groovy.grails.web.converters.exceptions.ConverterException: Unconvertable Object of class: java.util.LinkedHashMap
    at grails.converters.JSON.value(JSON.java:197)
    at grails.converters.JSON.render(JSON.java:134)

The code that is failing is the 'json' declaration of the RestBuilder.put method. I am pretty much following your example, which again works great typically but is failing during functional WAR tests:

def resp = rest.put(url) {
  json {
    param1 = "value"
    param2 = "value2"
  }
}

Not sure if it's because the application is not wired up the same in the functional tests where the app is not in the same JVM? I am using the geb plugin which is providing the functional testing abilities.

sukrit007 commented 11 years ago

I get the same issue when I run tests using -baseUrl. It seems that the DefaultConverterConfiguration is not initialized when targetting a particular server or using -war option.

I did try to initialize DefaultConverterConfiguration but with no luck . The only workaround I have found so far to work is to use "content" instead of "json" and creating "content" using JsonBuilder. This workaround also requires you to explicitly set contentType to "application/json".