Grails documentation says:
Grails does not invoke hooks or servlet filters when invoking actions during integration testing. You should test interceptors and filters in isolation using functional testing, if necessary.
This also applies to block tests; certain interceptors do not affect the actions of your controller.
Given that you have:
def afterInterceptor = [action: this.&interceptAfter, only: ['actionWithAfterInterceptor','someOther']] private interceptAfter(model) { model.lastName = "Threepwood" }
To check the interceptor, you must:
Make sure interception is applied to the desired actions.
void "After interceptor applied to correct actions"() { expect: 'Interceptor method is the correct one' controller.afterInterceptor.action.method == "interceptAfter" and: 'Interceptor is applied to correct action' that controller.afterInterceptor.only, contains('actionWithAfterInterceptor','someOther') }
Make sure the interceptor method has the desired effect.
void "Verify interceptor functionality"() { when: 'After interceptor is applied to the model' def model = [firstName: "Guybrush"] controller.afterInterceptor.action.doCall(model) then: 'Model is modified as expected' model.firstName == "Guybrush" model.lastName == "Threepwood" }
Or, if you don't have interceptors, check to see if
void "Verify there is no before interceptor"() { expect: 'There is no before interceptor' !controller.hasProperty('beforeInterceptor') }
These examples were intended to be tested after interceptors, but the same applies to interceptors.
source share