users@jersey.java.net

Jersey Test Framework update

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Fri, 19 Feb 2010 14:59:24 +0100

Hello,

we did some changes in jersey test framework which may affect you, so if
you are using it, please pay attention.

Test framework is now modularized and you have to specify that
particular module (or modules) on classpath. jersey-test-framework
itself doesn't provide any factories. There are some following rules to
determine which container will be used:

- when jersey.test.containerFactory property is not specified, container
factory from module in dependencies (on classpath) will be used. There
are two scenarios when your project depends on more than one test
framework module:
    - grizzly module is present on classpath: grizzly web container will
be used (because its default test container)
    - grizzly module is not present on classpath: warning will be
produced and first found factory used (which one is specified in warning
message)

- when jersey.test.containerFactory property is specified, and loadable
(its module is on classpath), then corresponding test factory will be used

examples:

1) I have maven based project which depends on:

        <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-inmemory</artifactId>
            <version>1.2-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>

when "mvn clean install" is executed, inmemory test factory will be used
and you don't have to do anything else.

2) I have maven based project which depends on:

        <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-grizzly</artifactId>
            <version>1.2-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-external</artifactId>
            <version>1.2-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>

then I can exec "mvn clean install" and tests will run on grizzly web
container (default containerFactory). Or if I want run my tests on
externalContainer, I can do:

mvn clean install
-Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory
-DJERSEY_HTTP_PORT=8080

and test will be executed against external container running on
http://localhost:8080/...


If you have own containerFactory implementation and you want to create
your module, take a look at
https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-test-framework/jersey-test-framework-external/
(or any other module). Basically you can just package your test factory
into jar and put it on classpath and activate it by specifying
"jersey.test.containerFactory" property. If you want get rid of that
property (and you have only one container module on classpath), you can
create
META-INF/services/com.sun.jersey.test.framework.spi.container.TestContainerFactory
file in your jar and put fully classified java class name of your
factory inside.

Please let me k now if you have some objections/suggestions in this
matter, jersey 1.2 is going to be released sometime in March so there is
time for adjustments.

Regads,
Pavel