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:
@@ -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> {}
|
||||
|
||||
Reference in New Issue
Block a user