In grails 1.3.7, I access some external properties via the ConfigurationHolder in my controller. Googling around suggests I can use the following in the setup of my unit test:
mockConfig '''
sys.admin.username = "username"
sys.admin.password = "password"
'''
when my unit tests run ConfigruationHolder.config is null. So more googling lead me to try this in the setup:
def mockedConfig = new ConfigObject()
mockedConfig.sys.admin.username = "username"
mockedConfig.sys.admin.password = "password"
ConfigurationHolder.config = mockedConfig
still getting a null config object in the unit test. I also tried the hiearctical syntax for this first style and it didn’t work either:
mockConfig('''
sys { admin {
username = 'username'
password = 'password'
} }
''')
I am new to grails so I am stumbling my way through this and would like to get my controller unit tested. How do I get around a null config object?
Alas, it was a timing issue. I held a reference to the configurationholder in my controller class:
Moving that inside the method where it was needed worked.