users@jersey.java.net

Re: [Jersey] jersey test framework modularity

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Mon, 15 Feb 2010 10:08:37 +0100

Srinivas Naresh Bhimisetty wrote:
> Modularization of the test framework - wow that sounds interesting :).
>
> Here's my opinion -
> As Paul mentioned, we had seen many limitations with Maven - profile
> activation based on multiple conditions, etc.
> Also, the current implementation allows developers to provide their
> own implementations for test container factories. Wouldn't the
> creation of multiple profiles make it complicated to define custom
> test container factories and use them? I'm assuming this has been
> thought about.
Hi Naresh,

yes, I thought about that and it will probably be more complicated :-/.

Users should be able to specify test container factory via system
property -Djersey.test.containerFactory (or whatever) and that would
work when that factory is on classpath. Pretty same for current case,
user will need to add another dependency in pom.xml and specify that
parameter when executing mvn test.

The other thing I thought about is use META.INF/services for container
factory discovery. Then we can omit command line parameter, but we need
to figure out correct rules for that discovery. It could look like:

CHECK "jersey.test.containerFactory" propery
IF set
    try ClassForName(System.getProperty("jersey.test.containerFactory")
    catch ClassNotFound
       ...
    catch ClassCastExp
       ...
ELSE
    try ClassForName(getDefaultTestContainerFactory)
    catch ClassNotFound
       
ServiceFinder.find("com.sun.jersey.test.framework.spi.container.TestContainerFactory")
       IF multiple results
          warning
          pick first?
       ELSE
          try ClassForName(result)
          ...
       ...
    catch ClassCastExp
       ...
  

Something like this would allow to control test container just by adding
dependency, but there are other things to think about - what should be
done when service finder return multiple results - prioritize non-jersey
factories? Or implement something like
TestContainerFactory.getPriority()? ..
   
Pavel


>
> - Naresh
>
> On Fri, Feb 12, 2010 at 9:47 PM, Paul Sandoz <Paul.Sandoz_at_sun.com
> <mailto:Paul.Sandoz_at_sun.com>> wrote:
>
> Hi Pavel,
>
> Perhaps for now with the samples we do not need to define multiple
> profiles and we can stick to explicitly using a single test
> framework module implementation dependency, as appropriate to the
> test implementation. (In any case not all framework
> implementations will work with all test setups.) Currently some
> use the low-level grizzly container, others use the grizzly
> servlet container etc.
>
> Jakub knows a lot more than I on the limitations of profiles in
> maven. IIRC he and Naresh has some similar issues. So i would tend
> to avoid complicating matters and keeping things simple.
>
> Paul.
>
>
> On Feb 12, 2010, at 3:12 PM, Pavel Bucek wrote:
>
> 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
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> <mailto:users-unsubscribe_at_jersey.dev.java.net>
> For additional commands, e-mail:
> users-help_at_jersey.dev.java.net
> <mailto:users-help_at_jersey.dev.java.net>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> <mailto:users-unsubscribe_at_jersey.dev.java.net>
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> <mailto:users-help_at_jersey.dev.java.net>
>
>