0

When using Spring's HATEOAS support, I really like the AnnotationMappingDiscoverer which helps avoid hard-coding REST resource paths in tests. With it, I can do things like

discoverer = new AnnotationMappingDiscoverer(RequestMapping.class);
Method method = MyController.class.getMethod("myResourceMethod", params);
String path = discoverer.getMapping(method);

And then use that path as the resource path in tests. Much better than hard-coding paths in tests that have to be kept in sync with the controller class and method annotations.

Is there anything similar for RESTEasy?

E-Riz
  • 31,431
  • 9
  • 97
  • 134

1 Answers1

2

You can use the UriBuilder:

Assuming following class:

@Path("persons")
public class PersonResource {

    @Path("/{id}")
    public Response get(@PathParam("id") String id) {
      //
    }

}

You would get the path like this:

URI path = UriBuilder.fromResource(PersonResource.class)
                     .path(PersonResource.class, "get")
                     .build("4711");
// path = /persons/4711
lefloh
  • 10,653
  • 3
  • 28
  • 50