From 98841f74b4b53ef8c99e158569515f731b17bf5e Mon Sep 17 00:00:00 2001 From: Christoph Frick Date: Mon, 27 Jan 2014 18:12:20 +0100 Subject: [PATCH 1/3] APIClient: reset response.data to in case the mimeType is not handled in the switch the data is still useable --- .../com/grailsrocks/functionaltest/client/APIClient.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy b/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy index bca80a8..8eef425 100644 --- a/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy +++ b/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy @@ -150,6 +150,7 @@ class APIClient implements Client { if (n) { responseString += "\r\n and $n more bytes" } + response.data.reset() break } } else { From 0fc74ad7a1875930fbf435ad8a8f349b3e43b206 Mon Sep 17 00:00:00 2001 From: Christoph Frick Date: Mon, 27 Jan 2014 18:20:25 +0100 Subject: [PATCH 2/3] APIClient: added more mimetypes that represent json- or xml-oid content --- .../com/grailsrocks/functionaltest/client/APIClient.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy b/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy index 8eef425..5bcac3a 100644 --- a/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy +++ b/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy @@ -139,6 +139,9 @@ class APIClient implements Client { switch (response.contentType) { case ~'application/json.*': + case ~'application/.*\\+json.*': + case ~'application/xml.*': + case ~'application/.*\\+xml.*': case ~'text/.*': responseString = response.data.text break From 9c60dbd9a84a220eda8df5da8efe6223b1d47da0 Mon Sep 17 00:00:00 2001 From: Christoph Frick Date: Mon, 27 Jan 2014 18:32:06 +0100 Subject: [PATCH 3/3] TestCaseBase: weaken the checks for the content-type in get(JSON|XML) so anything containing json/xml is accepted; let the according parsers fail if it is not for real --- .../com/grailsrocks/functionaltest/TestCaseBase.groovy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/groovy/com/grailsrocks/functionaltest/TestCaseBase.groovy b/src/groovy/com/grailsrocks/functionaltest/TestCaseBase.groovy index 3b3046e..738bfaa 100644 --- a/src/groovy/com/grailsrocks/functionaltest/TestCaseBase.groovy +++ b/src/groovy/com/grailsrocks/functionaltest/TestCaseBase.groovy @@ -426,12 +426,14 @@ abstract class TestCaseBase extends GroovyTestCase implements GroovyInterceptabl } */ JSONElement getJSON() { - assertContentType contentTypeForJSON + def contentType = stripWS(client.responseContentType.toLowerCase()) + assertTrue "Expected content type to contain json [${contentType}]", contentType.contains("json") grails.converters.JSON.parse(client.responseAsString) } GPathResult getXML() { - assertContentType contentTypeForXML + def contentType = stripWS(client.responseContentType.toLowerCase()) + assertTrue "Expected content type to contain xml [${contentType}]", contentType.contains("xml") grails.converters.XML.parse(client.responseAsString) }