DATAREST-661 - Fixed non-existant resource detection for PATCH requests.

PATCH requests to non existing resource now correctly return 404 Not Found as PersistentEntityResourceHandlerMethodArgumentResolver.read(…) now correctly throws the ResourceNotFoundException.
This commit is contained in:
Oliver Gierke
2015-08-28 10:51:27 +02:00
parent 1c1766ba12
commit a5ed63050f
2 changed files with 26 additions and 1 deletions

View File

@@ -155,7 +155,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolver implements Ha
if (request.isPatchRequest() && converter instanceof MappingJackson2HttpMessageConverter) {
if (objectToUpdate == null) {
new ResourceNotFoundException();
throw new ResourceNotFoundException();
}
ObjectMapper mapper = ((MappingJackson2HttpMessageConverter) converter).getObjectMapper();

View File

@@ -24,6 +24,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import net.minidev.json.JSONArray;
import java.net.URI;
import java.util.List;
import java.util.Map;
@@ -31,6 +32,7 @@ import org.junit.Test;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.ResultActions;
@@ -242,4 +244,27 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
assertThat(links.hasLink("profile"), is(true));
}
}
/**
* @see DATAREST-661
*/
@Test
public void patchToNonExistingResourceReturnsNotFound() throws Exception {
String rel = expectedRootLinkRels().iterator().next();
String uri = client.discoverUnique(rel).expand().getHref().concat("/");
String id = "4711";
Integer status = null;
do {
// Try to find non existing resource
uri = uri.concat(id);
status = mvc.perform(get(URI.create(uri))).andReturn().getResponse().getStatus();
} while (status != HttpStatus.NOT_FOUND.value());
// PATCH to non-existing resource
mvc.perform(patch(URI.create(uri))).andExpect(status().isNotFound());
}
}