This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch debian/master
in repository rest-gradle-plugin.

commit eab7dc331e007c433a20ee85c3bcd4955bd808f3
Author: Andrea Rossi <andrea.ro...@here.com>
Date:   Thu Jul 24 20:29:40 2014 +0200

    Add support for custom request headers
---
 README.md                                          |  2 ++
 .../groovy/org/_10ne/gradle/rest/RestTask.groovy   |  6 ++++
 .../org/_10ne/gradle/rest/RestTaskSpec.groovy      | 36 ++++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/README.md b/README.md
index 7b26b46..44b8f03 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ The plugin adds a new task named `rest`. This task exposes 
the following propert
  * contentType - The expected content type of both request and response. Type: 
groovyx.net.http.ContentType / String.
  * requestContentType - The expected content type of the request. Overrides 
the `contentType` parameter. Type: groovyx.net.http.ContentType / String.
  * requestBody - The request content. Type: Object.
+ * requestHeaders - Additional request headers. Type: Map.
 
 For example, a POST request task:
 
@@ -42,4 +43,5 @@ For example, a POST request task:
         password = 'password'
         requestBody = [battleCry: 'FOR LEEROY JENKINS!']
         contentType = groovyx.net.http.ContentType.JSON
+        requestHeaders = [customHeader: 'WoW']
     }
\ No newline at end of file
diff --git a/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy 
b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
index c93bd19..ddae22c 100644
--- a/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
+++ b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
@@ -47,6 +47,8 @@ class RestTask extends DefaultTask {
     @Optional Object contentType
     @Input
     @Optional Object requestBody
+    @Input
+    @Optional Object requestHeaders
 
     RestTask() {
         httpMethod = 'get'
@@ -67,6 +69,10 @@ class RestTask extends DefaultTask {
             client.auth.basic(username, password)
         }
 
+        if (requestHeaders instanceof Map) {
+            client.headers.putAll(requestHeaders);
+        }
+
         def params = [:]
         if (requestBody) {
             params.body = requestBody
diff --git a/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy 
b/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy
index b2de4f6..5647487 100644
--- a/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy
+++ b/src/test/groovy/org/_10ne/gradle/rest/RestTaskSpec.groovy
@@ -106,4 +106,40 @@ class RestTaskSpec extends Specification {
         }
         1 * mockResponse.getData() >> { 'somedata' }
     }
+
+    def 'Configure and execute a request with a custom header'() {
+        setup:
+        Task task = project.tasks.create(name: 'request', type: RestTask) {
+            httpMethod = 'post'
+            uri = 'bob.com'
+            username = 'username'
+            password = 'password'
+            requestContentType = 'requestContentType'
+            requestBody = 'requestBody'
+            contentType = 'contentType'
+            requestHeaders = ['key': 'value']
+        }
+        def mockClient = Mock(RESTClient)
+        task.client = mockClient
+
+        def mockAuth = Mock(AuthConfig)
+
+        def mockResponse = Mock(HttpResponseDecorator)
+
+        def headers = [:]
+
+        when:
+        task.executeRequest()
+
+        then:
+        1 * mockClient.setUri('bob.com')
+        1 * mockClient.getAuth() >> { mockAuth }
+        1 * mockClient.getHeaders() >> { headers }
+        1 * mockAuth.basic('username', 'password')
+        1 * mockClient.post(_ as Map) >> { Map params ->
+            assert headers.get('key') == 'value'
+            mockResponse
+        }
+        1 * mockResponse.getData() >> { 'somedata' }
+    }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-java/rest-gradle-plugin.git

_______________________________________________
pkg-java-commits mailing list
pkg-java-comm...@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

Reply via email to