#70 - Fixed link build for controllers with type-level mapping parameters.

This commit is contained in:
Dietrich Schulten
2013-05-18 14:01:45 +02:00
committed by Oliver Gierke
parent 0f5afe02ab
commit 3f995ee8f0
2 changed files with 21 additions and 5 deletions

View File

@@ -49,6 +49,7 @@ import org.springframework.web.util.UriTemplate;
*
* @author Ricardo Gladwell
* @author Oliver Gierke
* @author Dietrich Schulten
*/
public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<ControllerLinkBuilder> {
@@ -109,10 +110,9 @@ public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<Co
UriTemplate template = new UriTemplate(mapping);
Map<String, Object> values = new HashMap<String, Object>();
if (classMappingParameters.hasNext()) {
for (String variable : template.getVariableNames()) {
values.put(variable, classMappingParameters.next());
}
Iterator<String> names = template.getVariableNames().iterator();
while (classMappingParameters.hasNext()) {
values.put(names.next(), classMappingParameters.next());
}
for (BoundMethodParameter parameter : PATH_VARIABLE_ACCESSOR.getBoundParameters(invocation)) {

View File

@@ -41,6 +41,7 @@ import org.springframework.web.util.UriComponentsBuilder;
* Unit tests for {@link ControllerLinkBuilder}.
*
* @author Oliver Gierke
* @author Dietrich Schulten
*/
public class ControllerLinkBuilderUnitTest extends TestUtils {
@@ -60,6 +61,17 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
assertThat(link.getHref(), endsWith("/people/15/addresses"));
}
/**
* @see #70
*/
@Test
public void createsLinkToMethodOnParameterizedControllerRoot() {
Link link = linkTo(methodOn(PersonsAddressesController.class, 15).getAddressesForCountry("DE")).withSelfRel();
assertThat(link.getRel(), is(Link.REL_SELF));
assertThat(link.getHref(), endsWith("/people/15/addresses/DE"));
}
@Test
public void createsLinkToSubResource() {
@@ -220,8 +232,12 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
}
@RequestMapping("/people/{id}/addresses")
class PersonsAddressesController {
static class PersonsAddressesController {
@RequestMapping("/{country}")
public HttpEntity<Void> getAddressesForCountry(@PathVariable String country) {
return null;
}
}
@RequestMapping({ "/persons", "/people" })