Skip to content

Commit 0392103

Browse files
committed
DATAREST-1545 - Polishing.
1 parent 9737366 commit 0392103

File tree

3 files changed

+15
-104
lines changed

3 files changed

+15
-104
lines changed

spring-data-rest-hal-explorer/src/test/java/org/springframework/data/rest/webmvc/halexplorer/HalExplorerIntegrationTests.java

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,16 @@
1919
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
2020
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
2121

22-
import java.util.Optional;
23-
2422
import org.junit.Before;
2523
import org.junit.Test;
2624
import org.junit.runner.RunWith;
27-
import org.springframework.beans.BeansException;
28-
import org.springframework.beans.factory.ObjectFactory;
29-
import org.springframework.beans.factory.ObjectProvider;
3025
import org.springframework.beans.factory.annotation.Autowired;
31-
import org.springframework.context.ApplicationContext;
3226
import org.springframework.context.annotation.Bean;
3327
import org.springframework.context.annotation.Configuration;
34-
import org.springframework.core.convert.ConversionService;
35-
import org.springframework.data.geo.GeoModule;
28+
import org.springframework.context.annotation.Import;
3629
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
3730
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
3831
import org.springframework.hateoas.MediaTypes;
39-
import org.springframework.hateoas.mediatype.MessageResolver;
40-
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
4132
import org.springframework.http.HttpHeaders;
4233
import org.springframework.http.MediaType;
4334
import org.springframework.test.context.ContextConfiguration;
@@ -48,8 +39,6 @@
4839
import org.springframework.web.context.WebApplicationContext;
4940
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
5041

