users@jersey.java.net

jersey test framework modularity

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Fri, 12 Feb 2010 15:12:09 +0100

Hello,

I was able to modularize jersey-test-framework (jersey-test-framework
depends only on jersey-client, jersey-server and javax.servlet),
introduced several new modules (one for each container).

The problem I'm having now is correctly define dependencies in samples
or to be more precise - how to define dependency on default or specified
test container. I wanted to do this centrally - somehow in
jersey-test-framework pom or anywhere else BUT it doesn't seem possible.
Maven has limited profile inheritance and it looks like its not really
stable (discovered various bug reports).

Currently I have to define everything in every samples pom file. Not
really convenient but probably the safest way.

I'm playing with helloworld sample in
jersey-test-framework-modularization branch and current state is:

when you execute *mvn clean install*, project will be tested using
grizzly web container. If you want to use different one, you need to run
*mvn clean install
-Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory*
(or different factory). No further action needed, profile should be
selected according to this single property.

dependencies:

   <dependencies>
       <dependency>
           <groupId>com.sun.jersey</groupId>
           <artifactId>jersey-server</artifactId>
           <version>${project.version}</version>
       </dependency> <dependency>
           <groupId>com.sun.jersey</groupId>
           <artifactId>jersey-test-framework</artifactId>
           <version>${project.version}</version>
           <scope>test</scope>
       </dependency>
       <dependency>
           <groupId>com.sun.grizzly</groupId>
           <artifactId>grizzly-servlet-webserver</artifactId>
           <version>1.9.8</version>
       </dependency>
   </dependencies>

profiles (not complete yet):

       <profile>
           <id>JDK 1.5</id>
           <activation>
               <jdk>1.5</jdk>
           </activation>
           <dependencies>
               <dependency>
                   <groupId>com.sun.jersey</groupId>
                   <artifactId>jersey-test-framework-grizzly</artifactId>
                   <version>${project.version}</version>
               </dependency>
               <dependency> <!-- enabling WADL support -->
                   <groupId>com.sun.xml.bind</groupId>
                   <artifactId>jaxb-impl</artifactId>
                   <version>2.1</version>
               </dependency>
           </dependencies>
       </profile>


       <profile>
           <id>Grizzly Default</id>
           <activation>
               <property>
                  <name>!jersey.test.containerFactory</name>
               </property>
           </activation>
           <dependencies>
               <dependency>
                   <groupId>com.sun.jersey</groupId>
                   <artifactId>jersey-test-framework-grizzly</artifactId>
                   <version>${project.version}</version>
               </dependency>
               <dependency> <!-- enabling WADL support -->
                   <groupId>com.sun.xml.bind</groupId>
                   <artifactId>jaxb-impl</artifactId>
                   <version>2.1</version>
               </dependency>
           </dependencies>
       </profile>

       <profile>
           <id>Grizzly</id>
           <activation>
               <property>
                  <name>jersey.test.containerFactory</name>
                  
<value>com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory</value>

               </property>
           </activation>
           <dependencies>
               <dependency>
                   <groupId>com.sun.jersey</groupId>
                   <artifactId>jersey-test-framework-grizzly</artifactId>
                   <version>${project.version}</version>
               </dependency>
           </dependencies>
       </profile>

       <profile>
           <id>Grizzly Light</id>
           <activation>
               <property>
                  <name>jersey.test.containerFactory</name>
                  
<value>com.sun.jersey.test.framework.spi.container.grizzly.GrizzlyTestContainerFactory</value>

               </property>
           </activation>
           <dependencies>
               <dependency>
                   <groupId>com.sun.jersey</groupId>
                   <artifactId>jersey-test-framework-grizzly</artifactId>
                   <version>${project.version}</version>
               </dependency>
           </dependencies>
       </profile>

       <profile>
           <id>InMemory</id>
           <activation>
               <property>
                  <name>jersey.test.containerFactory</name>
                  
<value>com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory</value>

               </property>
           </activation>
           <dependencies>
               <dependency>
                   <groupId>com.sun.jersey</groupId>
                   <artifactId>jersey-test-framework-inmemory</artifactId>
                   <version>${project.version}</version>
               </dependency>
           </dependencies>
       </profile>

      ... (others)


I would like to have feedback from you so if you see some possible issue
or if you have any suggestions, please let me know.

Thanks,
Pavel