Permalink
Browse files

basic functional test

  • Loading branch information...
1 parent 12dbe64 commit 25c21501034c58c01fa81a1ad0a02e8891d4a49b robfletcher committed Feb 14, 2013
View
4 grails-app/conf/UrlMappings.groovy
@@ -7,7 +7,7 @@ class UrlMappings {
}
}
- "/"(view:"/index")
- "500"(view:'/error')
+ "404" controller: 'errors', action: 'notFound'
+ "500" controller: 'errors', action: 'serverError'
}
}
View
41 test/apps/shopping-list/grails-app/conf/BuildConfig.groovy
@@ -8,31 +8,38 @@ grails.project.source.level = 1.7
grails.project.dependency.resolution = {
- inherits 'global'
+ inherits 'global'
log 'error'
- checksums true
- legacyResolve false
+ checksums true
+ legacyResolve false
- repositories {
- inherits true
+ repositories {
+ inherits true
- grailsPlugins()
- grailsHome()
- grailsCentral()
+ grailsPlugins()
+ grailsHome()
+ grailsCentral()
- mavenLocal()
- mavenCentral()
- }
+ mavenLocal()
+ mavenCentral()
+ }
- dependencies {
+ dependencies {
compile 'com.google.code.gson:gson:2.2.2'
- }
- plugins {
- runtime ":hibernate:$grailsVersion"
+ test 'org.spockframework:spock-grails-support:0.7-groovy-2.0'
+ test 'org.codehaus.groovy.modules.http-builder:http-builder:0.6'
+ }
- build ":tomcat:$grailsVersion"
- }
+ plugins {
+ runtime ":hibernate:$grailsVersion"
+
+ build ":tomcat:$grailsVersion"
+
+ test(':spock:0.7') {
+ exclude 'spock-grails-support'
+ }
+ }
}
View
23 test/apps/shopping-list/grails-app/controllers/shopping/list/ErrorsController.groovy
@@ -0,0 +1,23 @@
+package shopping.list
+
+import grails.plugin.gson.GSON
+import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND
+
+class ErrorsController {
+
+ def notFound() {
+ def responseBody = [:]
+ responseBody.message = request.exception.message
+ response.status = SC_NOT_FOUND
+ render responseBody as GSON
+ }
+
+ def serverError() {
+ def responseBody = [:]
+ responseBody.message = request.exception.message
+ response.status = SC_INTERNAL_SERVER_ERROR
+ render responseBody as GSON
+ }
+
+}
View
2 test/apps/shopping-list/grails-app/controllers/shopping/list/ItemController.groovy
@@ -6,8 +6,6 @@ import static javax.servlet.http.HttpServletResponse.*
class ItemController {
- static allowedMethods = [save: 'POST', update: 'POST', delete: 'POST']
-
private static final int SC_UNPROCESSABLE_ENTITY = 422
def list(Integer max) {
View
4 test/apps/shopping-list/scripts/_Events.groovy
@@ -0,0 +1,4 @@
+eventAllTestsStart = {
+ def specTestTypeClass = loadSpecTestTypeClass()
+ functionalTests << specTestTypeClass.newInstance('spock', 'functional')
+}
View
23 test/apps/shopping-list/test/functional/shopping/list/RestEndpointSpec.groovy
@@ -0,0 +1,23 @@
+package shopping.list
+
+import groovyx.net.http.*
+import spock.lang.*
+import static javax.servlet.http.HttpServletResponse.SC_OK
+
+class RestEndpointSpec extends Specification {
+
+ static final BASE_URL = 'http://localhost:8080/shopping-list/item'
+
+ @Shared RESTClient http = new RESTClient(BASE_URL)
+
+ void 'returns an empty JSON array when there is no data'() {
+ when:
+ HttpResponseDecorator response = http.get(path: '/')
+
+ then:
+ response.status == SC_OK
+ response.contentType == 'application/json'
+ response.data == []
+ }
+
+}

0 comments on commit 25c2150

Please sign in to comment.