domainClass property won't available in Unit

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

domainClass property won't available in Unit

deadman
Hi,

I am trying access messageSource in src/groovy file as Burt suggested in one of his post . It works fine. However, the unit test case is failing with |  groovy.lang.MissingPropertyException: No such property: domainClass for class: 

Code: 
new mydomain().domainClass.grailsApplication.mainContext.messageSource.getMessage()



Any suggestions please.
Reply | Threaded
Open this post in threaded view
|

Re: domainClass property won't available in Unit

sergiomichels
In Grails 2.x you can use Holders (http://grails.org/doc/2.0.1/api/grails/util/Holders.html) to access grailsApplication. 

Holders.grailsApplication.mainContext

--
Sérgio Michels


On Fri, Aug 9, 2013 at 11:49 AM, Sridhar Thumma <[hidden email]> wrote:
Hi,

I am trying access messageSource in src/groovy file as Burt suggested in one of his post . It works fine. However, the unit test case is failing with |  groovy.lang.MissingPropertyException: No such property: domainClass for class: 

Code: 
new mydomain().domainClass.grailsApplication.mainContext.messageSource.getMessage()



Any suggestions please.

Reply | Threaded
Open this post in threaded view
|

Re: domainClass property won't available in Unit

deadman
Hi,

Thanks for the reply. I used Holders.getGrailsApplication() to get the mainContext. However, I am still stuck with it. I tried with two things. 

1. Holders.getGrailsApplication().mainContext.messageSource.getMessage()
2. Holders.getGrailsApplication().mainContext.getMessage() as you explained here 

However, I am getting same error for both of these.. No bean named 'messageSource' is defined.  




On Fri, Aug 9, 2013 at 9:38 PM, Sergio Michels <[hidden email]> wrote:
In Grails 2.x you can use Holders (http://grails.org/doc/2.0.1/api/grails/util/Holders.html) to access grailsApplication. 

Holders.grailsApplication.mainContext

--
Sérgio Michels


On Fri, Aug 9, 2013 at 11:49 AM, Sridhar Thumma <[hidden email]> wrote:
Hi,

I am trying access messageSource in src/groovy file as Burt suggested in one of his post . It works fine. However, the unit test case is failing with |  groovy.lang.MissingPropertyException: No such property: domainClass for class: 

Code: 
new mydomain().domainClass.grailsApplication.mainContext.messageSource.getMessage()



Any suggestions please.


Reply | Threaded
Open this post in threaded view
|

Re: domainClass property won't available in Unit

sergiomichels
Try to assign the mocked bean before calling it:

grailsApplication.mainContext.registerMockBean("messageSource", messageSource)  //messageSource is available as a static attribute in unit tests.

--
Sérgio Michels


On Mon, Aug 12, 2013 at 4:21 AM, Sridhar Thumma <[hidden email]> wrote:
Hi,

Thanks for the reply. I used Holders.getGrailsApplication() to get the mainContext. However, I am still stuck with it. I tried with two things. 

1. Holders.getGrailsApplication().mainContext.messageSource.getMessage()
2. Holders.getGrailsApplication().mainContext.getMessage() as you explained here 

However, I am getting same error for both of these.. No bean named 'messageSource' is defined.  




On Fri, Aug 9, 2013 at 9:38 PM, Sergio Michels <[hidden email]> wrote:
In Grails 2.x you can use Holders (http://grails.org/doc/2.0.1/api/grails/util/Holders.html) to access grailsApplication. 

Holders.grailsApplication.mainContext

--
Sérgio Michels


On Fri, Aug 9, 2013 at 11:49 AM, Sridhar Thumma <[hidden email]> wrote:
Hi,

I am trying access messageSource in src/groovy file as Burt suggested in one of his post . It works fine. However, the unit test case is failing with |  groovy.lang.MissingPropertyException: No such property: domainClass for class: 

Code: 
new mydomain().domainClass.grailsApplication.mainContext.messageSource.getMessage()



Any suggestions please.