DATAREST-1341 - Adapt to package refactorings in Spring HATEOAS.

This commit is contained in:
Oliver Drotbohm
2019-02-27 12:59:45 +01:00
parent 85694576b2
commit 1bf08180db
69 changed files with 370 additions and 1043 deletions

View File

@@ -31,7 +31,7 @@ import org.junit.runner.RunWith;
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.client.LinkDiscoverers;
import org.springframework.hateoas.LinkRelation;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;

View File

@@ -49,12 +49,12 @@ import org.springframework.data.rest.webmvc.support.PagingAndSortingTemplateVari
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.RelProvider;
import org.springframework.hateoas.ResourceProcessor;
import org.springframework.hateoas.core.EvoInflectorRelProvider;
import org.springframework.hateoas.hal.Jackson2HalModule;
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.hateoas.server.RelProvider;
import org.springframework.hateoas.server.RepresentationModelProcessor;
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
import org.springframework.plugin.core.PluginRegistry;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -121,7 +121,7 @@ public class RepositoryTestsConfig {
return new PersistentEntityJackson2Module(associations, persistentEntities(), uriToEntityConverter, collector,
invokerFactory, mock(LookupObjectSerializer.class),
new ResourceProcessorInvoker(Collections.<ResourceProcessor<?>> emptyList()),
new RepresentationModelProcessorInvoker(Collections.<RepresentationModelProcessor<?>> emptyList()),
new EmbeddedResourcesAssembler(persistentEntities(), associations, mock(ExcerptProjector.class)));
}

View File

