register
other register

Thursday, September 15, 2011

Mock grailsApplication and config in Unit Test

grailsApplication can be injected in controller before 2.0.0, and it is still the case for 2.0.0

Before grails 2.0.0, you can only access your config in the service by calling ConfigurationHolder.config. But now with Grails 2.0.0, grailsApplication can be injected in service.

In unit test, we should do the following, so that the grailsApplication and config is mocked properly.

service.grailsApplication = [config.config]

controller.grailsApplication = [config: config]

Monday, September 12, 2011

Specify your own environment in Grails

environments {
  foo {
    settings = 'bar'
  }
}

To specify your environment:

grails -Dgrails.env=foo