Is there a way to test a controller which uses a filter on an integration test?
There seems to be a way using the @Mock annotation for Unit Tests and than wrapping the controller call on a withFilter closure.
But I can't get to test filters on an integration test which from my pov should be very straight forward.
Update
So here is the solution I found. Instead of using the @Mock annotation, I instantiated the FiltersUnitTestMixin class and populated it with the necessary values.
public class ControllerTest {
def controller = new Controller()
FiltersUnitTestMixin f = new FiltersUnitTestMixin()
@Before
public void setup() {
f.grailsApplication = grailsApplication
f.applicationContext = grailsApplication.mainContext
f.mockFilters(ControllerFilters)
}
@Test
public void shouldPassTheTest() {
f.withFilters(action:"actionName") {
controller.actionName()
}
}
}