51-
import com.fasterxml.jackson.databind.ObjectMapper;
52-
5342
/**
5443
* Integration tests for {@link HalExplorer}.
5544
*
@@ -67,14 +56,8 @@ public class HalExplorerIntegrationTests {
6756

6857
@Configuration
6958
@EnableWebMvc
70-
static class TestConfiguration extends RepositoryRestMvcConfiguration {
71-
72-
public TestConfiguration(ApplicationContext context, ObjectFactory<ConversionService> conversionService) {
73-
74-
super(context, conversionService, Optional.empty(), Optional.empty(), Optional.empty(),
75-
new ObjectMapperProvider(), new RepresentationModelProcessorInvokerProvider(), MessageResolver.DEFAULTS_ONLY,
76-
new GeoModule());
77-
}
59+
@Import(RepositoryRestMvcConfiguration.class)
60+
static class TestConfiguration {
7861

7962
@Bean
8063
RepositoryRestConfigurer configExtension() {
@@ -131,51 +114,4 @@ public void retrunsApiIfHtmlIsNotExplicitlyListed() throws Exception {
131114
andExpect(status().isOk()).//
132115
andExpect(header().string(HttpHeaders.CONTENT_TYPE, startsWith(MediaType.APPLICATION_JSON_VALUE)));
133116
}
134-
135-
private static class ObjectMapperProvider implements ObjectProvider<ObjectMapper> {
136-
137-
@Override
138-
public ObjectMapper getObject(Object... args) throws BeansException {
139-
return null;
140-
}
141-
142-
@Override
143-
public ObjectMapper getIfAvailable() throws BeansException {
144-
return null;
145-
}
146-
147-
@Override
148-
public ObjectMapper getIfUnique() throws BeansException {
149-
return null;
150-
}
151-
152-
@Override
153-
public ObjectMapper getObject() throws BeansException {
154-
return null;
155-
}
156-
}
157-
158-
private static class RepresentationModelProcessorInvokerProvider
159-
implements ObjectProvider<RepresentationModelProcessorInvoker> {
160-
161-
@Override
162-
public RepresentationModelProcessorInvoker getObject(Object... args) throws BeansException {
163-
return null;
164-
}
165-
166-
@Override
167-
public RepresentationModelProcessorInvoker getIfAvailable() throws BeansException {
168-
return null;
169-
}
170-
171-
@Override
172-
public RepresentationModelProcessorInvoker getIfUnique() throws BeansException {
173-
return null;
174-
}
175-
176-
@Override
177-
public RepresentationModelProcessorInvoker getObject() throws BeansException {
178-
return null;
179-
}
180-
}
181117
}

spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractControllerIntegrationTests.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919

2020
import org.junit.Before;
2121
import org.junit.runner.RunWith;
22-
import org.springframework.beans.factory.ObjectFactory;
2322
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.context.ApplicationContext;
2523
import org.springframework.context.annotation.Bean;
2624
import org.springframework.context.annotation.Configuration;
27-
import org.springframework.core.convert.ConversionService;
25+
import org.springframework.context.annotation.Import;
2826
import org.springframework.data.mapping.PersistentEntity;
27+
import org.springframework.data.mapping.context.PersistentEntities;
2928
import org.springframework.data.repository.support.Repositories;
3029
import org.springframework.data.repository.support.RepositoryInvokerFactory;
3130
import org.springframework.data.rest.core.Path;
3231
import org.springframework.data.rest.core.mapping.ResourceMappings;
3332
import org.springframework.data.rest.core.mapping.ResourceMetadata;
3433
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
35-
import org.springframework.data.rest.core.support.EntityLookup;
3634
import org.springframework.data.rest.core.support.SelfLinkProvider;
3735
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
3836
import org.springframework.data.rest.webmvc.RootResourceInformation;
3937
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
38+
import org.springframework.data.rest.webmvc.mapping.Associations;
4039
import org.springframework.data.rest.webmvc.support.Projector;
40+
import org.springframework.hateoas.server.EntityLinks;
4141
import org.springframework.mock.web.MockHttpServletRequest;
4242
import org.springframework.test.context.ContextConfiguration;
4343
import org.springframework.test.context.junit4.SpringRunner;
@@ -59,19 +59,16 @@ public abstract class AbstractControllerIntegrationTests {
5959
public static final Path BASE = new Path("http://localhost");
6060

6161
@Configuration
62-
public static class TestConfiguration extends RepositoryRestMvcConfiguration {
63-
64-
public TestConfiguration(ApplicationContext context, ObjectFactory<ConversionService> conversionService) {
65-
super(context, conversionService);
66-
}
62+
@Import(RepositoryRestMvcConfiguration.class)
63+
public static class TestConfiguration {
6764

6865
@Bean
69-
public PersistentEntityResourceAssembler persistentEntityResourceAssembler() {
66+
public PersistentEntityResourceAssembler persistentEntityResourceAssembler(PersistentEntities entities,
67+
EntityLinks entityLinks, Associations associations) {
7068

71-
SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider(persistentEntities(), entityLinks(),
72-
Collections.<EntityLookup<?>> emptyList());
69+
SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider(entities, entityLinks, Collections.emptyList());
7370

74-
return new PersistentEntityResourceAssembler(persistentEntities(), StubProjector.INSTANCE, associationLinks(),
71+
return new PersistentEntityResourceAssembler(entities, StubProjector.INSTANCE, associations,
7572
selfLinkProvider);
7673
}
7774
}

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,12 @@
6969
import org.springframework.data.rest.core.support.RepositoryRelProvider;
7070
import org.springframework.data.rest.core.support.SelfLinkProvider;
7171
import org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory;
72-
import org.springframework.data.rest.webmvc.BasePathAwareController;
73-
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping;
74-
import org.springframework.data.rest.webmvc.BaseUri;
75-
import org.springframework.data.rest.webmvc.EmbeddedResourcesAssembler;
76-
import org.springframework.data.rest.webmvc.HttpHeadersPreparer;
77-
import org.springframework.data.rest.webmvc.ProfileResourceProcessor;
78-
import org.springframework.data.rest.webmvc.RepositoryRestController;
79-
import org.springframework.data.rest.webmvc.RepositoryRestExceptionHandler;
80-
import org.springframework.data.rest.webmvc.RepositoryRestHandlerAdapter;
81-
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
82-
import org.springframework.data.rest.webmvc.RestMediaTypes;
83-
import org.springframework.data.rest.webmvc.ServerHttpRequestMethodArgumentResolver;
72+
import org.springframework.data.rest.webmvc.*;
8473
import org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter;
8574
import org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter;
8675
import org.springframework.data.rest.webmvc.convert.UriListHttpMessageConverter;
87-
import org.springframework.data.rest.webmvc.json.DomainObjectReader;
88-
import org.springframework.data.rest.webmvc.json.EnumTranslator;
89-
import org.springframework.data.rest.webmvc.json.Jackson2DatatypeHelper;
90-
import org.springframework.data.rest.webmvc.json.JacksonMappingAwareSortTranslator;
91-
import org.springframework.data.rest.webmvc.json.JacksonSerializers;
92-
import org.springframework.data.rest.webmvc.json.MappingAwareDefaultedPageableArgumentResolver;
93-
import org.springframework.data.rest.webmvc.json.MappingAwarePageableArgumentResolver;
94-
import org.springframework.data.rest.webmvc.json.MappingAwareSortArgumentResolver;
95-
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module;
76+
import org.springframework.data.rest.webmvc.json.*;
9677
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.LookupObjectSerializer;
97-
import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter;
9878
import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.ValueTypeSchemaPropertyCustomizerFactory;
9979
import org.springframework.data.rest.webmvc.mapping.Associations;
10080
import org.springframework.data.rest.webmvc.mapping.LinkCollector;
@@ -215,7 +195,6 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
215195
private Lazy<ServerHttpRequestMethodArgumentResolver> serverHttpRequestMethodArgumentResolver;
216196
private Lazy<ETagArgumentResolver> eTagArgumentResolver;
217197
private Lazy<RepositoryInvokerFactory> repositoryInvokerFactory;
218-
private Lazy<MetadataConfiguration> metadataConfiguration;
219198
private Lazy<RepositoryRestConfiguration> repositoryRestConfiguration;
220199
private Lazy<HateoasPageableHandlerMethodArgumentResolver> pageableResolver;
221200
private Lazy<HateoasSortHandlerMethodArgumentResolver> sortResolver;
@@ -278,7 +257,6 @@ public RepositoryRestMvcConfiguration( //
278257
this.eTagArgumentResolver = Lazy.of(() -> context.getBean(ETagArgumentResolver.class));
279258
this.repositoryInvokerFactory = Lazy.of(() -> new UnwrappingRepositoryInvokerFactory(
280259
new DefaultRepositoryInvokerFactory(repositories.get(), defaultConversionService), getEntityLookups()));
281-
this.metadataConfiguration = Lazy.of(() -> context.getBean(MetadataConfiguration.class));
282260

283261
this.defaultConversionService = new DefaultFormattingConversionService();
284262
this.configurerDelegate = Lazy.of(() -> context.getBean(RepositoryRestConfigurerDelegate.class));

0 commit comments

Comments
 (0)