users@jersey.java.net

[Jersey] Using servlet filters in Jersey Test framework 2.17

From: naresh <baliga_naresh_at_yahoo.com>
Date: Tue, 7 Apr 2015 12:56:42 -0700 (MST)

Hi,

I'm upgrading from Jersey 1.5 to 2.17 and need this feature to port my unit
test cases.

I have Jersey deployed as a Servlet, but have a couple of Http Servlet
Filters that do some work for me.

I suppose one could say that the Filters should be able to tested
independent of Jersey, but since this was doable in Jersey 1.5 test
framework, I'm trying to use JerseyTest and Grizzly test container in 2.17
as well to achieve this.

The issue https://java.net/jira/browse/JERSEY-2259 is resolved, however I
cannot figure out a way to configure a javax.servlet.Filter into JerseyTest.

This is my test set up:
@Override
   protected DeploymentContext configureDeployment ()
   {
      final ResourceConfig resourceConfig = new ResourceConfig();

      resourceConfig.register( RequestContextFilter.class );

      resourceConfig.register( JacksonFeature.class );

      resourceConfig.register( DeclarativeLinkingFeature.class );

      resourceConfig.register( LoggingFilter.class );

      resourceConfig.property( "contextConfig", new
ClassPathXmlApplicationContext( "test-applicationContext.xml" ) );
      resourceConfig.packages( "com.myapp.rest" );

      return DeploymentContext.builder( resourceConfig ).contextPath(
"/myApp" ).build();
   }


and these are my dependencies:
   testCompile group: 'org.glassfish.jersey.test-framework.providers', name:
'jersey-test-framework-provider-grizzly2', version: jerseyVersion
   testCompile group: 'org.glassfish.jersey.test-framework', name:
'jersey-test-framework-core', version: jerseyVersion


Any help will be appreciated.





--
View this message in context: http://jersey.576304.n2.nabble.com/Using-servlet-filters-in-Jersey-Test-framework-2-17-tp7583241.html
Sent from the Jersey mailing list archive at Nabble.com.