DATAREST-311 - Fixed execution of query methods for compact media type.

Fixed the request parameter binding of RepositorySearchController. executeSearchCompact(…). Changed returned value to Resources to be able to use the EMPTY_RESOURCES_LIST constant to indicate no actual results.

Original pull request: #139.
This commit is contained in:
Rodrigue Bouleau
2014-05-30 12:20:21 +02:00
committed by Oliver Gierke
parent ee9a023b88
commit 9e2d8f674e
3 changed files with 37 additions and 2 deletions

View File

@@ -148,7 +148,7 @@ class RepositorySearchController extends AbstractRepositoryRestController {
* @return
*/
@ResponseBody
@RequestMapping(value = BASE_MAPPING + "/{method}", method = RequestMethod.GET, //
@RequestMapping(value = BASE_MAPPING + "/{search}", method = RequestMethod.GET, //
produces = { "application/x-spring-data-compact+json" })
public ResourceSupport executeSearchCompact(RootResourceInformation resourceInformation, WebRequest request,
@PathVariable String repository, @PathVariable String search, Pageable pageable) {
@@ -173,7 +173,7 @@ class RepositorySearchController extends AbstractRepositoryRestController {
links.add(resourceLink(resourceInformation, res));
}
return new Resource<Object>(EMPTY_RESOURCE_LIST, links);
return new Resources<Resource<?>>(EMPTY_RESOURCE_LIST, links);
}
/**

View File

@@ -94,6 +94,10 @@ public abstract class AbstractWebIntegrationTests {
return request(link.expand().getHref());
}
protected MockHttpServletResponse request(Link link, MediaType mediaType) throws Exception {
return request(link.expand().getHref(), mediaType);
}
protected MockHttpServletResponse request(String href) throws Exception {
return request(href, DEFAULT_MEDIA_TYPE);
}

View File

@@ -27,6 +27,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.minidev.json.JSONArray;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -467,6 +469,35 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
assertThat(relProvider.getCollectionResourceRelFor(Person.class), is("people"));
}
/**
* @see DATAREST-311
*/
@Test
public void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception {
Link peopleLink = discoverUnique("people");
Person daenerys = new Person("Daenerys", "Targaryen");
String daenerysString = mapper.writeValueAsString(daenerys);
MockHttpServletResponse createdPerson = postAndGet(peopleLink, daenerysString, MediaType.APPLICATION_JSON);
Link daenerysLink = assertHasLinkWithRel("self", createdPerson);
assertJsonPathEquals("$.firstName", "Daenerys", createdPerson);
Link searchLink = discoverUnique(peopleLink, "search");
Link byFirstNameLink = discoverUnique(searchLink, "findFirstPersonByFirstName");
MockHttpServletResponse response = request(byFirstNameLink.expand("Daenerys"),
MediaType.parseMediaType("application/x-spring-data-compact+json"));
String responseBody = response.getContentAsString();
JSONArray personLinks = JsonPath.<JSONArray> read(responseBody, "$.links[?(@.rel=='person')].href");
assertThat(personLinks, hasSize(1));
assertThat(personLinks.get(0), is((Object) daenerysLink.getHref()));
assertThat(JsonPath.<JSONArray> read(responseBody, "$.content"), hasSize(0));
}
/**
* Asserts the {@link Person} resource the given link points to contains siblings with the given names.
*