if (properties['use.grails.home']) {
ant.property(name:"grails.home", value:properties['env.GRAILS_HOME'])
properties['dont.checkout.grails'] = "true"
} else {
ant.property(name:"grails.home", location:"checkout/grails")
if (properties['force.checkout']) {
ant.delete(dir:properties['grails.home'], failonerror:"false")
}
if (new File(properties['grails.home']).exists()) {
properties['dont.checkout.grails'] = "true"
}
}
Checking out Grails
Updating Grails
GRAILS_HOME=${grails.home}
String scriptName = ant.antProject.properties."test.script.name"
def scriptFiles = new File("scripts").listFiles().findAll { it.name.endsWith('.xml') }
if(scriptName) {
println "Running functional test script: $scriptName"
def file = scriptFiles.find{ it.name.startsWith(scriptName) }
if(file) {
ant.ant(antfile:file, inheritRefs:true)
}
else {
ant.fail("No test script found for name $scriptName")
}
}
else {
println "Running all functional test scripts!"
scriptFiles.each { file ->
ant.ant(antfile:file, inheritRefs:true)
}
}
(\w.*)\/) {
if (it[1] != "..") {
appNames << it[1]
println "Test will include application ${it[1]}"
}
}
def grailsInvocationCounter = 0
appNames.each() {
properties.projectName = it
def appDir = new File("${properties.checkoutDir}/${properties.projectName}")
if (appDir.exists()) {
ant.antcall(target:"-update-app") {
param(name:"projectName", value:properties.projectName)
}
} else {
ant.antcall(target:"-checkout-app") {
param(name:"projectName", value:properties.projectName)
}
}
// Clear any existing webtest and functional test plugins.
ant.echo message: "Delete existing webtest/functional test plugins"
ant.delete(includeemptydirs: true) {
fileset(dir: appDir.path, includes: "**/webtest-*/**/*")
fileset(dir: appDir.path, includes: "**/functional-test-*/**/*")
}
// First upgrade.
ant.grails(command:"upgrade -force", projectName:properties.projectName, resultID:grailsInvocationCounter++)
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
outcomes << "Couldn't upgrade application ${properties.projectName}"
failure = true
}
// Install the appropriate testing plugin, run the tests, and check the reports..
if (new File(appDir, "test/functional").exists()) {
// Install the Functional Test plugin.
ant.grails(command:"install-plugin", args:"functional-test 1.2.2", projectName:properties.projectName, resultID:grailsInvocationCounter++)
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
outcomes << "Couldn't install functional-test plugin into application ${properties.projectName}"
failure = true
}
// Run the tests.
ant.grails(command:"functional-tests", args: "--dev-mode", environment:"dev", projectName:properties.projectName, resultID:grailsInvocationCounter++)
outcomes << "Functional tests in application ${properties.projectName}: " +
((properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) ? "Failed" : "OK")
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
failure = true
}
// Copy reports
ant.mkdir(dir:"reports/${properties.projectName}")
ant.copy(todir:"reports/${properties.projectName}") {
fileset(dir:"${properties.checkoutDir}/${properties.projectName}/test/reports")
}
// Run the WAR tests.
ant.grails(command:"functional-tests", environment:"dev", projectName:properties.projectName, resultID:grailsInvocationCounter++)
outcomes << "Functional tests in application ${properties.projectName}: " +
((properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) ? "Failed" : "OK")
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
failure = true
}
// Copy reports
ant.mkdir(dir:"reports/${properties.projectName}_war")
ant.copy(todir:"reports/${properties.projectName}_war") {
fileset(dir:"${properties.checkoutDir}/${properties.projectName}/test/reports")
}
}
else {
// Install the WebTest plugin.
ant.grails(command:"install-plugin", args: "webtest", projectName:properties.projectName, resultID:grailsInvocationCounter++)
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
outcomes << "Couldn't install webtest plugin into application ${properties.projectName}"
failure = true
}
// Run the tests.
ant.grails(command:"run-webtest", environment:"dev", projectName:properties.projectName, resultID:grailsInvocationCounter++)
outcomes << "Functional tests in application ${properties.projectName}: " +
((properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) ? "Failed" : "OK")
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
failure = true
}
// Copy reports
ant.mkdir(dir:"reports/${properties.projectName}")
ant.copy(todir:"reports/${properties.projectName}") {
fileset(dir:"${properties.checkoutDir}/${properties.projectName}/webtest/reports")
}
}
}
println "Grails Functional Test Results"
println "======================================================"
outcomes.each() {
println it
}
if (failure) ant.fail(message:"At least one of the tests failed")
}
catch(Exception e) {
println e.message
e.printStackTrace()
ant.fail(message:"functional tests failed due to error")
}
]]>
Creating new Grails app ${newWebApp} and running some tests on it
Checking out functional test application from :${app.checkout.url}${projectName}
Updating local copy of functional test application from :${app.checkout.url}${projectName}