Introduction

The template project, that you can download from the download page, follows the project structure outlined in the setup section. You will notice it features a build.gradle file for letting you build, test, run and deploy you project. This build file is using the Gradle build system, which is using the Groovy language for its build description DSL. This Gradle build file leverages key plugins that we'll describe below, and offers integration with the Spock testing framework for testing your groovlets.

Note: The template project conveniently provides the Gradle wrapper to run your code without having to install the Gradle runtime. You do not have to provide a Google App Engine SDK in your environment. It will automatically be downloaded by the build script.

Gradle build file

The Gradle build file uses the following Gradle plugins:

You'll find more information on the gae plugin and gaelyk plugin on their respective project pages. The pages describe all available configuration options and tasks in detail.

In a nutshell

You will find the following Gradle tasks handy:

Testing with Spock

You can test your groovlets with the Spock testing framework. As an example, lets imagine we have the following groovlet, in WEB-INF/groovy/dataStoreGroovlet.groovy, which inserts some data in the datastore:

import com.google.appengine.api.datastore.*

def e = new Entity("person")
e.firstname = 'Bart'
e.lastname = 'Simpson'
e.save()

You could test such a Groovlet with the following Spock test, in src/test/groovy/DatastoreServiceSpec.groovy:

import groovyx.gaelyk.spock.*
import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*

class DatastoreServiceSpec extends GaelykUnitSpec {

    def setup() {
        groovlet 'dataStoreGroovlet.groovy'
    }

    def "the datastore is used from within the groovlet"() {
        given: "the initialised groovlet is invoked and data is persisted"
        dataStoreGroovlet.get()

        when: "the datastore is queried for data"
        def query = new Query("person")
        query.addFilter("firstname", Query.FilterOperator.EQUAL, "Marco")
        def preparedQuery = datastore.prepare(query)
        def entities = preparedQuery.asList(withLimit(1))

        then: "the persisted data is found in the datastore"
        def person = entities[0]
        person.firstname == 'Bart'
        person.lastname == 'Simpson'
    }
}

Then, you could run the test by executing the gradle command: gradlew test.

For further information, please have a look at the Spock support for Gaelyk.