Skip to content

Commit

Permalink
Merge pull request Grailsrocks#1 from christoph-frick/gpc-improve-rest
Browse files Browse the repository at this point in the history
Improve REST
  • Loading branch information
ddelponte committed Mar 19, 2015
2 parents 1940034 + 9c60dbd commit 1fe811a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/groovy/com/grailsrocks/functionaltest/TestCaseBase.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -150,6 +153,7 @@ class APIClient implements Client {
if (n) {
responseString += "\r\n and $n more bytes"
}
response.data.reset()
break
}
} else {
Expand Down

0 comments on commit 1fe811a

Please sign in to comment.