(Quick Reference)

6 Using the Test Compatibility Kit

Version: 2023.3.0

6 Using the Test Compatibility Kit

The grace-datastore-gorm-tck project provides several hundred tests to guarantee that a particular GORM implementation is compliant. To use the TCK you need to define a dependency on the TCK in the subprojects build.gradle file:

testCompile project(':grace-datastore-gorm-tck')

Then create a Setup.groovy file that sets up your custom datastore in your implementation.

For example the ConcurrentHashMap implementation has one defined in grace-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/Setup.groovy:

class Setup {

    static destroy() {
        // noop
    }
    static Session setup(classes) {

        def ctx = new GenericApplicationContext()
        ctx.refresh()
        def simple = new SimpleMapDatastore(ctx)

        ...
        for (cls in classes) {
            simple.mappingContext.addPersistentEntity(cls)
        }

        ...
        def enhancer = new GormEnhancer(simple, new DatastoreTransactionManager(datastore: simple))
        enhancer.enhance()

        simple.mappingContext.addMappingContextListener({ e -> enhancer.enhance e } as MappingContext.Listener)

        simple.applicationContext.addApplicationListener new DomainEventListener(simple)
        simple.applicationContext.addApplicationListener new AutoTimestampEventListener(simple)

        return simple.connect()
    }
}

Some setup code has been omitted for clarity, but essentially, the Setup.groovy class should initialize the Datastore and return a Session from the static setup method, which is passed a list of classes to configure.

With this setup, all the TCK tests will be run against the subproject. If a specific test cannot be implemented due to the underlying datastore lacking support for a particular feature, you can create a test with the same name as the failing test, and that will then override the corresponding test in the TCK.

For example: SimpleDB doesn’t support pagination. Add a grails.gorm.tests.PagedResultSpec class that overrides the one from the TCK. Each test is a Spock specification and Spock has an Ignore annotation that can be used to ignore a particular test:

/**
 * Ignored for SimpleDB because SimpleDB doesn't support pagination
 */
@Ignore
class PagedResultSpec extends GormDatastoreSpec{
   ...
}