DATAREST-825 - Fixed exposure of DELETE HTTP method if findOne(…) is not exposed.

Previously our support for the HTTP DELETE method on item resources was requiring a repository's findOne(…) method to be available and exposed. However, the latter might not be desirable as the support of GET and HEAD requests for item resources depends on that.

We now changed that to only checking that a findOne(…) method is declared on the repository as the implementation of RepositoryEntityController.deleteItemResource(…) requires it to be present to be able to trigger the events that intercept deletes for a particular type.
This commit is contained in:
Oliver Gierke
2016-05-18 13:43:17 +02:00
parent 3306b5ce40
commit f2f9564882
2 changed files with 41 additions and 16 deletions

View File

@@ -121,6 +121,22 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
allOf(hasItem(GET), not(hasItems(DELETE, PATCH, PUT, POST))));
}
/**
* @see DATAREST-825
*/
@Test
public void supportsDeleteIfFindOneIsHidden() {
assertMethodsSupported(getSupportedHttpMethodsFor(HidesFindOne.class), ITEM, true, DELETE, PATCH, PUT, OPTIONS);
}
/**
* @see DATAREST-825
*/
@Test
public void doesNotSupportDeleteIfNoFindOneAvailable() {
assertMethodsSupported(getSupportedHttpMethodsFor(NoFindOne.class), ITEM, false, DELETE);
}
private static SupportedHttpMethods getSupportedHttpMethodsFor(Class<?> repositoryInterface) {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(repositoryInterface);
@@ -148,7 +164,18 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
interface HidesDelete extends CrudRepository<Object, Long> {
@RestResource(exported = false)
void delete(Object id);
void delete(Object entity);
}
interface HidesFindOne extends CrudRepository<Object, Long> {
@Override
@RestResource(exported = false)
Object findOne(Long id);
}
interface NoFindOne extends Repository<Object, Long> {
void delete(Object entity);
}
interface EntityRepository extends CrudRepository<Entity, Long> {}