@@ -22,10 +22,10 @@ import static org.junit.Assert.assertThat;
import org.hamcrest.Matcher;
import org.springframework.data.rest.core.Path;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.CollectionModel;
import org.springframework.util.Assert;
import org.springframework.web.util.UriTemplate;
@@ -36,11 +36,11 @@ import org.springframework.web.util.UriTemplate;
*/
public class ResourceTester {
private final ResourceSupport resource;
private final RepresentationModel resource;
public static ResourceTester of(Object object) {
assertThat(object, is(instanceOf(ResourceSupport.class)));
return new ResourceTester((ResourceSupport) object);
assertThat(object, is(instanceOf(RepresentationModel.class)));
return new ResourceTester((RepresentationModel) object);
}
/**
@@ -48,8 +48,8 @@ public class ResourceTester {
*
* @param resource must not be {@literal null}.
*/
private ResourceTester(ResourceSupport resource) {
Assert.notNull(resource, "Resource must not be null!");
private ResourceTester(RepresentationModel resource) {
Assert.notNull(resource, "EntityRepresentationModel must not be null!");
this.resource = resource;
}
@@ -96,27 +96,27 @@ public class ResourceTester {
}
@SuppressWarnings("unchecked")
public <T> PagedResources<T> assertIsPage() {
public <T> PagedModel<T> assertIsPage() {
assertThat(resource, is(instanceOf(PagedResources.class)));
return (PagedResources<T>) resource;
assertThat(resource, is(instanceOf(PagedModel.class)));
return (PagedModel<T>) resource;
}
public ResourceTester getContentResource() {
assertThat(resource, is(instanceOf(Resources.class)));
Object next = ((Resources<?>) resource).getContent().iterator().next();
assertThat(resource, is(instanceOf(CollectionModel.class)));
Object next = ((CollectionModel<?>) resource).getContent().iterator().next();
assertThat(next, is(instanceOf(ResourceSupport.class)));
return new ResourceTester((ResourceSupport) next);
assertThat(next, is(instanceOf(RepresentationModel.class)));
return new ResourceTester((RepresentationModel) next);
}
public void withContentResource(ContentResourceHandler handler) {
assertThat(resource, is(instanceOf(Resources.class)));
assertThat(resource, is(instanceOf(CollectionModel.class)));
for (Object element : ((Resources<?>) resource).getContent()) {
assertThat(element, is(instanceOf(ResourceSupport.class)));
for (Object element : ((CollectionModel<?>) resource).getContent()) {
assertThat(element, is(instanceOf(RepresentationModel.class)));
handler.doWith(of(element));
}
}

View File

@@ -26,8 +26,8 @@ import java.util.Iterator;
import java.util.Optional;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkDiscoverer;
import org.springframework.hateoas.LinkDiscoverers;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.Links;
import org.springframework.http.HttpEntity;
@@ -365,7 +365,7 @@ public class TestMvcClient {
* Using the servlet response's content type, find the corresponding link discoverer.
*
* @param response
* @return {@link org.springframework.hateoas.LinkDiscoverer}
* @return {@link org.springframework.hateoas.client.LinkDiscoverer}
*/
public LinkDiscoverer getDiscoverer(MockHttpServletResponse response) {

View File

@@ -48,7 +48,7 @@ import org.springframework.data.rest.webmvc.jpa.Order;
import org.springframework.data.rest.webmvc.jpa.Person;
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
import org.springframework.data.rest.webmvc.support.ETag;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -243,7 +243,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
Mockito.when(assembler.toFullResource(Mockito.any(Object.class))).thenReturn(resource);
ResponseEntity<Resource<?>> entity = controller.getItemResource(getResourceInformation(Address.class), address.id,
ResponseEntity<EntityModel<?>> entity = controller.getItemResource(getResourceInformation(Address.class), address.id,
assembler, new HttpHeaders());
assertThat(entity.getHeaders().getETag()).isNotNull();

View File

@@ -35,9 +35,9 @@ import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
import org.springframework.data.rest.webmvc.jpa.Person;
import org.springframework.data.rest.webmvc.jpa.TestDataPopulator;
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.CollectionModel;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -72,7 +72,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
public void rendersCorrectSearchLinksForPersons() throws Exception {
RootResourceInformation request = getResourceInformation(Person.class);
ResourceSupport resource = controller.listSearches(request);
RepresentationModel resource = controller.listSearches(request);
ResourceTester tester = ResourceTester.of(resource);
tester.assertNumberOfLinks(7); // Self link included
@@ -107,7 +107,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
Sort.unsorted(), assembler, new HttpHeaders());
ResourceTester tester = ResourceTester.of(response.getBody());
PagedResources<Object> pagedResources = tester.assertIsPage();
PagedModel<Object> pagedResources = tester.assertIsPage();
assertThat(pagedResources.getContent()).hasSize(1);
ResourceMetadata metadata = getMetadata(Person.class);
@@ -169,7 +169,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
ResponseEntity<?> result = controller.executeSearch(resourceInformation, parameters, "findByAuthorsContains",
PAGEABLE, Sort.unsorted(), assembler, new HttpHeaders());
assertThat(result.getBody()).isInstanceOf(Resources.class);
assertThat(result.getBody()).isInstanceOf(CollectionModel.class);
}
@Test // DATAREST-515

View File

@@ -38,9 +38,9 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
import org.springframework.data.rest.webmvc.jpa.Item;
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkDiscoverer;
import org.springframework.hateoas.LinkDiscoverers;
import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.client.JsonPathLinkDiscoverer;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;

View File

@@ -40,7 +40,7 @@ import org.springframework.data.rest.webmvc.PersistentEntityResource;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.MediaTypes;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -122,7 +122,7 @@ public class DataRest262Tests {
JpaPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(AircraftMovement.class);
Resource<Object> resource = PersistentEntityResource.build(movement, persistentEntity).//
EntityModel<Object> resource = PersistentEntityResource.build(movement, persistentEntity).//
withLink(new Link("/api/airports/" + movement.id)).//
build();

View File

@@ -28,9 +28,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.tests.TestMvcClient;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.hateoas.LinkDiscoverer;
import org.springframework.hateoas.LinkDiscoverers;
import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.client.JsonPathLinkDiscoverer;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@@ -41,7 +41,7 @@ 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.hateoas.server.RelProvider;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;

View File

@@ -31,7 +31,7 @@ import org.springframework.data.rest.webmvc.ProfileResourceProcessor;
import org.springframework.data.rest.webmvc.RestMediaTypes;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkDiscoverers;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;

View File

@@ -41,14 +41,14 @@ import org.springframework.data.rest.webmvc.PersistentEntityResource;
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.client.LinkDiscoverer;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.PagedResources.PageMetadata;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.core.EmbeddedWrapper;
import org.springframework.hateoas.core.EmbeddedWrappers;
import org.springframework.hateoas.hal.HalLinkDiscoverer;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.PagedModel.PageMetadata;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.server.core.EmbeddedWrapper;
import org.springframework.hateoas.server.core.EmbeddedWrappers;
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -204,7 +204,7 @@ public class PersistentEntitySerializationTests {
withLink(new Link("/orders/1")).//
build();
PagedResources<PersistentEntityResource> persistentEntityResource = new PagedResources<PersistentEntityResource>(
PagedModel<PersistentEntityResource> persistentEntityResource = new PagedModel<PersistentEntityResource>(
Arrays.asList(orderResource), new PageMetadata(1, 0, 10));
String result = mapper.writeValueAsString(persistentEntityResource);
@@ -260,7 +260,7 @@ public class PersistentEntitySerializationTests {
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
PersonSummary projection = factory.createProjection(PersonSummary.class, person);
String result = mapper.writeValueAsString(new Resource<PersonSummary>(projection));
String result = mapper.writeValueAsString(new EntityModel<PersonSummary>(projection));
assertThat(JsonPath.<Object> read(result, "$._links.self")).isNotNull();
}

View File

@@ -50,12 +50,12 @@ import org.springframework.data.rest.webmvc.support.PagingAndSortingTemplateVari
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.RelProvider;
import org.springframework.hateoas.ResourceProcessor;
import org.springframework.hateoas.core.EvoInflectorRelProvider;
import org.springframework.hateoas.hal.Jackson2HalModule;
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.hateoas.server.RelProvider;
import org.springframework.hateoas.server.RepresentationModelProcessor;
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
import org.springframework.plugin.core.PluginRegistry;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -129,7 +129,7 @@ public class RepositoryTestsConfig {
return new PersistentEntityJackson2Module(associations, persistentEntities(), uriToEntityConverter, collector,
invokerFactory, mock(LookupObjectSerializer.class),
new ResourceProcessorInvoker(Collections.<ResourceProcessor<?>> emptyList()),
new RepresentationModelProcessorInvoker(Collections.<RepresentationModelProcessor<?>> emptyList()),
new EmbeddedResourcesAssembler(persistentEntities(), associations, mock(ExcerptProjector.class)));
}

View File

@@ -51,7 +51,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
@Test
public void returnsLinkToSingleResource() {
Link link = entityLinks.linkToSingleResource(Person.class, 1);
Link link = entityLinks.linkToItemResource(Person.class, 1);
assertThat(link.getHref(), endsWith("/people/1{?projection}"));
assertThat(link.getRel()).isEqualTo(LinkRelation.of("person"));
@@ -70,7 +70,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
@Test // DATAREST-221
public void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() {
Link link = entityLinks.linkToSingleResource(Order.class, 1);
Link link = entityLinks.linkToItemResource(Order.class, 1);
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains(configuration.getProjectionConfiguration().getParameterName());
@@ -79,7 +79,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
@Test // DATAREST-155
public void usesCustomGeneratedBackendId() {
Link link = entityLinks.linkToSingleResource(Book.class, 7L);
Link link = entityLinks.linkToItemResource(Book.class, 7L);
assertThat(link.expand().getHref(), endsWith("/7-7-7-7-7-7-7"));
}

View File

@@ -313,7 +313,7 @@ public class MongoWebTests extends CommonWebTests {
Link link = client.discoverUnique("users", "search", "findByColleaguesContains");
User thomas = userRepository.findAll(QUser.user.firstname.eq("Thomas")).iterator().next();
Link thomasUri = entityLinks.linkToSingleResource(User.class, thomas.id).expand();
Link thomasUri = entityLinks.linkToItemResource(User.class, thomas.id).expand();
String href = link.expand(thomasUri.getHref()).getHref();

View File

@@ -33,7 +33,7 @@ import org.springframework.data.rest.tests.mongodb.MongoDbRepositoryConfig;
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.server.EntityLinks;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Links;
import org.springframework.test.context.ContextConfiguration;
@@ -63,7 +63,7 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
User user = new User();
user.id = BigInteger.valueOf(4711);
PersistentEntityResource resource = assembler.toResource(user);
PersistentEntityResource resource = assembler.toModel(user);
Links links = resource.getLinks();

View File

@@ -42,10 +42,10 @@ import org.springframework.data.rest.tests.mongodb.User.Nested;
import org.springframework.data.rest.tests.mongodb.UserRepository;
import org.springframework.data.rest.webmvc.PersistentEntityResource;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkDiscoverer;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.PagedResources.PageMetadata;
import org.springframework.hateoas.hal.HalLinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.PagedModel;
import org.springframework.hateoas.PagedModel.PageMetadata;
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -109,7 +109,7 @@ public class PersistentEntitySerializationTests {
withLink(new Link("/users/1")).//
build();
PagedResources<PersistentEntityResource> persistentEntityResource = new PagedResources<PersistentEntityResource>(
PagedModel<PersistentEntityResource> persistentEntityResource = new PagedModel<PersistentEntityResource>(
Arrays.asList(userResource), new PageMetadata(1, 0, 10));
String result = mapper.writeValueAsString(persistentEntityResource);

View File

@@ -28,8 +28,8 @@ import org.springframework.data.rest.tests.shop.Customer.Gender;
import org.springframework.data.rest.tests.shop.Product.ProductNameOnlyProjection;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.ResourceProcessor;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.server.RepresentationModelProcessor;
/**
* @author Oliver Gierke
@@ -44,15 +44,15 @@ public class ShopConfiguration {
@Autowired LineItemTypeRepository lineItemTypes;
@Bean
public ResourceProcessor<Resource<LineItem>> lineItemResourceProcessor() {
return new ResourceProcessor<Resource<LineItem>>() {
public RepresentationModelProcessor<EntityModel<LineItem>> lineItemResourceProcessor() {
return new RepresentationModelProcessor<EntityModel<LineItem>>() {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceProcessor#process(org.springframework.hateoas.ResourceSupport)
* @see org.springframework.hateoas.server.RepresentationModelProcessor#process(org.springframework.hateoas.RepresentationModel)
*/
@Override
public Resource<LineItem> process(Resource<LineItem> resource) {
public EntityModel<LineItem> process(EntityModel<LineItem> resource) {
resource.add(new Link("foo", "bar"));
return resource;
}
@@ -60,16 +60,16 @@ public class ShopConfiguration {
}
@Bean
public ResourceProcessor<Resource<ProductNameOnlyProjection>> productNameOnlyProjectionResourceProcessor() {
public RepresentationModelProcessor<EntityModel<ProductNameOnlyProjection>> productNameOnlyProjectionResourceProcessor() {
return new ResourceProcessor<Resource<ProductNameOnlyProjection>>() {
return new RepresentationModelProcessor<EntityModel<ProductNameOnlyProjection>>() {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.ResourceProcessor#process(org.springframework.hateoas.ResourceSupport)
* @see org.springframework.hateoas.server.RepresentationModelProcessor#process(org.springframework.hateoas.RepresentationModel)
*/
@Override
public Resource<ProductNameOnlyProjection> process(Resource<Product.ProductNameOnlyProjection> resource) {
public EntityModel<ProductNameOnlyProjection> process(EntityModel<Product.ProductNameOnlyProjection> resource) {
resource.add(new Link("alpha", "beta"));
return resource;
}

View File

@@ -51,7 +51,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
ResultActions actions = client.follow(selfLink)
// Lookup type is rendered as String
.andExpect(jsonPath("items[0].type", is("good")))//
// Invokes ResourceProcessor for nested Resource
// Invokes RepresentationModelProcessor for nested Resource
.andExpect(jsonPath("items[0]._links.bar").exists());//
// Adds excerpt projection for related product