users@jersey.java.net

Re: Unit test with maven and Light Weigt HTTP server

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 01 Feb 2008 17:39:30 +0100

Hi Jean,

I recommend when unit testing you:

1) either be explicit about the root resource classes by
    modifying them on an instance of:

    com.sun.ws.rest.api.core.DefaultResourceConfig

2) use the com.sun.ws.rest.api.core.PackagesResourceConfig with
    the packages set to the location of your root resources.

As an example look at the abstract class in the Jersey unit tests for
testing with the Light Weight HTTP server:

   com.sun.ws.rest.impl.container.httpserver.AbstractHttpServerTester [1]

hopefully you should be able to copy and modify that code to suite your
needs. In the past we have had some race condition issues with the LW
HTTP server when starting and stopping very quickly, hence the ability
to sleep. I recommend using the latest 5 or 6 JRE as it seems to improve
things.


If you want to be explicit about the root resource classes you can do this:

   ResourceConfig rc = new DefaultResourceConfig();
   rc.getResourceClasses().add(com.foo.MyRootResource.class);

   HttpHandler handler = ContainerFactory.createContainer(
       HttpHandler.class, rc);

   URI baseUri = ...
   HttpServer server = HttpServerFactory.create(baseUri, handler);
   server.start();

   ... test some stuff

   server.stop();


Alternatively if you want to scan using the PackagesResourceConfig then
the the first two lines of above can be replaced by:

   String[] packageNames = {"com.foo"};
   ResourceConfig rc = new PackagesResourceConfig(packageNames);

Hope this helps,
Paul.


[1]
https://jersey.dev.java.net/source/browse/*checkout*/jersey/trunk/jersey/test/com/sun/ws/rest/impl/container/httpserver/AbstractHttpServerTester.java

Jean Aurambault wrote:
> Hi,
>
> I would to make unit tests using the Light Weight HTTP server. I use
> maven. When I run unit test, there is a problem with the resources scan
> as (I suppose) the classpath is managed with classworlds
>
> INFO: Scanning for root resource classes in the paths:
> /home/aurambaj/Desktop/apache-maven-2.0.8/boot/classworlds-1.1.jar
> Feb 1, 2008 3:06:53 PM
> com.sun.ws.rest.impl.application.WebApplicationImpl processRootResources
> SEVERE: The ResourceConfig instance does not contain any root resource
> classes.
>
> I would like to know if you have some tips to solve/get around this
> problem.
>
> regards,
>
> Jean
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109