Upgrade the Grails sample to Grails 3.2.6

Closes gh-357
This commit is contained in:
Andy Wilkinson
2017-03-03 16:57:55 +00:00
parent 722048e20f
commit 31ad4b40a0
12 changed files with 48 additions and 192 deletions

View File

@@ -1,36 +1,26 @@
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate:4.3.10.5"
classpath 'org.ajoberstar:gradle-git:1.1.0'
classpath "org.grails.plugins:hibernate5:6.0.7"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.4.RELEASE"
id 'org.asciidoctor.convert' version '1.5.3'
}
version "0.1"
group "com.example"
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "org.grails.grails-web"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
restDocsVersion = "1.2.0.BUILD-SNAPSHOT"
snippetsDir = file('src/docs/generated-snippets')
}
@@ -43,12 +33,12 @@ repositories {
dependencyManagement {
dependencies {
dependency "org.springframework.restdocs:spring-restdocs-core:$restDocsVersion"
dependency "org.springframework.restdocs:spring-restdocs-restassured:$restDocsVersion"
dependency "org.springframework.restdocs:spring-restdocs-asciidoctor:$restDocsVersion"
}
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
mavenBom "org.springframework:spring-framework-bom:4.3.1.RELEASE"
}
applyMavenExclusions false
}
@@ -57,11 +47,13 @@ dependencies {
asciidoctor "org.springframework.restdocs:spring-restdocs-asciidoctor"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-core"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-codecs"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-datasource"
@@ -69,22 +61,25 @@ dependencies {
compile "org.grails:grails-plugin-async"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.2.Final"
compile "org.hibernate:hibernate-ehcache:5.1.2.Final"
compile "org.grails.plugins:views-json"
compile "org.grails.plugins:views-json-templates"
console "org.grails:grails-console"
profile "org.grails.profiles:rest-api"
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testCompile 'org.springframework.restdocs:spring-restdocs-restassured'
testCompile "org.grails:grails-datastore-rest-client"
testCompile "org.springframework.restdocs:spring-restdocs-restassured"
console "org.grails:grails-console"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
ext {

View File

@@ -1,2 +1,2 @@
grailsVersion=3.0.15
gradleWrapperVersion=2.3
grailsVersion=3.2.6
gradleWrapperVersion=3.4

View File

@@ -1,6 +1,6 @@
---
grails:
profile: web-api
profile: rest-api
codegen:
defaultPackage: com.example
info:

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example
import grails.core.GrailsApplication
import grails.util.Environment
class IndexController {
GrailsApplication grailsApplication
def index() {
render(contentType: 'application/json') {
message = "Welcome to Grails!"
environment = Environment.current.name
appversion = grailsApplication.metadata['info.app.version']
grailsversion = grailsApplication.metadata['info.app.grailsVersion']
appprofile = grailsApplication.config.grails?.profile
groovyversion = GroovySystem.getVersion()
jvmversion = System.getProperty('java.version')
controllers = array {
for (c in grailsApplication.controllerClasses) {
controller([name: c.fullName])
}
}
plugins = array {
for (p in grailsApplication.mainContext.pluginManager.allPlugins) {
plugin([name: p.fullName])
}
}
}
}
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example
class InternalServerErrorController {
def index() {
render(contentType: 'application/json') {
error = 500
message = "Internal server error"
}
}
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example
class NotFoundController {
def index() {
render(contentType: 'application/json') {
error = 404
message = "Not Found"
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,12 +14,20 @@
* limitations under the License.
*/
package com.example
class UrlMappings {
static mappings = {
"/"(controller: 'index')
"500"(controller: 'InternalServerError')
"404"(controller: 'NotFound')
delete "/$controller/$id(.$format)?"(action:"delete")
get "/$controller(.$format)?"(action:"index")
get "/$controller/$id(.$format)?"(action:"show")
post "/$controller(.$format)?"(action:"save")
put "/$controller/$id(.$format)?"(action:"update")
patch "/$controller/$id(.$format)?"(action:"patch")
"500"(view: '/error')
"404"(view: '/notFound')
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import com.example.Note
package com.example
class BootStrap {

View File

@@ -0,0 +1,6 @@
response.status 500
json {
message "Internal server error"
error 500
}

View File

@@ -0,0 +1,6 @@
response.status 404
json {
message "Not Found"
error 404
}

View File

@@ -62,30 +62,6 @@ use of HTTP status codes.
= Resources
[[resources-index]]
== Index
The index provides the entry point into the service.
[[resources-index-access]]
=== Accessing the index
A `GET` request is used to access the index
==== Example request
include::{snippets}/index-example/curl-request.adoc[]
==== Response structure
include::{snippets}/index-example/response-fields.adoc[]
==== Example response
include::{snippets}/index-example/http-response.adoc[]
[[resources-notes]]
== Notes

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,34 +59,6 @@ class ApiDocumentationSpec extends Specification {
.build()
}
void 'test and document get request for /index'() {
expect:
given(this.documentationSpec)
.accept(MediaType.APPLICATION_JSON.toString())
.filter(document('index-example',
preprocessRequest(modifyUris()
.host('api.example.com')
.removePort()),
preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath('message').description('Welcome to Grails!'),
fieldWithPath('environment').description("The running environment"),
fieldWithPath('appversion').description('version of the app that is running'),
fieldWithPath('grailsversion').description('the version of grails used in this project'),
fieldWithPath('appprofile').description('the profile of grails used in this project'),
fieldWithPath('groovyversion').description('the version of groovy used in this project'),
fieldWithPath('jvmversion').description('the version of the jvm used in this project'),
subsectionWithPath('controllers').type(JsonFieldType.ARRAY).description('the list of available controllers'),
subsectionWithPath('plugins').type(JsonFieldType.ARRAY).description('the plugins active for this project'),
)))
.when()
.port(this.serverPort)
.get('/')
.then()
.assertThat()
.statusCode(is(200))
}
void 'test and document notes list request'() {
expect:
given(this.documentationSpec)
@@ -97,7 +69,6 @@ class ApiDocumentationSpec extends Specification {
.removePort()),
preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath('[].class').description('the class of the resource'),
fieldWithPath('[].id').description('the id of the note'),
fieldWithPath('[].title').description('the title of the note'),
fieldWithPath('[].body').description('the body of the note'),
@@ -127,7 +98,6 @@ class ApiDocumentationSpec extends Specification {
subsectionWithPath('tags').type(JsonFieldType.ARRAY).description('a list of tags associated to the note')
),
responseFields(
fieldWithPath('class').description('the class of the resource'),
fieldWithPath('id').description('the id of the note'),
fieldWithPath('title').description('the title of the note'),
fieldWithPath('body').description('the body of the note'),
@@ -152,7 +122,6 @@ class ApiDocumentationSpec extends Specification {
.removePort()),
preprocessResponse(prettyPrint()),
responseFields(
fieldWithPath('class').description('the class of the resource'),
fieldWithPath('id').description('the id of the note'),
fieldWithPath('title').description('the title of the note'),
fieldWithPath('body').description('the body of the note'),