Created
September 17, 2014 16:33
-
-
Save ddelponte/80f582979b44687d39da to your computer and use it in GitHub Desktop.
How to test REST UrlMappings
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
import grails.test.mixin.Mock | |
import grails.test.mixin.TestFor | |
import spock.lang.IgnoreRest | |
import spock.lang.Specification | |
import spock.lang.Unroll | |
@Unroll | |
@TestFor(UrlMappings) | |
@Mock([MockYourController]) | |
class UrlMappingsSpec extends Specification { | |
def "Ensure basic mapping operations"() { | |
expect: | |
assertForwardUrlMapping(url, controller: expectCtrl, action: expectAction) { | |
someId = expectId | |
} | |
where: | |
url | expectCtrl | expectAction | expectId | |
'/blah/123/blah/blah' | 'myController' | 'myAction' | '123' | |
} | |
def "Verify REST endpoint for url #url and request method #requestMethod is properly resolved"() { | |
given: | |
webRequest.currentRequest.method = requestMethod | |
expect: | |
assertForwardUrlMapping(url, controller: expectCtrl, action: expectAction) | |
where: | |
url | expectCtrl | expectAction | requestMethod | |
"/something" | "something" | "show" | "GET" | |
"/something/1" | "something" | "show" | "GET" | |
"/something" | "something" | "save" | "POST" | |
"/something" | "something" | "update" | "PUT" | |
"/something" | "something" | "delete" | "DELETE" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment