




My adventure of creating an application with the Groovy language and the Grails framework.
{
success:true,
count:1,
data: [
{id:1,task:'Home Page is waiting to be promoted'}
]
}
def tasks = .... // an array of tasks
render(builder:'json') {
success(true)
count(tasks.size())
data {
tasks.each {
data(
id: it.id,
task: it.task
)
}
}
}
def sqlConnection = Sql.newInstance(
'jdbc:mysql://localhost:3306/test3',
'sp', 'sp',
'com.mysql.jdbc.Driver')
class MyIntegrationTestCase extends GroovyTestCase {
def dataSourceConfig
def getDBUnitConnection() {
def sqlConnection = Sql.newInstance(dataSourceConfig.url,
dataSourceConfig.username,
dataSourceConfig.password,
dataSourceConfig.driverClassName)
return new DatabaseConnection(sqlConnection.connection)
}
void setUp() {
dataSourceConfig =
ApplicationHolder.application.config.dataSource
}
}
class FirstJob {
def cronExpression = "0 0 0 ? * *" //midnight, every day
def execute() {
log.info("firstjob executed")
}
}
target(default:"a simple gant script") {
echo( message : "hello world" )
}
Ant.property(environment:"env")
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"
baseDir = Ant.project.properties.basedir
Ant.property ( file : 'application.properties' )
includeTargets << new File ( "${grailsHome}/scripts/War.groovy" )
args = "scott.war"
target(default: "a simple gant script") {
Ant.property ( file : 'application.properties' )
Ant.property ( file : 'environment.properties' )
def appName = Ant.project.properties.'app.name'
def appVersion = Ant.project.properties.'app.version'
def host = Ant.project.properties.'deployhost'
def port = Ant.project.properties.'deployport'
def username = Ant.project.properties.'deployusername'
def password = Ant.project.properties.'deploypassword'
echo ( message : "starting deployment" )
war()
scp(file:args, todir:"${username}@${host}", password:password,port:port)
void setUp() {
}
void testAccessDataObject() {
def service = new SampleService()
def siteMock = new groovy.mock.interceptor.StubFor(Site)
siteMock.demand.get {id ->
return new Site()
}
siteMock.demand.getName {id ->
return 'my sample site'
}
def results
siteMock.use {
results = service.accessDataObject()
assertEquals 'my sample site', results.name
}
}