Skip to content

Commit

Permalink
DATAREST-1205 - Use Affordances API
Browse files Browse the repository at this point in the history
* Leverage the Affordances API while making other media types work.
  • Loading branch information
gregturn committed Jan 7, 2019
1 parent a56a6d9 commit f1b8029
Show file tree
Hide file tree
Showing 33 changed files with 754 additions and 130 deletions.
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
<springdata.solr>4.1.0.BUILD-SNAPSHOT</springdata.solr>
<springdata.cassandra>2.2.0.BUILD-SNAPSHOT</springdata.cassandra>
<springdata.keyvalue>2.2.0.BUILD-SNAPSHOT</springdata.keyvalue>
<spring-hateoas>0.25.0.RELEASE</spring-hateoas>
<springplugin>2.0.0.BUILD-SNAPSHOT</springplugin>
<spring-hateoas>1.0.0.BUILD-SNAPSHOT</spring-hateoas>

<evoinflector>1.2.2</evoinflector>
<hibernate.version>4.3.10.Final</hibernate.version>
<jsonpath>1.1.0</jsonpath>
<bundlor.enabled>false</bundlor.enabled>
Expand Down
2 changes: 0 additions & 2 deletions spring-data-rest-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
</parent>

<properties>
<springplugin>1.2.0.RELEASE</springplugin>
<evoinflector>1.2.2</evoinflector>
<java-module-name>spring.data.rest.core</java-module-name>
<project.root>${basedir}/..</project.root>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Set;

import org.springframework.data.rest.core.Path;
import org.springframework.hateoas.IanaLinkRelation;
import org.springframework.util.Assert;

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

private static final Path PATH = new Path("/search");
private static final String REL = "search";

private final Map<Path, MethodResourceMapping> mappings;

Expand Down Expand Up @@ -155,7 +155,7 @@ public Path getPath() {
*/
@Override
public String getRel() {
return REL;
return IanaLinkRelation.SEARCH.value();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static <T extends Plugin<S>, S> Java8PluginRegistry<T, S> empty() {
}

public Optional<T> getPluginFor(S delimiter) {
return Optional.ofNullable(registry.getPluginFor(delimiter));
return registry.getPluginFor(delimiter);
}

public T getPluginOrDefaultFor(S delimiter, T fallback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import net.minidev.json.JSONArray;

import java.util.Collections;
import java.util.Map;

import net.minidev.json.JSONArray;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.junit.Test;
import org.springframework.data.rest.webmvc.RestMediaTypes;
import org.springframework.hateoas.IanaLinkRelation;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import org.springframework.hateoas.MediaTypes;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void exposesSchemasForResourcesExposed() throws Exception {
// Resource
client.follow(link).andExpect(status().is2xxSuccessful());

Link profileLink = client.discoverUnique(link, "profile");
Link profileLink = client.discoverUnique(link, IanaLinkRelation.PROFILE.value());

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

Link link = client.assertHasLinkWithRel(rel, response);
String rootResourceRepresentation = client.request(link).getContentAsString();
Link searchLink = client.getDiscoverer(response).findLinkWithRel("search", rootResourceRepresentation);
Link searchLink = client.getDiscoverer(response).findLinkWithRel(IanaLinkRelation.SEARCH.value(), rootResourceRepresentation);

if (searchLink != null) {
client.follow(searchLink).//
Expand Down Expand Up @@ -183,17 +184,15 @@ public void accessLinkedResources() throws Exception {
@Test // DATAREST-230
public void exposesDescriptionAsAlpsDocuments() throws Exception {

MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json");

MockHttpServletResponse response = client.request("/");
Link profileLink = client.assertHasLinkWithRel("profile", response);
Link profileLink = client.assertHasLinkWithRel(IanaLinkRelation.PROFILE.value(), response);

mvc.perform(//
get(profileLink.expand().getHref()).//
accept(ALPS_MEDIA_TYPE))
accept(RestMediaTypes.ALPS_JSON))
.//
andExpect(status().isOk()).//
andExpect(content().contentTypeCompatibleWith(ALPS_MEDIA_TYPE));
andExpect(content().contentTypeCompatibleWith(RestMediaTypes.ALPS_JSON));
}

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

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

assertThat(links.hasLink(Link.REL_SELF)).isTrue();
assertThat(links.hasLink("profile")).isTrue();
assertThat(links.hasLink(IanaLinkRelation.SELF.value())).isTrue();
assertThat(links.hasLink(IanaLinkRelation.PROFILE.value())).isTrue();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Link assertHasLinkEndingWith(String rel, String hrefEnd) {

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

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

Expand Down
13 changes: 13 additions & 0 deletions spring-data-rest-tests/spring-data-rest-tests-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring}</version>
</dependency>

<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>${spring-hateoas}</version>
<scope>test</scope>
</dependency>

<!-- Jackson Hibernate -->

<dependency>
Expand Down
Loading

0 comments on commit f1b8029

Please sign in to comment.