DATACMNS-1718 - Migrate tests to JUnit 5.
This commit is contained in:
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -33,11 +33,11 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class HateoasPageableHandlerMethodArgumentResolverUnitTests
|
||||
class HateoasPageableHandlerMethodArgumentResolverUnitTests
|
||||
extends PageableHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
@Test
|
||||
public void buildsUpRequestParameters() {
|
||||
void buildsUpRequestParameters() {
|
||||
|
||||
String basicString = String.format("page=%d&size=%d", PAGE_NUMBER, PAGE_SIZE);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class HateoasPageableHandlerMethodArgumentResolverUnitTests
|
||||
}
|
||||
|
||||
@Test // DATACMNS-343
|
||||
public void replacesExistingPaginationInformation() throws Exception {
|
||||
void replacesExistingPaginationInformation() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(Sample.class.getMethod("supportedMethod", Pageable.class), 0);
|
||||
UriComponentsContributor resolver = new HateoasPageableHandlerMethodArgumentResolver();
|
||||
@@ -66,12 +66,12 @@ public class HateoasPageableHandlerMethodArgumentResolverUnitTests
|
||||
}
|
||||
|
||||
@Test // DATACMNS-335
|
||||
public void preventsPageSizeFromExceedingMayValueIfConfiguredOnWrite() throws Exception {
|
||||
void preventsPageSizeFromExceedingMayValueIfConfiguredOnWrite() throws Exception {
|
||||
assertUriStringFor(PageRequest.of(0, 200), "page=0&size=100");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void appendsTemplateVariablesCorrectly() {
|
||||
void appendsTemplateVariablesCorrectly() {
|
||||
|
||||
assertTemplateEnrichment("/foo", "{?page,size,sort}");
|
||||
assertTemplateEnrichment("/foo?bar=1", "{&page,size,sort}");
|
||||
@@ -82,7 +82,7 @@ public class HateoasPageableHandlerMethodArgumentResolverUnitTests
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void returnsCustomizedTemplateVariables() {
|
||||
void returnsCustomizedTemplateVariables() {
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo").build();
|
||||
|
||||
@@ -94,7 +94,7 @@ public class HateoasPageableHandlerMethodArgumentResolverUnitTests
|
||||
}
|
||||
|
||||
@Test // DATACMNS-563
|
||||
public void enablingOneIndexedParameterReturnsOneForFirstPage() {
|
||||
void enablingOneIndexedParameterReturnsOneForFirstPage() {
|
||||
|
||||
HateoasPageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setOneIndexedParameters(true);
|
||||
@@ -110,7 +110,7 @@ public class HateoasPageableHandlerMethodArgumentResolverUnitTests
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1455
|
||||
public void enhancesUnpaged() {
|
||||
void enhancesUnpaged() {
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/");
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.springframework.data.domain.Sort.Direction.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
@@ -31,10 +31,10 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class HateoasSortHandlerMethodArgumentResolverUnitTests extends SortHandlerMethodArgumentResolverUnitTests {
|
||||
class HateoasSortHandlerMethodArgumentResolverUnitTests extends SortHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
@Test
|
||||
public void buildsUpRequestParameters() throws Exception {
|
||||
void buildsUpRequestParameters() throws Exception {
|
||||
|
||||
assertUriStringFor(SORT, "sort=firstname,lastname,desc");
|
||||
assertUriStringFor(Sort.by(ASC, "foo").and(Sort.by(DESC, "bar").and(Sort.by(ASC, "foobar"))),
|
||||
@@ -44,12 +44,12 @@ public class HateoasSortHandlerMethodArgumentResolverUnitTests extends SortHandl
|
||||
}
|
||||
|
||||
@Test // DATACMNS-407
|
||||
public void replacesExistingRequestParameters() throws Exception {
|
||||
void replacesExistingRequestParameters() throws Exception {
|
||||
assertUriStringFor(SORT, "/?sort=firstname,lastname,desc", "/?sort=foo,asc");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void returnCorrectTemplateVariables() {
|
||||
void returnCorrectTemplateVariables() {
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromPath("/").build();
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.io.ByteArrayInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
|
||||
@@ -41,13 +41,13 @@ import com.jayway.jsonpath.spi.mapper.MappingProvider;
|
||||
* @since 1.13
|
||||
* @soundtrack Richard Spaven - Assemble (Whole Other*)
|
||||
*/
|
||||
public class JsonProjectingMethodInterceptorFactoryUnitTests {
|
||||
class JsonProjectingMethodInterceptorFactoryUnitTests {
|
||||
|
||||
ProjectionFactory projectionFactory;
|
||||
Customer customer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
String json = "{\"firstname\" : \"Dave\", "//
|
||||
+ "\"address\" : { \"zipCode\" : \"01097\", \"city\" : \"Dresden\" }," //
|
||||
@@ -63,47 +63,47 @@ public class JsonProjectingMethodInterceptorFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessSimpleProperty() {
|
||||
void accessSimpleProperty() {
|
||||
assertThat(customer.getFirstname()).isEqualTo("Dave");
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessPropertyWithExplicitAnnotation() {
|
||||
void accessPropertyWithExplicitAnnotation() {
|
||||
assertThat(customer.getBar()).isEqualTo("Dave");
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessPropertyWithComplexReturnType() {
|
||||
void accessPropertyWithComplexReturnType() {
|
||||
assertThat(customer.getAddress()).isEqualTo(new Address("01097", "Dresden"));
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessComplexPropertyWithProjection() {
|
||||
void accessComplexPropertyWithProjection() {
|
||||
assertThat(customer.getAddressProjection().getCity()).isEqualTo("Dresden");
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessPropertyWithNestedJsonPath() {
|
||||
void accessPropertyWithNestedJsonPath() {
|
||||
assertThat(customer.getNestedZipCode()).isEqualTo("01097");
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessCollectionProperty() {
|
||||
void accessCollectionProperty() {
|
||||
assertThat(customer.getAddresses().get(0)).isEqualTo(new Address("01097", "Dresden"));
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessPropertyOnNestedProjection() {
|
||||
void accessPropertyOnNestedProjection() {
|
||||
assertThat(customer.getAddressProjections().get(0).getZipCode()).isEqualTo("01097");
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessPropertyThatUsesJsonPathProjectionInTurn() {
|
||||
void accessPropertyThatUsesJsonPathProjectionInTurn() {
|
||||
assertThat(customer.getAnotherAddressProjection().getZipCodeButNotCity()).isEqualTo("01097");
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessCollectionPropertyThatUsesJsonPathProjectionInTurn() {
|
||||
void accessCollectionPropertyThatUsesJsonPathProjectionInTurn() {
|
||||
|
||||
List<AnotherAddressProjection> projections = customer.getAnotherAddressProjections();
|
||||
|
||||
@@ -112,7 +112,7 @@ public class JsonProjectingMethodInterceptorFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessAsCollectionPropertyThatUsesJsonPathProjectionInTurn() {
|
||||
void accessAsCollectionPropertyThatUsesJsonPathProjectionInTurn() {
|
||||
|
||||
Set<AnotherAddressProjection> projections = customer.getAnotherAddressProjectionAsCollection();
|
||||
|
||||
@@ -121,7 +121,7 @@ public class JsonProjectingMethodInterceptorFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void accessNestedPropertyButStayOnRootLevel() {
|
||||
void accessNestedPropertyButStayOnRootLevel() {
|
||||
|
||||
Name name = customer.getName();
|
||||
|
||||
@@ -130,19 +130,19 @@ public class JsonProjectingMethodInterceptorFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-885
|
||||
public void accessNestedFields() {
|
||||
void accessNestedFields() {
|
||||
|
||||
assertThat(customer.getNestedCity()).isEqualTo("Dresden");
|
||||
assertThat(customer.getNestedCities()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1144
|
||||
public void returnsNullForNonExistantValue() {
|
||||
void returnsNullForNonExistantValue() {
|
||||
assertThat(customer.getName().getLastname()).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1144
|
||||
public void triesMultipleDeclaredPathsIfNotAvailable() {
|
||||
void triesMultipleDeclaredPathsIfNotAvailable() {
|
||||
assertThat(customer.getName().getSomeName()).isEqualTo(customer.getName().getFirstname());
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.ConfigurablePropertyAccessor;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.NotWritablePropertyException;
|
||||
@@ -42,10 +42,10 @@ import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class MapDataBinderUnitTests {
|
||||
class MapDataBinderUnitTests {
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void honorsFormattingAnnotationOnAccessor() {
|
||||
void honorsFormattingAnnotationOnAccessor() {
|
||||
|
||||
Date reference = new Date();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MapDataBinderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void bindsNestedCollectionElement() {
|
||||
void bindsNestedCollectionElement() {
|
||||
|
||||
MutablePropertyValues values = new MutablePropertyValues();
|
||||
values.add("foo.bar.fooBar[0]", "String");
|
||||
@@ -73,7 +73,7 @@ public class MapDataBinderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void bindsNestedPrimitive() {
|
||||
void bindsNestedPrimitive() {
|
||||
|
||||
MutablePropertyValues values = new MutablePropertyValues();
|
||||
values.add("foo.firstname", "Dave");
|
||||
@@ -89,7 +89,7 @@ public class MapDataBinderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void skipsPropertyNotExposedByTheTypeHierarchy() {
|
||||
void skipsPropertyNotExposedByTheTypeHierarchy() {
|
||||
|
||||
MutablePropertyValues values = new MutablePropertyValues();
|
||||
values.add("somethingWeird", "Value");
|
||||
@@ -98,7 +98,7 @@ public class MapDataBinderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1264
|
||||
public void dropsMapExpressionsForCollectionReferences() {
|
||||
void dropsMapExpressionsForCollectionReferences() {
|
||||
|
||||
ConfigurablePropertyAccessor accessor = new MapDataBinder(Bar.class, new DefaultFormattingConversionService())
|
||||
.getPropertyAccessor();
|
||||
@@ -109,7 +109,7 @@ public class MapDataBinderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1264
|
||||
public void rejectsExpressionContainingTypeExpression() {
|
||||
void rejectsExpressionContainingTypeExpression() {
|
||||
|
||||
ConfigurablePropertyAccessor accessor = new MapDataBinder(Bar.class, new DefaultFormattingConversionService())
|
||||
.getPropertyAccessor();
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.springframework.data.web.SortDefaultUnitTests.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.AbstractPageRequest;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
* @author Oliver Gierke
|
||||
* @author Nick Williams
|
||||
*/
|
||||
public abstract class PageableDefaultUnitTests {
|
||||
abstract class PageableDefaultUnitTests {
|
||||
|
||||
static final int PAGE_SIZE = 47;
|
||||
static final int PAGE_NUMBER = 23;
|
||||
@@ -53,50 +53,50 @@ public abstract class PageableDefaultUnitTests {
|
||||
Sort.by(SORT_FIELDS));
|
||||
|
||||
@Test
|
||||
public void supportsPageable() {
|
||||
void supportsPageable() {
|
||||
assertThat(getResolver().supportsParameter(getParameterOfMethod("supportedMethod"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotSupportNonPageable() {
|
||||
void doesNotSupportNonPageable() {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "unsupportedMethod", String.class);
|
||||
assertThat(getResolver().supportsParameter(parameter)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsDefaultIfNoRequestParametersAndNoDefault() throws Exception {
|
||||
void returnsDefaultIfNoRequestParametersAndNoDefault() throws Exception {
|
||||
assertSupportedAndResult(getParameterOfMethod("supportedMethod"),
|
||||
(Pageable) ReflectionTestUtils.getField(getResolver(), "fallbackPageable"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleDefault() throws Exception {
|
||||
void simpleDefault() throws Exception {
|
||||
assertSupportedAndResult(getParameterOfMethod("simpleDefault"), REFERENCE_WITHOUT_SORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleDefaultWithSort() throws Exception {
|
||||
void simpleDefaultWithSort() throws Exception {
|
||||
assertSupportedAndResult(getParameterOfMethod("simpleDefaultWithSort"), REFERENCE_WITH_SORT_FIELDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleDefaultWithSortAndDirection() throws Exception {
|
||||
void simpleDefaultWithSortAndDirection() throws Exception {
|
||||
assertSupportedAndResult(getParameterOfMethod("simpleDefaultWithSortAndDirection"), REFERENCE_WITH_SORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleDefaultWithExternalSort() throws Exception {
|
||||
void simpleDefaultWithExternalSort() throws Exception {
|
||||
assertSupportedAndResult(getParameterOfMethod("simpleDefaultWithExternalSort"), REFERENCE_WITH_SORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleDefaultWithContaineredExternalSort() throws Exception {
|
||||
void simpleDefaultWithContaineredExternalSort() throws Exception {
|
||||
assertSupportedAndResult(getParameterOfMethod("simpleDefaultWithContaineredExternalSort"), REFERENCE_WITH_SORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidQulifiers() throws Exception {
|
||||
void rejectsInvalidQulifiers() throws Exception {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "invalidQualifiers",
|
||||
Pageable.class, Pageable.class);
|
||||
@@ -110,7 +110,7 @@ public abstract class PageableDefaultUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNoQualifiers() throws Exception {
|
||||
void rejectsNoQualifiers() throws Exception {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "noQualifiers", Pageable.class,
|
||||
Pageable.class);
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.data.web;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.web.PageableHandlerMethodArgumentResolver.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -36,17 +36,17 @@ import org.springframework.web.context.request.ServletWebRequest;
|
||||
* @author Oliver Gierke
|
||||
* @author Nick Williams
|
||||
*/
|
||||
public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefaultUnitTests {
|
||||
class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefaultUnitTests {
|
||||
|
||||
MethodParameter supportedMethodParameter;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
this.supportedMethodParameter = new MethodParameter(Sample.class.getMethod("supportedMethod", Pageable.class), 0);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-335
|
||||
public void preventsPageSizeFromExceedingMayValueIfConfigured() throws Exception {
|
||||
void preventsPageSizeFromExceedingMayValueIfConfigured() throws Exception {
|
||||
|
||||
// Read side
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -57,31 +57,31 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsEmptyPageParameterName() {
|
||||
void rejectsEmptyPageParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new PageableHandlerMethodArgumentResolver().setPageParameterName(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNullPageParameterName() {
|
||||
void rejectsNullPageParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new PageableHandlerMethodArgumentResolver().setPageParameterName(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsEmptySizeParameterName() {
|
||||
void rejectsEmptySizeParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new PageableHandlerMethodArgumentResolver().setSizeParameterName(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNullSizeParameterName() {
|
||||
void rejectsNullSizeParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new PageableHandlerMethodArgumentResolver().setSizeParameterName(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void qualifierIsUsedInParameterLookup() throws Exception {
|
||||
void qualifierIsUsedInParameterLookup() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(Sample.class.getMethod("validQualifier", Pageable.class), 0);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-377
|
||||
public void usesDefaultPageSizeIfRequestPageSizeIsLessThanOne() throws Exception {
|
||||
void usesDefaultPageSizeIfRequestPageSizeIsLessThanOne() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("page", "0");
|
||||
@@ -103,7 +103,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-377
|
||||
public void rejectsInvalidCustomDefaultForPageSize() throws Exception {
|
||||
void rejectsInvalidCustomDefaultForPageSize() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(Sample.class.getMethod("invalidDefaultPageSize", Pageable.class),
|
||||
0);
|
||||
@@ -113,7 +113,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-408
|
||||
public void fallsBackToFirstPageIfNegativePageNumberIsGiven() throws Exception {
|
||||
void fallsBackToFirstPageIfNegativePageNumberIsGiven() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("page", "-1");
|
||||
@@ -122,7 +122,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-408
|
||||
public void pageParamIsNotNumeric() throws Exception {
|
||||
void pageParamIsNotNumeric() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("page", "a");
|
||||
@@ -131,7 +131,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-408
|
||||
public void sizeParamIsNotNumeric() throws Exception {
|
||||
void sizeParamIsNotNumeric() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("size", "a");
|
||||
@@ -140,7 +140,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-477
|
||||
public void returnsNullIfFallbackIsUnpagedAndNoParametersGiven() throws Exception {
|
||||
void returnsNullIfFallbackIsUnpagedAndNoParametersGiven() throws Exception {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -150,7 +150,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-477
|
||||
public void returnsFallbackIfOnlyPageIsGiven() throws Exception {
|
||||
void returnsFallbackIfOnlyPageIsGiven() throws Exception {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -163,7 +163,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-477
|
||||
public void returnsFallbackIfFallbackIsUnpagedAndOnlySizeIsGiven() throws Exception {
|
||||
void returnsFallbackIfFallbackIsUnpagedAndOnlySizeIsGiven() throws Exception {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -176,7 +176,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-563
|
||||
public void considersOneIndexedParametersSetting() {
|
||||
void considersOneIndexedParametersSetting() {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setOneIndexedParameters(true);
|
||||
@@ -190,7 +190,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-640
|
||||
public void usesNullSortIfNoDefaultIsConfiguredAndPageAndSizeAreGiven() {
|
||||
void usesNullSortIfNoDefaultIsConfiguredAndPageAndSizeAreGiven() {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -207,7 +207,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-692
|
||||
public void oneIndexedParametersDefaultsIndexOutOfRange() {
|
||||
void oneIndexedParametersDefaultsIndexOutOfRange() {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setOneIndexedParameters(true);
|
||||
@@ -221,7 +221,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-761
|
||||
public void returnsCorrectPageSizeForOneIndexParameters() {
|
||||
void returnsCorrectPageSizeForOneIndexParameters() {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setOneIndexedParameters(true);
|
||||
@@ -235,7 +235,7 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
|
||||
}
|
||||
|
||||
@Test // DATACMNS-929
|
||||
public void detectsFallbackPageableIfNullOneIsConfigured() {
|
||||
void detectsFallbackPageableIfNullOneIsConfigured() {
|
||||
|
||||
PageableHandlerMethodArgumentResolver resolver = getResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
|
||||
@@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -36,12 +36,12 @@ import org.springframework.web.util.UriComponents;
|
||||
* @author Oliver Gierke
|
||||
* @since 1.7
|
||||
*/
|
||||
public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
|
||||
PagedResourcesAssemblerArgumentResolver resolver;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
WebTestUtils.initWebTest();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void createsPlainAssemblerWithoutContext() throws Exception {
|
||||
void createsPlainAssemblerWithoutContext() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("noContext", PagedResourcesAssembler.class);
|
||||
Object result = resolver.resolveArgument(new MethodParameter(method, 0), null, null, null);
|
||||
@@ -60,28 +60,28 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void selectsUniquePageableParameter() throws Exception {
|
||||
void selectsUniquePageableParameter() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("unique", PagedResourcesAssembler.class, Pageable.class);
|
||||
assertSelectsParameter(method, 1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void selectsUniquePageableParameterForQualifiedAssembler() throws Exception {
|
||||
void selectsUniquePageableParameterForQualifiedAssembler() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("unnecessarilyQualified", PagedResourcesAssembler.class, Pageable.class);
|
||||
assertSelectsParameter(method, 1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void selectsUniqueQualifiedPageableParameter() throws Exception {
|
||||
void selectsUniqueQualifiedPageableParameter() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("qualifiedUnique", PagedResourcesAssembler.class, Pageable.class);
|
||||
assertSelectsParameter(method, 1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void selectsQualifiedPageableParameter() throws Exception {
|
||||
void selectsQualifiedPageableParameter() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("qualified", PagedResourcesAssembler.class, Pageable.class,
|
||||
Pageable.class);
|
||||
@@ -89,22 +89,22 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void rejectsAmbiguousPageableParameters() throws Exception {
|
||||
void rejectsAmbiguousPageableParameters() throws Exception {
|
||||
assertRejectsAmbiguity("unqualifiedAmbiguity");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void rejectsAmbiguousPageableParametersForQualifiedAssembler() throws Exception {
|
||||
void rejectsAmbiguousPageableParametersForQualifiedAssembler() throws Exception {
|
||||
assertRejectsAmbiguity("assemblerQualifiedAmbiguity");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void rejectsAmbiguityWithoutMatchingQualifiers() throws Exception {
|
||||
void rejectsAmbiguityWithoutMatchingQualifiers() throws Exception {
|
||||
assertRejectsAmbiguity("noMatchingQualifiers");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-419
|
||||
public void doesNotFailForTemplatedMethodMapping() throws Exception {
|
||||
void doesNotFailForTemplatedMethodMapping() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("methodWithPathVariable", PagedResourcesAssembler.class);
|
||||
Object result = resolver.resolveArgument(new MethodParameter(method, 0), null, null, null);
|
||||
@@ -113,7 +113,7 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-513
|
||||
public void detectsMappingOfInvokedSubType() throws Exception {
|
||||
void detectsMappingOfInvokedSubType() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("methodWithMapping", PagedResourcesAssembler.class);
|
||||
|
||||
@@ -136,7 +136,7 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
});
|
||||
}
|
||||
|
||||
private void assertSelectsParameter(Method method, int expectedIndex) throws Exception {
|
||||
private void assertSelectsParameter(Method method, int expectedIndex) {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
|
||||
@@ -162,7 +162,7 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
static interface Controller {
|
||||
interface Controller {
|
||||
|
||||
void noContext(PagedResourcesAssembler<Object> resolver);
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.AbstractPageRequest;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
@@ -48,7 +48,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
* @author Nick Williams
|
||||
* @author Marcel Overdijk
|
||||
*/
|
||||
public class PagedResourcesAssemblerUnitTests {
|
||||
class PagedResourcesAssemblerUnitTests {
|
||||
|
||||
static final Pageable PAGEABLE = PageRequest.of(0, 20);
|
||||
static final Page<Person> EMPTY_PAGE = new PageImpl<>(Collections.emptyList(), PAGEABLE, 0);
|
||||
@@ -56,13 +56,13 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
HateoasPageableHandlerMethodArgumentResolver resolver = new HateoasPageableHandlerMethodArgumentResolver();
|
||||
PagedResourcesAssembler<Person> assembler = new PagedResourcesAssembler<>(resolver, null);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
WebTestUtils.initWebTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addsNextLinkForFirstPage() {
|
||||
void addsNextLinkForFirstPage() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(0));
|
||||
|
||||
@@ -72,7 +72,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addsPreviousAndNextLinksForMiddlePage() {
|
||||
void addsPreviousAndNextLinksForMiddlePage() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(1));
|
||||
|
||||
@@ -82,7 +82,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addsPreviousLinkForLastPage() {
|
||||
void addsPreviousLinkForLastPage() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(2));
|
||||
|
||||
@@ -92,7 +92,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesBaseUriIfConfigured() {
|
||||
void usesBaseUriIfConfigured() {
|
||||
|
||||
UriComponents baseUri = UriComponentsBuilder.fromUriString("https://foo:9090").build();
|
||||
|
||||
@@ -105,7 +105,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesCustomLinkProvided() {
|
||||
void usesCustomLinkProvided() {
|
||||
|
||||
Link link = Link.of("https://foo:9090", "rel");
|
||||
|
||||
@@ -117,7 +117,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-358
|
||||
public void createsPagedResourcesForOneIndexedArgumentResolver() {
|
||||
void createsPagedResourcesForOneIndexedArgumentResolver() {
|
||||
|
||||
resolver.setOneIndexedParameters(true);
|
||||
|
||||
@@ -128,7 +128,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418, DATACMNS-515
|
||||
public void createsACanonicalLinkWithoutTemplateParameters() {
|
||||
void createsACanonicalLinkWithoutTemplateParameters() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(1));
|
||||
|
||||
@@ -136,7 +136,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-418
|
||||
public void invokesCustomElementResourceAssembler() {
|
||||
void invokesCustomElementResourceAssembler() {
|
||||
|
||||
PersonResourceAssembler personAssembler = new PersonResourceAssembler();
|
||||
|
||||
@@ -150,7 +150,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAMCNS-563
|
||||
public void createsPaginationLinksForOneIndexedArgumentResolverCorrectly() {
|
||||
void createsPaginationLinksForOneIndexedArgumentResolverCorrectly() {
|
||||
|
||||
HateoasPageableHandlerMethodArgumentResolver argumentResolver = new HateoasPageableHandlerMethodArgumentResolver();
|
||||
argumentResolver.setOneIndexedParameters(true);
|
||||
@@ -169,7 +169,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-515
|
||||
public void generatedLinksShouldNotBeTemplated() {
|
||||
void generatedLinksShouldNotBeTemplated() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(1));
|
||||
|
||||
@@ -179,7 +179,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-699
|
||||
public void generatesEmptyPagedResourceWithEmbeddedWrapper() {
|
||||
void generatesEmptyPagedResourceWithEmbeddedWrapper() {
|
||||
|
||||
PagedModel<?> result = assembler.toEmptyModel(EMPTY_PAGE, Person.class);
|
||||
|
||||
@@ -192,17 +192,17 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-699
|
||||
public void emptyPageCreatorRejectsPageWithContent() {
|
||||
void emptyPageCreatorRejectsPageWithContent() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> assembler.toEmptyModel(createPage(1), Person.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-699
|
||||
public void emptyPageCreatorRejectsNullType() {
|
||||
void emptyPageCreatorRejectsNullType() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> assembler.toEmptyModel(EMPTY_PAGE, null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-701
|
||||
public void addsFirstAndLastLinksForMultiplePages() {
|
||||
void addsFirstAndLastLinksForMultiplePages() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(1));
|
||||
|
||||
@@ -211,7 +211,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-701
|
||||
public void addsFirstAndLastLinksForFirstPage() {
|
||||
void addsFirstAndLastLinksForFirstPage() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(0));
|
||||
|
||||
@@ -220,7 +220,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-701
|
||||
public void addsFirstAndLastLinksForLastPage() {
|
||||
void addsFirstAndLastLinksForLastPage() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resources = assembler.toModel(createPage(2));
|
||||
|
||||
@@ -229,7 +229,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-701
|
||||
public void alwaysAddsFirstAndLastLinkIfConfiguredTo() {
|
||||
void alwaysAddsFirstAndLastLinkIfConfiguredTo() {
|
||||
|
||||
PagedResourcesAssembler<Person> assembler = new PagedResourcesAssembler<>(resolver, null);
|
||||
assembler.setForceFirstAndLastRels(true);
|
||||
@@ -241,7 +241,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-802
|
||||
public void usesCustomPagedResources() {
|
||||
void usesCustomPagedResources() {
|
||||
|
||||
RepresentationModelAssembler<Page<Person>, PagedModel<EntityModel<Person>>> assembler = new CustomPagedResourcesAssembler<>(
|
||||
resolver, null);
|
||||
@@ -250,7 +250,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1042
|
||||
public void selfLinkContainsCoordinatesForCurrentPage() {
|
||||
void selfLinkContainsCoordinatesForCurrentPage() {
|
||||
|
||||
PagedModel<EntityModel<Person>> resource = assembler.toModel(createPage(0));
|
||||
|
||||
@@ -297,7 +297,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
|
||||
static class CustomPagedResourcesAssembler<T> extends PagedResourcesAssembler<T> {
|
||||
|
||||
public CustomPagedResourcesAssembler(HateoasPageableHandlerMethodArgumentResolver resolver, UriComponents baseUri) {
|
||||
CustomPagedResourcesAssembler(HateoasPageableHandlerMethodArgumentResolver resolver, UriComponents baseUri) {
|
||||
super(resolver, baseUri);
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ public class PagedResourcesAssemblerUnitTests {
|
||||
|
||||
static class CustomPagedResources<R extends RepresentationModel> extends PagedModel<R> {
|
||||
|
||||
public CustomPagedResources(Collection<R> content, PageMetadata metadata) {
|
||||
CustomPagedResources(Collection<R> content, PageMetadata metadata) {
|
||||
super(content, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
@@ -31,28 +31,28 @@ import org.springframework.http.MediaType;
|
||||
* @soundtrack Richard Spaven - Tribute (Whole Other*)
|
||||
* @since 1.13
|
||||
*/
|
||||
public class ProjectingJackson2HttpMessageConverterUnitTests {
|
||||
class ProjectingJackson2HttpMessageConverterUnitTests {
|
||||
|
||||
ProjectingJackson2HttpMessageConverter converter = new ProjectingJackson2HttpMessageConverter();
|
||||
MediaType ANYTHING_JSON = MediaType.parseMediaType("application/*+json");
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void canReadJsonIntoAnnotatedInterface() {
|
||||
void canReadJsonIntoAnnotatedInterface() {
|
||||
assertThat(converter.canRead(SampleInterface.class, ANYTHING_JSON)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void cannotReadUnannotatedInterface() {
|
||||
void cannotReadUnannotatedInterface() {
|
||||
assertThat(converter.canRead(UnannotatedInterface.class, ANYTHING_JSON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATCMNS-885
|
||||
public void cannotReadClass() {
|
||||
void cannotReadClass() {
|
||||
assertThat(converter.canRead(SampleClass.class, ANYTHING_JSON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-972
|
||||
public void doesNotConsiderTypeVariableBoundTo() throws Throwable {
|
||||
void doesNotConsiderTypeVariableBoundTo() throws Throwable {
|
||||
|
||||
Method method = BaseController.class.getDeclaredMethod("createEntity", AbstractDto.class);
|
||||
Type type = method.getGenericParameterTypes()[0];
|
||||
@@ -61,7 +61,7 @@ public class ProjectingJackson2HttpMessageConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-972
|
||||
public void genericTypeOnConcreteOne() throws Throwable {
|
||||
void genericTypeOnConcreteOne() throws Throwable {
|
||||
|
||||
Method method = ConcreteController.class.getMethod("createEntity", AbstractDto.class);
|
||||
Type type = method.getGenericParameterTypes()[0];
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.web.ProjectingJackson2HttpMessageConverterUnitTests.SampleInterface;
|
||||
@@ -38,7 +38,7 @@ public class ProxyingHandlerMethodArgumentResolverUnitTests {
|
||||
() -> new DefaultConversionService(), true);
|
||||
|
||||
@Test // DATACMNS-776
|
||||
public void supportAnnotatedInterface() throws Exception {
|
||||
void supportAnnotatedInterface() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("with", AnnotatedInterface.class);
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
@@ -47,7 +47,7 @@ public class ProxyingHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-776
|
||||
public void supportsUnannotatedInterfaceFromUserPackage() throws Exception {
|
||||
void supportsUnannotatedInterfaceFromUserPackage() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("with", SampleInterface.class);
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
@@ -56,7 +56,7 @@ public class ProxyingHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-776
|
||||
public void doesNotSupportUnannotatedInterfaceFromSpringNamespace() throws Exception {
|
||||
void doesNotSupportUnannotatedInterfaceFromSpringNamespace() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("with", UnannotatedInterface.class);
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
@@ -65,7 +65,7 @@ public class ProxyingHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-776
|
||||
public void doesNotSupportCoreJavaType() throws Exception {
|
||||
void doesNotSupportCoreJavaType() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("with", List.class);
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
|
||||
@@ -19,10 +19,9 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.web.PageableDefaultUnitTests.*;
|
||||
import static org.springframework.data.web.PageableHandlerMethodArgumentResolver.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -38,19 +37,17 @@ import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentR
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
@Rule public final ExpectedException exception = ExpectedException.none();
|
||||
class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
MethodParameter supportedMethodParameter;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
this.supportedMethodParameter = new MethodParameter(Sample.class.getMethod("supportedMethod", Pageable.class), 0);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void preventsPageSizeFromExceedingMayValueIfConfigured() {
|
||||
void preventsPageSizeFromExceedingMayValueIfConfigured() {
|
||||
|
||||
// Read side
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?page=0&size=200").build();
|
||||
@@ -58,28 +55,32 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
assertSupportedAndResult(supportedMethodParameter, PageRequest.of(0, 100), request);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-1211
|
||||
public void rejectsEmptyPageParameterName() {
|
||||
new ReactivePageableHandlerMethodArgumentResolver().setPageParameterName("");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-1211
|
||||
public void rejectsNullPageParameterName() {
|
||||
new ReactivePageableHandlerMethodArgumentResolver().setPageParameterName(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-1211
|
||||
public void rejectsEmptySizeParameterName() {
|
||||
new ReactivePageableHandlerMethodArgumentResolver().setSizeParameterName("");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-1211
|
||||
public void rejectsNullSizeParameterName() {
|
||||
new ReactivePageableHandlerMethodArgumentResolver().setSizeParameterName(null);
|
||||
@Test // DATACMNS-1211
|
||||
void rejectsEmptyPageParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactivePageableHandlerMethodArgumentResolver().setPageParameterName(""));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void qualifierIsUsedInParameterLookup() throws Exception {
|
||||
void rejectsNullPageParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactivePageableHandlerMethodArgumentResolver().setPageParameterName(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
void rejectsEmptySizeParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactivePageableHandlerMethodArgumentResolver().setSizeParameterName(""));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
void rejectsNullSizeParameterName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactivePageableHandlerMethodArgumentResolver().setSizeParameterName(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
void qualifierIsUsedInParameterLookup() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(Sample.class.getMethod("validQualifier", Pageable.class), 0);
|
||||
|
||||
@@ -89,7 +90,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void usesDefaultPageSizeIfRequestPageSizeIsLessThanOne() {
|
||||
void usesDefaultPageSizeIfRequestPageSizeIsLessThanOne() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?page=0&size=0").build();
|
||||
|
||||
@@ -97,19 +98,17 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void rejectsInvalidCustomDefaultForPageSize() throws Exception {
|
||||
void rejectsInvalidCustomDefaultForPageSize() throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(Sample.class.getMethod("invalidDefaultPageSize", Pageable.class),
|
||||
0);
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectMessage("invalidDefaultPageSize");
|
||||
|
||||
assertSupportedAndResult(parameter, DEFAULT_PAGE_REQUEST);
|
||||
assertThatIllegalStateException().isThrownBy(() -> assertSupportedAndResult(parameter, DEFAULT_PAGE_REQUEST))
|
||||
.withMessageContaining("invalidDefaultPageSize");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void fallsBackToFirstPageIfNegativePageNumberIsGiven() {
|
||||
void fallsBackToFirstPageIfNegativePageNumberIsGiven() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?page=-1").build();
|
||||
|
||||
@@ -117,7 +116,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void pageParamIsNotNumeric() {
|
||||
void pageParamIsNotNumeric() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?page=a").build();
|
||||
|
||||
@@ -125,7 +124,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void sizeParamIsNotNumeric() {
|
||||
void sizeParamIsNotNumeric() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?size=a").build();
|
||||
|
||||
@@ -133,7 +132,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void returnsNullIfFallbackIsUnpagedAndNoParametersGiven() {
|
||||
void returnsNullIfFallbackIsUnpagedAndNoParametersGiven() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -142,7 +141,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void returnsFallbackIfOnlyPageIsGiven() {
|
||||
void returnsFallbackIfOnlyPageIsGiven() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -153,7 +152,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void returnsFallbackIfFallbackIsUnpagedAndOnlySizeIsGiven() {
|
||||
void returnsFallbackIfFallbackIsUnpagedAndOnlySizeIsGiven() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -164,7 +163,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void considersOneIndexedParametersSetting() {
|
||||
void considersOneIndexedParametersSetting() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setOneIndexedParameters(true);
|
||||
@@ -175,7 +174,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void usesNullSortIfNoDefaultIsConfiguredAndPageAndSizeAreGiven() {
|
||||
void usesNullSortIfNoDefaultIsConfiguredAndPageAndSizeAreGiven() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
@@ -190,7 +189,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void oneIndexedParametersDefaultsIndexOutOfRange() {
|
||||
void oneIndexedParametersDefaultsIndexOutOfRange() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setOneIndexedParameters(true);
|
||||
@@ -201,7 +200,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void returnsCorrectPageSizeForOneIndexParameters() {
|
||||
void returnsCorrectPageSizeForOneIndexParameters() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setOneIndexedParameters(true);
|
||||
@@ -212,7 +211,7 @@ public class ReactivePageableHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void detectsFallbackPageableIfNullOneIsConfigured() {
|
||||
void detectsFallbackPageableIfNullOneIsConfigured() {
|
||||
|
||||
ReactivePageableHandlerMethodArgumentResolver resolver = getReactiveResolver();
|
||||
resolver.setFallbackPageable(Pageable.unpaged());
|
||||
|
||||
@@ -19,10 +19,9 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.Sort.Direction.*;
|
||||
import static org.springframework.data.web.SortDefaultUnitTests.*;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -39,19 +38,17 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
static MethodParameter PARAMETER;
|
||||
|
||||
@Rule public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
PARAMETER = new MethodParameter(Controller.class.getMethod("supportedMethod", Sort.class), 0);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void supportsSortParameter() {
|
||||
void supportsSortParameter() {
|
||||
|
||||
ReactiveSortHandlerMethodArgumentResolver resolver = new ReactiveSortHandlerMethodArgumentResolver();
|
||||
|
||||
@@ -59,22 +56,22 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void returnsNullForNoDefault() {
|
||||
void returnsNullForNoDefault() {
|
||||
assertSupportedAndResolvedTo(getParameterOfMethod("supportedMethod"), Sort.unsorted());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void discoversSimpleDefault() {
|
||||
void discoversSimpleDefault() {
|
||||
assertSupportedAndResolvedTo(getParameterOfMethod("simpleDefault"), Sort.by(SORT_FIELDS).ascending());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void discoversSimpleDefaultWithDirection() {
|
||||
void discoversSimpleDefaultWithDirection() {
|
||||
assertSupportedAndResolvedTo(getParameterOfMethod("simpleDefaultWithDirection"), SORT);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void fallbackToGivenDefaultSort() {
|
||||
void fallbackToGivenDefaultSort() {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(Controller.class, "unsupportedMethod", String.class);
|
||||
ReactiveSortHandlerMethodArgumentResolver resolver = new ReactiveSortHandlerMethodArgumentResolver();
|
||||
@@ -85,7 +82,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void fallbackToDefaultDefaultSort() {
|
||||
void fallbackToDefaultDefaultSort() {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(Controller.class, "unsupportedMethod", String.class);
|
||||
ReactiveSortHandlerMethodArgumentResolver resolver = new ReactiveSortHandlerMethodArgumentResolver();
|
||||
@@ -94,7 +91,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void discoversSimpleSortFromRequest() {
|
||||
void discoversSimpleSortFromRequest() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("simpleDefault");
|
||||
Sort reference = Sort.by("bar", "foo");
|
||||
@@ -104,7 +101,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void discoversComplexSortFromRequest() {
|
||||
void discoversComplexSortFromRequest() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("simpleDefault");
|
||||
Sort reference = Sort.by("bar", "foo").and(Sort.by("fizz", "buzz"));
|
||||
@@ -113,7 +110,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void discoversQualifiedSortFromRequest() {
|
||||
void discoversQualifiedSortFromRequest() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("qualifiedSort");
|
||||
Sort reference = Sort.by("bar", "foo");
|
||||
@@ -122,7 +119,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void requestForMultipleSortPropertiesIsUnmarshalledCorrectly() {
|
||||
void requestForMultipleSortPropertiesIsUnmarshalledCorrectly() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get(String.format("foo?sort=%s", SortDefaultUnitTests.SORT_3))
|
||||
.build();
|
||||
@@ -134,7 +131,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void parsesEmptySortToNull() {
|
||||
void parsesEmptySortToNull() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?sort=").build();
|
||||
|
||||
@@ -142,7 +139,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void sortParamIsInvalidProperty() {
|
||||
void sortParamIsInvalidProperty() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?sort=,DESC").build();
|
||||
|
||||
@@ -150,7 +147,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void sortParamIsInvalidPropertyWhenMultiProperty() {
|
||||
void sortParamIsInvalidPropertyWhenMultiProperty() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?sort=property1,,DESC").build();
|
||||
|
||||
@@ -158,24 +155,23 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void rejectsDoubleAnnotatedMethod() {
|
||||
void rejectsDoubleAnnotatedMethod() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("invalid");
|
||||
|
||||
ReactiveSortHandlerMethodArgumentResolver resolver = new ReactiveSortHandlerMethodArgumentResolver();
|
||||
assertThat(resolver.supportsParameter(parameter)).isTrue();
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(SortDefault.class.getSimpleName());
|
||||
exception.expectMessage(SortDefaults.class.getSimpleName());
|
||||
exception.expectMessage(parameter.toString());
|
||||
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() ->
|
||||
resolver.resolveArgumentValue(parameter, null,
|
||||
MockServerWebExchange.from(TestUtils.getWebfluxRequest()));
|
||||
MockServerWebExchange.from(TestUtils.getWebfluxRequest())))
|
||||
.withMessageContaining(SortDefault.class.getSimpleName())
|
||||
.withMessageContaining(SortDefaults.class.getSimpleName()).withMessageContaining(parameter.toString());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void sortParamIsEmptyWhenMultiParams() {
|
||||
void sortParamIsEmptyWhenMultiParams() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?sort=property,DESC&sort=").build();
|
||||
|
||||
@@ -183,7 +179,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void parsesCommaParameterForSort() {
|
||||
void parsesCommaParameterForSort() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?sort=,").build();
|
||||
|
||||
@@ -191,7 +187,7 @@ public class ReactiveSortHandlerMethodArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1211
|
||||
public void doesNotReturnNullWhenAnnotatedWithSortDefault() {
|
||||
void doesNotReturnNullWhenAnnotatedWithSortDefault() {
|
||||
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("foo?sort=").build();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -35,7 +35,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public abstract class SortDefaultUnitTests {
|
||||
abstract class SortDefaultUnitTests {
|
||||
|
||||
static final String SORT_0 = "username";
|
||||
static final String SORT_1 = "username,asc";
|
||||
@@ -48,7 +48,7 @@ public abstract class SortDefaultUnitTests {
|
||||
static final Sort SORT = Sort.by(SORT_DIRECTION, SORT_FIELDS);
|
||||
|
||||
@Test
|
||||
public void parsesSimpleSortStringCorrectly() {
|
||||
void parsesSimpleSortStringCorrectly() {
|
||||
|
||||
assertSortStringParsedInto(Sort.by(Order.asc("username")), SORT_1);
|
||||
assertSortStringParsedInto(Sort.by(Order.asc("username"), //
|
||||
@@ -65,34 +65,34 @@ public abstract class SortDefaultUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSortParameter() {
|
||||
void supportsSortParameter() {
|
||||
assertThat(getResolver().supportsParameter(getParameterOfMethod("supportedMethod"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForNoDefault() throws Exception {
|
||||
void returnsNullForNoDefault() throws Exception {
|
||||
assertSupportedAndResolvedTo(getParameterOfMethod("supportedMethod"), Sort.unsorted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversSimpleDefault() throws Exception {
|
||||
void discoversSimpleDefault() throws Exception {
|
||||
assertSupportedAndResolvedTo(getParameterOfMethod("simpleDefault"), Sort.by(SORT_FIELDS).ascending());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversSimpleDefaultWithDirection() throws Exception {
|
||||
void discoversSimpleDefaultWithDirection() throws Exception {
|
||||
assertSupportedAndResolvedTo(getParameterOfMethod("simpleDefaultWithDirection"), SORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsNonSortParameter() {
|
||||
void rejectsNonSortParameter() {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "unsupportedMethod", String.class);
|
||||
assertThat(getResolver().supportsParameter(parameter)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsDoubleAnnotatedMethod() {
|
||||
void rejectsDoubleAnnotatedMethod() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("invalid");
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class SortDefaultUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversContaineredDefault() throws Exception {
|
||||
void discoversContaineredDefault() throws Exception {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("containeredDefault");
|
||||
Sort reference = Sort.by("foo", "bar");
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.stream.Stream;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -46,17 +46,17 @@ import org.springframework.web.context.request.ServletWebRequest;
|
||||
* @author Nick Williams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitTests {
|
||||
class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitTests {
|
||||
|
||||
static MethodParameter PARAMETER;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
@BeforeAll
|
||||
static void setUp() throws Exception {
|
||||
PARAMETER = new MethodParameter(Controller.class.getMethod("supportedMethod", Sort.class), 0);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-351
|
||||
public void fallbackToGivenDefaultSort() {
|
||||
void fallbackToGivenDefaultSort() {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "unsupportedMethod", String.class);
|
||||
SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();
|
||||
@@ -68,7 +68,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-351
|
||||
public void fallbackToDefaultDefaultSort() {
|
||||
void fallbackToDefaultDefaultSort() {
|
||||
|
||||
MethodParameter parameter = TestUtils.getParameterOfMethod(getControllerClass(), "unsupportedMethod", String.class);
|
||||
SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();
|
||||
@@ -78,7 +78,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversSimpleSortFromRequest() {
|
||||
void discoversSimpleSortFromRequest() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("simpleDefault");
|
||||
Sort reference = Sort.by("bar", "foo");
|
||||
@@ -88,7 +88,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversComplexSortFromRequest() {
|
||||
void discoversComplexSortFromRequest() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("simpleDefault");
|
||||
Sort reference = Sort.by("bar", "foo").and(Sort.by("fizz", "buzz"));
|
||||
@@ -97,7 +97,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversQualifiedSortFromRequest() {
|
||||
void discoversQualifiedSortFromRequest() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("qualifiedSort");
|
||||
Sort reference = Sort.by("bar", "foo");
|
||||
@@ -106,7 +106,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForSortParameterSetToNothing() {
|
||||
void returnsNullForSortParameterSetToNothing() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("supportedMethod");
|
||||
|
||||
@@ -119,7 +119,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-366
|
||||
public void requestForMultipleSortPropertiesIsUnmarshalledCorrectly() {
|
||||
void requestForMultipleSortPropertiesIsUnmarshalledCorrectly() {
|
||||
|
||||
MethodParameter parameter = getParameterOfMethod("supportedMethod");
|
||||
|
||||
@@ -132,7 +132,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-408
|
||||
public void parsesEmptySortToNull() throws Exception {
|
||||
void parsesEmptySortToNull() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "");
|
||||
@@ -141,7 +141,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-408
|
||||
public void sortParamIsInvalidProperty() throws Exception {
|
||||
void sortParamIsInvalidProperty() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", ",DESC");
|
||||
@@ -150,7 +150,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-408
|
||||
public void sortParamIsInvalidPropertyWhenMultiProperty() throws Exception {
|
||||
void sortParamIsInvalidPropertyWhenMultiProperty() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "property1,,DESC");
|
||||
@@ -159,7 +159,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-408
|
||||
public void sortParamIsEmptyWhenMultiParams() throws Exception {
|
||||
void sortParamIsEmptyWhenMultiParams() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "property,DESC");
|
||||
@@ -169,7 +169,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-658
|
||||
public void sortParamHandlesSortOrderAndIgnoreCase() throws Exception {
|
||||
void sortParamHandlesSortOrderAndIgnoreCase() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "property,DESC,IgnoreCase");
|
||||
@@ -179,7 +179,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-658
|
||||
public void sortParamHandlesMultiplePropertiesWithSortOrderAndIgnoreCase() throws Exception {
|
||||
void sortParamHandlesMultiplePropertiesWithSortOrderAndIgnoreCase() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "property1,property2,DESC,IgnoreCase");
|
||||
@@ -189,7 +189,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-658
|
||||
public void sortParamHandlesIgnoreCase() throws Exception {
|
||||
void sortParamHandlesIgnoreCase() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "property,IgnoreCase");
|
||||
@@ -199,7 +199,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-658
|
||||
public void returnsDefaultCaseInsensitive() throws Exception {
|
||||
void returnsDefaultCaseInsensitive() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "");
|
||||
@@ -209,7 +209,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-379
|
||||
public void parsesCommaParameterForSort() throws Exception {
|
||||
void parsesCommaParameterForSort() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", ",");
|
||||
@@ -218,7 +218,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-753, DATACMNS-408
|
||||
public void doesNotReturnNullWhenAnnotatedWithSortDefault() throws Exception {
|
||||
void doesNotReturnNullWhenAnnotatedWithSortDefault() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("sort", "");
|
||||
@@ -228,7 +228,7 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1551
|
||||
public void resolvesDotOnlyInputToDefault() {
|
||||
void resolvesDotOnlyInputToDefault() {
|
||||
|
||||
Stream.of(".", ".,ASC").forEach(it -> {
|
||||
|
||||
|
||||
@@ -32,21 +32,21 @@ import org.springframework.web.context.request.ServletWebRequest;
|
||||
*/
|
||||
class TestUtils {
|
||||
|
||||
public static NativeWebRequest getWebRequest() {
|
||||
static NativeWebRequest getWebRequest() {
|
||||
return new ServletWebRequest(new MockHttpServletRequest());
|
||||
}
|
||||
|
||||
public static MockServerHttpRequest getWebfluxRequest() {
|
||||
static MockServerHttpRequest getWebfluxRequest() {
|
||||
return MockServerHttpRequest.get("foo").build();
|
||||
}
|
||||
|
||||
public static MethodParameter getParameterOfMethod(Class<?> controller, String name, Class<?>... argumentTypes) {
|
||||
static MethodParameter getParameterOfMethod(Class<?> controller, String name, Class<?>... argumentTypes) {
|
||||
|
||||
Method method = getMethod(controller, name, argumentTypes);
|
||||
return new MethodParameter(method, 0);
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> controller, String name, Class<?>... argumentTypes) {
|
||||
static Method getMethod(Class<?> controller, String name, Class<?>... argumentTypes) {
|
||||
|
||||
try {
|
||||
return controller.getMethod(name, argumentTypes);
|
||||
|
||||
@@ -21,14 +21,16 @@ import static org.mockito.Mockito.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.data.web.ProjectingJackson2HttpMessageConverterUnitTests.UnannotatedInterface;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xmlbeam.annotation.XBRead;
|
||||
|
||||
@@ -38,15 +40,15 @@ import org.xmlbeam.annotation.XBRead;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Dr. Kobayashi Maru & The Mothership Connection - Anthem (EPisode One)
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class XmlBeamHttpMessageConverterUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class XmlBeamHttpMessageConverterUnitTests {
|
||||
|
||||
XmlBeamHttpMessageConverter converter = new XmlBeamHttpMessageConverter();
|
||||
|
||||
@Mock HttpInputMessage message;
|
||||
|
||||
@Test // DATACMNS-885
|
||||
public void findsTopLevelElements() throws Exception {
|
||||
void findsTopLevelElements() throws Exception {
|
||||
|
||||
preparePayload("<user><firstname>Dave</firstname><lastname>Matthews</lastname></user>");
|
||||
|
||||
@@ -57,7 +59,7 @@ public class XmlBeamHttpMessageConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-885
|
||||
public void findsNestedElements() throws Exception {
|
||||
void findsNestedElements() throws Exception {
|
||||
|
||||
preparePayload("<user><username><firstname>Dave</firstname><lastname>Matthews</lastname></username></user>");
|
||||
|
||||
@@ -68,29 +70,29 @@ public class XmlBeamHttpMessageConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-885
|
||||
public void supportsAnnotatedInterface() {
|
||||
void supportsAnnotatedInterface() {
|
||||
assertThat(converter.canRead(Customer.class, MediaType.APPLICATION_XML)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-885
|
||||
public void supportsXmlBasedMediaType() {
|
||||
void supportsXmlBasedMediaType() {
|
||||
assertThat(converter.canRead(Customer.class, MediaType.APPLICATION_ATOM_XML)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-885
|
||||
public void doesNotSupportUnannotatedInterface() {
|
||||
void doesNotSupportUnannotatedInterface() {
|
||||
assertThat(converter.canRead(UnannotatedInterface.class, MediaType.APPLICATION_XML)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-885
|
||||
public void supportsInterfaceAfterLookupForDifferrentMediaType() {
|
||||
void supportsInterfaceAfterLookupForDifferrentMediaType() {
|
||||
|
||||
assertThat(converter.canRead(Customer.class, MediaType.APPLICATION_JSON)).isFalse();
|
||||
assertThat(converter.canRead(Customer.class, MediaType.APPLICATION_XML)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1292
|
||||
public void doesNotSupportEntityExpansion() throws Exception {
|
||||
void doesNotSupportEntityExpansion() throws Exception {
|
||||
|
||||
preparePayload("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" //
|
||||
+ "<!DOCTYPE foo [\n" //
|
||||
@@ -107,7 +109,7 @@ public class XmlBeamHttpMessageConverterUnitTests {
|
||||
}
|
||||
|
||||
@ProjectedPayload
|
||||
public interface Customer {
|
||||
interface Customer {
|
||||
|
||||
@XBRead("//firstname")
|
||||
String getFirstname();
|
||||
@@ -116,5 +118,5 @@ public class XmlBeamHttpMessageConverterUnitTests {
|
||||
String getLastname();
|
||||
}
|
||||
|
||||
public interface UnnannotatedInterface {}
|
||||
interface UnnannotatedInterface {}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -57,14 +57,15 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Jens Schauder
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public class EnableSpringDataWebSupportIntegrationTests {
|
||||
class EnableSpringDataWebSupportIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@EnableSpringDataWebSupport
|
||||
static class SampleConfig {
|
||||
|
||||
public @Bean SampleController controller() {
|
||||
@Bean
|
||||
SampleController controller() {
|
||||
return new SampleController();
|
||||
}
|
||||
}
|
||||
@@ -75,7 +76,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
static class PageableResolverCustomizerConfig extends SampleConfig {
|
||||
|
||||
@Bean
|
||||
public PageableHandlerMethodArgumentResolverCustomizer testPageableResolverCustomizer() {
|
||||
PageableHandlerMethodArgumentResolverCustomizer testPageableResolverCustomizer() {
|
||||
return pageableResolver -> pageableResolver.setMaxPageSize(100);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
static class SortResolverCustomizerConfig extends SampleConfig {
|
||||
|
||||
@Bean
|
||||
public SortHandlerMethodArgumentResolverCustomizer testSortResolverCustomizer() {
|
||||
SortHandlerMethodArgumentResolverCustomizer testSortResolverCustomizer() {
|
||||
return sortResolver -> sortResolver.setSortParameter("foo");
|
||||
}
|
||||
}
|
||||
@@ -104,7 +105,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-330
|
||||
public void registersBasicBeanDefinitions() throws Exception {
|
||||
void registersBasicBeanDefinitions() throws Exception {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
@@ -116,7 +117,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-330
|
||||
public void registersHateoasSpecificBeanDefinitions() throws Exception {
|
||||
void registersHateoasSpecificBeanDefinitions() throws Exception {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
@@ -126,7 +127,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-330
|
||||
public void doesNotRegisterHateoasSpecificComponentsIfHateoasNotPresent() throws Exception {
|
||||
void doesNotRegisterHateoasSpecificComponentsIfHateoasNotPresent() throws Exception {
|
||||
|
||||
HidingClassLoader classLoader = HidingClassLoader.hide(Link.class);
|
||||
|
||||
@@ -139,7 +140,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-475
|
||||
public void registersJacksonSpecificBeanDefinitions() throws Exception {
|
||||
void registersJacksonSpecificBeanDefinitions() throws Exception {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
@@ -148,7 +149,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-475
|
||||
public void doesNotRegisterJacksonSpecificComponentsIfJacksonNotPresent() throws Exception {
|
||||
void doesNotRegisterJacksonSpecificComponentsIfJacksonNotPresent() throws Exception {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(HidingClassLoader.hide(ObjectMapper.class),
|
||||
SampleConfig.class);
|
||||
@@ -159,7 +160,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-626
|
||||
public void registersFormatters() {
|
||||
void registersFormatters() {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
|
||||
|
||||
@@ -172,7 +173,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
public void createsProxyForInterfaceBasedControllerMethodParameter() throws Exception {
|
||||
void createsProxyForInterfaceBasedControllerMethodParameter() throws Exception {
|
||||
|
||||
WebApplicationContext applicationContext = WebTestUtils.createApplicationContext(SampleConfig.class);
|
||||
MockMvc mvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
|
||||
@@ -190,7 +191,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-660
|
||||
public void picksUpWebConfigurationMixins() {
|
||||
void picksUpWebConfigurationMixins() {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
@@ -199,7 +200,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-822
|
||||
public void picksUpPageableResolverCustomizer() {
|
||||
void picksUpPageableResolverCustomizer() {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(PageableResolverCustomizerConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
@@ -210,7 +211,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-822
|
||||
public void picksUpSortResolverCustomizer() {
|
||||
void picksUpSortResolverCustomizer() {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SortResolverCustomizerConfig.class);
|
||||
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
|
||||
@@ -221,7 +222,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1237
|
||||
public void configuresProxyingHandlerMethodArgumentResolver() {
|
||||
void configuresProxyingHandlerMethodArgumentResolver() {
|
||||
|
||||
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
|
||||
|
||||
@@ -231,7 +232,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1235
|
||||
public void picksUpEntityPathResolverIfRegistered() {
|
||||
void picksUpEntityPathResolverIfRegistered() {
|
||||
|
||||
WebApplicationContext context = WebTestUtils.createApplicationContext(CustomEntityPathResolver.class);
|
||||
|
||||
|
||||
@@ -19,8 +19,9 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -31,9 +32,9 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.data.web.WebTestUtils;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
@@ -43,25 +44,25 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PageableResourcesAssemblerIntegrationTests {
|
||||
class PageableResourcesAssemblerIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableSpringDataWebSupport
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
public SampleController controller() {
|
||||
SampleController controller() {
|
||||
return new SampleController();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
WebTestUtils.initWebTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void injectsPagedResourcesAssembler() {
|
||||
void injectsPagedResourcesAssembler() {
|
||||
|
||||
WebApplicationContext context = WebTestUtils.createApplicationContext(Config.class);
|
||||
SampleController controller = context.getBean(SampleController.class);
|
||||
@@ -76,7 +77,7 @@ public class PageableResourcesAssemblerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-471
|
||||
public void setsUpPagedResourcesAssemblerFromManualXmlConfig() {
|
||||
void setsUpPagedResourcesAssemblerFromManualXmlConfig() {
|
||||
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("manual.xml", getClass());
|
||||
assertThat(context.getBean(PagedResourcesAssembler.class)).isNotNull();
|
||||
@@ -84,7 +85,7 @@ public class PageableResourcesAssemblerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-471
|
||||
public void setsUpPagedResourcesAssemblerFromJavaConfigXmlConfig() {
|
||||
void setsUpPagedResourcesAssemblerFromJavaConfigXmlConfig() {
|
||||
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("via-config-class.xml", getClass());
|
||||
assertThat(context.getBean(PagedResourcesAssembler.class)).isNotNull();
|
||||
|
||||
@@ -31,10 +31,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Controller
|
||||
public class SampleController {
|
||||
class SampleController {
|
||||
|
||||
@RequestMapping("/proxy")
|
||||
public String someMethod(SampleDto sampleDto) {
|
||||
String someMethod(SampleDto sampleDto) {
|
||||
|
||||
assertThat(sampleDto).isNotNull();
|
||||
assertThat(sampleDto.getName()).isEqualTo("Foo");
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.context.annotation.Bean;
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SampleMixin implements SpringDataJacksonModules {
|
||||
class SampleMixin implements SpringDataJacksonModules {
|
||||
|
||||
@Bean
|
||||
String sampleBean() {
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -46,10 +46,10 @@ import com.jayway.jsonpath.DocumentContext;
|
||||
* @author Jens Schauder
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SpringDataWebConfigurationIntegrationTests {
|
||||
class SpringDataWebConfigurationIntegrationTests {
|
||||
|
||||
@Test // DATACMNS-987
|
||||
public void shouldNotLoadJacksonConverterWhenJacksonNotPresent() {
|
||||
void shouldNotLoadJacksonConverterWhenJacksonNotPresent() {
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
|
||||
@@ -60,7 +60,7 @@ public class SpringDataWebConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-987
|
||||
public void shouldNotLoadJacksonConverterWhenJaywayNotPresent() {
|
||||
void shouldNotLoadJacksonConverterWhenJaywayNotPresent() {
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SpringDataWebConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-987
|
||||
public void shouldNotLoadXBeamConverterWhenXBeamNotPresent() throws Exception {
|
||||
void shouldNotLoadXBeamConverterWhenXBeamNotPresent() throws Exception {
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
|
||||
@@ -82,7 +82,7 @@ public class SpringDataWebConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-987
|
||||
public void shouldLoadAllConvertersWhenDependenciesArePresent() throws Exception {
|
||||
void shouldLoadAllConvertersWhenDependenciesArePresent() throws Exception {
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
|
||||
@@ -93,7 +93,7 @@ public class SpringDataWebConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1152
|
||||
public void usesCustomObjectMapper() {
|
||||
void usesCustomObjectMapper() {
|
||||
|
||||
createConfigWithClassLoader(getClass().getClassLoader(), it -> {
|
||||
|
||||
@@ -111,7 +111,7 @@ public class SpringDataWebConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1386
|
||||
public void doesNotFailWithJacksonMissing() throws Exception {
|
||||
void doesNotFailWithJacksonMissing() throws Exception {
|
||||
ReflectionUtils.getUniqueDeclaredMethods(loadWithout(SpringDataWebConfiguration.class, ObjectMapper.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import static org.springframework.data.web.querydsl.QuerydslPredicateArgumentRes
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -53,13 +53,13 @@ import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
class QuerydslPredicateArgumentResolverUnitTests {
|
||||
|
||||
QuerydslPredicateArgumentResolver resolver;
|
||||
MockHttpServletRequest request;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
resolver = new QuerydslPredicateArgumentResolver(new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE),
|
||||
Optional.empty());
|
||||
@@ -67,30 +67,30 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void supportsParameterReturnsTrueWhenMethodParameterIsPredicateAndAnnotatedCorrectly() {
|
||||
void supportsParameterReturnsTrueWhenMethodParameterIsPredicateAndAnnotatedCorrectly() {
|
||||
assertThat(resolver.supportsParameter(getMethodParameterFor("simpleFind", Predicate.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void supportsParameterReturnsTrueWhenMethodParameterIsPredicateButNotAnnotatedAsSuch() {
|
||||
void supportsParameterReturnsTrueWhenMethodParameterIsPredicateButNotAnnotatedAsSuch() {
|
||||
assertThat(resolver.supportsParameter(getMethodParameterFor("predicateWithoutAnnotation", Predicate.class)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void supportsParameterShouldThrowExceptionWhenMethodParameterIsNoPredicateButAnnotatedAsSuch() {
|
||||
void supportsParameterShouldThrowExceptionWhenMethodParameterIsNoPredicateButAnnotatedAsSuch() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> resolver.supportsParameter(getMethodParameterFor("nonPredicateWithAnnotation", String.class)));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void supportsParameterReturnsFalseWhenMethodParameterIsNoPredicate() {
|
||||
void supportsParameterReturnsFalseWhenMethodParameterIsNoPredicate() {
|
||||
assertThat(resolver.supportsParameter(getMethodParameterFor("nonPredicateWithoutAnnotation", String.class)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void resolveArgumentShouldCreateSingleStringParameterPredicateCorrectly() throws Exception {
|
||||
void resolveArgumentShouldCreateSingleStringParameterPredicateCorrectly() throws Exception {
|
||||
|
||||
request.addParameter("firstname", "rand");
|
||||
|
||||
@@ -101,7 +101,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void resolveArgumentShouldCreateMultipleParametersPredicateCorrectly() throws Exception {
|
||||
void resolveArgumentShouldCreateMultipleParametersPredicateCorrectly() throws Exception {
|
||||
|
||||
request.addParameter("firstname", "rand");
|
||||
request.addParameter("lastname", "al'thor");
|
||||
@@ -113,7 +113,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void resolveArgumentShouldCreateNestedObjectPredicateCorrectly() throws Exception {
|
||||
void resolveArgumentShouldCreateNestedObjectPredicateCorrectly() throws Exception {
|
||||
|
||||
request.addParameter("address.city", "two rivers");
|
||||
|
||||
@@ -126,7 +126,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void resolveArgumentShouldResolveTypePropertyFromPageCorrectly() throws Exception {
|
||||
void resolveArgumentShouldResolveTypePropertyFromPageCorrectly() throws Exception {
|
||||
|
||||
request.addParameter("address.city", "tar valon");
|
||||
|
||||
@@ -137,7 +137,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void resolveArgumentShouldHonorCustomSpecification() throws Exception {
|
||||
void resolveArgumentShouldHonorCustomSpecification() throws Exception {
|
||||
|
||||
request.addParameter("firstname", "egwene");
|
||||
request.addParameter("lastname", "al'vere");
|
||||
@@ -150,7 +150,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void shouldCreatePredicateForNonStringPropertyCorrectly() throws Exception {
|
||||
void shouldCreatePredicateForNonStringPropertyCorrectly() throws Exception {
|
||||
|
||||
request.addParameter("inceptionYear", "978");
|
||||
|
||||
@@ -161,7 +161,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void shouldCreatePredicateForNonStringListPropertyCorrectly() throws Exception {
|
||||
void shouldCreatePredicateForNonStringListPropertyCorrectly() throws Exception {
|
||||
|
||||
request.addParameter("inceptionYear", new String[] { "978", "998" });
|
||||
|
||||
@@ -172,7 +172,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void shouldExcludePropertiesCorrectly() throws Exception {
|
||||
void shouldExcludePropertiesCorrectly() throws Exception {
|
||||
|
||||
request.addParameter("address.street", "downhill");
|
||||
request.addParameter("inceptionYear", "973");
|
||||
@@ -185,7 +185,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void extractTypeInformationShouldUseTypeExtractedFromMethodReturnTypeIfPredicateNotAnnotated() {
|
||||
void extractTypeInformationShouldUseTypeExtractedFromMethodReturnTypeIfPredicateNotAnnotated() {
|
||||
|
||||
TypeInformation<?> type = ReflectionTestUtils.invokeMethod(resolver, "extractTypeInfo",
|
||||
getMethodParameterFor("predicateWithoutAnnotation", Predicate.class));
|
||||
@@ -195,7 +195,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void detectsDomainTypesCorrectly() {
|
||||
void detectsDomainTypesCorrectly() {
|
||||
|
||||
TypeInformation USER_TYPE = ClassTypeInformation.from(User.class);
|
||||
TypeInformation MODELA_AND_VIEW_TYPE = ClassTypeInformation.from(ModelAndView.class);
|
||||
@@ -206,7 +206,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1593
|
||||
public void returnsEmptyPredicateForEmptyInput() throws Exception {
|
||||
void returnsEmptyPredicateForEmptyInput() throws Exception {
|
||||
|
||||
MethodParameter parameter = getMethodParameterFor("predicateWithoutAnnotation", Predicate.class);
|
||||
|
||||
@@ -217,7 +217,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1635
|
||||
public void forwardsNullValueForNullablePredicate() throws Exception {
|
||||
void forwardsNullValueForNullablePredicate() throws Exception {
|
||||
|
||||
MethodParameter parameter = getMethodParameterFor("nullablePredicateWithoutAnnotation", Predicate.class);
|
||||
|
||||
@@ -227,7 +227,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1635
|
||||
public void returnsOptionalIfDeclared() throws Exception {
|
||||
void returnsOptionalIfDeclared() throws Exception {
|
||||
|
||||
MethodParameter parameter = getMethodParameterFor("optionalPredicateWithoutAnnotation", Optional.class);
|
||||
|
||||
@@ -289,7 +289,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
User optionalPredicateWithoutAnnotation(Optional<Predicate> predicate);
|
||||
}
|
||||
|
||||
public static class SampleRepo implements QuerydslBinderCustomizer<QUser> {
|
||||
static class SampleRepo implements QuerydslBinderCustomizer<QUser> {
|
||||
|
||||
@Override
|
||||
public void customize(QuerydslBindings bindings, QUser user) {
|
||||
|
||||
Reference in New Issue
Block a user