vendredi 30 janvier 2015

Facing Issue with Unit testing in Grails

I need to get messagesource to get access message.properties file in simple groovy class(Exception class) so that i am using Holders.getGrailsApplication(). My problem is Holders.getGrailsApplication() is getting null when i execute unit test case.It works fine if i deploy it in web server. Variable :-



static def grailsApplicationCntx=Holders.getGrailsApplication().getMainContext().getBean(‘messageSource’)


Error:-



`Failure: testActivateService_Case1(com.xyz.ActivationServiceTests)
| java.lang.ExceptionInInitializerError
at java.lang.Class.forName(Class.java:186)
at com.xyz.DatabaseService.addBankUser(DatabaseService.groovy:11)
at com.xyz.RegisterService.register(RegisterService.groovy:39)
at com.xyz.ActivationServiceTests.setUp(ActivationServiceTests.groovy:60)
Caused by: java.lang.NullPointerException: Cannot invoke method getMainContext() on null object
at com.xyz.exception.Exception.(Exception.groovy:55)
… 4 more

Aucun commentaire:

Enregistrer un commentaire