I'm writing a Rest API and my automated tests are calling the class directly without deploying the to the server. As an example, I am testing this method:
@GET
@Path("/{referenceId}")
@Produces("application/json")
public String findByReferenceId(@PathParam("referenceId") String referenceId,
String view) {
My tests are checking that the logic works and they pass. But this code has a bug: I forgot to put a @QueryParam
annotation on that view
parameter. So this code works when tested, but if you try to use this resource on the deployed app, the view
parameter will never be settable.
There are many ways I can solve this, but my current preference is to somehow write an automated check that if a method has a @Path
annotation, then every parameter must have either a @PathParam
, a @QueryParam
or whatever other valid annotation can be there.
I prefer this over a new end-to-end test, because my other tests are already covering 95% of that logic. I just don't know how to automate this check. I'm using Maven and CXF (which means I'm using Spring). I'm hoping there's a plugin that can be configured to do this.
Something I just realized: It's valid to have a single parameter without an annotation. When you do this, jax-rs sets it to the entity you pass in. I'm not sure how to deal with this scenario. I could create my own custom annotation called @Payload
and tell people to use it, but something seems wrong about that.