After much trial and error while trying to test one of my JAX-RS resource using the JerseyTest framework (to be precise, I am extending JerseyTestNg.ContainerPerClassTest), I narrowed down my problem to the @Inject annotation. That is, whenever my resource contains at least 1 such field annotated with @Inject, any call to that resource inside the test framework fails with HTTP-500, even though that field is never used. Running the same resource in Glassfish certainly works as expected.
What would be the recommended way of testing such resources? Using jersey 2.9 (as shipped with Glassfish)
I also tried creating a ServletDeploymentContext, but in that, however, I received countless warnings from HK2, that injection points can not be satisfied.
Jersey 2.13 was a tad better. It did not crash with HTTP-500, but printed more meaningful exceptions (HK2 complaining about no object being available for injection) even without using ServletDeploymentContext. However, my test could not be run. Not sure how to tell HK2 that I either: don’t need those fields, or where to find the for injection?
Regards,
Matyas