Getting grailsApplication as null when running spock test cases using UnitSpec for service class in Grails application.
Error - Cannot get property 'config' on null object
Can anybody tell me how to configure grailsApplication while spock testing service classes.
I have googled a lot, but didn't solve my problem.
Here is the code.
def accountServiceMock = Mock(AccountService)
def accountClientService = new AccountClientService()
def setup(){
accountClientService.accountWS = accountServiceMock
accountClientService.basicAuthInterceptor = authenticatorServiceMock
}
def "test account by status() " (){
setup:
def mockAccountStatus = "ACTIVE"
mockDomain(Account, [accountInstance])
accountClientService.grailsApplication = grailsApplication
when:
accountClientService.getAccountByStatus(mockAccountStatus) //calling web service by fetching url from default.properties file which is context
then:
Account.count() != 0
where:
accountInstance = new Account(10L, "ACTIVE","1234", "firstName", "LastName")
}
In AccountService class getAccountByStatus() method calling webservice with url = grailsApplication.config.ACCOUNTWEBSERVICEURL which is there default.properties file but when i run spock test case it is throwing error like
Cannot get property 'config' on null object