Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
burtbeckwith committed Nov 11, 2013
1 parent f88973d commit b7474d9
Show file tree
Hide file tree
Showing 19 changed files with 361 additions and 290 deletions.
1 change: 0 additions & 1 deletion build.xml
Expand Up @@ -68,7 +68,6 @@
<delete dir='grails-app/utils'/>
<delete dir='src/groovy'/>
<delete dir='src/java'/>
<delete dir='test/functional'/>
<delete dir='test/integration'/>
<delete dir='web-app/META-INF'/>
<delete dir='web-app/WEB-INF'/>
Expand Down
160 changes: 113 additions & 47 deletions scripts/CreateS2UiTestApps.groovy
@@ -1,4 +1,18 @@
includeTargets << grailsScript('_GrailsBootstrap')
/* Copyright 2006-2013 SpringSource.
*
* 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.
*/
includeTargets << new File(springSecurityCorePluginDir, "scripts/_S2Common.groovy")

functionalTestPluginVersion = '1.2.7'
projectfiles = new File(basedir, 'webtest/projectFiles')
Expand All @@ -7,59 +21,59 @@ dotGrails = null
projectDir = null
appName = null
pluginVersion = null
pluginZip = null
testprojectRoot = null
deleteAll = false
grailsVersion = null

target(createS2UiTestApp: 'Creates test apps for functional tests') {

def configFile = new File(basedir, 'testapps.config.groovy')
if (!configFile.exists()) {
die "$configFile.path not found"
error "$configFile.path not found"
}

new ConfigSlurper().parse(configFile.text).each { name, config ->
printMessage "\nCreating app based on configuration $name: ${config.flatten()}\n"
init name, config
createApp()
installPlugins()
installPlugins(false)
runQuickstart()
copySampleFiles()
copyTests(false)

printMessage "\nCreating extended app based on configuration $name: ${config.flatten()}\n"
init name + '_ext', config
createApp()
installPlugins()
installPlugins(true)
runQuickstart()
copySampleFiles()
copyTests(true)
runCreatePersistentToken()
installAclPlugin()
}
}

private void init(String name, config) {

pluginVersion = config.pluginVersion
if (!pluginVersion) {
die "pluginVersion wasn't specified for config '$name'"
error "pluginVersion wasn't specified for config '$name'"
}

pluginZip = new File(basedir, "grails-spring-security-ui-${pluginVersion}.zip")
def pluginZip = new File(basedir, "grails-spring-security-ui-${pluginVersion}.zip")
if (!pluginZip.exists()) {
die "plugin $pluginZip.absolutePath not found"
error "plugin $pluginZip.absolutePath not found"
}

grailsHome = config.grailsHome
if (!new File(grailsHome).exists()) {
die "Grails home $grailsHome not found"
error "Grails home $grailsHome not found"
}

projectDir = config.projectDir
appName = 'spring-security-ui-test-' + name
testprojectRoot = "$projectDir/$appName"
dotGrails = config.dotGrails
grailsVersion = config.grailsVersion
dotGrails = config.dotGrails + '/' + grailsVersion
}

