SPR-9093: UriTemplate not throwing IllegalArgumentException when URIVariables map missing values
This commit is contained in:
parent
a3bb3769ba
commit
3ec78e2c04
|
|
@ -1002,6 +1002,9 @@ public final class UriComponents {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getValue(String name) {
|
public Object getValue(String name) {
|
||||||
|
if (!this.uriVariables.containsKey(name)) {
|
||||||
|
throw new IllegalArgumentException("Map has no value for '" + name + "'");
|
||||||
|
}
|
||||||
return this.uriVariables.get(name);
|
return this.uriVariables.get(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1010,6 +1013,7 @@ public final class UriComponents {
|
||||||
* URI template variables backed by a variable argument array.
|
* URI template variables backed by a variable argument array.
|
||||||
*/
|
*/
|
||||||
private static class VarArgsTemplateVariables implements UriTemplateVariables {
|
private static class VarArgsTemplateVariables implements UriTemplateVariables {
|
||||||
|
|
||||||
private final Iterator<Object> valueIterator;
|
private final Iterator<Object> valueIterator;
|
||||||
|
|
||||||
public VarArgsTemplateVariables(Object... uriVariableValues) {
|
public VarArgsTemplateVariables(Object... uriVariableValues) {
|
||||||
|
|
@ -1018,7 +1022,7 @@ public final class UriComponents {
|
||||||
|
|
||||||
public Object getValue(String name) {
|
public Object getValue(String name) {
|
||||||
if (!valueIterator.hasNext()) {
|
if (!valueIterator.hasNext()) {
|
||||||
throw new IllegalArgumentException("Not enough variable values available to expand [" + name + "]");
|
throw new IllegalArgumentException("Not enough variable values available to expand '" + name + "'");
|
||||||
}
|
}
|
||||||
return valueIterator.next();
|
return valueIterator.next();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -89,6 +89,15 @@ public class UriTemplateTests {
|
||||||
assertEquals("Invalid expanded template", new URI("http://example.com/hotel%20list/Z%C3%BCrich"), result);
|
assertEquals("Invalid expanded template", new URI("http://example.com/hotel%20list/Z%C3%BCrich"), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void expandMapUnboundVariables() throws Exception {
|
||||||
|
Map<String, String> uriVariables = new HashMap<String, String>(2);
|
||||||
|
uriVariables.put("booking", "42");
|
||||||
|
uriVariables.put("bar", "1");
|
||||||
|
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
|
||||||
|
template.expand(uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void expandEncoded() throws Exception {
|
public void expandEncoded() throws Exception {
|
||||||
UriTemplate template = new UriTemplate("http://example.com/hotel list/{hotel}");
|
UriTemplate template = new UriTemplate("http://example.com/hotel list/{hotel}");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue