Created
June 2, 2014 01:47
-
-
Save alvarosanchez/007f3fce932a935ffbf4 to your computer and use it in GitHub Desktop.
This file contains 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 com.odobo.gr8conf | |
import spock.lang.Shared | |
import spock.lang.Specification | |
import wslite.rest.ContentType | |
import wslite.rest.RESTClient | |
import wslite.rest.Response | |
class CategorySpec extends Specification { | |
@Shared | |
RESTClient restClient = new RESTClient("http://localhost:8080/restful-gr8conf-2014") | |
def "it returns all the cateogories"() { | |
when: | |
Response response = restClient.get(path: "/categories", accept: ContentType.JSON) | |
then: | |
response.json.size() == 5 | |
} | |
def "it returns just the categories of a game when is a nested resource"() { | |
when: | |
Response response = restClient.get(path: "/games/5/categories", accept: ContentType.JSON) | |
then: | |
response.json.size() == 2 | |
} | |
def "class attribute is not on the JSON response of a category"() { | |
when: | |
Response response = restClient.get(path: "/categories/1", accept: ContentType.JSON) | |
then: | |
!response.json.'class' | |
} | |
def "class attribute is not on the JSON response of a nested category"() { | |
when: | |
Response response = restClient.get(path: "/games/5/categories", accept: ContentType.JSON) | |
then: | |
response.json.every { !it.'class' } | |
} | |
} |
This file contains 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 com.odobo.gr8conf | |
import spock.lang.Shared | |
import spock.lang.Specification | |
import wslite.rest.ContentType | |
import wslite.rest.RESTClient | |
import wslite.rest.RESTClientException | |
import wslite.rest.Response | |
/** | |
* Created by mariscal on 01/06/14. | |
*/ | |
class GameSpec extends Specification { | |
@Shared | |
RESTClient restClient = new RESTClient("http://localhost:8080/restful-gr8conf-2014") | |
def "it returns a list of games in JSON"() { | |
when: | |
Response response = restClient.get(path: "/games", accept: ContentType.JSON) | |
then: | |
response.json | |
response.contentType == 'application/json' | |
} | |
def "it creates games"() { | |
when: | |
Response response = restClient.post(path: "/games") { | |
json name:"New game" | |
} | |
then: | |
response.statusCode == 201 | |
response.headers['Location'] | |
} | |
def "it modifies games"() { | |
when: | |
restClient.put(path: "/games/6") { | |
json name:"New game, modified" | |
} | |
and: | |
Response response = restClient.get(path: "/games/6", accept: ContentType.JSON) | |
then: | |
response.statusCode == 200 | |
response.json.name == "New game, modified" | |
} | |
def "it removes games"() { | |
when: | |
Response response = restClient.delete(path: "/games/6") | |
then: | |
response.statusCode == 204 | |
when: | |
restClient.get(path: "/games/6", accept: ContentType.JSON) | |
then: | |
RESTClientException e = thrown(RESTClientException) | |
e.response.statusCode == 404 | |
} | |
def "class attribute is not on the JSON response of a game"() { | |
when: | |
Response response = restClient.get(path: "/games/1", accept: ContentType.JSON) | |
then: | |
!response.json.'class' | |
response.json.categories.every { !it.'class' } | |
} | |
} |
This file contains 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 com.odobo.gr8conf.Category | |
import com.odobo.gr8conf.Game | |
import grails.rest.render.json.JsonCollectionRenderer | |
import grails.rest.render.json.JsonRenderer | |
// Place your Spring DSL code here | |
beans = { | |
gamesRenderer(JsonCollectionRenderer, Game) { | |
excludes = ['class'] | |
} | |
gameRenderer(JsonRenderer, Game) { | |
excludes = ['class'] | |
} | |
categoriesRenderer(JsonCollectionRenderer, Category) { | |
excludes = ['class'] | |
} | |
categoryRenderer(JsonRenderer, Category) { | |
excludes = ['class'] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment