DATACMNS-822 - Provide customizers for default pageable and sort resolvers.
Introduced dedicated callback interfaces to customize the HandlerMethodArgumentResolver instances registered by SpringDataWebConfiguration. This allows bean definition registration of those customizer interfaces instead of having to extend a configuration class. Original pull request: #208.
This commit is contained in:
committed by
Oliver Gierke
parent
34ce83c657
commit
c1036b2204
@@ -35,6 +35,7 @@ import org.springframework.data.web.PagedResourcesAssemblerArgumentResolver;
|
||||
import org.springframework.data.web.SortHandlerMethodArgumentResolver;
|
||||
import org.springframework.data.web.WebTestUtils;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
@@ -50,6 +51,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public class EnableSpringDataWebSupportIntegrationTests {
|
||||
|
||||
@@ -63,6 +65,44 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@EnableSpringDataWebSupport
|
||||
static class PageableResolverCustomizerConfig extends SampleConfig {
|
||||
|
||||
@Bean
|
||||
public PageableHandlerMethodArgumentResolverCustomizer testPageableResolverCustomizer() {
|
||||
return new PageableHandlerMethodArgumentResolverCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(PageableHandlerMethodArgumentResolver pageableResolver) {
|
||||
pageableResolver.setMaxPageSize(100);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@EnableSpringDataWebSupport
|
||||
static class SortResolverCustomizerConfig extends SampleConfig {
|
||||
|
||||
@Bean
|
||||
public SortHandlerMethodArgumentResolverCustomizer testSortResolverCustomizer() {
|
||||
return new SortHandlerMethodArgumentResolverCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(SortHandlerMethodArgumentResolver sortResolver) {
|
||||
sortResolver.setSortParameter("foo");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test // DATACMNS-330
|
||||
public void registersBasicBeanDefinitions() throws Exception {
|
||||
|
||||
@@ -159,6 +199,26 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
assertThat(names).contains("sampleBean");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-822
|
||||
public void picksUpPageableResolverCustomizer() {
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(PageableResolverCustomizerConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
PageableHandlerMethodArgumentResolver resolver = context.getBean(PageableHandlerMethodArgumentResolver.class);
|
||||
|
||||
assertThat(names, hasItem("testPageableResolverCustomizer"));
|
||||
assertThat((Integer) ReflectionTestUtils.getField(resolver, "maxPageSize"), equalTo(100));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-822
|
||||
public void picksUpSortResolverCustomizer() {
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SortResolverCustomizerConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
SortHandlerMethodArgumentResolver resolver = context.getBean(SortHandlerMethodArgumentResolver.class);
|
||||
|
||||
assertThat(names, hasItem("testSortResolverCustomizer"));
|
||||
assertThat((String) ReflectionTestUtils.getField(resolver, "sortParameter"), equalTo("foo"));
|
||||
}
|
||||
|
||||
private static void assertResolversRegistered(ApplicationContext context, Class<?>... resolverTypes) {
|
||||
|
||||
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
|
||||
|
||||
Reference in New Issue
Block a user