private void createApp() {
Expand All @@ -69,19 +83,14 @@ private void createApp() {
deleteDir testprojectRoot
deleteDir "$dotGrails/projects/$appName"

callGrails(grailsHome, projectDir, 'dev', 'create-app') {
ant.arg value: appName
}
callGrails grailsHome, projectDir, 'dev', 'create-app', [appName]
}

private void copySampleFiles() {
ant.unzip src: "$projectfiles.path/testDb.zip", dest: "$testprojectRoot/db"
ant.copy file: "$projectfiles.path/DataSource.groovy", todir: "$testprojectRoot/grails-app/conf"
ant.copy file: "$projectfiles.path/index.gsp", todir: "$testprojectRoot/grails-app/views"
ant.copy file: "$projectfiles.path/User.groovy", todir: "$testprojectRoot/grails-app/domain/com/testapp", overwrite: true

ant.mkdir dir: "${testprojectRoot}/src/templates/war"
ant.copy file: "$projectfiles.path/web.xml", todir: "$testprojectRoot/src/templates/war"
ant.copy file: "$projectfiles.path/error.gsp", todir: "$testprojectRoot/grails-app/views", overwrite: true
ant.copy file: "$projectfiles.path/index.gsp", todir: "$testprojectRoot/grails-app/views", overwrite: true

new File("$testprojectRoot/grails-app/conf/Config.groovy").withWriterAppend {
it.writeLine 'grails {'
Expand All @@ -96,26 +105,78 @@ private void copySampleFiles() {
}
}

private void installPlugins() {
private void installPlugins(boolean includeAcl) {

// install plugins in local dir to make optional STS setup easier
ant.copy file: "$projectfiles.path/BuildConfig.groovy", todir: "$testprojectRoot/grails-app/conf"
File buildConfig = new File(testprojectRoot, 'grails-app/conf/BuildConfig.groovy')
String contents = buildConfig.text

ant.mkdir dir: "${testprojectRoot}/plugins"
contents = contents.replace('grails.project.class.dir = "target/classes"', "grails.project.work.dir = 'target'")
contents = contents.replace('grails.project.test.class.dir = "target/test-classes"', '')
contents = contents.replace('grails.project.test.reports.dir = "target/test-reports"', '')

callGrails(grailsHome, testprojectRoot, 'dev', 'install-plugin') {
ant.arg value: "functional-test ${functionalTestPluginVersion}"
}
contents = contents.replace('//mavenLocal()', 'mavenLocal()')
contents = contents.replace('repositories {', '''repositories {
mavenRepo 'http://repo.spring.io/milestone' // TODO remove
''')

callGrails(grailsHome, testprojectRoot, 'dev', 'install-plugin') {
ant.arg value: pluginZip.absolutePath
}
contents = contents.replace('grails.project.fork', 'grails.project.forkDISABLED')

contents = contents.replace('plugins {', """plugins {
runtime ":mail:1.0.1"
runtime ":famfamfam:1.0"
runtime ":jquery:1.10.2"
runtime ":jquery-ui:1.10.3"
test ":functional-test:$functionalTestPluginVersion"
runtime ":spring-security-ui:$pluginVersion"
${includeAcl ? 'runtime ":spring-security-acl:2.0-RC1"' : ''}
""")

contents = contents.replace('dependencies {', """dependencies {
runtime 'com.h2database:h2:1.3.163'
test('dumbster:dumbster:1.6') {
excludes 'mail', 'activation'
}
""")

buildConfig.withWriter { it.writeLine contents }

callGrails grailsHome, testprojectRoot, 'dev', 'compile', null, true // can fail when installing the functional-test plugin
callGrails grailsHome, testprojectRoot, 'dev', 'compile'
}


private void runQuickstart() {
callGrails(grailsHome, testprojectRoot, 'dev', 's2-quickstart') {
['com.testapp', 'User', 'Role', 'Requestmap'].each { ant.arg value: it }
}
callGrails grailsHome, testprojectRoot, 'dev', 's2-quickstart', ['com.testapp', 'User', 'Role', 'Requestmap']

File user = new File(testprojectRoot, 'grails-app/domain/com/testapp/User.groovy')
String contents = user.text
contents = contents.replace('boolean passwordExpired', '''boolean passwordExpired
String email''')
contents = contents.replace('static constraints = {', '''static constraints = {
email blank: false, email: true, unique: true
''')
contents = contents.replace("password column: '`password`'", '')

user.withWriter { it.writeLine contents }

File config = new File(testprojectRoot, 'grails-app/conf/Config.groovy')
contents = config.text

contents += '''
grails.plugin.springsecurity.fii.rejectPublicInvocations = false
grails.plugin.springsecurity.rejectIfNoRule = false
'''

config.withWriter { it.writeLine contents }

File requestmap = new File(testprojectRoot, 'grails-app/domain/com/testapp/Requestmap.groovy')
contents = requestmap.text

contents = contents.replace('HttpMethod httpMethod', '')
contents = contents.replace('httpMethod nullable: true', '')
contents = contents.replace("unique: 'httpMethod'", 'unique: true')

requestmap.withWriter { it.writeLine contents }
}

private void copyTests(boolean extraTests) {
Expand All @@ -139,15 +200,7 @@ private void copyTests(boolean extraTests) {
}

private void runCreatePersistentToken() {
callGrails(grailsHome, testprojectRoot, 'dev', 's2-create-persistent-token') {
ant.arg value: 'com.testapp.PersistentToken'
}
}

private void installAclPlugin() {
callGrails(grailsHome, testprojectRoot, 'dev', 'install-plugin') {
ant.arg value: 'spring-security-acl'
}
callGrails grailsHome, testprojectRoot, 'dev', 's2-create-persistent-token', ['com.testapp.PersistentToken']
}

private void deleteDir(String path) {
Expand All @@ -167,21 +220,34 @@ private void deleteDir(String path) {
ant.delete dir: path
}

private void die(String message) {
private void error(String message) {
errorMessage "\n\nERROR: $message\n\n"
exit 1
}

private void callGrails(String grailsHome, String dir, String env, String action, extraArgs = null) {
ant.exec(executable: "${grailsHome}/bin/grails", dir: dir, failonerror: 'true') {
private void callGrails(String grailsHome, String dir, String env, String action, List extraArgs = null, boolean ignoreFailure = false) {

String resultproperty = 'exitCode' + System.currentTimeMillis()
String outputproperty = 'execOutput' + System.currentTimeMillis()

println "Running 'grails $env $action ${extraArgs?.join(' ') ?: ''}'"

ant.exec(executable: "${grailsHome}/bin/grails", dir: dir, failonerror: false,
resultproperty: resultproperty, outputproperty: outputproperty) {
ant.env key: 'GRAILS_HOME', value: grailsHome
ant.arg value: env
ant.arg value: action
extraArgs?.call()
extraArgs.each { ant.arg value: it }
ant.arg value: '--stacktrace'
}

println ant.project.getProperty(outputproperty)

int exitCode = ant.project.getProperty(resultproperty) as Integer
if (exitCode && !ignoreFailure) {
exit exitCode
}
}

printMessage = { String message -> event('StatusUpdate', [message]) }
errorMessage = { String message -> event('StatusError', [message]) }

setDefaultTarget 'createS2UiTestApp'
36 changes: 36 additions & 0 deletions testapps.config.groovy
@@ -0,0 +1,36 @@
String version = '1.0-RC1'
String grailsHomeRoot = '/usr/local/javalib'
String dotGrailsCommon = '/home/burt/.grails'
String projectDirCommon = '/home/burt/workspace/testapps/spring-security-test'

v20 {
grailsVersion = '2.0.4'
pluginVersion = version
dotGrails = dotGrailsCommon
projectDir = projectDirCommon
grailsHome = grailsHomeRoot + '/grails-' + grailsVersion
}

v21 {
grailsVersion = '2.1.4' // 2.1.5 has a plugin i18n bug
pluginVersion = version
dotGrails = dotGrailsCommon
projectDir = projectDirCommon
grailsHome = grailsHomeRoot + '/grails-' + grailsVersion
}

v22 {
grailsVersion = '2.2.4'
pluginVersion = version
dotGrails = dotGrailsCommon
projectDir = projectDirCommon
grailsHome = grailsHomeRoot + '/grails-' + grailsVersion
}

v23 {
grailsVersion = '2.3.1'
pluginVersion = version
dotGrails = dotGrailsCommon
projectDir = projectDirCommon
grailsHome = grailsHomeRoot + '/grails-' + grailsVersion
}
19 changes: 0 additions & 19 deletions webtest/projectFiles/BuildConfig.groovy

This file was deleted.

6 changes: 4 additions & 2 deletions webtest/projectFiles/DataSource.groovy
Expand Up @@ -3,12 +3,14 @@ dataSource {
username = 'sa'
password = ''
driverClassName = 'org.h2.Driver'
dialect = org.hibernate.dialect.H2Dialect
url = 'jdbc:h2:./db/testDb'
// logSql = true
}

hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.use_query_cache = false
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
format_sql = true
use_sql_comments = true
}
22 changes: 0 additions & 22 deletions webtest/projectFiles/User.groovy

This file was deleted.

11 changes: 11 additions & 0 deletions webtest/projectFiles/error.gsp
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Grails Runtime Exception</title>
<meta name="layout" content="main">
<link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css">
</head>
<body>
<g:renderException exception="${exception}" />
</body>
</html>

0 comments on commit b7474d9

Please sign in to comment.