DATAREST-1341 - Further API adaption for Spring HATEOAS 1.0.

This commit is contained in:
Oliver Drotbohm
2019-02-15 11:05:05 +01:00
parent ce321da807
commit 554d6cb27b
44 changed files with 423 additions and 401 deletions

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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

View File

@@ -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"));
}
}

View File

@@ -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();
}