Skip to content

Commit 1c3f906

Browse files
committed
DATAREST-1205 - Use Affordances API
* Leverage the Affordances API while making other media types work. * Create test case showing diff between HAL and HAL-FORMS * Handle Spring Data 2.1 tweak
1 parent a56a6d9 commit 1c3f906

File tree

33 files changed

+754
-130
lines changed

33 files changed

+754
-130
lines changed

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
<springdata.solr>4.1.0.BUILD-SNAPSHOT</springdata.solr>
3636
<springdata.cassandra>2.2.0.BUILD-SNAPSHOT</springdata.cassandra>
3737
<springdata.keyvalue>2.2.0.BUILD-SNAPSHOT</springdata.keyvalue>
38-
<spring-hateoas>0.25.0.RELEASE</spring-hateoas>
38+
<springplugin>2.0.0.BUILD-SNAPSHOT</springplugin>
39+
<spring-hateoas>1.0.0.BUILD-SNAPSHOT</spring-hateoas>
3940

41+
<evoinflector>1.2.2</evoinflector>
4042
<hibernate.version>4.3.10.Final</hibernate.version>
4143
<jsonpath>1.1.0</jsonpath>
4244
<bundlor.enabled>false</bundlor.enabled>

spring-data-rest-core/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
</parent>
1717

1818
<properties>
19-
<springplugin>1.2.0.RELEASE</springplugin>
20-
<evoinflector>1.2.2</evoinflector>
2119
<java-module-name>spring.data.rest.core</java-module-name>
2220
<project.root>${basedir}/..</project.root>
2321
</properties>

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/SearchResourceMappings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Set;
2525

2626
import org.springframework.data.rest.core.Path;
27+
import org.springframework.hateoas.IanaLinkRelation;
2728
import org.springframework.util.Assert;
2829

2930
/**
@@ -37,7 +38,6 @@ public class SearchResourceMappings implements Iterable<MethodResourceMapping>,
3738
+ "%s are mapped to %s! Tweak configuration to get to unambiguous paths!";
3839

3940
private static final Path PATH = new Path("/search");
40-
private static final String REL = "search";
4141

4242
private final Map<Path, MethodResourceMapping> mappings;
4343

@@ -155,7 +155,7 @@ public Path getPath() {
155155
*/
156156
@Override
157157
public String getRel() {
158-
return REL;
158+
return IanaLinkRelation.SEARCH.value();
159159
}
160160

161161
/*

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/Java8PluginRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static <T extends Plugin<S>, S> Java8PluginRegistry<T, S> empty() {
4646
}
4747

4848
public Optional<T> getPluginFor(S delimiter) {
49-
return Optional.ofNullable(registry.getPluginFor(delimiter));
49+
return registry.getPluginFor(delimiter);
5050
}
5151

5252
public T getPluginOrDefaultFor(S delimiter, T fallback) {

spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
2222
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
2323

24-
import net.minidev.json.JSONArray;
25-
2624
import java.util.Collections;
2725
import java.util.Map;
2826

27+
import net.minidev.json.JSONArray;
2928
import org.junit.Before;
3029
import org.junit.runner.RunWith;
3130
import org.springframework.beans.factory.annotation.Autowired;

spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.junit.Test;
3131
import org.springframework.data.rest.webmvc.RestMediaTypes;
32+
import org.springframework.hateoas.IanaLinkRelation;
3233
import org.springframework.hateoas.Link;
3334
import org.springframework.hateoas.Links;
3435
import org.springframework.hateoas.MediaTypes;
@@ -79,7 +80,7 @@ public void exposesSchemasForResourcesExposed() throws Exception {
7980
// Resource
8081
client.follow(link).andExpect(status().is2xxSuccessful());
8182

82-
Link profileLink = client.discoverUnique(link, "profile");
83+
Link profileLink = client.discoverUnique(link, IanaLinkRelation.PROFILE.value());
8384

8485
// Default metadata
8586
client.follow(profileLink).andExpect(status().is2xxSuccessful());
@@ -117,7 +118,7 @@ public void exposesSearchesForRootResources() throws Exception {
117118

118119
Link link = client.assertHasLinkWithRel(rel, response);
119120
String rootResourceRepresentation = client.request(link).getContentAsString();
120-
Link searchLink = client.getDiscoverer(response).findLinkWithRel("search", rootResourceRepresentation);
121+
Link searchLink = client.getDiscoverer(response).findLinkWithRel(IanaLinkRelation.SEARCH.value(), rootResourceRepresentation);
121122

122123
if (searchLink != null) {
123124
client.follow(searchLink).//
@@ -183,17 +184,15 @@ public void accessLinkedResources() throws Exception {
183184
@Test // DATAREST-230
184185
public void exposesDescriptionAsAlpsDocuments() throws Exception {
185186

186-
MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json");
187-
188187
MockHttpServletResponse response = client.request("/");
189-
Link profileLink = client.assertHasLinkWithRel("profile", response);
188+
Link profileLink = client.assertHasLinkWithRel(IanaLinkRelation.PROFILE.value(), response);
190189

191190
mvc.perform(//
192191
get(profileLink.expand().getHref()).//
193-
accept(ALPS_MEDIA_TYPE))
192+
accept(RestMediaTypes.ALPS_JSON))
194193
.//
195194
andExpect(status().isOk()).//
196-
andExpect(content().contentTypeCompatibleWith(ALPS_MEDIA_TYPE));
195+
andExpect(content().contentTypeCompatibleWith(RestMediaTypes.ALPS_JSON));
197196
}
198197

199198
@Test // DATAREST-448
@@ -216,8 +215,8 @@ public void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Excep
216215

217216
Links links = Links.valueOf(response.getHeader("Link"));
218217

219-
assertThat(links.hasLink(Link.REL_SELF)).isTrue();
220-
assertThat(links.hasLink("profile")).isTrue();
218+
assertThat(links.hasLink(IanaLinkRelation.SELF.value())).isTrue();
219+
assertThat(links.hasLink(IanaLinkRelation.PROFILE.value())).isTrue();
221220
}
222221
}
223222

spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/ResourceTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Link assertHasLinkEndingWith(String rel, String hrefEnd) {
8383

8484
private final Link assertHasLinkMatching(String rel, Matcher<String> hrefMatcher) {
8585

86-
Link link = resource.getLink(rel);
86+
Link link = resource.getRequiredLink(rel);
8787
assertThat("Expected link with rel '" + rel + "' but didn't find it in " + resource.getLinks(), link,
8888
is(notNullValue()));
8989

spring-data-rest-tests/spring-data-rest-tests-jpa/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
<scope>test</scope>
4848
</dependency>
4949

50+
<dependency>
51+
<groupId>org.springframework</groupId>
52+
<artifactId>spring-web</artifactId>
53+
<version>${spring}</version>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>org.springframework.hateoas</groupId>
58+
<artifactId>spring-hateoas</artifactId>
59+
<version>${spring-hateoas}</version>
60+
<scope>test</scope>
61+
</dependency>
62+
5063
<!-- Jackson Hibernate -->
5164

5265
<dependency>

0 commit comments

Comments
 (0)