Created
January 31, 2016 02:35
-
-
Save ctoestreich/77d6a38f10af62fe3e3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.grails.demo | |
import grails.plugins.rest.client.RequestCustomizer | |
import grails.plugins.rest.client.RestResponse | |
import grails.test.mixin.TestFor | |
import org.springframework.http.HttpStatus | |
import org.springframework.http.ResponseEntity | |
@TestFor(ExternalRestBuilderService) | |
class extends BaseRestBuilderSpec { | |
def "Mocked Post InvokeRestBuilderWithUrl"() { | |
given: | |
final String restUrl = "http://api.twitter.com" | |
String capturedUrl = null | |
def requestCustomizer = Mock(RequestCustomizer) | |
MockRestBuilder.metaClass.post = { String url, Closure closure -> | |
capturedUrl = url | |
closure.delegate = requestCustomizer | |
closure.call() | |
return new RestResponse(new ResponseEntity(HttpStatus.OK)) | |
} | |
when: | |
service.invokeRestBuilderPostWithUrl(restUrl) | |
then: | |
capturedUrl == restUrl | |
1 * requestCustomizer.header('Cookie', "TEST=test") | |
1 * requestCustomizer.header('X-DEBUG', 'true') | |
1 * requestCustomizer.contentType("application/json") | |
} | |
def "Mocked Get InvokeRestBuilderWithUrl"() { | |
given: | |
final String restUrl = "http://api.twitter.com" | |
String capturedUrl = null | |
def requestCustomizer = Mock(RequestCustomizer) | |
MockRestBuilder.metaClass.get = { String url, Closure closure -> | |
capturedUrl = url | |
closure.delegate = requestCustomizer | |
closure.call() | |
return new RestResponse(new ResponseEntity(HttpStatus.OK)) | |
} | |
when: | |
service.invokeRestBuilderGetWithUrl(restUrl) | |
then: | |
capturedUrl == restUrl | |
1 * requestCustomizer.header('Cookie', "TEST=test2") | |
1 * requestCustomizer.header('X-DEBUG', 'false') | |
1 * requestCustomizer.contentType("application/json") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment