I use Apache Wink 1.2.1. I would like to unit test my REST service, and I'd rather doing it without using a RestClient. I haven't found any example, but after a lot of searching around I guessed that MockServletInvocationTest was the right starting point ... however I have not been able to make it work.
Here is a minimal example that fails for me.
My REST service:
@Path("greetings")
public class GreetingsResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello World!";
}
}
The corresponding unit test:
public class GreetingsResourceTest extends MockServletInvocationTest {
@Override
protected Class<?>[] getClasses() {
return new Class<?>[] { GreetingsResource.class };
}
public void testHello() throws ServletException, IOException {
MockHttpServletRequest request = MockRequestConstructor.
constructMockRequest("GET", "/greetings", MediaType.TEXT_PLAIN);
MockHttpServletResponse response = invoke(request);
assertEquals(200, response.getStatus());
}
}
So, I have a couple of questions:
Am I going in the wrong direction?
If I'm going in the right direction, then what am I doing wrong? When executing the previous test case I get the following error (which I really don't understand):
java.lang.NoSuchMethodError: javax/servlet/http/HttpServletResponse.getContentType()Ljava/lang/String; at org.apache.wink.server.internal.handlers.FlushResultHandler$FlushHeadersOutputStream.flushHeaders(FlushResultHandler.java:350) ~[wink-server-1.2.1-incubating.jar:1.2.1-incubating]