DATAREST-353 - Fixed potential NullPointerException when trying to delete a non-existing resource.
We now correctly return a 404 Not Found in case we receive a DELETE request for a resource not existing.
This commit is contained in:
@@ -360,6 +360,10 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
RepositoryInvoker invoker = resourceInformation.getInvoker();
|
||||
Object domainObj = invoker.invokeFindOne(id);
|
||||
|
||||
if (domainObj == null) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
publisher.publishEvent(new BeforeDeleteEvent(domainObj));
|
||||
invoker.invokeDelete(id);
|
||||
publisher.publishEvent(new AfterDeleteEvent(domainObj));
|
||||
|
||||
@@ -545,6 +545,18 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
|
||||
follow(new Link(href)).andExpect(hasLinkWithRel("books"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-353
|
||||
*/
|
||||
@Test
|
||||
public void returns404WhenTryingToDeleteANonExistingResource() throws Exception {
|
||||
|
||||
Link authorsLink = discoverUnique("authors");
|
||||
|
||||
mvc.perform(delete(authorsLink.getHref().concat("/{id}"), 4711)).//
|
||||
andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the {@link Person} resource the given link points to contains siblings with the given names.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user