diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java index 7224f63d2..4f919cda9 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java @@ -100,11 +100,13 @@ class AbstractRepositoryRestController { if (source instanceof Iterable) { return toResources((Iterable) source, assembler, baseLink); - } else if (source == null || ClassUtils.isPrimitiveOrWrapper(source.getClass())) { + } else if (source == null) { + throw new ResourceNotFoundException(); + } else if (ClassUtils.isPrimitiveOrWrapper(source.getClass())) { return source; - } else { - return assembler.toFullResource(source); } + + return assembler.toFullResource(source); } protected Resources> entitiesToResources(Page page, diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java index 2e5b32017..a10414860 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/MongoWebTests.java @@ -315,4 +315,16 @@ public class MongoWebTests extends CommonWebTests { mvc.perform(get(link.expand(profile.getId()).getHref())).// andExpect(status().isOk()); } + + /** + * @see DATAREST-517 + */ + @Test + public void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception { + + Link link = client.discoverUnique("profiles", "search", "findById"); + + mvc.perform(get(link.expand("").getHref())).// + andExpect(status().isNotFound()); + } }