DATAREST-1341 - Further API adaption for Spring HATEOAS 1.0.
This commit is contained in:
@@ -26,6 +26,7 @@ import org.springframework.data.rest.webmvc.BasePathAwareController;
|
||||
import org.springframework.data.rest.webmvc.RepositoryRestController;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -61,7 +62,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-573
|
||||
public void appliesSelectiveDefaultCorsConfiguration() throws Exception {
|
||||
|
||||
Link findItems = client.discoverUnique("items");
|
||||
Link findItems = client.discoverUnique(LinkRelation.of("items"));
|
||||
|
||||
// Preflight request
|
||||
mvc.perform(options(findItems.expand().getHref()).header(HttpHeaders.ORIGIN, "http://far.far.away")
|
||||
@@ -74,7 +75,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-573
|
||||
public void appliesGlobalCorsConfiguration() throws Exception {
|
||||
|
||||
Link findBooks = client.discoverUnique("books");
|
||||
Link findBooks = client.discoverUnique(LinkRelation.of("books"));
|
||||
|
||||
// Preflight request
|
||||
mvc.perform(options(findBooks.expand().getHref()).header(HttpHeaders.ORIGIN, "http://far.far.away")
|
||||
@@ -132,7 +133,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-573
|
||||
public void appliesCorsConfigurationOnRepository() throws Exception {
|
||||
|
||||
Link authorsLink = client.discoverUnique("authors");
|
||||
Link authorsLink = client.discoverUnique(LinkRelation.of("authors"));
|
||||
|
||||
// Preflight request
|
||||
mvc.perform(options(authorsLink.expand().getHref()).header(HttpHeaders.ORIGIN, "http://not.so.far.away")
|
||||
|
||||
@@ -37,7 +37,9 @@ import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||
import org.springframework.data.rest.webmvc.RepositoryRestController;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@@ -83,6 +85,7 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
@Autowired TestDataPopulator loader;
|
||||
@Autowired ApplicationContext context;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
loader.populateRepositories();
|
||||
@@ -92,7 +95,8 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-906
|
||||
public void executesSearchThatTakesAMappedSortProperty() throws Exception {
|
||||
|
||||
Link findBySortedLink = client.discoverUnique("books", "search", "find-spring-books-sorted");
|
||||
Link findBySortedLink = client.discoverUnique(LinkRelation.of("books"), IanaLinkRelations.SEARCH,
|
||||
LinkRelation.of("find-spring-books-sorted"));
|
||||
|
||||
// Assert sort options advertised
|
||||
assertThat(findBySortedLink.isTemplated()).isTrue();
|
||||
|
||||
@@ -28,7 +28,6 @@ import net.minidev.json.JSONArray;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -38,7 +37,9 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.tests.CommonWebTests;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -90,8 +91,8 @@ public class JpaWebTests extends CommonWebTests {
|
||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#expectedRootLinkRels()
|
||||
*/
|
||||
@Override
|
||||
protected Iterable<String> expectedRootLinkRels() {
|
||||
return Arrays.asList("people", "authors", "books");
|
||||
protected Iterable<LinkRelation> expectedRootLinkRels() {
|
||||
return LinkRelation.manyOf("people", "authors", "books");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -99,8 +100,8 @@ public class JpaWebTests extends CommonWebTests {
|
||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#getPayloadToPost()
|
||||
*/
|
||||
@Override
|
||||
protected Map<String, String> getPayloadToPost() throws Exception {
|
||||
return Collections.singletonMap("people", readFileFromClasspath("person.json"));
|
||||
protected Map<LinkRelation, String> getPayloadToPost() throws Exception {
|
||||
return Collections.singletonMap(LinkRelation.of("people"), readFileFromClasspath("person.json"));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -108,11 +109,11 @@ public class JpaWebTests extends CommonWebTests {
|
||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#getRootAndLinkedResources()
|
||||
*/
|
||||
@Override
|
||||
protected MultiValueMap<String, String> getRootAndLinkedResources() {
|
||||
protected MultiValueMap<LinkRelation, String> getRootAndLinkedResources() {
|
||||
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||
map.add("authors", "books");
|
||||
map.add("books", "authors");
|
||||
MultiValueMap<LinkRelation, String> map = new LinkedMultiValueMap<>();
|
||||
map.add(LinkRelation.of("authors"), "books");
|
||||
map.add(LinkRelation.of("books"), "authors");
|
||||
|
||||
return map;
|
||||
}
|
||||
@@ -130,26 +131,26 @@ public class JpaWebTests extends CommonWebTests {
|
||||
|
||||
MockHttpServletResponse response = client.request("/people?page=0&size=1");
|
||||
|
||||
Link nextLink = client.assertHasLinkWithRel(Link.REL_NEXT, response);
|
||||
assertDoesNotHaveLinkWithRel(Link.REL_PREVIOUS, response);
|
||||
Link nextLink = client.assertHasLinkWithRel(IanaLinkRelations.NEXT, response);
|
||||
assertDoesNotHaveLinkWithRel(IanaLinkRelations.PREV, response);
|
||||
|
||||
response = client.request(nextLink);
|
||||
client.assertHasLinkWithRel(Link.REL_PREVIOUS, response);
|
||||
nextLink = client.assertHasLinkWithRel(Link.REL_NEXT, response);
|
||||
client.assertHasLinkWithRel(IanaLinkRelations.PREV, response);
|
||||
nextLink = client.assertHasLinkWithRel(IanaLinkRelations.NEXT, response);
|
||||
|
||||
response = client.request(nextLink);
|
||||
client.assertHasLinkWithRel(Link.REL_PREVIOUS, response);
|
||||
assertDoesNotHaveLinkWithRel(Link.REL_NEXT, response);
|
||||
client.assertHasLinkWithRel(IanaLinkRelations.PREV, response);
|
||||
assertDoesNotHaveLinkWithRel(IanaLinkRelations.NEXT, response);
|
||||
}
|
||||
|
||||
@Test // DATAREST-169
|
||||
public void exposesLinkForRelatedResource() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
Link ordersLink = client.assertHasLinkWithRel("orders", response);
|
||||
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
||||
|
||||
MockHttpServletResponse orders = client.request(ordersLink);
|
||||
Link creatorLink = assertHasContentLinkWithRel("creator", orders);
|
||||
Link creatorLink = assertHasContentLinkWithRel(LinkRelation.of("creator"), orders);
|
||||
|
||||
assertThat(client.request(creatorLink)).isNotNull();
|
||||
}
|
||||
@@ -158,7 +159,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
public void exposesInlinedEntities() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
Link ordersLink = client.assertHasLinkWithRel("orders", response);
|
||||
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
||||
|
||||
MockHttpServletResponse orders = client.request(ordersLink);
|
||||
assertHasJsonPathValue("$..lineItems", orders);
|
||||
@@ -176,7 +177,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-117
|
||||
public void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique("people");
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Person frodo = new Person("Frodo", "Baggins");
|
||||
frodo.setAge(77);
|
||||
@@ -196,12 +197,12 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-95
|
||||
public void createThenPatch() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique("people");
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
MockHttpServletResponse bilbo = postAndGet(peopleLink, "{ \"firstName\" : \"Bilbo\", \"lastName\" : \"Baggins\" }",
|
||||
MediaType.APPLICATION_JSON);
|
||||
|
||||
Link bilboLink = client.assertHasLinkWithRel("self", bilbo);
|
||||
Link bilboLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, bilbo);
|
||||
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName")).isEqualTo("Bilbo");
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName")).isEqualTo("Baggins");
|
||||
@@ -220,13 +221,13 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-150
|
||||
public void createThenPut() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique("people");
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
MockHttpServletResponse bilbo = postAndGet(peopleLink, //
|
||||
"{ \"firstName\" : \"Bilbo\", \"lastName\" : \"Baggins\" }", //
|
||||
MediaType.APPLICATION_JSON);
|
||||
|
||||
Link bilboLink = client.assertHasLinkWithRel("self", bilbo);
|
||||
Link bilboLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, bilbo);
|
||||
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName"), equalTo("Bilbo"));
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName"), equalTo("Baggins"));
|
||||
@@ -343,7 +344,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-50
|
||||
public void propertiesCanHaveNulls() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique("people");
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
Person frodo = new Person();
|
||||
frodo.setFirstName("Frodo");
|
||||
@@ -360,14 +361,14 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-238
|
||||
public void putShouldWorkDespiteExistingLinks() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique("people");
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
Person frodo = new Person("Frodo", "Baggins");
|
||||
String frodoString = mapper.writeValueAsString(frodo);
|
||||
|
||||
MockHttpServletResponse createdPerson = postAndGet(peopleLink, frodoString, MediaType.APPLICATION_JSON);
|
||||
|
||||
Link frodoLink = client.assertHasLinkWithRel("self", createdPerson);
|
||||
Link frodoLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, createdPerson);
|
||||
assertJsonPathEquals("$.firstName", "Frodo", createdPerson);
|
||||
|
||||
String bilboWithFrodosLinks = createdPerson.getContentAsString().replace("Frodo", "Bilbo");
|
||||
@@ -375,14 +376,14 @@ public class JpaWebTests extends CommonWebTests {
|
||||
MockHttpServletResponse overwrittenResponse = putAndGet(frodoLink, bilboWithFrodosLinks,
|
||||
MediaType.APPLICATION_JSON);
|
||||
|
||||
client.assertHasLinkWithRel("self", overwrittenResponse);
|
||||
client.assertHasLinkWithRel(IanaLinkRelations.SELF, overwrittenResponse);
|
||||
assertJsonPathEquals("$.firstName", "Bilbo", overwrittenResponse);
|
||||
}
|
||||
|
||||
@Test // DATAREST-217
|
||||
public void doesNotAllowGetToCollectionResourceIfFindAllIsNotExported() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("addresses");
|
||||
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
||||
|
||||
mvc.perform(get(link.getHref())).//
|
||||
andExpect(status().isMethodNotAllowed());
|
||||
@@ -391,7 +392,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-217
|
||||
public void doesNotAllowPostToCollectionResourceIfSaveIsNotExported() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("addresses");
|
||||
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
||||
|
||||
mvc.perform(post(link.getHref()).content("{}").contentType(MediaType.APPLICATION_JSON)).//
|
||||
andExpect(status().isMethodNotAllowed());
|
||||
@@ -405,10 +406,10 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-221
|
||||
public void returnsProjectionIfRequested() throws Exception {
|
||||
|
||||
Link orders = client.discoverUnique("orders");
|
||||
Link orders = client.discoverUnique(LinkRelation.of("orders"));
|
||||
|
||||
MockHttpServletResponse response = client.request(orders);
|
||||
Link orderLink = assertContentLinkWithRel("self", response, true).expand();
|
||||
Link orderLink = assertContentLinkWithRel(IanaLinkRelations.SELF, response, true).expand();
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(orderLink.getHref());
|
||||
String uri = builder.queryParam("projection", "summary").build().toUriString();
|
||||
@@ -423,18 +424,18 @@ public class JpaWebTests extends CommonWebTests {
|
||||
|
||||
@Test // DATAREST-261
|
||||
public void relProviderDetectsCustomizedMapping() {
|
||||
assertThat(relProvider.getCollectionResourceRelFor(Person.class)).isEqualTo("people");
|
||||
assertThat(relProvider.getCollectionResourceRelFor(Person.class)).isEqualTo(LinkRelation.of("people"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-311
|
||||
public void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique("people");
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
Person daenerys = new Person("Daenerys", "Targaryen");
|
||||
String daenerysString = mapper.writeValueAsString(daenerys);
|
||||
|
||||
MockHttpServletResponse createdPerson = postAndGet(peopleLink, daenerysString, MediaType.APPLICATION_JSON);
|
||||
Link daenerysLink = client.assertHasLinkWithRel("self", createdPerson);
|
||||
Link daenerysLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, createdPerson);
|
||||
assertJsonPathEquals("$.firstName", "Daenerys", createdPerson);
|
||||
|
||||
Link searchLink = client.discoverUnique(peopleLink, "search");
|
||||
@@ -448,7 +449,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
JSONArray personLinks = JsonPath.<JSONArray> read(responseBody, "$.links[?(@.rel=='person')].href");
|
||||
|
||||
assertThat(personLinks).hasSize(1);
|
||||
assertThat(personLinks.get(0)).isEqualTo((Object) daenerysLink.getHref());
|
||||
assertThat(personLinks.get(0)).isEqualTo(daenerysLink.getHref());
|
||||
assertThat(JsonPath.<JSONArray> read(responseBody, "$.content")).hasSize(0);
|
||||
}
|
||||
|
||||
@@ -499,12 +500,12 @@ public class JpaWebTests extends CommonWebTests {
|
||||
client.follow(findBySortedLink.expand("title,desc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
|
||||
client.follow(findBySortedLink.expand("title,asc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
@@ -519,7 +520,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
String stringReceipt = mapper.writeValueAsString(receipt);
|
||||
|
||||
MockHttpServletResponse createdReceipt = postAndGet(receiptLink, stringReceipt, MediaType.APPLICATION_JSON);
|
||||
Link tacosLink = client.assertHasLinkWithRel("self", createdReceipt);
|
||||
Link tacosLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, createdReceipt);
|
||||
assertJsonPathEquals("$.saleItem", "Springy Tacos", createdReceipt);
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(tacosLink.getHref());
|
||||
@@ -569,15 +570,15 @@ public class JpaWebTests extends CommonWebTests {
|
||||
@Test // DATAREST-658
|
||||
public void returnsLinkHeadersForHeadRequestToItemResource() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request(client.discoverUnique("people"));
|
||||
MockHttpServletResponse response = client.request(client.discoverUnique(LinkRelation.of("people")));
|
||||
String personHref = JsonPath.read(response.getContentAsString(), "$._embedded.people[0]._links.self.href");
|
||||
|
||||
response = mvc.perform(head(personHref))//
|
||||
.andExpect(status().isNoContent())//
|
||||
.andReturn().getResponse();
|
||||
|
||||
Links links = Links.valueOf(response.getHeader("Link"));
|
||||
assertThat(links.hasLink("self")).isTrue();
|
||||
Links links = Links.parse(response.getHeader("Link"));
|
||||
assertThat(links.hasLink(IanaLinkRelations.SELF)).isTrue();
|
||||
assertThat(links.hasLink("person")).isTrue();
|
||||
}
|
||||
|
||||
@@ -594,12 +595,12 @@ public class JpaWebTests extends CommonWebTests {
|
||||
client.follow(findBySortedLink.expand("sales,desc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
|
||||
client.follow(findBySortedLink.expand("sales,asc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
}
|
||||
|
||||
@Test // DATAREST-883
|
||||
@@ -614,12 +615,12 @@ public class JpaWebTests extends CommonWebTests {
|
||||
client.follow(findByLink.expand("0", "10", "sales,desc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
|
||||
client.follow(findByLink.expand("0", "10", "unknown,asc,sales,asc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
@@ -644,17 +645,17 @@ public class JpaWebTests extends CommonWebTests {
|
||||
client.follow(findBySortedLink.expand("offer.price,desc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
|
||||
client.follow(findBySortedLink.expand("offer.price,asc")).//
|
||||
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).//
|
||||
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).//
|
||||
andExpect(client.hasLinkWithRel("self"));
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF));
|
||||
}
|
||||
|
||||
private List<Link> preparePersonResources(Person primary, Person... persons) throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique("people");
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
|
||||
MockHttpServletResponse primaryResponse = postAndGet(peopleLink, mapper.writeValueAsString(primary),
|
||||
@@ -666,7 +667,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
String payload = mapper.writeValueAsString(person);
|
||||
MockHttpServletResponse response = postAndGet(peopleLink, payload, MediaType.APPLICATION_JSON);
|
||||
|
||||
links.add(client.assertHasLinkWithRel(Link.REL_SELF, response));
|
||||
links.add(client.assertHasLinkWithRel(IanaLinkRelations.SELF, response));
|
||||
}
|
||||
|
||||
return links;
|
||||
@@ -690,7 +691,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
|
||||
private void assertPersonWithNameAndSiblingLink(String name) throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request(client.discoverUnique("people"));
|
||||
MockHttpServletResponse response = client.request(client.discoverUnique(LinkRelation.of("people")));
|
||||
|
||||
String jsonPath = String.format("$._embedded.people[?(@.firstName == '%s')]", name);
|
||||
|
||||
|
||||
@@ -108,5 +108,4 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
||||
client.follow(profileLink, RestMediaTypes.SCHEMA_JSON).andExpect(status().is2xxSuccessful())
|
||||
.andExpect(content().contentTypeCompatibleWith(RestMediaTypes.SCHEMA_JSON));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,21 +38,11 @@ import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.rest.webmvc.jpa.CreditCard;
|
||||
import org.springframework.data.rest.webmvc.jpa.Dinner;
|
||||
import org.springframework.data.rest.webmvc.jpa.Guest;
|
||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
import org.springframework.data.rest.webmvc.jpa.LineItem;
|
||||
import org.springframework.data.rest.webmvc.jpa.Order;
|
||||
import org.springframework.data.rest.webmvc.jpa.OrderRepository;
|
||||
import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
|
||||
import org.springframework.data.rest.webmvc.jpa.PersonSummary;
|
||||
import org.springframework.data.rest.webmvc.jpa.Suite;
|
||||
import org.springframework.data.rest.webmvc.jpa.UserExcerpt;
|
||||
import org.springframework.data.rest.webmvc.jpa.*;
|
||||
import org.springframework.data.rest.webmvc.util.TestUtils;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.PagedResources.PageMetadata;
|
||||
import org.springframework.hateoas.Resource;
|
||||
@@ -105,7 +95,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
}
|
||||
|
||||
LinkDiscoverer linkDiscoverer;
|
||||
LinkDiscoverer discoverer;
|
||||
ProjectionFactory projectionFactory;
|
||||
|
||||
@Before
|
||||
@@ -113,7 +103,7 @@ public class PersistentEntitySerializationTests {
|
||||
|
||||
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
|
||||
|
||||
this.linkDiscoverer = new HalLinkDiscoverer();
|
||||
this.discoverer = new HalLinkDiscoverer();
|
||||
this.projectionFactory = new SpelAwareProxyProjectionFactory();
|
||||
}
|
||||
|
||||
@@ -156,11 +146,15 @@ public class PersistentEntitySerializationTests {
|
||||
|
||||
String s = writer.toString();
|
||||
|
||||
Link fatherLink = linkDiscoverer.findLinkWithRel("father", s);
|
||||
assertThat(fatherLink.getHref(), endsWith(new UriTemplate("/{id}/father").expand(person.getId()).toString()));
|
||||
assertThat(discoverer.findLinkWithRel("father", s)) //
|
||||
.map(Link::getHref) //
|
||||
.hasValueSatisfying(
|
||||
it -> assertThat(it).endsWith(new UriTemplate("/{id}/father").expand(person.getId()).toString()));
|
||||
|
||||
Link siblingLink = linkDiscoverer.findLinkWithRel("siblings", s);
|
||||
assertThat(siblingLink.getHref(), endsWith(new UriTemplate("/{id}/siblings").expand(person.getId()).toString()));
|
||||
assertThat(discoverer.findLinkWithRel("siblings", s)) //
|
||||
.map(Link::getHref) //
|
||||
.hasValueSatisfying(
|
||||
it -> assertThat(it).endsWith(new UriTemplate("/{id}/siblings").expand(person.getId()).toString()));
|
||||
}
|
||||
|
||||
@Test // DATAREST-248
|
||||
@@ -229,7 +223,7 @@ public class PersistentEntitySerializationTests {
|
||||
oliver.setFather(dave);
|
||||
|
||||
UserExcerpt daveExcerpt = projectionFactory.createProjection(UserExcerpt.class, dave);
|
||||
EmbeddedWrapper wrapper = new EmbeddedWrappers(false).wrap(daveExcerpt, "father");
|
||||
EmbeddedWrapper wrapper = new EmbeddedWrappers(false).wrap(daveExcerpt, LinkRelation.of("father"));
|
||||
|
||||
PersistentEntityResource resource = PersistentEntityResource.//
|
||||
build(oliver, repositories.getPersistentEntity(Person.class)).//
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
import org.springframework.data.rest.webmvc.jpa.Order;
|
||||
import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
@@ -53,7 +54,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
Link link = entityLinks.linkToSingleResource(Person.class, 1);
|
||||
|
||||
assertThat(link.getHref(), endsWith("/people/1{?projection}"));
|
||||
assertThat(link.getRel()).isEqualTo("person");
|
||||
assertThat(link.getRel()).isEqualTo(LinkRelation.of("person"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,7 +64,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
assertThat(link.getVariableNames()).contains("page", "size", "sort");
|
||||
assertThat(link.getRel()).isEqualTo("people");
|
||||
assertThat(link.getRel()).isEqualTo(LinkRelation.of("people"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
@@ -107,7 +108,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
@Test // DATAREST-467
|
||||
public void returnsLinkToSearchResource() {
|
||||
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, "firstname");
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"));
|
||||
|
||||
assertThat(link).isNotNull();
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
@@ -117,7 +118,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
@Test // DATAREST-467, DATAREST-519
|
||||
public void prepopulatesPaginationInformationForSearchResourceLink() {
|
||||
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, "firstname", PageRequest.of(0, 10));
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"), PageRequest.of(0, 10));
|
||||
|
||||
assertThat(link).isNotNull();
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
@@ -131,7 +132,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
@Test // DATAREST-467
|
||||
public void returnsTemplatedLinkForSortedSearchResource() {
|
||||
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, "lastname");
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"));
|
||||
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
assertThat(link.getVariableNames()).contains("lastname", "sort");
|
||||
@@ -140,7 +141,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
@Test // DATAREST-467, DATAREST-519
|
||||
public void prepopulatesSortInformationForSearchResourceLink() {
|
||||
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, "lastname", Sort.by("firstname"));
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"), Sort.by("firstname"));
|
||||
|
||||
assertThat(link).isNotNull();
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
|
||||
Reference in New Issue
Block a user