I'm writing a test using JerseyTest v2.5 and the Grizzly container. My Resource depends on a filter that's defined in my web.xml, so the test is failing.
Is there a way to configure a servlet filter when using JerseyTest?
Even better, is there a way to use my web.xml to configure the servlet container?
There an issue about that already opened that you might have seen : https://java.net/jira/browse/JERSEY-2259
Ultimately, it seems like
you can't currently register servlet and filter class concurrently with jersey test framework (setting one will erase the other).
This quote is taken from this reply by Pavel Bucek.
I wonder if you saw it, he seems to have found a workaround, but I'm not sure if that would be applicable for you.
What you can do is deploy your application on (for example) embedded glassfish and run your tests against it using support for external container. Command for executing tests will look like:
jersey version 1.2+:
mvn test
Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory
Djersey.test.port=XXX -Djersey.test.host=XXX
jersey version 1.1.5.1-:
mvn test
Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory
DJERSEY_HTTP_PORT=XXX -DJERSEY_HOST_NAME=XXX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With