DATAREST-111 - Slightly raised precedence of RepositoryRestHandlerMapping.

Set order of RepositoryRestHandlerMapping to LOWEST_PRECEDENCE - 100 to give core Spring Framework components the chance to hook into the right place in the chain.

Refactored RepositoryRestHandlerMapping to really check for the exposed path and added test cases for handler method resolution.
This commit is contained in:
Oliver Gierke
2013-08-21 12:14:40 +02:00
parent 252efc5196
commit 9acad5d55d
5 changed files with 211 additions and 17 deletions

View File

@@ -161,6 +161,25 @@ public class ResourceMappings implements Iterable<ResourceMetadata> {
return metadata.isExported();
}
/**
* Returns whether we export a top-level resource for the given path.
*
* @param path must not be {@literal null} or empty.
* @return
*/
public boolean exportsTopLevelResourceFor(String path) {
Assert.hasText(path);
for (ResourceMetadata metadata : cache.values()) {
if (metadata.getPath().matches(path)) {
return metadata.isExported();
}
}
return false;
}
/**
* Returns whether we have a {@link ResourceMapping} for the given type.
*

View File

@@ -97,4 +97,20 @@ public class ResourceMappingsIntegrationTest {
assertThat(mapping.getPath(), is(new Path("siblings")));
assertThat(mapping.isExported(), is(true));
}
/**
* @see DATAREST-111
*/
@Test
public void exposesResourceByPath() {
assertThat(mappings.exportsTopLevelResourceFor("people"), is(true));
assertThat(mappings.exportsTopLevelResourceFor("orders"), is(true));
ResourceMetadata creditCardMapping = mappings.getMappingFor(CreditCard.class);
assertThat(creditCardMapping, is(notNullValue()));
assertThat(creditCardMapping.getPath(), is(new Path("creditCards")));
assertThat(creditCardMapping.isExported(), is(false));
assertThat(mappings.exportsTopLevelResourceFor("creditCards"), is(false));
}
}