DATAREST-1545 - Polishing.

This commit is contained in:
Oliver Drotbohm
2020-09-15 17:09:59 +02:00
parent 9737366174
commit 0392103371
3 changed files with 15 additions and 104 deletions

View File

@@ -19,25 +19,16 @@ import static org.hamcrest.CoreMatchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.geo.GeoModule;
import org.springframework.context.annotation.Import;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.hateoas.MediaTypes;
import org.springframework.hateoas.mediatype.MessageResolver;
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
@@ -48,8 +39,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Integration tests for {@link HalExplorer}.
*
@@ -67,14 +56,8 @@ public class HalExplorerIntegrationTests {
@Configuration
@EnableWebMvc
static class TestConfiguration extends RepositoryRestMvcConfiguration {
public TestConfiguration(ApplicationContext context, ObjectFactory<ConversionService> conversionService) {
super(context, conversionService, Optional.empty(), Optional.empty(), Optional.empty(),
new ObjectMapperProvider(), new RepresentationModelProcessorInvokerProvider(), MessageResolver.DEFAULTS_ONLY,
new GeoModule());
}
@Import(RepositoryRestMvcConfiguration.class)
static class TestConfiguration {
@Bean
RepositoryRestConfigurer configExtension() {
@@ -131,51 +114,4 @@ public class HalExplorerIntegrationTests {
andExpect(status().isOk()).//
andExpect(header().string(HttpHeaders.CONTENT_TYPE, startsWith(MediaType.APPLICATION_JSON_VALUE)));
}
private static class ObjectMapperProvider implements ObjectProvider<ObjectMapper> {
@Override
public ObjectMapper getObject(Object... args) throws BeansException {
return null;
}
@Override
public ObjectMapper getIfAvailable() throws BeansException {
return null;
}
@Override
public ObjectMapper getIfUnique() throws BeansException {
return null;
}
@Override
public ObjectMapper getObject() throws BeansException {
return null;
}
}
private static class RepresentationModelProcessorInvokerProvider
implements ObjectProvider<RepresentationModelProcessorInvoker> {
@Override
public RepresentationModelProcessorInvoker getObject(Object... args) throws BeansException {
return null;
}
@Override
public RepresentationModelProcessorInvoker getIfAvailable() throws BeansException {
return null;
}
@Override
public RepresentationModelProcessorInvoker getIfUnique() throws BeansException {
return null;
}
@Override
public RepresentationModelProcessorInvoker getObject() throws BeansException {
return null;
}
}
}

View File

@@ -19,25 +19,25 @@ import java.util.Collections;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.context.annotation.Import;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.repository.support.RepositoryInvokerFactory;
import org.springframework.data.rest.core.Path;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.core.mapping.ResourceMetadata;
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
import org.springframework.data.rest.core.support.EntityLookup;
import org.springframework.data.rest.core.support.SelfLinkProvider;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RootResourceInformation;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.data.rest.webmvc.mapping.Associations;
import org.springframework.data.rest.webmvc.support.Projector;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -59,19 +59,16 @@ public abstract class AbstractControllerIntegrationTests {
public static final Path BASE = new Path("http://localhost");
@Configuration
public static class TestConfiguration extends RepositoryRestMvcConfiguration {
public TestConfiguration(ApplicationContext context, ObjectFactory<ConversionService> conversionService) {
super(context, conversionService);
}
@Import(RepositoryRestMvcConfiguration.class)
public static class TestConfiguration {
@Bean
public PersistentEntityResourceAssembler persistentEntityResourceAssembler() {
public PersistentEntityResourceAssembler persistentEntityResourceAssembler(PersistentEntities entities,
EntityLinks entityLinks, Associations associations) {
SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider(persistentEntities(), entityLinks(),
Collections.<EntityLookup<?>> emptyList());
SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider(entities, entityLinks, Collections.emptyList());
return new PersistentEntityResourceAssembler(persistentEntities(), StubProjector.INSTANCE, associationLinks(),
return new PersistentEntityResourceAssembler(entities, StubProjector.INSTANCE, associations,
selfLinkProvider);
}
}

View File

@@ -69,32 +69,12 @@ import org.springframework.data.rest.core.support.EntityLookup;
import org.springframework.data.rest.core.support.RepositoryRelProvider;
import org.springframework.data.rest.core.support.SelfLinkProvider;
import org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory;
import org.springframework.data.rest.webmvc.BasePathAwareController;
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping;
import org.springframework.data.rest.webmvc.BaseUri;
import org.springframework.data.rest.webmvc.EmbeddedResourcesAssembler;
import org.springframework.data.rest.webmvc.HttpHeadersPreparer;
import org.springframework.data.rest.webmvc.ProfileResourceProcessor;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.data.rest.webmvc.RepositoryRestExceptionHandler;
import org.springframework.data.rest.webmvc.RepositoryRestHandlerAdapter;
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
import org.springframework.data.rest.webmvc.RestMediaTypes;
import org.springframework.data.rest.webmvc.ServerHttpRequestMethodArgumentResolver;
import org.springframework.data.rest.webmvc.*;
import org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter;
import org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter;
import org.springframework.data.rest.webmvc.convert.UriListHttpMessageConverter;
import org.springframework.data.rest.webmvc.json.DomainObjectReader;
import org.springframework.data.rest.webmvc.json.EnumTranslator;
import org.springframework.data.rest.webmvc.json.Jackson2DatatypeHelper;
import org.springframework.data.rest.webmvc.json.JacksonMappingAwareSortTranslator;
import org.springframework.data.rest.webmvc.json.JacksonSerializers;
import org.springframework.data.rest.webmvc.json.MappingAwareDefaultedPageableArgumentResolver;
import org.springframework.data.rest.webmvc.json.MappingAwarePageableArgumentResolver;
import org.springframework.data.rest.webmvc.json.MappingAwareSortArgumentResolver;
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module;
import org.springframework.data.rest.webmvc.json.*;
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.LookupObjectSerializer;
import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter;
import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.ValueTypeSchemaPropertyCustomizerFactory;
import org.springframework.data.rest.webmvc.mapping.Associations;
import org.springframework.data.rest.webmvc.mapping.LinkCollector;
@@ -215,7 +195,6 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
private Lazy<ServerHttpRequestMethodArgumentResolver> serverHttpRequestMethodArgumentResolver;
private Lazy<ETagArgumentResolver> eTagArgumentResolver;
private Lazy<RepositoryInvokerFactory> repositoryInvokerFactory;
private Lazy<MetadataConfiguration> metadataConfiguration;
private Lazy<RepositoryRestConfiguration> repositoryRestConfiguration;
private Lazy<HateoasPageableHandlerMethodArgumentResolver> pageableResolver;
private Lazy<HateoasSortHandlerMethodArgumentResolver> sortResolver;
@@ -278,7 +257,6 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
this.eTagArgumentResolver = Lazy.of(() -> context.getBean(ETagArgumentResolver.class));
this.repositoryInvokerFactory = Lazy.of(() -> new UnwrappingRepositoryInvokerFactory(
new DefaultRepositoryInvokerFactory(repositories.get(), defaultConversionService), getEntityLookups()));
this.metadataConfiguration = Lazy.of(() -> context.getBean(MetadataConfiguration.class));
this.defaultConversionService = new DefaultFormattingConversionService();
this.configurerDelegate = Lazy.of(() -> context.getBean(RepositoryRestConfigurerDelegate.class));