Permalink
Browse files

cleanup

  • Loading branch information...
1 parent 0aa2164 commit ac1c6b46779d2eb2ae8746cee3c6b0f764903e36 Burt Beckwith committed Dec 5, 2012
View
1 .gitignore
@@ -5,3 +5,4 @@ target
web-app
*.zip
*.log
+.settings
View
3 .settings/org.codehaus.groovy.eclipse.preferences.prefs
@@ -1,3 +0,0 @@
-#Created by grails
-eclipse.preferences.version=1
-groovy.dont.generate.class.files=true
View
17 README.md
@@ -4,8 +4,8 @@
Edit `BuildConfig.groovy` and add the following dependency:
- compile ":rest-client-builder:1.0"
-
+ compile ":rest-client-builder:1.0.3"
+
## Basic Usage
Main entry point is the `grails.plugins.rest.client.RestBuilder` class. Construct and use one of the REST "verbs".
@@ -20,12 +20,12 @@ There are convenience methods for obtaining JSON:
resp.json instanceof JSONObject
resp.json.name == 'acegi'
-
+
And XML:
resp.xml instanceof GPathResult
resp.xml.name == 'acegi'
-
+
## POST and PUT requests
`POST` and `PUT` requests can be issued with the `post` and `put` methods respectively:
@@ -38,7 +38,7 @@ And XML:
description = "A temporary test group"
}
}
-
+
In the example above the `auth` method performs HTTP basic auth, the `contentType` method sets the content type, and the `json` method constructs a JSON body.
## Exchanging JSON and XML content
@@ -55,7 +55,7 @@ As demonstrated in the previous example you can send JSON data using the json me
...
contentType "application/vnd.org.jfrog.artifactory.security.Group+json"
json '{ name: "test-group", description: "A temporary test group" }'
- }
+ }
If you don't explicitly set the contentType like is done above then the default content type for the `json` method is "application/json".
@@ -65,7 +65,7 @@ The response object has `xml` or `json` properties for reading the response of t
## Multipart Requests
-Multipart requests are possible by setting properties of the request body to `File`, `URL`, `byte[]` or `InputStream` instances:
+Multipart requests are possible by setting properties of the request body to `File`, `URL`, `byte[]` or `InputStream` instances:
def resp = rest.post(url) {
contentType "multipart/form-data"
@@ -81,6 +81,3 @@ Connection and proxy configuration can be specified in the constructor to `RestB
def rest = new RestBuilder(connectTimeout:1000, readTimeout:20000, proxy:['localhost':8888])
The proxy setting can either be map containing the key for the host name and a value for the port or an instance of `java.net.Proxy`.
-
-
-
View
17 test/unit/grails/plugins/rest/client/RestBuilderSpec.groovy
@@ -18,8 +18,8 @@ class RestBuilderSpec extends Specification {
def "Test proxy configuration"() {
when:"RestBuilder is configured with proxy settings"
def rest = new RestBuilder(proxy:['localhost':8888])
-
def proxyAddress = rest.restTemplate.requestFactory?.@proxy?.address()
+
then:"The proxy settings are correct"
proxyAddress != null
proxyAddress.hostName == "localhost"
@@ -92,7 +92,7 @@ class RestBuilderSpec extends Specification {
then:"The response is a gpath result"
resp != null
- resp.json instanceof JSONArray
+ resp.json instanceof JSONArray
}
def "Test basic authentication with PUT request"() {
@@ -138,7 +138,7 @@ class RestBuilderSpec extends Specification {
def rest = new RestBuilder()
when:"A get request is issued for a response that returns XML"
- def builder = new JSONBuilder()
+ def builder = new JSONBuilder()
JSON j = builder.build {
name = "test-group"
description = "A temporary test group"
@@ -171,14 +171,14 @@ class RestBuilderSpec extends Specification {
resp != null
resp.status == 200
resp.text == "Group 'test-group' has been removed successfully."
- }
+ }
def "Test basic authentication with PUT request and JSON as map"() {
given:"A rest client instance"
def rest = new RestBuilder()
when:"A get request is issued for a response that returns XML"
- def builder = new JSONBuilder()
+ def builder = new JSONBuilder()
def j = [
name : "test-group",
description : "A temporary test group"
@@ -211,25 +211,24 @@ class RestBuilderSpec extends Specification {
resp != null
resp.status == 200
resp.text == "Group 'test-group' has been removed successfully."
- }
+ }
def "Test PUT request passing binary content in the body"() {
setup:
def rest = new RestBuilder(connectTimeout: 1000, readTimeout:10000)
rest.delete("http://repo.grails.org/grails/libs-snapshots-local/org/mycompany/1.0/foo-1.0.jar") {
auth System.getProperty("artifactory.user"), System.getProperty("artifactory.pass")
}
-
+
when:"A put request is issued that contains binary content"
def resp = rest.put("http://repo.grails.org/grails/libs-snapshots-local/org/mycompany/1.0/foo-1.0.jar") {
auth System.getProperty("artifactory.user"), System.getProperty("artifactory.pass")
body "foo".bytes
}
-
+
then:"The response JSON is correct"
resp.json.uri == "http://repo.grails.org/grails/libs-snapshots-local/org/mycompany/1.0/foo-1.0.jar"
new URL( "http://repo.grails.org/grails/libs-snapshots-local/org/mycompany/1.0/foo-1.0.jar").text == "foo"
-
}
// Note that this test uses JSON query parameters, but they are not actually validated due to the call

0 comments on commit ac1c6b4

Please sign in to comment.