Question

I have written a Jersey service which I have deployed in Jetty server. Here is a sample:

@Path("/simple-on-off")
public class SimpleOnOffService {

    @GET
    @Path("/get-state")
    @Produces(MediaType.TEXT_PLAIN)
    public String getCurrentState(@Context HttpServletRequest request) {        
        return request.getRemoteAddr();
    }
}

If this service is deployed in the Jetty server then I can see my IP address in the browser by following the URL: localhost:8080/rpi/service/simple-on-off/get-state

My question is how can I perform JUnit Test by accessing this service? Any pointer would be very helpful.

Was it helpful?

Solution

You can do that by using some testing frameworks such as: Jersey Test Framework or REST-Assured (https://code.google.com/p/rest-assured). I personally like a lot REST-Assured. See my answer in another question here: Unit testing jersey Restful Services

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top