Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interceptor tests do not correctly register Interceptor in applicationContext #29

Open
sjrd218 opened this issue Mar 12, 2018 · 2 comments

Comments

@sjrd218
Copy link

sjrd218 commented Mar 12, 2018

When writing an Interceptor test, the first test does not actually call the before method in the interceptor at all even if you have a matchAll() in the constructor.

All subsequent tests after the first appear to work fine. It's only the first one that doesn't work. It seems that the bean isn't correctly registered in the application context and the call to: applicationContext.getBeansOfType(Interceptor).values() as Interceptor[] in the mockInterceptor method of InterceptorUnitTest returns an empty list.

I've attached a test project showing the behavior.
InterceptorTestBug.zip

@sbglasius
Copy link
Contributor

I have the same issue. This can also be seen in this test project:

https://github.com/sbglasius/grailsInterceptorBugs

interceptorbug.NotCalledInterceptorSpec

@markoong
Copy link

I am somewhat surprised because this is pretty subtle and still present (Grails 4.0.1) and has taken me one full day of trials to understand why even the most simple test wouldn't call the interceptor before() logic.
A workaround is to "fake" an initial "loading" test which calls the infamous withInterceptors() method to load the needed interceptor(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants