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:
Oliver Gierke
2014-04-29 12:29:48 +02:00
parent 29c16a0e74
commit b43cbb42d8
2 changed files with 10 additions and 1 deletions

View File

@@ -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;

View File

@@ -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> {