From c953e6f54d05279d323aac63336ba53bae9df758 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Sat, 28 Dec 2013 15:50:45 +0100 Subject: [PATCH] DATAREST-203 - Fixed accidentally broken RepositorySearchController. Due to the change in the default media type, the RepositorySearchController was totally broken as it used "produces" clauses in the request mapping. I've removed them and added test cases to make sure the search resources are exposed and are accessible. --- .../webmvc/RepositorySearchController.java | 6 ++--- .../webmvc/AbstractWebIntegrationTests.java | 17 ++++++++++++++ .../webmvc/mongodb/ProfileRepository.java | 23 ++++++++++++++++++- .../rest/webmvc/mongodb/UserRepository.java | 2 ++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java index b5ea01140..012f5361e 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySearchController.java @@ -90,8 +90,7 @@ class RepositorySearchController extends AbstractRepositoryRestController { * @return */ @ResponseBody - @RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET, // - produces = { "application/json", "application/x-spring-data-compact+json" }) + @RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET) public Resource listSearches(RepositoryRestRequest request) { SearchResourceMappings resourceMappings = request.getSearchMappings(); @@ -120,8 +119,7 @@ class RepositorySearchController extends AbstractRepositoryRestController { * @throws ResourceNotFoundException */ @ResponseBody - @RequestMapping(value = BASE_MAPPING + "/{search}", method = RequestMethod.GET, // - produces = { "application/json", "application/x-spring-data-verbose+json" }) + @RequestMapping(value = BASE_MAPPING + "/{search}", method = RequestMethod.GET) public ResponseEntity> executeSearch(RepositoryRestRequest request, @PathVariable String search, Pageable pageable) { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractWebIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractWebIntegrationTests.java index cebc410b1..4a0cdcf85 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractWebIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AbstractWebIntegrationTests.java @@ -255,5 +255,22 @@ public abstract class AbstractWebIntegrationTests { andExpect(jsonPath("$._links", notNullValue())); } + /** + * @see DATAREST-203 + */ + @Test + public void exposesSearchesForRootResources() throws Exception { + + MockHttpServletResponse response = request("/"); + + for (String rel : expectedRootLinkRels()) { + + Link link = assertHasLinkWithRel(rel, response); + Link searchLink = assertHasLinkWithRel("search", request(link)); + + request(searchLink); + } + } + protected abstract Iterable expectedRootLinkRels(); } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/ProfileRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/ProfileRepository.java index bd39f3517..c09e5b5f2 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/ProfileRepository.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/ProfileRepository.java @@ -1,8 +1,29 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.rest.webmvc.mongodb; +import java.util.List; + import org.springframework.data.repository.PagingAndSortingRepository; /** * @author Jon Brisbin + * @author Oliver Gierke */ -public interface ProfileRepository extends PagingAndSortingRepository {} +public interface ProfileRepository extends PagingAndSortingRepository { + + List findByType(String type); +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/UserRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/UserRepository.java index b1a5c051d..428729cfa 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/UserRepository.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/UserRepository.java @@ -16,6 +16,7 @@ package org.springframework.data.rest.webmvc.mongodb; import java.math.BigInteger; +import java.util.List; import org.springframework.data.repository.CrudRepository; @@ -24,4 +25,5 @@ import org.springframework.data.repository.CrudRepository; */ public interface UserRepository extends CrudRepository { + List findByFirstname(String firstname); }