DATACMNS-470 - Removed code deprecated in version 1.6.
Removed support for Jackson 1 based repository populators in favor of Jackson 2 based ones. Removed PageableArgumentResolver in favor of PageableHandlerMethodArgumentResolver. Removed legacy setup code of the new HandlerMethodArgumentResolver implementations.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,6 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.repository.init.Jackson2ResourceReader;
|
||||
import org.springframework.data.repository.init.JacksonResourceReader;
|
||||
import org.springframework.data.repository.init.ResourceReaderRepositoryPopulator;
|
||||
import org.springframework.data.repository.init.UnmarshallingResourceReader;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
@@ -41,28 +40,6 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
*/
|
||||
public class ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests {
|
||||
|
||||
/**
|
||||
* @see DATACMNS-58
|
||||
*/
|
||||
@Test
|
||||
public void registersJacksonInitializerCorrectly() {
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
|
||||
reader.loadBeanDefinitions(getPopulatorResource());
|
||||
|
||||
BeanDefinition definition = beanFactory.getBeanDefinition("jackson-populator");
|
||||
assertThat(definition, is(notNullValue()));
|
||||
|
||||
Object bean = beanFactory.getBean("jackson-populator");
|
||||
assertThat(bean, is(instanceOf(ResourceReaderRepositoryPopulator.class)));
|
||||
Object resourceReader = ReflectionTestUtils.getField(bean, "reader");
|
||||
assertThat(resourceReader, is(instanceOf(JacksonResourceReader.class)));
|
||||
|
||||
Object resources = ReflectionTestUtils.getField(bean, "resources");
|
||||
assertIsListOfClasspathResourcesWithPath(resources, "org/springframework/data/repository/init/data.json");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-333
|
||||
*/
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.repository.init;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link JacksonResourceReader}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class JacksonResourceReaderIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void readsFileWithMultipleObjects() throws Exception {
|
||||
|
||||
ResourceReader reader = new JacksonResourceReader();
|
||||
Object result = reader.readFrom(new ClassPathResource("data.json", getClass()), null);
|
||||
|
||||
assertThat(result, is(instanceOf(Collection.class)));
|
||||
assertThat((Collection<?>) result, hasSize(1));
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.web;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.web.PageableHandlerMethodArgumentResolver.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.web.SortDefault.SortDefaults;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PageableHandlerMethodArgumentResolver} in it's legacy mode. Essentially a copy of
|
||||
* {@link PageableArgumentResolverUnitTests} but but executed against {@link PageableHandlerMethodArgumentResolver}.
|
||||
*
|
||||
* @since 1.6
|
||||
* @author Oliver Gierke
|
||||
* @author Nick Williams
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class LegacyPageableHandlerMethodArgumentResolverUnitTests extends PageableDefaultUnitTests {
|
||||
|
||||
Method correctMethod, noQualifiers, invalidQualifiers, defaultsMethod, defaultsMethodWithSort,
|
||||
defaultsMethodWithSortAndDirection, otherMethod;
|
||||
|
||||
MockHttpServletRequest request;
|
||||
|
||||
@Before
|
||||
public void setUp() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
correctMethod = SampleController.class.getMethod("correctMethod", Pageable.class, Pageable.class);
|
||||
noQualifiers = SampleController.class.getMethod("noQualifiers", Pageable.class, Pageable.class);
|
||||
invalidQualifiers = SampleController.class.getMethod("invalidQualifiers", Pageable.class, Pageable.class);
|
||||
otherMethod = SampleController.class.getMethod("unsupportedMethod", String.class);
|
||||
|
||||
defaultsMethod = SampleController.class.getMethod("simpleDefault", Pageable.class);
|
||||
defaultsMethodWithSort = SampleController.class.getMethod("simpleDefaultWithSort", Pageable.class);
|
||||
defaultsMethodWithSortAndDirection = SampleController.class.getMethod("simpleDefaultWithSortAndDirection",
|
||||
Pageable.class);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
|
||||
// Add pagination info for foo table
|
||||
request.addParameter("foo_page.size", "50");
|
||||
request.addParameter("foo_page.sort", "foo");
|
||||
request.addParameter("foo_page.sort.dir", "asc");
|
||||
|
||||
// Add pagination info for bar table
|
||||
request.addParameter("bar_page.size", "60");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsPageableParameter() {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
|
||||
resolver.supportsParameter(new MethodParameter(correctMethod, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotSupportNonPageableParameter() {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
|
||||
resolver.supportsParameter(new MethodParameter(otherMethod, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testname() throws Exception {
|
||||
|
||||
assertSizeForPrefix(50, new Sort(Direction.ASC, "foo"), 0);
|
||||
assertSizeForPrefix(60, null, 1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void rejectsInvalidlyMappedPageables() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(noQualifiers, 0);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
|
||||
new PageableHandlerMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void rejectsInvalidQualifiers() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(invalidQualifiers, 0);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
|
||||
new PageableHandlerMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertDefaults() throws Exception {
|
||||
|
||||
Object argument = setupAndResolve(defaultsMethod);
|
||||
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(PAGE_SIZE));
|
||||
assertThat(pageable.getPageNumber(), is(PAGE_NUMBER));
|
||||
assertThat(pageable.getSort(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertOverridesDefaults() throws Exception {
|
||||
|
||||
Integer sizeParam = 5;
|
||||
|
||||
MethodParameter parameter = new MethodParameter(defaultsMethod, 0);
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
|
||||
|
||||
mockRequest.addParameter("page.page", sizeParam.toString());
|
||||
NativeWebRequest webRequest = new ServletWebRequest(mockRequest);
|
||||
Object argument = LEGACY.resolveArgument(parameter, null, webRequest, null);
|
||||
|
||||
assertTrue(argument instanceof Pageable);
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertEquals(PAGE_SIZE, pageable.getPageSize());
|
||||
assertEquals(sizeParam - 1, pageable.getPageNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appliesDefaultSort() throws Exception {
|
||||
|
||||
Object argument = setupAndResolve(defaultsMethodWithSort);
|
||||
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(PAGE_SIZE));
|
||||
assertThat(pageable.getPageNumber(), is(PAGE_NUMBER));
|
||||
assertThat(pageable.getSort(), is(new Sort("firstname", "lastname")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appliesDefaultSortAndDirection() throws Exception {
|
||||
|
||||
Object argument = setupAndResolve(defaultsMethodWithSortAndDirection);
|
||||
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(PAGE_SIZE));
|
||||
assertThat(pageable.getPageNumber(), is(PAGE_NUMBER));
|
||||
assertThat(pageable.getSort(), is(new Sort(Direction.DESC, "firstname", "lastname")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildsUpRequestParameters() {
|
||||
|
||||
// Set up basic page representation based on 1-indexed page numbers
|
||||
String basicString = String.format("page.page=%d&page.size=%d", PAGE_NUMBER + 1, PAGE_SIZE);
|
||||
|
||||
assertUriStringFor(REFERENCE_WITHOUT_SORT, basicString);
|
||||
assertUriStringFor(REFERENCE_WITH_SORT, basicString + "&page.sort=firstname,lastname&page.sort.dir=desc");
|
||||
assertUriStringFor(REFERENCE_WITH_SORT_FIELDS, basicString + "&page.sort=firstname,lastname&page.sort.dir=asc");
|
||||
}
|
||||
|
||||
private void assertSizeForPrefix(int size, Sort sort, int index) throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(correctMethod, index);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
|
||||
Object argument = LEGACY.resolveArgument(parameter, null, webRequest, null);
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(size));
|
||||
|
||||
if (null != sort) {
|
||||
assertThat(pageable.getSort(), is(sort));
|
||||
}
|
||||
}
|
||||
|
||||
private Object setupAndResolve(Method method) throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest());
|
||||
|
||||
return LEGACY.resolveArgument(parameter, null, webRequest, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> getControllerClass() {
|
||||
return SampleController.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HateoasPageableHandlerMethodArgumentResolver getResolver() {
|
||||
return HateoasPageableHandlerMethodArgumentResolver.LEGACY;
|
||||
}
|
||||
|
||||
protected void assertUriStringFor(Pageable pageable, String expected) {
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/");
|
||||
MethodParameter parameter = getParameterOfMethod("supportedMethod");
|
||||
|
||||
getResolver().enhance(builder, parameter, pageable);
|
||||
|
||||
assertThat(builder.build().toUriString(), endsWith(expected));
|
||||
}
|
||||
|
||||
static interface SampleController {
|
||||
|
||||
void simpleDefault(@PageableDefaults(value = PAGE_SIZE, pageNumber = PAGE_NUMBER) Pageable pageable);
|
||||
|
||||
void simpleDefaultWithSort(@PageableDefaults(value = PAGE_SIZE, pageNumber = PAGE_NUMBER, sort = { "firstname",
|
||||
"lastname" }) Pageable pageable);
|
||||
|
||||
void simpleDefaultWithSortAndDirection(@PageableDefaults(value = PAGE_SIZE, pageNumber = PAGE_NUMBER, sort = {
|
||||
"firstname", "lastname" }, sortDir = Direction.DESC) Pageable pageable);
|
||||
|
||||
void simpleDefaultWithExternalSort(@PageableDefaults(value = PAGE_SIZE, pageNumber = PAGE_NUMBER) @SortDefault(
|
||||
sort = { "firstname", "lastname" }, direction = Direction.DESC) Pageable pageable);
|
||||
|
||||
void simpleDefaultWithContaineredExternalSort(
|
||||
@PageableDefaults(value = PAGE_SIZE, pageNumber = PAGE_NUMBER) @SortDefaults(@SortDefault(sort = { "firstname",
|
||||
"lastname" }, direction = Direction.DESC)) Pageable pageable);
|
||||
|
||||
void correctMethod(@Qualifier("foo") Pageable first, @Qualifier("bar") Pageable second);
|
||||
|
||||
void invalidQualifiers(@Qualifier("foo") Pageable first, @Qualifier("foo") Pageable second);
|
||||
|
||||
void noQualifiers(Pageable first, Pageable second);
|
||||
|
||||
void supportedMethod(Pageable pageable);
|
||||
|
||||
void unsupportedMethod(String foo);
|
||||
}
|
||||
}
|
||||
@@ -1,218 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.web;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
|
||||
/**
|
||||
* Unit test for {@link PageableArgumentResolver}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PageableArgumentResolverUnitTests {
|
||||
|
||||
Method correctMethod, failedMethod, invalidQualifiers, defaultsMethod, defaultsMethodWithSort,
|
||||
defaultsMethodWithSortAndDirection;
|
||||
|
||||
MockHttpServletRequest request;
|
||||
|
||||
@Before
|
||||
public void setUp() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
correctMethod = SampleController.class.getMethod("correctMethod", Pageable.class, Pageable.class);
|
||||
failedMethod = SampleController.class.getMethod("noQualifiers", Pageable.class, Pageable.class);
|
||||
invalidQualifiers = SampleController.class.getMethod("invalidQualifiers", Pageable.class, Pageable.class);
|
||||
|
||||
defaultsMethod = SampleController.class.getMethod("defaultsMethod", Pageable.class);
|
||||
defaultsMethodWithSort = SampleController.class.getMethod("defaultsMethodWithSort", Pageable.class);
|
||||
defaultsMethodWithSortAndDirection = SampleController.class.getMethod("defaultsMethodWithSortAndDirection",
|
||||
Pageable.class);
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
|
||||
// Add pagination info for foo table
|
||||
request.addParameter("foo_page.size", "50");
|
||||
request.addParameter("foo_page.sort", "foo");
|
||||
request.addParameter("foo_page.sort.dir", "asc");
|
||||
|
||||
// Add pagination info for bar table
|
||||
request.addParameter("bar_page.size", "60");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testname() throws Exception {
|
||||
|
||||
assertSizeForPrefix(50, new Sort(Direction.ASC, "foo"), 0);
|
||||
assertSizeForPrefix(60, null, 1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void rejectsInvalidlyMappedPageables() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(failedMethod, 0);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
|
||||
new PageableArgumentResolver().resolveArgument(parameter, webRequest);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void rejectsInvalidQualifiers() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(invalidQualifiers, 0);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
|
||||
new PageableArgumentResolver().resolveArgument(parameter, webRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertDefaults() throws Exception {
|
||||
|
||||
Object argument = setupAndResolve(defaultsMethod);
|
||||
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(SampleController.DEFAULT_PAGESIZE));
|
||||
assertThat(pageable.getPageNumber(), is(SampleController.DEFAULT_PAGENUMBER));
|
||||
assertThat(pageable.getSort(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertOverridesDefaults() throws Exception {
|
||||
|
||||
Integer sizeParam = 5;
|
||||
|
||||
MethodParameter parameter = new MethodParameter(defaultsMethod, 0);
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
|
||||
|
||||
mockRequest.addParameter("page.page", sizeParam.toString());
|
||||
NativeWebRequest webRequest = new ServletWebRequest(mockRequest);
|
||||
PageableArgumentResolver resolver = new PageableArgumentResolver();
|
||||
Object argument = resolver.resolveArgument(parameter, webRequest);
|
||||
|
||||
assertTrue(argument instanceof Pageable);
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertEquals(SampleController.DEFAULT_PAGESIZE, pageable.getPageSize());
|
||||
assertEquals(sizeParam - 1, pageable.getPageNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-146
|
||||
*/
|
||||
@Test
|
||||
public void appliesDefaultSort() {
|
||||
|
||||
Object argument = setupAndResolve(defaultsMethodWithSort);
|
||||
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(SampleController.DEFAULT_PAGESIZE));
|
||||
assertThat(pageable.getPageNumber(), is(SampleController.DEFAULT_PAGENUMBER));
|
||||
assertThat(pageable.getSort(), is(new Sort("foo")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-146
|
||||
*/
|
||||
@Test
|
||||
public void appliesDefaultSortAndDirection() {
|
||||
|
||||
Object argument = setupAndResolve(defaultsMethodWithSortAndDirection);
|
||||
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(SampleController.DEFAULT_PAGESIZE));
|
||||
assertThat(pageable.getPageNumber(), is(SampleController.DEFAULT_PAGENUMBER));
|
||||
assertThat(pageable.getSort(), is(new Sort(Direction.DESC, "foo")));
|
||||
}
|
||||
|
||||
private void assertSizeForPrefix(int size, Sort sort, int index) throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(correctMethod, index);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
|
||||
PageableArgumentResolver resolver = new PageableArgumentResolver();
|
||||
|
||||
Object argument = resolver.resolveArgument(parameter, webRequest);
|
||||
assertThat(argument, is(instanceOf(Pageable.class)));
|
||||
|
||||
Pageable pageable = (Pageable) argument;
|
||||
assertThat(pageable.getPageSize(), is(size));
|
||||
|
||||
if (null != sort) {
|
||||
assertThat(pageable.getSort(), is(sort));
|
||||
}
|
||||
}
|
||||
|
||||
private Object setupAndResolve(Method method) {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
NativeWebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest());
|
||||
PageableArgumentResolver resolver = new PageableArgumentResolver();
|
||||
return resolver.resolveArgument(parameter, webRequest);
|
||||
}
|
||||
|
||||
static class SampleController {
|
||||
|
||||
static final int DEFAULT_PAGESIZE = 198;
|
||||
static final int DEFAULT_PAGENUMBER = 42;
|
||||
|
||||
public void defaultsMethod(
|
||||
@PageableDefaults(value = DEFAULT_PAGESIZE, pageNumber = DEFAULT_PAGENUMBER) Pageable pageable) {
|
||||
|
||||
}
|
||||
|
||||
public void defaultsMethodWithSort(
|
||||
@PageableDefaults(value = DEFAULT_PAGESIZE, pageNumber = DEFAULT_PAGENUMBER, sort = "foo") Pageable pageable) {
|
||||
|
||||
}
|
||||
|
||||
public void defaultsMethodWithSortAndDirection(
|
||||
@PageableDefaults(value = DEFAULT_PAGESIZE, pageNumber = DEFAULT_PAGENUMBER, sort = "foo", sortDir = Direction.DESC) Pageable pageable) {
|
||||
|
||||
}
|
||||
|
||||
public void correctMethod(@Qualifier("foo") Pageable first, @Qualifier("bar") Pageable second) {
|
||||
|
||||
}
|
||||
|
||||
public void noQualifiers(Pageable first, Pageable second) {
|
||||
|
||||
}
|
||||
|
||||
public void invalidQualifiers(@Qualifier("foo") Pageable first, @Qualifier("foo") Pageable second) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,6 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
|
||||
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<repository:jackson-populator id="jackson-populator"
|
||||
locations="classpath:org/springframework/data/repository/init/data.json" />
|
||||
|
||||
<repository:jackson2-populator id="jackson2-populator"
|
||||
locations="classpath:org/springframework/data/repository/init/data.json" />
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
|
||||
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<repository:jackson-populator id="jackson-populator"
|
||||
locations="classpath:org/springframework/data/repository/init/data.json" />
|
||||
|
||||
<repository:jackson2-populator id="jackson2-populator"
|
||||
locations="classpath:org/springframework/data/repository/init/data.json" />
|
||||
|
||||
Reference in New Issue
Block a user