From 8700c60ceffa35ea2b685fa190b159604b7a7c35 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 16 Jan 2015 12:22:17 +0100 Subject: [PATCH] DATAREST-445 - Fixed domain type lookup in RepositoryCollectionResourceMapping. We now use the domain type provided by RepositoryMetadata instead of manually looking up to be sure to pick up customizations correctly. --- .../RepositoryCollectionResourceMapping.java | 2 +- ...oryCollectionResourceMappingUnitTests.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMapping.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMapping.java index d94442262..c192c130e 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMapping.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMapping.java @@ -74,7 +74,7 @@ class RepositoryCollectionResourceMapping implements CollectionResourceMapping { this.repositoryAnnotation = AnnotationUtils.findAnnotation(repositoryType, RepositoryRestResource.class); this.repositoryIsExportCandidate = Modifier.isPublic(repositoryType.getModifiers()); - Class domainType = RepositoriesUtils.getDomainType(repositoryType); + Class domainType = metadata.getDomainType(); this.domainTypeMapping = EVO_INFLECTOR_IS_PRESENT ? new EvoInflectorTypeBasedCollectionResourceMapping(domainType, relProvider) : new TypeBasedCollectionResourceMapping(domainType, relProvider); diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java index 184896f1c..0f21071aa 100644 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/RepositoryCollectionResourceMappingUnitTests.java @@ -91,6 +91,25 @@ public class RepositoryCollectionResourceMappingUnitTests { assertThat(mapping.getItemResourceRel(), is("bar")); } + /** + * @see DATAREST-445 + */ + @Test + public void usesDomainTypeFromRepositoryMetadata() { + + RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class) { + + @Override + public Class getDomainType() { + return Object.class; + } + }; + + RepositoryCollectionResourceMapping mapping = new RepositoryCollectionResourceMapping(metadata); + + assertThat(mapping.getPath(), is(new Path("/objects"))); + } + private static CollectionResourceMapping getResourceMappingFor(Class repositoryInterface) { RepositoryMetadata metadata = new DefaultRepositoryMetadata(repositoryInterface);