Reputation: 160
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 ??
Upvotes: 3
Views: 534
Reputation: 160
Found Jersey framework for Testing (com.sun.jersey.test.framework) that is useful too. or do it the normal junit way as above.
Upvotes: 1
Reputation: 88378
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.
Upvotes: 2