Testing filters grails-2.0 using withFilters, How do i inject services that filters use?

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

Testing filters grails-2.0 using withFilters, How do i inject services that filters use?

netbrain
As the subject states. how can i inject services that filters use or mock them?

-Kim
Reply | Threaded
Open this post in threaded view
|

Re: Testing filters grails-2.0 using withFilters, How do i inject services that filters use?

Stephen Smithstone-2

i have a service

class SimpleService

 def aMethod(){}




in my filter class i had the following


applicationContext.getBean(SImpleService).aMethod()

then in my filter test class i had

class MockedOutSimpleService extends SimpleService {
   
    def aMethod(){}

}


in side my test method i have

defineBeans {

    simpleService(MockedOutSimpleService)
}

the the 

withFilters(action:"" , controller:""){

 controller.doAction()
}

hope that helps I've put up an example code at

github.com/ssmithstone/grails-filter-example




On Jan 21, 2012, at 01:19 PM, Kim Eik <[hidden email]> wrote:

As the subject states. how can i inject services that filters use or mock them?

-Kim