DATAREST-1401 - RepositoryCollectionResourceMapping now rejects multi-segment path configurations.

Tweaked implementation of lookups to use Lazy to avoid repeated annotation inspections.
This commit is contained in:
Oliver Drotbohm
2019-06-26 16:21:05 +02:00
parent 49ee111504
commit 2d994c7076
2 changed files with 104 additions and 66 deletions

View File

@@ -106,6 +106,25 @@ public class RepositoryCollectionResourceMappingUnitTests {
assertThat(mapping.getPath()).isEqualTo(new Path("/objects"));
}
@Test // DATAREST-1401
public void rejectsPathsWithMultipleSegments() {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(InvalidPath.class);
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> new RepositoryCollectionResourceMapping(metadata, RepositoryDetectionStrategies.DEFAULT)) //
.withMessageContaining("first/second") //
.withMessageContaining(InvalidPath.class.getName()) //
.withMessageContaining("path segment");
}
@Test // DATAREST-1401
public void exposesProjectionTypeIfConfigured() {
assertThat(getResourceMappingFor(WithProjection.class).getExcerptProjection()).isEqualTo(Object.class);
assertThat(getResourceMappingFor(WithoutProjection.class).getExcerptProjection()).isNull();
}
private static CollectionResourceMapping getResourceMappingFor(Class<?> repositoryInterface) {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(repositoryInterface);
@@ -133,4 +152,12 @@ public class RepositoryCollectionResourceMappingUnitTests {
@RepositoryRestResource(collectionResourceRel = "foo", itemResourceRel = "bar")
interface RepositoryAnnotatedRepository extends Repository<Person, Long> {}
@RepositoryRestResource(path = "first/second")
interface InvalidPath extends Repository<Person, Long> {}
@RepositoryRestResource(excerptProjection = Object.class)
interface WithProjection extends Repository<Person, Long> {}
interface WithoutProjection extends Repository<Person, Long> {}
}