users@jersey.java.net

running unit tests using maven and jetty

From: Arul Dhesiaseelan <arul_at_fluxcorp.com>
Date: Tue, 03 Jun 2008 12:01:15 -0600

Hello,

I am working on writing unit tests for some of my resource classes using
embedded Jetty. My project is using maven. I have my unit tests in a
different location than that of the sources. I have set the package of
my resource classes in the servlet init params.

When I run my test, I am getting the following error. Lookslike, its not
able to scan my resources located in the src dir. I am using the latest
Jersey 0.8 snapshots.

SEVERE: Nested in javax.servlet.ServletException:
java.lang.IllegalArgumentException:
com.sun.jersey.config.property.classpath contains no paths:
java.lang.IllegalArgumentException:
com.sun.jersey.config.property.classpath contains no paths
    at
com.sun.jersey.api.core.ClasspathResourceConfig.getPaths(ClasspathResourceConfig.java:170)
    at
com.sun.jersey.api.core.ClasspathResourceConfig.<init>(ClasspathResourceConfig.java:88)
    at
com.sun.jersey.spi.container.servlet.ServletContainer.createResourceConfig(ServletContainer.java:205)
    at
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:133)
    at
org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
    at
org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:342)
    at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
    at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
    at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at
org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
    at
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)

Here is my AbstractTest lookslike:

public class AbstractTest extends TestCase {
  private static Server server;

  public void setUp() throws Exception {
    ServletHolder sh = new ServletHolder(ServletContainer.class);
    
sh.setInitParameter("com.sun.ws.rest.config.property.resourceConfigClass",
"com.sun.ws.rest.api.core.PackagesResourceConfig");
    sh.setInitParameter("com.sun.ws.rest.config.property.packages",
"impl.rest.resources");
    server = new Server(9080);
    Context context = new Context(server, "/", Context.SESSIONS);
    context.addServlet(sh, "/*");
    server.start();
  }

  public void tearDown() throws Exception {
    if (server != null)
      server.stop();
  }
}


My package structure looks like:

webapp
--src
    --main\java\impl\rest\resources
    -- test\java\unittests

Can some one help me understand this error?

Thanks,
Arul