Skip to content

Commit

Permalink
tests generated scaffolding test template
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed May 12, 2011
1 parent f4de081 commit 7fc5ec0
Show file tree
Hide file tree
Showing 17 changed files with 827 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/groovy/ScaffoldingSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import spock.lang.*

class ScaffoldingSpec extends BaseSpec {
void "failing before class methods should be handled"() {
when:
execute('scaffolding', 'test-app', ':unit')
then:
exitStatus == 0
output.contains("Running test scaffolding.ItemControllerTests...PASSED")
output.contains("""-------------------------------------------------------
Tests passed: 9
Tests failed: 0
-------------------------------------------------------""")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Grails Metadata file
#Thu May 12 18:14:20 CEST 2011
app.grails.version=1.4.0.BUILD-SNAPSHOT
app.name=scaffolding
app.servlet.version=2.4
app.version=0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
grailsPlugins()
grailsHome()
grailsCentral()

// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//mavenCentral()
//mavenLocal()
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

// runtime 'mysql:mysql-connector-java:5.1.5'
}

plugins {
compile ":hibernate:$grailsVersion"
compile ":jquery:1.6"

build ":tomcat:$grailsVersion"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts

// grails.config.locations = [ "classpath:${appName}-config.properties",
// "classpath:${appName}-config.groovy",
// "file:${userHome}/.grails/${appName}-config.properties",
// "file:${userHome}/.grails/${appName}-config.groovy"]

// if(System.properties["${appName}.config.location"]) {
// grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }

grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
grails.mime.use.accept.header = false
grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
xml: ['text/xml', 'application/xml'],
text: 'text/plain',
js: 'text/javascript',
rss: 'application/rss+xml',
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
all: '*/*',
json: ['application/json','text/json'],
form: 'application/x-www-form-urlencoded',
multipartForm: 'multipart/form-data'
]

// URL Mapping Cache Max Size, defaults to 5000
//grails.urlmapping.cache.maxsize = 1000

// The default codec used to encode data with ${}
grails.views.default.codec = "none" // none, html, base64
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"
// enable Sitemesh preprocessing of GSP pages
grails.views.gsp.sitemesh.preprocess = true
// scaffolding templates configuration
grails.scaffolding.templates.domainSuffix = 'Instance'

// Set to false to use the new Grails 1.2 JSONBuilder in the render method
grails.json.legacy.builder = false
// enabled native2ascii conversion of i18n properties files
grails.enable.native2ascii = true
// whether to install the java.util.logging bridge for sl4j. Disable for AppEngine!
grails.logging.jul.usebridge = true
// packages to include in Spring bean scanning
grails.spring.bean.packages = []

// request parameters to mask when logging exceptions
grails.exceptionresolver.params.exclude = ['password']

// set per-environment serverURL stem for creating absolute links
environments {
production {
grails.serverURL = "http://www.changeme.com"
}
development {
grails.serverURL = "http://localhost:8080/${appName}"
}
test {
grails.serverURL = "http://localhost:8080/${appName}"
}

}

// log4j configuration
log4j = {
// Example of changing the log pattern for the default console
// appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}

error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'

warn 'org.mortbay.log'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:h2:mem:devDb"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class UrlMappings {

static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}

"/"(view:"/index")
"500"(view:'/error')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package scaffolding

import grails.converters.JSON

class ItemController {

static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

def index = {
redirect(action: "list", params: params)
}

def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[itemInstanceList: Item.list(params), itemInstanceTotal: Item.count()]
}

def create = {
def itemInstance = new Item()
itemInstance.properties = params
return [itemInstance: itemInstance]
}

def save = {
def itemInstance = new Item(params)
if (itemInstance.save(flush: true)) {
flash.message = message(code: 'default.created.message', args: [message(code: 'item.label', default: 'Item'), itemInstance.id])
redirect(action: "show", id: itemInstance.id)
}
else {
render(view: "create", model: [itemInstance: itemInstance])
}
}

def show = {
def itemInstance = Item.get(params.id)
if (!itemInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'item.label', default: 'Item'), params.id])
redirect(action: "list")
}
else {
[itemInstance: itemInstance]
}
}

def edit = {
def itemInstance = Item.get(params.id)
if (!itemInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'item.label', default: 'Item'), params.id])
redirect(action: "list")
}
else {
return [itemInstance: itemInstance]
}
}

def update = {
def itemInstance = Item.get(params.id)
if (itemInstance) {
if (params.version) {
def version = params.version.toLong()
if (itemInstance.version > version) {

itemInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'item.label', default: 'Item')] as Object[], "Another user has updated this Item while you were editing")
render(view: "edit", model: [itemInstance: itemInstance])
return
}
}
itemInstance.properties = params
if (!itemInstance.hasErrors() && itemInstance.save(flush: true)) {
flash.message = message(code: 'default.updated.message', args: [message(code: 'item.label', default: 'Item'), itemInstance.id])
redirect(action: "show", id: itemInstance.id)
}
else {
render(view: "edit", model: [itemInstance: itemInstance])
}
}
else {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'item.label', default: 'Item'), params.id])
redirect(action: "list")
}
}

def delete = {
def itemInstance = Item.get(params.id)
if (itemInstance) {
try {
itemInstance.delete(flush: true)
flash.message = message(code: 'default.deleted.message', args: [message(code: 'item.label', default: 'Item'), params.id])
redirect(action: "list")
}
catch (org.springframework.dao.DataIntegrityViolationException e) {
flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'item.label', default: 'Item'), params.id])
redirect(action: "show", id: params.id)
}
}
else {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'item.label', default: 'Item'), params.id])
redirect(action: "list")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scaffolding

class Item {

String title
static constraints = {
title nullable:false, blank:false
}
}
54 changes: 54 additions & 0 deletions src/test/resources/projects/scaffolding/grails-app/views/error.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<html>
<head>
<title>Grails Runtime Exception</title>
<style type="text/css">
.message {
border: 1px solid black;
padding: 5px;
background-color:#E9E9E9;
}
.stack {
border: 1px solid black;
padding: 5px;
overflow:auto;
height: 300px;
}
.snippet {
padding: 5px;
background-color:white;
border:1px solid black;
margin:3px;
font-family:courier;
}
</style>
</head>

<body>
<h1>Grails Runtime Exception</h1>
<h2>Error Details</h2>

<div class="message">
<strong>Error ${request.'javax.servlet.error.status_code'}:</strong> ${request.'javax.servlet.error.message'.encodeAsHTML()}<br/>
<strong>Servlet:</strong> ${request.'javax.servlet.error.servlet_name'}<br/>
<strong>URI:</strong> ${request.'javax.servlet.error.request_uri'}<br/>
<g:if test="${exception}">
<strong>Exception Message:</strong> ${exception.message?.encodeAsHTML()} <br />
<strong>Caused by:</strong> ${exception.cause?.message?.encodeAsHTML()} <br />
<strong>Class:</strong> ${exception.className} <br />
<strong>At Line:</strong> [${exception.lineNumber}] <br />
<strong>Code Snippet:</strong><br />
<div class="snippet">
<g:each var="cs" in="${exception.codeSnippet}">
${cs?.encodeAsHTML()}<br />
</g:each>
</div>
</g:if>
</div>
<g:if test="${exception}">
<h2>Stack Trace</h2>
<div class="stack">
<pre><g:each in="${exception.stackTraceLines}">${it.encodeAsHTML()}<br/></g:each></pre>
</div>
</g:if>
</body>
</html>
Loading

0 comments on commit 7fc5ec0

Please sign in to comment.