I am building a Grails REST application and I have written my Functional Tests using Spock. Note that these functional tests are for REST services only.
class LoginFunctionalSpec extends Specification {
def setUp() {
// here I want to access grailsApplication.config
}
}
I have already tried the following approaches:
- Injecting grailsApplication (by defining as class level variable), but nothing get's injected.
- Using ApplicationHolder.application.config but it has been deprecated and the suggested approach was the previous point.
- Tried using plugin remote-control:1.4 but although grails console showed the plugin as installed I didn't find the class RemoteControl. Also I was never sure of this approach
- I tried reading grails-app/conf/Config.groovy as a file (as explained here) but got a FileNotFoundException.
But none of them provide me grailsApplication.config inside my functional test.
Is there any way to achieve this ?
UPDATE
@dmahapatro
I am not using Geb because I am testing REST services and there is no browser automation required.
As I said in point#1 grails Application is not being auto-injected.
class LoginFunctionalSpec extends Specification {
def grailsApplication
def setUp() {
def port = grailsApplication.config.mongo.port //throws NPE
}
}
It throws a NPE saying that config property is being invoked on null object.