DATAREST-298 - Fixed rel lookup in RepositoryMethodResourceMapping.
In case @RestResource was used to customize the path a method resource was mapped to, we didn't correctly fall back to the method name as rel in case no rel was configured explicitly. We now check for a rel being configured and fall back to the method name if we don't discover manual configuration.
This commit is contained in:
@@ -63,7 +63,7 @@ class RepositoryMethodResourceMapping implements MethodResourceMapping {
|
||||
RestResource annotation = AnnotationUtils.findAnnotation(method, RestResource.class);
|
||||
|
||||
this.isExported = annotation != null ? annotation.exported() : true;
|
||||
this.rel = annotation != null ? annotation.rel() : method.getName();
|
||||
this.rel = annotation == null || !StringUtils.hasText(annotation.rel()) ? method.getName() : annotation.rel();
|
||||
this.path = annotation == null || !StringUtils.hasText(annotation.path()) ? new Path(method.getName()) : new Path(
|
||||
annotation.path());
|
||||
this.method = method;
|
||||
|
||||
@@ -95,6 +95,15 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
assertThat(mapping.isPagingResource(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesMethodNameAsRelFallbackEvenIfPathIsConfigured() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
||||
MethodResourceMapping mapping = new RepositoryMethodResourceMapping(method, resourceMapping);
|
||||
|
||||
assertThat(mapping.getRel(), is("findByEmailAddress"));
|
||||
}
|
||||
|
||||
static class Person {}
|
||||
|
||||
interface PersonRepository extends Repository<Person, Long> {
|
||||
|
||||
Reference in New Issue
Block a user