I have a resource for rest API which uses a service. This service has a constructor with parameters. I want to test this resource and to mock this service. This Question: How to pass parameters to REST resource using Jersey 2.5
wasn't helpful because they used @Inject and I cannot use it. Any suggestions?
The second question is how do I pass parameter to test this resouce: My code is:
@Path("/2/{subversion: [0-3]}/users")
public class UserResource {
Logger log = Logger.getLogger(UserResource.class);
private MyService service;
public void setService(Service ser) {
this.service = ser;
}
@Context HttpServletRequest currentRequest;
@GET
@Produces("application/json")
public Response getUsers(@Context HttpHeaders httpHeaders, @Context UriInfo
uriInfo) {
// my function
}
}
How can I pass "httpHeaders" and "UriInfo". My test looks like this:
Response response = target("/2/0/users/").request().get();
Users users = response.readEntity(Users.class);
assertNotNull(users);