I want to test a REST Resource:
@GET
@Path("/{dbName}")
@Produces(MediaType.APPLICATION_JSON)
public String getRequest(@PathParam("dbName") String dbName)
throws JSONException {
}
I want to do this :
assert(someExpectedOutput,getRequest())
Now How the PAth will be set for @Path annotation ??
If you are going to call getRequest directly for testing, as a Java method, go right ahead and pass it a single string:
assertEquals(someExpectedOutput, getRequest("someMockDbName"));
It is after all, just a Java method with one string parameter.
The JAX-RS annotations only kick in when you are running a server, in which case the framework will match the path parameter to your Java parameter dbname. I assume for testing you are just going to use mock objects, so no worries. Pass whatever string you like.
Now if you are going to test within a server (more like an integration test), consider something like Jetty for the webserver and HSQLDB or Derby for a database. That kind of testing is much more involved.
Found Jersey framework for Testing (com.sun.jersey.test.framework) that is useful too. or do it the normal junit way as above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With