users@jersey.java.net

Re: [Jersey] 0.6 -> 0.7 problem with jetty

From: Lars Tackmann <lars_at_randompage.org>
Date: Tue, 3 Jun 2008 17:44:17 +0200

On Tue, Jun 3, 2008 at 5:34 PM, Lars Tackmann <lars_at_randompage.org> wrote:
> On Tue, Jun 3, 2008 at 4:46 PM, Jean Aurambault <aurambaj_at_yahoo-inc.com> wrote:
>> Hi,
>>
>> I've the following error when running unit tests (I've just updated to
>> jersey 0.7). I suppose there is a problem with jetty configuration but I
>> don't know where to start... Any idea?
>
> I will look into it tomorrow after work.

Ok I couldn't wait that long. It is definitely a unit test
instrumentation issue and properly related to the way TestNG runs it
tests. If I rewrite the above code into the following Junit 3.X test
(I have not yet tried JUnit 4.X) then it actually works:

--
package jetty;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import junit.framework.TestCase;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import com.sun.ws.rest.api.client.Client;
import com.sun.ws.rest.api.client.WebResource;
import com.sun.ws.rest.spi.container.servlet.ServletContainer;
public class JettyTest extends TestCase {
	private static Server server;
	@Path("/")
	public static class TestResource {
		@GET
		public String get() {
			return "GET";
		}
	}
	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",
						"jetty");
		server = new Server(9999);
		Context context = new Context(server, "/", Context.SESSIONS);
		context.addServlet(sh, "/*");
		server.start();
	}
	public void tearDown() throws Exception {
		if (server != null)
			server.stop();
	}
	public void simpleTest() {
		Client c = Client.create();
		WebResource r = c.resource("http://localhost:9999/");
		assert r.get(String.class).equals("GET");
	}
}
--
will try to look into why testng do this.
-- 
Yours sincerely
Lars Tackmann