DATAREST-1341 - Further API adaption for Spring HATEOAS 1.0.
This commit is contained in:
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.tests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -25,6 +24,7 @@ import net.minidev.json.JSONArray;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -39,7 +40,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
@@ -118,10 +118,8 @@ public abstract class AbstractWebIntegrationTests {
|
||||
|
||||
String href = link.isTemplated() ? link.expand().getHref() : link.getHref();
|
||||
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(MockMvcRequestBuilders.request(HttpMethod.PATCH, href).//
|
||||
content(payload.toString()).contentType(mediaType))
|
||||
.andExpect(status().is2xxSuccessful())//
|
||||
MockHttpServletResponse response = mvc.perform(MockMvcRequestBuilders.request(HttpMethod.PATCH, href).//
|
||||
content(payload.toString()).contentType(mediaType)).andExpect(status().is2xxSuccessful())//
|
||||
.andReturn().getResponse();
|
||||
|
||||
return StringUtils.hasText(response.getContentAsString()) ? response : client.request(href);
|
||||
@@ -140,15 +138,16 @@ public abstract class AbstractWebIntegrationTests {
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
protected Link assertHasContentLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
|
||||
return assertContentLinkWithRel(rel, response, true);
|
||||
protected Link assertHasContentLinkWithRel(LinkRelation relation, MockHttpServletResponse response) throws Exception {
|
||||
return assertContentLinkWithRel(relation, response, true);
|
||||
}
|
||||
|
||||
protected void assertDoesNotHaveContentLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
|
||||
protected void assertDoesNotHaveContentLinkWithRel(LinkRelation rel, MockHttpServletResponse response)
|
||||
throws Exception {
|
||||
assertContentLinkWithRel(rel, response, false);
|
||||
}
|
||||
|
||||
protected Link assertContentLinkWithRel(String rel, MockHttpServletResponse response, boolean expected)
|
||||
protected Link assertContentLinkWithRel(LinkRelation rel, MockHttpServletResponse response, boolean expected)
|
||||
throws Exception {
|
||||
|
||||
String content = response.getContentAsString();
|
||||
@@ -170,19 +169,19 @@ public abstract class AbstractWebIntegrationTests {
|
||||
} catch (InvalidPathException o_O) {
|
||||
|
||||
if (expected) {
|
||||
fail("Didn't find any content in the given response!");
|
||||
fail("Didn't find any content in the given response!", o_O);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertDoesNotHaveLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
|
||||
protected void assertDoesNotHaveLinkWithRel(LinkRelation rel, MockHttpServletResponse response) throws Exception {
|
||||
|
||||
String content = response.getContentAsString();
|
||||
Link link = client.getDiscoverer(response).findLinkWithRel(rel, content);
|
||||
Optional<Link> link = client.getDiscoverer(response).findLinkWithRel(rel, content);
|
||||
|
||||
assertThat(link).as("Expected not to find link with rel %s but found %s!", rel, link).isNull();
|
||||
assertThat(link).as("Expected not to find link with rel %s but found %s!", rel, link).isEmpty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -231,28 +230,24 @@ public abstract class AbstractWebIntegrationTests {
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
protected ResultMatcher doesNotHaveLinkWithRel(final String rel) {
|
||||
protected ResultMatcher doesNotHaveLinkWithRel(final LinkRelation relation) {
|
||||
|
||||
return new ResultMatcher() {
|
||||
return result -> {
|
||||
|
||||
@Override
|
||||
public void match(MvcResult result) throws Exception {
|
||||
MockHttpServletResponse response = result.getResponse();
|
||||
String s = response.getContentAsString();
|
||||
|
||||
MockHttpServletResponse response = result.getResponse();
|
||||
String s = response.getContentAsString();
|
||||
|
||||
assertThat(client.getDiscoverer(response).findLinkWithRel(rel, s))//
|
||||
.as("Expected not to find link with rel %s but found one in %s!", rel, s)//
|
||||
.isNull();
|
||||
}
|
||||
assertThat(client.getDiscoverer(response).findLinkWithRel(relation, s))//
|
||||
.as("Expected not to find link with rel %s but found one in %s!", relation, s)//
|
||||
.isEmpty();
|
||||
};
|
||||
}
|
||||
|
||||
protected Map<String, String> getPayloadToPost() throws Exception {
|
||||
protected Map<LinkRelation, String> getPayloadToPost() throws Exception {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
protected MultiValueMap<String, String> getRootAndLinkedResources() {
|
||||
return new LinkedMultiValueMap<String, String>(0);
|
||||
protected MultiValueMap<LinkRelation, String> getRootAndLinkedResources() {
|
||||
return new LinkedMultiValueMap<LinkRelation, String>(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.rest.webmvc.RestMediaTypes;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -37,7 +39,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
@@ -53,7 +54,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
*/
|
||||
public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
protected abstract Iterable<String> expectedRootLinkRels();
|
||||
protected abstract Iterable<LinkRelation> expectedRootLinkRels();
|
||||
|
||||
// Root test cases
|
||||
|
||||
@@ -62,8 +63,8 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
ResultActions actions = mvc.perform(get("/").accept(TestMvcClient.DEFAULT_MEDIA_TYPE)).andExpect(status().isOk());
|
||||
|
||||
for (String rel : expectedRootLinkRels()) {
|
||||
actions.andDo(MockMvcResultHandlers.print()).andExpect(client.hasLinkWithRel(rel));
|
||||
for (LinkRelation rel : expectedRootLinkRels()) {
|
||||
actions.andExpect(client.hasLinkWithRel(rel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,14 +73,14 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
|
||||
for (String rel : expectedRootLinkRels()) {
|
||||
for (LinkRelation rel : expectedRootLinkRels()) {
|
||||
|
||||
Link link = client.assertHasLinkWithRel(rel, response);
|
||||
|
||||
// Resource
|
||||
client.follow(link).andExpect(status().is2xxSuccessful());
|
||||
|
||||
Link profileLink = client.discoverUnique(link, "profile");
|
||||
Link profileLink = client.discoverUnique(link, LinkRelation.of("profile"));
|
||||
|
||||
// Default metadata
|
||||
client.follow(profileLink).andExpect(status().is2xxSuccessful());
|
||||
@@ -113,29 +114,37 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
|
||||
for (String rel : expectedRootLinkRels()) {
|
||||
for (LinkRelation rel : expectedRootLinkRels()) {
|
||||
|
||||
Link link = client.assertHasLinkWithRel(rel, response);
|
||||
String rootResourceRepresentation = client.request(link).getContentAsString();
|
||||
Link searchLink = client.getDiscoverer(response).findLinkWithRel("search", rootResourceRepresentation);
|
||||
|
||||
if (searchLink != null) {
|
||||
client.follow(searchLink).//
|
||||
andExpect(client.hasLinkWithRel("self")).//
|
||||
andExpect(jsonPath("$.domainType").doesNotExist()); // DATAREST-549
|
||||
}
|
||||
client.getDiscoverer(response) //
|
||||
.findLinkWithRel("search", rootResourceRepresentation) //
|
||||
.ifPresent(it -> {
|
||||
|
||||
try {
|
||||
|
||||
client.follow(it).//
|
||||
andExpect(client.hasLinkWithRel(IanaLinkRelations.SELF)).//
|
||||
andExpect(jsonPath("$.domainType").doesNotExist());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nic() throws Exception {
|
||||
|
||||
Map<String, String> payloads = getPayloadToPost();
|
||||
Map<LinkRelation, String> payloads = getPayloadToPost();
|
||||
assumeFalse(payloads.isEmpty());
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
|
||||
for (String rel : expectedRootLinkRels()) {
|
||||
for (LinkRelation rel : expectedRootLinkRels()) {
|
||||
|
||||
String payload = payloads.get(rel);
|
||||
|
||||
@@ -159,7 +168,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
MockHttpServletResponse rootResource = client.request("/");
|
||||
|
||||
for (Map.Entry<String, List<String>> linked : getRootAndLinkedResources().entrySet()) {
|
||||
for (Map.Entry<LinkRelation, List<String>> linked : getRootAndLinkedResources().entrySet()) {
|
||||
|
||||
Link resourceLink = client.assertHasLinkWithRel(linked.getKey(), rootResource);
|
||||
MockHttpServletResponse resource = client.request(resourceLink);
|
||||
@@ -186,7 +195,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json");
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
Link profileLink = client.assertHasLinkWithRel("profile", response);
|
||||
Link profileLink = client.assertHasLinkWithRel(LinkRelation.of("profile"), response);
|
||||
|
||||
mvc.perform(//
|
||||
get(profileLink.expand().getHref()).//
|
||||
@@ -206,7 +215,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-658
|
||||
public void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Exception {
|
||||
|
||||
for (String rel : expectedRootLinkRels()) {
|
||||
for (LinkRelation rel : expectedRootLinkRels()) {
|
||||
|
||||
Link link = client.discoverUnique(rel);
|
||||
|
||||
@@ -214,9 +223,9 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
.andExpect(status().isNoContent())//
|
||||
.andReturn().getResponse();
|
||||
|
||||
Links links = Links.valueOf(response.getHeader("Link"));
|
||||
Links links = Links.parse(response.getHeader("Link"));
|
||||
|
||||
assertThat(links.hasLink(Link.REL_SELF)).isTrue();
|
||||
assertThat(links.hasLink(IanaLinkRelations.SELF)).isTrue();
|
||||
assertThat(links.hasLink("profile")).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -224,7 +233,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-661
|
||||
public void patchToNonExistingResourceReturnsNotFound() throws Exception {
|
||||
|
||||
String rel = expectedRootLinkRels().iterator().next();
|
||||
LinkRelation rel = expectedRootLinkRels().iterator().next();
|
||||
String uri = client.discoverUnique(rel).expand().getHref().concat("/");
|
||||
String id = "4711";
|
||||
Integer status = null;
|
||||
@@ -244,7 +253,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
@Test // DATAREST-1003
|
||||
public void rejectsUnsupportedAcceptTypeForResources() throws Exception {
|
||||
|
||||
for (String string : expectedRootLinkRels()) {
|
||||
for (LinkRelation string : expectedRootLinkRels()) {
|
||||
|
||||
Link link = client.discoverUnique(string);
|
||||
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.rest.tests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
@@ -58,7 +59,7 @@ public class ResourceTester {
|
||||
* @param number
|
||||
*/
|
||||
public void assertNumberOfLinks(int number) {
|
||||
assertThat(resource.getLinks().size(), is(number));
|
||||
assertThat(resource.getLinks()).hasSize(number);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,18 +15,21 @@
|
||||
*/
|
||||
package org.springframework.data.rest.tests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -34,7 +37,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -208,10 +210,14 @@ public class TestMvcClient {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<Link> discover(String rel) throws Exception {
|
||||
public Links discover(LinkRelation rel) throws Exception {
|
||||
return discover(new Link("/"), rel);
|
||||
}
|
||||
|
||||
public Link discoverUnique(String rel) throws Exception {
|
||||
return discoverUnique(LinkRelation.of(rel));
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover single URI associated with a rel, starting at the root node ("/")
|
||||
*
|
||||
@@ -219,11 +225,15 @@ public class TestMvcClient {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Link discoverUnique(String rel) throws Exception {
|
||||
public Link discoverUnique(LinkRelation rel) throws Exception {
|
||||
|
||||
List<Link> discover = discover(rel);
|
||||
assertThat(discover, hasSize(1));
|
||||
return discover.get(0);
|
||||
Links discover = discover(rel);
|
||||
assertThat(discover).hasSize(1);
|
||||
return discover.toList().get(0);
|
||||
}
|
||||
|
||||
public Link discoverUnique(String... rels) throws Exception {
|
||||
return discoverUnique(Arrays.stream(rels).map(LinkRelation::of).toArray(LinkRelation[]::new));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,15 +243,18 @@ public class TestMvcClient {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Link discoverUnique(String... rels) throws Exception {
|
||||
public Link discoverUnique(LinkRelation... rels) throws Exception {
|
||||
|
||||
Iterator<String> toTraverse = Arrays.asList(rels).iterator();
|
||||
Iterator<LinkRelation> toTraverse = Arrays.asList(rels).iterator();
|
||||
Link lastLink = null;
|
||||
|
||||
while (toTraverse.hasNext()) {
|
||||
|
||||
String rel = toTraverse.next();
|
||||
lastLink = lastLink == null ? discoverUnique(rel) : discoverUnique(lastLink, rel);
|
||||
LinkRelation relation = toTraverse.next();
|
||||
|
||||
lastLink = lastLink == null //
|
||||
? discoverUnique(relation) //
|
||||
: discoverUnique(lastLink, relation);
|
||||
}
|
||||
|
||||
return lastLink;
|
||||
@@ -251,31 +264,39 @@ public class TestMvcClient {
|
||||
* Given a URI (root), discover the URIs for a given rel.
|
||||
*
|
||||
* @param root - URI to start from
|
||||
* @param rel - name of the relationship to seek links
|
||||
* @param relation - name of the relationship to seek links
|
||||
* @return list of {@link org.springframework.hateoas.Link Link} objects associated with the rel
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<Link> discover(Link root, String rel) throws Exception {
|
||||
public Links discover(Link root, LinkRelation relation) throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc.perform(get(root.expand().getHref()).accept(DEFAULT_MEDIA_TYPE)).//
|
||||
andExpect(status().isOk()).//
|
||||
andExpect(hasLinkWithRel(rel)).//
|
||||
andExpect(hasLinkWithRel(relation)).//
|
||||
andReturn().getResponse();
|
||||
|
||||
String s = response.getContentAsString();
|
||||
return getDiscoverer(response).findLinksWithRel(rel, s);
|
||||
String content = response.getContentAsString();
|
||||
return getDiscoverer(response).findLinksWithRel(relation, content);
|
||||
}
|
||||
|
||||
public Link discoverUnique(Link root, String relation) throws Exception {
|
||||
return discoverUnique(root, LinkRelation.of(relation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a URI (root), discover the unique URI for a given rel. NOTE: Assumes there is only one URI
|
||||
*
|
||||
* @param root
|
||||
* @param rel
|
||||
* @param relation
|
||||
* @return {@link org.springframework.hateoas.Link Link} tied to a given rel
|
||||
* @throws Exception
|
||||
*/
|
||||
public Link discoverUnique(Link root, String rel) throws Exception {
|
||||
return discoverUnique(root, rel, DEFAULT_MEDIA_TYPE);
|
||||
public Link discoverUnique(Link root, LinkRelation relation) throws Exception {
|
||||
return discoverUnique(root, relation, DEFAULT_MEDIA_TYPE);
|
||||
}
|
||||
|
||||
public Link discoverUnique(Link root, String rel, MediaType mediaType) throws Exception {
|
||||
return discoverUnique(root, LinkRelation.of(rel), mediaType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,35 +308,39 @@ public class TestMvcClient {
|
||||
* @return {@link org.springframework.hateoas.Link Link} tied to a given rel
|
||||
* @throws Exception
|
||||
*/
|
||||
public Link discoverUnique(Link root, String rel, MediaType mediaType) throws Exception {
|
||||
public Link discoverUnique(Link root, LinkRelation rel, MediaType mediaType) throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc
|
||||
.perform(get(root.expand().getHref())//
|
||||
.accept(mediaType))
|
||||
.andExpect(status().isOk())//
|
||||
MockHttpServletResponse response = mvc.perform(get(root.expand().getHref())//
|
||||
.accept(mediaType)).andExpect(status().isOk())//
|
||||
.andExpect(hasLinkWithRel(rel))//
|
||||
.andReturn().getResponse();
|
||||
|
||||
return assertHasLinkWithRel(rel, response);
|
||||
}
|
||||
|
||||
public Link assertHasLinkWithRel(String relation, MockHttpServletResponse response) throws Exception {
|
||||
return assertHasLinkWithRel(LinkRelation.of(relation), response);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given servlet response, verify that the provided rel exists in its hypermedia. If so, return the URI link.
|
||||
*
|
||||
* @param rel
|
||||
* @param relation
|
||||
* @param response
|
||||
* @return {@link org.springframework.hateoas.Link} of the rel found in the response
|
||||
* @throws Exception
|
||||
*/
|
||||
public Link assertHasLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
|
||||
public Link assertHasLinkWithRel(LinkRelation relation, MockHttpServletResponse response) throws Exception {
|
||||
|
||||
String content = response.getContentAsString();
|
||||
Link link = getDiscoverer(response).findLinkWithRel(rel, content);
|
||||
Optional<Link> link = getDiscoverer(response).findLinkWithRel(relation, content);
|
||||
|
||||
assertThat("Expected to find link with rel " + rel + " but found none in " + content + "!", link,
|
||||
is(notNullValue()));
|
||||
return link.orElseThrow(() -> new IllegalStateException(
|
||||
"Expected to find link with rel " + relation + " but found none in " + content + "!"));
|
||||
}
|
||||
|
||||
return link;
|
||||
public ResultMatcher hasLinkWithRel(String rel) {
|
||||
return hasLinkWithRel(LinkRelation.of(rel));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,19 +349,15 @@ public class TestMvcClient {
|
||||
* @param rel
|
||||
* @return
|
||||
*/
|
||||
public ResultMatcher hasLinkWithRel(final String rel) {
|
||||
public ResultMatcher hasLinkWithRel(LinkRelation rel) {
|
||||
|
||||
return new ResultMatcher() {
|
||||
return result -> {
|
||||
|
||||
@Override
|
||||
public void match(MvcResult result) throws Exception {
|
||||
MockHttpServletResponse response = result.getResponse();
|
||||
String s = response.getContentAsString();
|
||||
|
||||
MockHttpServletResponse response = result.getResponse();
|
||||
String s = response.getContentAsString();
|
||||
|
||||
assertThat("Expected to find link with rel " + rel + " but found none in " + s, //
|
||||
getDiscoverer(response).findLinkWithRel(rel, s), notNullValue());
|
||||
}
|
||||
assertThat("Expected to find link with rel " + rel + " but found none in " + s, //
|
||||
getDiscoverer(response).findLinkWithRel(rel, s), notNullValue());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -349,11 +370,7 @@ public class TestMvcClient {
|
||||
public LinkDiscoverer getDiscoverer(MockHttpServletResponse response) {
|
||||
|
||||
String contentType = response.getContentType();
|
||||
LinkDiscoverer linkDiscovererFor = discoverers.getLinkDiscovererFor(contentType);
|
||||
|
||||
assertThat("Did not find a LinkDiscoverer for returned media type " + contentType + "!", linkDiscovererFor,
|
||||
is(notNullValue()));
|
||||
|
||||
return linkDiscovererFor;
|
||||
return discoverers.getRequiredLinkDiscovererFor(contentType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ public class GemfireRepositoryConfig {
|
||||
* TODO: Remove, once Spring Data Gemfire exposes a mapping context.
|
||||
*/
|
||||
@Bean
|
||||
@SuppressWarnings("unchecked")
|
||||
public GemfireMappingContext gemfireMappingContext() {
|
||||
|
||||
AnnotatedTypeScanner scanner = new AnnotatedTypeScanner(Region.class);
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.tests.gemfire;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.data.rest.tests.CommonWebTests;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
@@ -31,7 +30,7 @@ public class GemfireWebTests extends CommonWebTests {
|
||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#expectedRootLinkRels()
|
||||
*/
|
||||
@Override
|
||||
protected Iterable<String> expectedRootLinkRels() {
|
||||
return Arrays.asList("products");
|
||||
protected Iterable<LinkRelation> expectedRootLinkRels() {
|
||||
return LinkRelation.manyOf("products");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -33,7 +33,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.tests.CommonWebTests;
|
||||
import org.springframework.data.rest.webmvc.RestMediaTypes;
|
||||
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -106,8 +108,8 @@ public class MongoWebTests extends CommonWebTests {
|
||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#expectedRootLinkRels()
|
||||
*/
|
||||
@Override
|
||||
protected Iterable<String> expectedRootLinkRels() {
|
||||
return Arrays.asList("profiles", "users");
|
||||
protected Iterable<LinkRelation> expectedRootLinkRels() {
|
||||
return LinkRelation.manyOf("profiles", "users");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,7 +124,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
public void rendersEmbeddedDocuments() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel("self", client.request(usersLink));
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
client.follow(userLink).//
|
||||
andExpect(jsonPath("$.address.zipCode").value(is(notNullValue())));
|
||||
}
|
||||
@@ -145,7 +147,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
public void testname() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel("self", client.request(usersLink));
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
|
||||
MockHttpServletResponse response = patchAndGet(userLink,
|
||||
"{\"lastname\" : null, \"address\" : { \"zipCode\" : \"ZIP\"}}",
|
||||
@@ -159,7 +161,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
public void testname2() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel("self", client.request(usersLink));
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
|
||||
MockHttpServletResponse response = patchAndGet(userLink,
|
||||
"[{ \"op\": \"replace\", \"path\": \"/address/zipCode\", \"value\": \"ZIP\" },"
|
||||
@@ -183,7 +185,7 @@ public class MongoWebTests 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());
|
||||
@@ -213,7 +215,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
public void putDoesNotRemoveAssociations() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel("self", client.request(usersLink));
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
Link colleaguesLink = client.assertHasLinkWithRel("colleagues", client.request(userLink));
|
||||
|
||||
// Expect a user returned as colleague
|
||||
@@ -236,7 +238,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
public void emptiesAssociationForEmptyUriList() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel("self", client.request(usersLink));
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
Link colleaguesLink = client.assertHasLinkWithRel("colleagues", client.request(userLink));
|
||||
|
||||
putAndGet(colleaguesLink, "", MediaType.parseMediaType("text/uri-list"));
|
||||
@@ -250,7 +252,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
public void updatesMapPropertyCorrectly() throws Exception {
|
||||
|
||||
Link profilesLink = client.discoverUnique("profiles");
|
||||
Link profileLink = assertHasContentLinkWithRel("self", client.request(profilesLink));
|
||||
Link profileLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(profilesLink));
|
||||
|
||||
Profile profile = new Profile();
|
||||
profile.setMetadata(Collections.singletonMap("Key", "Value"));
|
||||
@@ -272,7 +274,9 @@ public class MongoWebTests extends CommonWebTests {
|
||||
MockHttpServletResponse response = postAndGet(receiptsLink, mapper.writeValueAsString(receipt),
|
||||
MediaType.APPLICATION_JSON);
|
||||
|
||||
Link receiptLink = client.getDiscoverer(response).findLinkWithRel("self", response.getContentAsString());
|
||||
Link receiptLink = client.getDiscoverer(response) //
|
||||
.findLinkWithRel(IanaLinkRelations.SELF, response.getContentAsString()) //
|
||||
.orElseThrow(() -> new IllegalStateException("Did not find self link!"));
|
||||
|
||||
mvc.perform(get(receiptLink.getHref()).header(IF_MODIFIED_SINCE, response.getHeader(LAST_MODIFIED))).//
|
||||
andExpect(status().isNotModified()).//
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.EntityLookup;
|
||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests.TestConfiguration;
|
||||
import org.springframework.data.rest.tests.mongodb.MongoDbRepositoryConfig;
|
||||
@@ -35,6 +34,7 @@ import org.springframework.data.rest.tests.mongodb.User;
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
import org.springframework.data.rest.webmvc.support.Projector;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -58,17 +58,17 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
|
||||
when(projector.projectExcerpt(any())).thenAnswer(new ReturnsArgumentAt(0));
|
||||
|
||||
PersistentEntityResourceAssembler assembler = new PersistentEntityResourceAssembler(entities, projector,
|
||||
associations, new DefaultSelfLinkProvider(entities, entityLinks, Collections.<EntityLookup<?>> emptyList()));
|
||||
associations, new DefaultSelfLinkProvider(entities, entityLinks, Collections.emptyList()));
|
||||
|
||||
User user = new User();
|
||||
user.id = BigInteger.valueOf(4711);
|
||||
|
||||
PersistentEntityResource resource = assembler.toResource(user);
|
||||
|
||||
Links links = new Links(resource.getLinks());
|
||||
Links links = resource.getLinks();
|
||||
|
||||
assertThat(links).hasSize(2);
|
||||
assertThat(links.getLink("self").orElseThrow(() -> new RuntimeException("Unable to find 'self' link")).getVariables()).isEmpty();
|
||||
assertThat(links.getLink("user").orElseThrow(() -> new RuntimeException("Unable to find 'user' link")).getVariableNames()).contains("projection");
|
||||
assertThat(links.getRequiredLink(IanaLinkRelations.SELF).getVariables()).isEmpty();
|
||||
assertThat(links.getRequiredLink("user").getVariableNames()).contains("projection");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.rest.tests.CommonWebTests;
|
||||
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -65,6 +67,7 @@ public class SolrWebTests extends CommonWebTests {
|
||||
|
||||
@Autowired ProductRepository repo;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -82,16 +85,16 @@ public class SolrWebTests extends CommonWebTests {
|
||||
|
||||
MockHttpServletResponse response = client.request("/products?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-387
|
||||
@@ -121,8 +124,8 @@ public class SolrWebTests extends CommonWebTests {
|
||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#expectedRootLinkRels()
|
||||
*/
|
||||
@Override
|
||||
protected Iterable<String> expectedRootLinkRels() {
|
||||
return Arrays.asList("products");
|
||||
protected Iterable<LinkRelation> expectedRootLinkRels() {
|
||||
return LinkRelation.manyOf("products");
|
||||
}
|
||||
|
||||
private void assertJsonDocumentMatches(Product reference) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user