diff --git a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/NodeApiExpectTest.java b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/NodeApiExpectTest.java index bb96efe8db..c47897f384 100644 --- a/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/NodeApiExpectTest.java +++ b/apis/rackspace-cloudloadbalancers/src/test/java/org/jclouds/rackspace/cloudloadbalancers/features/NodeApiExpectTest.java @@ -137,7 +137,7 @@ public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest { Set extractors = indexToParamExtractor.getUnchecked(entry.getKey()); String paramKey = ((QueryParam) key).value(); Optional paramValue = getParamValue(method, args, extractors, entry, paramKey); - if (paramValue.isPresent()) - queryParamValues.put(paramKey, paramValue.get().toString()); + if (paramValue.isPresent()) { + if (paramValue.get() instanceof Iterable) { + Iterable iterableStrings = transform(Iterable.class.cast(paramValue.get()), toStringFunction()); + queryParamValues.putAll(paramKey, iterableStrings); + } + else { + queryParamValues.put(paramKey, paramValue.get().toString()); + } + } } } diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index 3050d2eba5..1bc0288e2e 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -150,6 +150,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Multimap; import com.google.common.io.Files; import com.google.common.util.concurrent.Futures; @@ -506,6 +507,11 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) public void foo3Nullable(@Nullable @QueryParam("robbie") String robbie) { } + + @FOO + @Path("/") + public void queryParamIterable(@Nullable @QueryParam("foo") Iterable bars) { + } } public void testUnEncodeQuery() { @@ -563,6 +569,55 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { assertEquals(request.getEndpoint().getQuery(), "foo=bar&fooble=baz"); assertEquals(request.getMethod(), "FOO"); } + + public void testQueryParamIterableOneString() throws SecurityException, NoSuchMethodException { + Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Set bars = ImmutableSortedSet. of("1"); + HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/"); + assertEquals(request.getEndpoint().getQuery(), "foo=1"); + assertEquals(request.getMethod(), "FOO"); + } + + public void testQueryParamIterableString() throws SecurityException, NoSuchMethodException { + Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Set bars = ImmutableSortedSet. of("1", "2", "3"); + HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/"); + assertEquals(request.getEndpoint().getQuery(), "foo=1&foo=2&foo=3"); + assertEquals(request.getMethod(), "FOO"); + } + + public void testQueryParamIterableInteger() throws SecurityException, NoSuchMethodException { + Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Set bars = ImmutableSortedSet. of(1, 2, 3); + HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/"); + assertEquals(request.getEndpoint().getQuery(), "foo=1&foo=2&foo=3"); + assertEquals(request.getMethod(), "FOO"); + } + + public void testQueryParamIterableEmpty() throws SecurityException, NoSuchMethodException { + Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Set bars = Collections.emptySet(); + HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/"); + assertEquals(request.getEndpoint().getQuery(), null); + assertEquals(request.getMethod(), "FOO"); + } + + public void testQueryParamIterableNull() throws SecurityException, NoSuchMethodException { + Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + HttpRequest request = factory(TestPath.class).createRequest(method, (Iterable) null); + assertEquals(request.getEndpoint().getHost(), "localhost"); + assertEquals(request.getEndpoint().getPath(), "/"); + assertEquals(request.getEndpoint().getQuery(), null); + assertEquals(request.getMethod(), "FOO"); + } public interface TestPayloadParamVarargs { @POST