DATACMNS-513 - PagedResourcesAssemblerArgumentResolver now correctly resolves mappings for sub-class invocations.
We're now using the newly introduced method on ControllerLinkBuilderFactory that takes both a type and a method to forward the method the invocation is happening on independently from the method being invoked.
This commit is contained in:
33
pom.xml
33
pom.xml
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons</artifactId>
|
||||
<version>1.7.3.BUILD-SNAPSHOT</version>
|
||||
@@ -15,13 +15,13 @@
|
||||
<version>1.3.3.BUILD-SNAPSHOT</version>
|
||||
<relativePath>../spring-data-build/parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
<properties>
|
||||
<jackson1>1.9.7</jackson1>
|
||||
<springhateoas>0.9.0.RELEASE</springhateoas>
|
||||
<springhateoas>0.13.0.BUILD-SNAPSHOT</springhateoas>
|
||||
<dist.key>DATACMNS</dist.key>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@@ -74,7 +74,7 @@
|
||||
<artifactId>spring-web</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
@@ -109,7 +109,7 @@
|
||||
<version>${querydsl}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- EJB Transactions -->
|
||||
<dependency>
|
||||
<groupId>javax.ejb</groupId>
|
||||
@@ -126,21 +126,21 @@
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>el-api</artifactId>
|
||||
<version>${cdi}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.openwebbeans.test</groupId>
|
||||
<artifactId>cditest-owb</artifactId>
|
||||
<version>${webbeans}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.hateoas</groupId>
|
||||
<artifactId>spring-hateoas</artifactId>
|
||||
@@ -152,14 +152,14 @@
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>2.2.3U1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>xmlunit</groupId>
|
||||
<artifactId>xmlunit</artifactId>
|
||||
@@ -175,10 +175,11 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.mysema.maven</groupId>
|
||||
<artifactId>apt-maven-plugin</artifactId>
|
||||
<version>${apt}</version>
|
||||
@@ -205,14 +206,14 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-libs-snapshot</id>
|
||||
<url>http://repo.spring.io/libs-snapshot</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-plugins-release</id>
|
||||
|
||||
@@ -101,7 +101,7 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg
|
||||
private UriComponents resolveBaseUri(MethodParameter parameter) {
|
||||
|
||||
try {
|
||||
Link linkToMethod = linkBuilderFactory.linkTo(parameter.getMethod(), new Object[0]).withSelfRel();
|
||||
Link linkToMethod = linkBuilderFactory.linkTo(parameter.getDeclaringClass(), parameter.getMethod()).withSelfRel();
|
||||
return UriComponentsBuilder.fromUriString(linkToMethod.getHref()).build();
|
||||
} catch (IllegalArgumentException o_O) {
|
||||
return null;
|
||||
|
||||
@@ -27,7 +27,9 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PagedResourcesAssemblerArgumentResolver}.
|
||||
@@ -140,6 +142,30 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
assertThat(result, is(notNullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-513
|
||||
*/
|
||||
@Test
|
||||
public void detectsMappingOfInvokedSubType() throws Exception {
|
||||
|
||||
Method method = Controller.class.getMethod("methodWithMapping", PagedResourcesAssembler.class);
|
||||
|
||||
// Simulate HandlerMethod.HandlerMethodParameter.getDeclaringClass()
|
||||
// as it's returning the invoked class as the declared one
|
||||
MethodParameter methodParameter = new MethodParameter(method, 0) {
|
||||
public java.lang.Class<?> getDeclaringClass() {
|
||||
return SubController.class;
|
||||
}
|
||||
};
|
||||
|
||||
Object result = resolver.resolveArgument(methodParameter, null, null, null);
|
||||
|
||||
assertThat(result, is(instanceOf(PagedResourcesAssembler.class)));
|
||||
UriComponents uriComponents = (UriComponents) ReflectionTestUtils.getField(result, "baseUri");
|
||||
|
||||
assertThat(uriComponents.getPath(), is("/foo/mapping"));
|
||||
}
|
||||
|
||||
private void assertSelectsParameter(Method method, int expectedIndex) throws Exception {
|
||||
|
||||
MethodParameter parameter = new MethodParameter(method, 0);
|
||||
@@ -190,5 +216,13 @@ public class PagedResourcesAssemblerArgumentResolverUnitTests {
|
||||
|
||||
@RequestMapping("/{variable}/foo")
|
||||
void methodWithPathVariable(PagedResourcesAssembler<Object> assembler);
|
||||
|
||||
@RequestMapping("/mapping")
|
||||
Object methodWithMapping(PagedResourcesAssembler<Object> pageable);
|
||||
}
|
||||
|
||||
@RequestMapping("/foo")
|
||||
interface SubController extends Controller {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user