DATAREST-1341 - Further API adaption for Spring HATEOAS 1.0.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
|
||||
/**
|
||||
* A custom resource mapping for collection resources.
|
||||
*
|
||||
@@ -27,7 +29,7 @@ public interface CollectionResourceMapping extends ResourceMapping {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getItemResourceRel();
|
||||
LinkRelation getItemResourceRel();
|
||||
|
||||
/**
|
||||
* Returns the {@link ResourceDescription} for the item resource.
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.rest.core.annotation.Description;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -42,8 +43,8 @@ public final class ParameterMetadata {
|
||||
Assert.hasText(name, "Parameter name must not be null or empty!");
|
||||
Assert.hasText(baseRel, "Method rel must not be null!");
|
||||
|
||||
ResourceDescription fallback = TypedResourceDescription.defaultFor(baseRel.concat(".").concat(name),
|
||||
parameter.getParameterType());
|
||||
ResourceDescription fallback = TypedResourceDescription
|
||||
.defaultFor(LinkRelation.of(baseRel.concat(".").concat(name)), parameter.getParameterType());
|
||||
Description annotation = parameter.getParameterAnnotation(Description.class);
|
||||
|
||||
this.description = annotation == null ? fallback : new AnnotationBasedResourceDescription(annotation, fallback);
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.Description;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.data.util.Optionals;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -71,11 +72,11 @@ class PersistentPropertyResourceMapping implements PropertyAwareResourceMapping
|
||||
* @see org.springframework.data.rest.core.mapping.ResourceMapping#getRel()
|
||||
*/
|
||||
@Override
|
||||
public String getRel() {
|
||||
public LinkRelation getRel() {
|
||||
|
||||
return annotation.filter(it -> StringUtils.hasText(it.rel()))//
|
||||
.map(it -> it.rel())//
|
||||
.orElseGet(() -> property.getName());
|
||||
return LinkRelation.of(annotation.filter(it -> StringUtils.hasText(it.rel())) //
|
||||
.map(it -> it.rel()) //
|
||||
.orElseGet(() -> property.getName()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -129,7 +130,7 @@ class RepositoryAwareResourceMetadata implements ResourceMetadata {
|
||||
* @see org.springframework.data.rest.core.mapping.CollectionResourceMapping#getCollectionRel()
|
||||
*/
|
||||
@Override
|
||||
public String getRel() {
|
||||
public LinkRelation getRel() {
|
||||
return mapping.getRel();
|
||||
}
|
||||
|
||||
@@ -138,7 +139,7 @@ class RepositoryAwareResourceMetadata implements ResourceMetadata {
|
||||
* @see org.springframework.data.rest.core.mapping.CollectionResourceMapping#getSingleResourceRel()
|
||||
*/
|
||||
@Override
|
||||
public String getItemResourceRel() {
|
||||
public LinkRelation getItemResourceRel() {
|
||||
return mapping.getItemResourceRel();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -111,18 +112,18 @@ class RepositoryCollectionResourceMapping implements CollectionResourceMapping {
|
||||
* @see org.springframework.data.rest.core.mapping.ResourceMapping#getRel()
|
||||
*/
|
||||
@Override
|
||||
public String getRel() {
|
||||
public LinkRelation getRel() {
|
||||
|
||||
String fallback = domainTypeMapping.getRel();
|
||||
LinkRelation fallback = domainTypeMapping.getRel();
|
||||
|
||||
if (repositoryAnnotation != null) {
|
||||
String rel = repositoryAnnotation.collectionResourceRel();
|
||||
return StringUtils.hasText(rel) ? rel : fallback;
|
||||
return StringUtils.hasText(rel) ? LinkRelation.of(rel) : fallback;
|
||||
}
|
||||
|
||||
if (annotation != null) {
|
||||
String rel = annotation.rel();
|
||||
return StringUtils.hasText(rel) ? rel : fallback;
|
||||
return StringUtils.hasText(rel) ? LinkRelation.of(rel) : fallback;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
@@ -133,13 +134,13 @@ class RepositoryCollectionResourceMapping implements CollectionResourceMapping {
|
||||
* @see org.springframework.data.rest.core.mapping.CollectionResourceMapping#getSingleResourceRel()
|
||||
*/
|
||||
@Override
|
||||
public String getItemResourceRel() {
|
||||
public LinkRelation getItemResourceRel() {
|
||||
|
||||
String fallback = domainTypeMapping.getItemResourceRel();
|
||||
LinkRelation fallback = domainTypeMapping.getItemResourceRel();
|
||||
|
||||
if (repositoryAnnotation != null) {
|
||||
String rel = repositoryAnnotation.itemResourceRel();
|
||||
return StringUtils.hasText(rel) ? rel : fallback;
|
||||
return StringUtils.hasText(rel) ? LinkRelation.of(rel) : fallback;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.core.AnnotationAttribute;
|
||||
import org.springframework.hateoas.core.MethodParameters;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -46,7 +47,7 @@ class RepositoryMethodResourceMapping implements MethodResourceMapping {
|
||||
private static final AnnotationAttribute PARAM_VALUE = new AnnotationAttribute(Param.class);
|
||||
|
||||
private final boolean isExported;
|
||||
private final String rel;
|
||||
private final LinkRelation rel;
|
||||
private final Path path;
|
||||
private final Method method;
|
||||
private final boolean paging;
|
||||
@@ -70,14 +71,15 @@ class RepositoryMethodResourceMapping implements MethodResourceMapping {
|
||||
Assert.notNull(resourceMapping, "ResourceMapping must not be null!");
|
||||
|
||||
RestResource annotation = AnnotationUtils.findAnnotation(method, RestResource.class);
|
||||
String resourceRel = resourceMapping.getRel();
|
||||
LinkRelation resourceRel = resourceMapping.getRel();
|
||||
|
||||
this.isExported = annotation != null ? annotation.exported() : exposeMethodsByDefault;
|
||||
this.rel = annotation == null || !StringUtils.hasText(annotation.rel()) ? method.getName() : annotation.rel();
|
||||
this.rel = LinkRelation
|
||||
.of(annotation == null || !StringUtils.hasText(annotation.rel()) ? method.getName() : annotation.rel());
|
||||
this.path = annotation == null || !StringUtils.hasText(annotation.path()) ? new Path(method.getName())
|
||||
: new Path(annotation.path());
|
||||
this.method = method;
|
||||
this.parameterMetadata = discoverParameterMetadata(method, resourceRel.concat(".").concat(rel));
|
||||
this.parameterMetadata = discoverParameterMetadata(method, resourceRel.value().concat(".").concat(rel.value()));
|
||||
|
||||
List<Class<?>> parameterTypes = Arrays.asList(method.getParameterTypes());
|
||||
|
||||
@@ -114,7 +116,7 @@ class RepositoryMethodResourceMapping implements MethodResourceMapping {
|
||||
* @see org.springframework.data.rest.core.mapping.ResourceMapping#getRel()
|
||||
*/
|
||||
@Override
|
||||
public String getRel() {
|
||||
public LinkRelation getRel() {
|
||||
return rel;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
|
||||
/**
|
||||
* Mapping information for components to be exported as REST resources.
|
||||
@@ -36,7 +37,7 @@ public interface ResourceMapping {
|
||||
*
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
String getRel();
|
||||
LinkRelation getRel();
|
||||
|
||||
/**
|
||||
* Returns the path the resource is exposed under.
|
||||
|
||||
@@ -17,13 +17,14 @@ package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,7 @@ 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 static final LinkRelation REL = IanaLinkRelations.SEARCH;
|
||||
|
||||
private final Map<Path, MethodResourceMapping> mappings;
|
||||
|
||||
@@ -57,8 +58,8 @@ public class SearchResourceMappings implements Iterable<MethodResourceMapping>,
|
||||
MethodResourceMapping existing = this.mappings.get(mapping.getPath());
|
||||
|
||||
if (existing != null) {
|
||||
throw new IllegalStateException(String.format(AMBIGUOUS_MAPPING, existing.getMethod(), mapping.getMethod(),
|
||||
existing.getPath()));
|
||||
throw new IllegalStateException(
|
||||
String.format(AMBIGUOUS_MAPPING, existing.getMethod(), mapping.getMethod(), existing.getPath()));
|
||||
}
|
||||
|
||||
this.mappings.put(mapping.getPath(), mapping);
|
||||
@@ -85,38 +86,27 @@ public class SearchResourceMappings implements Iterable<MethodResourceMapping>,
|
||||
* @return
|
||||
* @since 2.3
|
||||
*/
|
||||
public Iterable<MethodResourceMapping> getExportedMappings() {
|
||||
public Stream<MethodResourceMapping> getExportedMappings() {
|
||||
|
||||
Set<MethodResourceMapping> result = new HashSet<MethodResourceMapping>(mappings.values().size());
|
||||
|
||||
for (MethodResourceMapping mapping : this) {
|
||||
if (mapping.isExported()) {
|
||||
result.add(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return mappings.values().stream() //
|
||||
.filter(MethodResourceMapping::isExported);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link MappingResourceMetadata} for the given relation name.
|
||||
*
|
||||
* @param rel must not be {@literal null} or empty.
|
||||
* @param rel must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.3
|
||||
*/
|
||||
public MethodResourceMapping getExportedMethodMappingForRel(String rel) {
|
||||
public MethodResourceMapping getExportedMethodMappingForRel(LinkRelation rel) {
|
||||
|
||||
Assert.hasText(rel, "Rel must not be null or empty!");
|
||||
Assert.notNull(rel, "Rel must not be null!");
|
||||
|
||||
for (MethodResourceMapping mapping : this) {
|
||||
|
||||
if (mapping.isExported() && mapping.getRel().equals(rel)) {
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return mappings.values().stream() //
|
||||
.filter(MethodResourceMapping::isExported) //
|
||||
.filter(it -> it.getRel().isSameAs(rel)) //
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +144,7 @@ public class SearchResourceMappings implements Iterable<MethodResourceMapping>,
|
||||
* @see org.springframework.data.rest.core.mapping.ResourceMapping#getRel()
|
||||
*/
|
||||
@Override
|
||||
public String getRel() {
|
||||
public LinkRelation getRel() {
|
||||
return REL;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -45,8 +46,8 @@ public class SimpleResourceDescription extends ResolvableResourceDescriptionSupp
|
||||
this.mediaType = mediaType;
|
||||
}
|
||||
|
||||
public static ResourceDescription defaultFor(String rel) {
|
||||
return new SimpleResourceDescription(String.format("%s.%s", DEFAULT_KEY_PREFIX, rel), DEFAULT_MEDIA_TYPE);
|
||||
public static ResourceDescription defaultFor(LinkRelation rel) {
|
||||
return new SimpleResourceDescription(String.format("%s.%s", DEFAULT_KEY_PREFIX, rel.value()), DEFAULT_MEDIA_TYPE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.Description;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -91,13 +92,13 @@ class TypeBasedCollectionResourceMapping implements CollectionResourceMapping {
|
||||
* @see org.springframework.data.rest.core.mapping.ResourceMapping#getRel()
|
||||
*/
|
||||
@Override
|
||||
public String getRel() {
|
||||
public LinkRelation getRel() {
|
||||
|
||||
if (annotation == null || !StringUtils.hasText(annotation.rel())) {
|
||||
return relProvider.getCollectionResourceRelFor(type);
|
||||
}
|
||||
|
||||
return annotation.rel();
|
||||
return LinkRelation.of(annotation.rel());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -105,7 +106,7 @@ class TypeBasedCollectionResourceMapping implements CollectionResourceMapping {
|
||||
* @see org.springframework.data.rest.core.mapping.CollectionResourceMapping#getSingleResourceRel()
|
||||
*/
|
||||
@Override
|
||||
public String getItemResourceRel() {
|
||||
public LinkRelation getItemResourceRel() {
|
||||
return relProvider.getItemResourceRelFor(type);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.rest.core.mapping;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -46,19 +47,19 @@ public class TypedResourceDescription extends SimpleResourceDescription {
|
||||
this.type = type == null ? Object.class : type;
|
||||
}
|
||||
|
||||
public static ResourceDescription defaultFor(String rel, PersistentProperty<?> property) {
|
||||
public static ResourceDescription defaultFor(LinkRelation rel, PersistentProperty<?> property) {
|
||||
return defaultFor(rel, property.getName(), property.getType());
|
||||
}
|
||||
|
||||
public static ResourceDescription defaultFor(String rel, String name, Class<?> type) {
|
||||
public static ResourceDescription defaultFor(LinkRelation rel, String name, Class<?> type) {
|
||||
|
||||
String message = String.format("%s.%s.%s", DEFAULT_KEY_PREFIX, rel, name);
|
||||
String message = String.format("%s.%s.%s", DEFAULT_KEY_PREFIX, rel.value(), name);
|
||||
return new TypedResourceDescription(message, DEFAULT_MEDIA_TYPE, type);
|
||||
}
|
||||
|
||||
public static ResourceDescription defaultFor(String rel, Class<?> type) {
|
||||
public static ResourceDescription defaultFor(LinkRelation rel, Class<?> type) {
|
||||
|
||||
String message = String.format("%s.%s", DEFAULT_KEY_PREFIX, rel);
|
||||
String message = String.format("%s.%s", DEFAULT_KEY_PREFIX, rel.value());
|
||||
return new TypedResourceDescription(message, DEFAULT_MEDIA_TYPE, type);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class RepositoryRelProvider implements RelProvider {
|
||||
* @see org.springframework.hateoas.RelProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public String getCollectionResourceRelFor(Class<?> type) {
|
||||
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
|
||||
return mappings.getObject().getMetadataFor(type).getRel();
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ public class RepositoryRelProvider implements RelProvider {
|
||||
* @see org.springframework.hateoas.RelProvider#getItemResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public String getItemResourceRelFor(Class<?> type) {
|
||||
public LinkRelation getItemResourceRelFor(Class<?> type) {
|
||||
return mappings.getObject().getMetadataFor(type).getItemResourceRel();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core.support;
|
||||
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -37,10 +38,10 @@ public class SimpleRelProvider implements RelProvider {
|
||||
* @see org.springframework.hateoas.RelProvider#getItemResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public String getItemResourceRelFor(Class<?> type) {
|
||||
public LinkRelation getItemResourceRelFor(Class<?> type) {
|
||||
|
||||
String collectionRel = getCollectionResourceRelFor(type);
|
||||
return String.format("%s.%s", collectionRel, collectionRel);
|
||||
LinkRelation collectionRel = getCollectionResourceRelFor(type);
|
||||
return LinkRelation.of(String.format("%s.%s", collectionRel.value(), collectionRel.value()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -48,7 +49,7 @@ public class SimpleRelProvider implements RelProvider {
|
||||
* @see org.springframework.hateoas.RelProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public String getCollectionResourceRelFor(Class<?> type) {
|
||||
return StringUtils.uncapitalize(type.getSimpleName());
|
||||
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
|
||||
return LinkRelation.of(StringUtils.uncapitalize(type.getSimpleName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.Description;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PersistentPropertyResourceMapping}.
|
||||
@@ -49,7 +51,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
|
||||
assertThat(mapping).isNotNull();
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("first"));
|
||||
assertThat(mapping.getRel()).isEqualTo("first");
|
||||
assertThat(mapping.getRel()).isEqualTo(IanaLinkRelations.FIRST);
|
||||
assertThat(mapping.isExported()).isFalse();
|
||||
}
|
||||
|
||||
@@ -60,7 +62,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
|
||||
assertThat(mapping).isNotNull();
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("secPath"));
|
||||
assertThat(mapping.getRel()).isEqualTo("secRel");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("secRel"));
|
||||
assertThat(mapping.isExported()).isFalse();
|
||||
}
|
||||
|
||||
@@ -71,7 +73,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
|
||||
assertThat(mapping).isNotNull();
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("thirdPath"));
|
||||
assertThat(mapping.getRel()).isEqualTo("thirdRel");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("thirdRel"));
|
||||
assertThat(mapping.isExported()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.RepositoryDetectionStrategies;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RepositoryCollectionResourceMapping}.
|
||||
@@ -41,8 +42,8 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(PersonRepository.class);
|
||||
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("persons"));
|
||||
assertThat(mapping.getRel()).isEqualTo("persons");
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo("person");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("persons"));
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo(LinkRelation.of("person"));
|
||||
assertThat(mapping.isExported()).isTrue();
|
||||
}
|
||||
|
||||
@@ -52,8 +53,8 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedPersonRepository.class);
|
||||
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("bar"));
|
||||
assertThat(mapping.getRel()).isEqualTo("foo");
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo("annotatedPerson");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("foo"));
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo(LinkRelation.of("annotatedPerson"));
|
||||
assertThat(mapping.isExported()).isFalse();
|
||||
}
|
||||
|
||||
@@ -63,8 +64,8 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedAnnotatedPersonRepository.class);
|
||||
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("/trumpsAll"));
|
||||
assertThat(mapping.getRel()).isEqualTo("foo");
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo("annotatedPerson");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("foo"));
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo(LinkRelation.of("annotatedPerson"));
|
||||
assertThat(mapping.isExported()).isTrue();
|
||||
}
|
||||
|
||||
@@ -84,8 +85,8 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
public void discoversCustomizationsUsingRestRepositoryResource() {
|
||||
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(RepositoryAnnotatedRepository.class);
|
||||
assertThat(mapping.getRel()).isEqualTo("foo");
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo("bar");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("foo"));
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo(LinkRelation.of("bar"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-445
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.RepositoryDetectionStrategies;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RepositoryMethodResourceMapping}.
|
||||
@@ -94,7 +95,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
||||
MethodResourceMapping mapping = getMappingFor(method);
|
||||
|
||||
assertThat(mapping.getRel()).isEqualTo("findByEmailAddress");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("findByEmailAddress"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-384
|
||||
@@ -118,7 +119,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
||||
MethodResourceMapping mapping = getMappingFor(method);
|
||||
|
||||
assertThat(mapping.getReturnedDomainType()).isEqualTo((Class) Person.class);
|
||||
assertThat(mapping.getReturnedDomainType()).isEqualTo(Person.class);
|
||||
}
|
||||
|
||||
@Test // DATAREST-699
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.data.rest.core.domain.CreditCard;
|
||||
import org.springframework.data.rest.core.domain.JpaRepositoryConfig;
|
||||
import org.springframework.data.rest.core.domain.Person;
|
||||
import org.springframework.data.rest.core.domain.Profile;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -106,7 +107,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
ResourceMetadata metadata = mappings.getMetadataFor(Person.class);
|
||||
ResourceMapping mapping = metadata.getMappingFor(property);
|
||||
|
||||
assertThat(mapping.getRel()).isEqualTo("siblings");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("siblings"));
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("siblings"));
|
||||
assertThat(mapping.isExported()).isTrue();
|
||||
}
|
||||
@@ -168,7 +169,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
|
||||
PropertyAwareResourceMapping propertyMapping = metadata.getProperty("father-mapped");
|
||||
|
||||
assertThat(propertyMapping.getRel()).isEqualTo("father");
|
||||
assertThat(propertyMapping.getRel()).isEqualTo(LinkRelation.of("father"));
|
||||
assertThat(propertyMapping.getPath()).isEqualTo(new Path("father-mapped"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link TypeBasedCollectionResourceMapping}.
|
||||
@@ -34,8 +35,8 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
|
||||
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("sample"));
|
||||
assertThat(mapping.getRel()).isEqualTo("samples");
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo("sample");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("samples"));
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo(LinkRelation.of("sample"));
|
||||
assertThat(mapping.isExported()).isTrue();
|
||||
}
|
||||
|
||||
@@ -45,8 +46,8 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(CustomizedSample.class);
|
||||
|
||||
assertThat(mapping.getPath()).isEqualTo(new Path("customizedSample"));
|
||||
assertThat(mapping.getRel()).isEqualTo("myRel");
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo("customizedSample");
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("myRel"));
|
||||
assertThat(mapping.getItemResourceRel()).isEqualTo(LinkRelation.of("customizedSample"));
|
||||
assertThat(mapping.isExported()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user