diff --git a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java index 70d8dbe7fe..b32961f0df 100644 --- a/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java +++ b/core/src/main/java/org/jclouds/concurrent/internal/SyncProxy.java @@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkState; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -36,6 +37,7 @@ import javax.inject.Named; import org.jclouds.internal.ClassInvokerArgs; import org.jclouds.internal.ClassInvokerArgsAndReturnVal; import org.jclouds.logging.Logger; +import org.jclouds.reflect.AbstractInvocationHandler; import org.jclouds.rest.annotations.Delegate; import org.jclouds.util.Optionals2; import org.jclouds.util.Throwables2; @@ -47,7 +49,7 @@ import com.google.common.base.Throwables; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.AbstractInvocationHandler; +import com.google.common.reflect.Invokable; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.ProvisionException; import com.google.inject.assistedinject.Assisted; @@ -77,13 +79,14 @@ public final class SyncProxy extends AbstractInvocationHandler { private final Function> optionalConverter; private final Object delegate; private final Class declaring; - private final Map methodMap; - private final Map syncMethodMap; - private final Map> timeoutMap; + private final Map, Invokable>> methodMap; + private final Map, Invokable> syncMethodMap; + private final Map, Optional> timeoutMap; private final LoadingCache delegateMap; private final Map, Class> sync2Async; private static final Set objectMethods = ImmutableSet.copyOf(Object.class.getMethods()); + @SuppressWarnings("unchecked") @Inject @VisibleForTesting SyncProxy(Function> optionalConverter, @@ -96,8 +99,8 @@ public final class SyncProxy extends AbstractInvocationHandler { this.declaring = declaring; this.sync2Async = ImmutableMap.copyOf(sync2Async); - ImmutableMap.Builder methodMapBuilder = ImmutableMap.builder(); - ImmutableMap.Builder syncMethodMapBuilder = ImmutableMap.builder(); + ImmutableMap.Builder, Invokable>> methodMapBuilder = ImmutableMap.builder(); + ImmutableMap.Builder, Invokable> syncMethodMapBuilder = ImmutableMap.builder(); for (Method method : declaring.getMethods()) { if (!objectMethods.contains(method)) { @@ -106,17 +109,17 @@ public final class SyncProxy extends AbstractInvocationHandler { throw new IllegalArgumentException(String.format( "method %s has different typed exceptions than delegated method %s", method, delegatedMethod)); if (delegatedMethod.getReturnType().isAssignableFrom(ListenableFuture.class)) { - methodMapBuilder.put(method, delegatedMethod); + methodMapBuilder.put(Invokable.from(method), Invokable.class.cast(Invokable.from(delegatedMethod))); } else { - syncMethodMapBuilder.put(method, delegatedMethod); + syncMethodMapBuilder.put(Invokable.from(method), Invokable.class.cast(Invokable.from(delegatedMethod))); } } } methodMap = methodMapBuilder.build(); syncMethodMap = syncMethodMapBuilder.build(); - ImmutableMap.Builder> timeoutMapBuilder = ImmutableMap.builder(); - for (Method method : methodMap.keySet()) { + ImmutableMap.Builder, Optional> timeoutMapBuilder = ImmutableMap.builder(); + for (Invokable method : methodMap.keySet()) { timeoutMapBuilder.put(method, timeoutInNanos(method, timeouts)); } timeoutMap = timeoutMapBuilder.build(); @@ -127,7 +130,7 @@ public final class SyncProxy extends AbstractInvocationHandler { } @Override - protected Object handleInvocation(Object o, Method method, Object[] args) throws Exception { + protected Object handleInvocation(Object proxy, Invokable method, List args) throws Throwable { if (method.isAnnotationPresent(Delegate.class)) { Class syncClass = Optionals2.returnTypeOrTypeOfOptional(method); // get the return type of the asynchronous class associated with this client @@ -148,16 +151,16 @@ public final class SyncProxy extends AbstractInvocationHandler { return returnVal; } else if (syncMethodMap.containsKey(method)) { try { - return syncMethodMap.get(method).invoke(delegate, args); + return syncMethodMap.get(method).invoke(delegate, args.toArray()); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } } else { try { Optional timeoutNanos = timeoutMap.get(method); - Method asyncMethod = methodMap.get(method); + Invokable> asyncMethod = methodMap.get(method); String name = asyncMethod.getDeclaringClass().getSimpleName() + "." + asyncMethod.getName(); - ListenableFuture future = ((ListenableFuture) asyncMethod.invoke(delegate, args)); + ListenableFuture future = asyncMethod.invoke(delegate, args.toArray()); if (timeoutNanos.isPresent()) { logger.debug(">> blocking on %s for %s", name, timeoutNanos); return future.get(timeoutNanos.get(), TimeUnit.NANOSECONDS); @@ -175,7 +178,7 @@ public final class SyncProxy extends AbstractInvocationHandler { } // override timeout by values configured in properties(in ms) - private Optional timeoutInNanos(Method method, Map timeouts) { + private Optional timeoutInNanos(Invokable method, Map timeouts) { String className = declaring.getSimpleName(); Optional timeoutMillis = fromNullable(timeouts.get(className + "." + method.getName())) .or(fromNullable(timeouts.get(className))) diff --git a/core/src/main/java/org/jclouds/http/HttpCommand.java b/core/src/main/java/org/jclouds/http/HttpCommand.java index 08499bb82f..b433d24173 100644 --- a/core/src/main/java/org/jclouds/http/HttpCommand.java +++ b/core/src/main/java/org/jclouds/http/HttpCommand.java @@ -133,7 +133,7 @@ public class HttpCommand { public String toString() { if (request instanceof GeneratedHttpRequest) return String.format("[method=%s.%s, request=%s]", GeneratedHttpRequest.class.cast(request).getDeclaring() - .getSimpleName(), GeneratedHttpRequest.class.cast(request).getJavaMethod().getName(), request + .getSimpleName(), GeneratedHttpRequest.class.cast(request).getInvoker().getName(), request .getRequestLine()); else return "[request=" + request.getRequestLine() + "]"; diff --git a/core/src/main/java/org/jclouds/internal/ClassInvokerArgs.java b/core/src/main/java/org/jclouds/internal/ClassInvokerArgs.java index 3c2b047568..427bb13e6b 100644 --- a/core/src/main/java/org/jclouds/internal/ClassInvokerArgs.java +++ b/core/src/main/java/org/jclouds/internal/ClassInvokerArgs.java @@ -21,13 +21,11 @@ package org.jclouds.internal; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; -import java.lang.reflect.Method; import java.util.List; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import com.google.common.reflect.Invokable; /** @@ -71,22 +69,6 @@ public class ClassInvokerArgs { this.invoker = invoker; return self(); } - - /** - * @see ClassInvokerArgs#getInvoker() - */ - @Deprecated - public B invoker(Method method) { - return invoker(Invokable.from(method)); - } - - /** - * @see ClassInvokerArgs#getArgs() - */ - @Deprecated - public B args(Object[] args) { - return args(args == null ? Lists.newArrayList(new Object[] { null }) : Lists.newArrayList(args)); - } /** * @see ClassInvokerArgs#getArgs() diff --git a/core/src/main/java/org/jclouds/rest/InputParamValidator.java b/core/src/main/java/org/jclouds/rest/InputParamValidator.java index 804ab73fee..de10b7d1d8 100644 --- a/core/src/main/java/org/jclouds/rest/InputParamValidator.java +++ b/core/src/main/java/org/jclouds/rest/InputParamValidator.java @@ -21,12 +21,10 @@ package org.jclouds.rest; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Collections2.filter; -import java.lang.reflect.Method; import java.util.List; import javax.inject.Inject; -import org.jclouds.javax.annotation.Nullable; import org.jclouds.predicates.Validator; import org.jclouds.rest.annotations.ParamValidators; @@ -72,12 +70,6 @@ public class InputParamValidator { * @throws IllegalStateException * if validation failed */ - @Deprecated - public void validateMethodParametersOrThrow(Method method, @Nullable Object... args) { - validateMethodParametersOrThrow(Invokable.from(checkNotNull(method, "method")), - Lists.newArrayList(args)); - } - public void validateMethodParametersOrThrow(Invokable method, List args) { try { performMethodValidation(checkNotNull(method, "method"), args); diff --git a/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java b/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java index 98b22130e3..d43c3e8e84 100644 --- a/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java +++ b/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java @@ -44,9 +44,9 @@ public class BindMapToStringPayload implements MapBinder { public R bindToRequest(R request, Map postParams) { checkNotNull(postParams, "postParams"); GeneratedHttpRequest r = GeneratedHttpRequest.class.cast(checkNotNull(request, "request")); - checkArgument(r.getJavaMethod().isAnnotationPresent(Payload.class), - "method %s must have @Payload annotation to use this binder", r.getJavaMethod()); - String payload = r.getJavaMethod().getAnnotation(Payload.class).value(); + checkArgument(r.getInvoker().isAnnotationPresent(Payload.class), + "method %s must have @Payload annotation to use this binder", r.getInvoker()); + String payload = r.getInvoker().getAnnotation(Payload.class).value(); if (postParams.size() > 0) { payload = urlDecode(expand(payload, postParams)); } diff --git a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java index c18750fb6c..f720d3bf04 100644 --- a/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java +++ b/core/src/main/java/org/jclouds/rest/internal/AsyncRestClientProxy.java @@ -22,9 +22,6 @@ import static com.google.common.base.Functions.compose; import static com.google.common.base.Throwables.propagate; import static com.google.common.collect.Iterables.any; import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Sets.difference; -import static com.google.common.util.concurrent.Callables.returning; import static com.google.common.util.concurrent.Futures.immediateFailedFuture; import static com.google.common.util.concurrent.Futures.transform; import static com.google.common.util.concurrent.Futures.withFallback; @@ -80,6 +77,7 @@ import org.jclouds.internal.ClassInvokerArgs; import org.jclouds.internal.ClassInvokerArgsAndReturnVal; import org.jclouds.json.internal.GsonWrapper; import org.jclouds.logging.Logger; +import org.jclouds.reflect.AbstractInvocationHandler; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.InvocationContext; import org.jclouds.rest.annotations.Delegate; @@ -91,20 +89,21 @@ import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.rest.internal.RestAnnotationProcessor.InvokerKey; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; +import com.google.common.base.Objects; import com.google.common.base.Optional; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.base.Supplier; -import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.AbstractInvocationHandler; +import com.google.common.collect.Maps; import com.google.common.reflect.Invokable; import com.google.common.reflect.Parameter; import com.google.common.reflect.TypeToken; @@ -141,6 +140,7 @@ import com.google.inject.assistedinject.Assisted; */ @Singleton public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { + public static interface Factory { Declaring declaring(Class declaring); @@ -180,38 +180,52 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { private final RestAnnotationProcessor annotationProcessor; private final ParseSax.Factory parserFactory; private final Class declaring; + + private static final LoadingCache, Set> delegationMapCache = CacheBuilder.newBuilder().build( + new CacheLoader, Set>() { + public Set load(Class declaring) throws ExecutionException { + FluentIterable> methodsToProcess = FluentIterable + .from(ImmutableSet.copyOf(declaring.getMethods())) + .filter(Predicates.not(Predicates.in(ImmutableSet.copyOf(Object.class.getMethods())))) + .transform(new Function>() { + public Invokable apply(Method in) { + return Invokable.from(in); + } + }).filter(new Predicate>() { + public boolean apply(Invokable in) { + return in.isAnnotationPresent(Path.class) || tryFindHttpMethod(in).isPresent() + || any(in.getParameters(), new Predicate(){ + public boolean apply(Parameter in) { + return in.getType().getRawType().isAssignableFrom(HttpRequest.class); + } + }); + } + }).filter(new Predicate>() { + public boolean apply(Invokable in) { + return in.getReturnType().getRawType().isAssignableFrom(ListenableFuture.class); + } - private static final LoadingCache, Cache>> delegationMapCache = CacheBuilder - .newBuilder().build(new CacheLoader, Cache>>() { - public Cache> load(Class declaring) throws ExecutionException { - Cache> delegationMap = CacheBuilder.newBuilder() - .> build(); - for (Method method : difference(ImmutableSet.copyOf(declaring.getMethods()), - ImmutableSet.copyOf(Object.class.getMethods()))) { - Invokable invoker = Invokable.from(method); - if (isHttpMethod(invoker) || method.isAnnotationPresent(Delegate.class)) { - delegationMap.get(new InvokerKey(invoker), returning(invoker)); - } else if (!method.getDeclaringClass().equals(declaring)) { // potentially overridden - } else if (method.isAnnotationPresent(Provides.class)) { - } - } - return delegationMap; + }); + return Maps.uniqueIndex(methodsToProcess, HashSignatureExceptReturnVal.INSTANCE).keySet(); } }); - private Invokable getDelegateOrNull(Invokable in) { - return delegationMapCache.getUnchecked(declaring).getIfPresent(new InvokerKey(in)); + private static enum HashSignatureExceptReturnVal implements Function, Integer> { + INSTANCE; + public Integer apply(Invokable in) { + int parametersTypeHashCode = hashParameterTypes(in); + return Objects.hashCode(in.getDeclaringClass(), in.getName(), parametersTypeHashCode); + } } - private static boolean isHttpMethod(Invokable invoker) { - return invoker.isAnnotationPresent(Path.class) || tryFindHttpMethod(invoker).isPresent() - || any(invoker.getParameters(), new Predicate() { - public boolean apply(Parameter in) { - return in.getType().isAssignableFrom(HttpRequest.class); - } - }); + private static int hashParameterTypes(Invokable in) { + int parametersTypeHashCode = 0; + for (Parameter param : in.getParameters()) + parametersTypeHashCode += param.getType().hashCode(); + return parametersTypeHashCode; } + private AsyncRestClientProxy(Injector injector, Function> optionalConverter, HttpCommandExecutorService http, ExecutorService userThreads, LoadingCache delegateMap, @@ -236,12 +250,12 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { }; @Override - protected Object handleInvocation(Object proxy, Method method, Object[] args) throws ExecutionException { + protected Object handleInvocation(Object proxy, Invokable method, List args) throws Throwable { if (method.isAnnotationPresent(Provides.class)) { return lookupValueFromGuice(method); } else if (method.isAnnotationPresent(Delegate.class)) { return propagateContextToDelegate(method, args); - } else if (isRestCall(method)) { + } else if (isAsyncOrDelegate(method)) { return createListenableFutureForHttpRequestMappedToMethodAndArgs(method, args); } else { throw new RuntimeException(String.format("Method is not annotated as either http or provider method: %s", @@ -249,12 +263,11 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { } } - private boolean isRestCall(Method method) { - return getDelegateOrNull(Invokable.from(method)) != null - && ListenableFuture.class.isAssignableFrom(method.getReturnType()); + private boolean isAsyncOrDelegate(Invokable method) { + return delegationMapCache.getUnchecked(declaring).contains(HashSignatureExceptReturnVal.INSTANCE.apply(method)); } - private Object propagateContextToDelegate(Method method, Object[] args) throws ExecutionException { + private Object propagateContextToDelegate(Invokable method, List args) throws ExecutionException { Class asyncClass = returnTypeOrTypeOfOptional(method); ClassInvokerArgs cma = ClassInvokerArgs.builder().clazz(asyncClass).invoker(method).args(args).build(); Object returnVal = delegateMap.get(cma); @@ -266,9 +279,9 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { return returnVal; } - private Object lookupValueFromGuice(Method method) { + private Object lookupValueFromGuice(Invokable method) { try { - Type genericReturnType = method.getGenericReturnType(); + Type genericReturnType = method.getReturnType().getType(); try { Annotation qualifier = find(ImmutableList.copyOf(method.getAnnotations()), isQualifierPresent); return getInstanceOfTypeWithQualifier(genericReturnType, qualifier); @@ -320,15 +333,9 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { return injector.getInstance(Key.get(genericReturnType, qualifier)); } - @Deprecated - static Function createResponseParser(ParseSax.Factory parserFactory, Injector injector, - Method method, HttpRequest request) { - return createResponseParser(parserFactory, injector, Invokable.from(method), request); - } - @SuppressWarnings("unchecked") @VisibleForTesting - private static Function createResponseParser(ParseSax.Factory parserFactory, Injector injector, + static Function createResponseParser(ParseSax.Factory parserFactory, Injector injector, Invokable method, HttpRequest request) { Function transformer; Class> handler = getSaxResponseParserClassOrNull(method); @@ -377,14 +384,8 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { return transformer; } - private ListenableFuture createListenableFutureForHttpRequestMappedToMethodAndArgs(Method method, Object[] args) - throws ExecutionException { - return createListenableFutureForHttpRequestMappedToMethodAndArgs(method, Invokable.from(method), - args == null ? newArrayList(new Object[] { null }) : newArrayList(args)); - } - - private ListenableFuture createListenableFutureForHttpRequestMappedToMethodAndArgs(Method method, - Invokable invoker, List args) throws ExecutionException { + private ListenableFuture createListenableFutureForHttpRequestMappedToMethodAndArgs(Invokable invoker, + List args) { String name = invoker.getDeclaringClass().getSimpleName() + "." + invoker.getName(); logger.trace(">> converting %s", name); FutureFallback fallback = fallbacks.getUnchecked(invoker); @@ -394,7 +395,7 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { } ListenableFuture result; try { - GeneratedHttpRequest request = annotationProcessor.createRequest(method, invoker, newArrayList(args)); + GeneratedHttpRequest request = annotationProcessor.createRequest(invoker, args); if (fallback instanceof InvocationContext) { InvocationContext.class.cast(fallback).setContext(request); } @@ -457,13 +458,9 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { private static final long serialVersionUID = 1L; }; - @Deprecated - static Key> getParserOrThrowException(Method method) { - return getParserOrThrowException(Invokable.from(method)); - } - @SuppressWarnings("unchecked") - private static Key> getParserOrThrowException(Invokable method) { + @VisibleForTesting + static Key> getParserOrThrowException(Invokable method) { ResponseParser annotation = method.getAnnotation(ResponseParser.class); if (annotation == null) { @@ -478,9 +475,9 @@ public abstract class AsyncRestClientProxy extends AbstractInvocationHandler { } else if (method.getReturnType().equals(HttpResponse.class) || method.getReturnType().equals(futureHttpResponseLiteral)) { return Key.get(Class.class.cast(IdentityFunction.class)); - } else if (RestAnnotationProcessor.getAcceptHeadersOrNull(method).contains(APPLICATION_JSON)) { + } else if (RestAnnotationProcessor.getAcceptHeaders(method).contains(APPLICATION_JSON)) { return getJsonParserKeyForMethod(method); - } else if (RestAnnotationProcessor.getAcceptHeadersOrNull(method).contains(APPLICATION_XML) + } else if (RestAnnotationProcessor.getAcceptHeaders(method).contains(APPLICATION_XML) || method.isAnnotationPresent(JAXBResponseParser.class)) { return getJAXBParserKeyForMethod(method); } else if (method.getReturnType().equals(String.class) || method.getReturnType().equals(futureStringLiteral)) { diff --git a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java index 989f9bc62e..d66ef3c4d8 100644 --- a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java +++ b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java @@ -20,7 +20,6 @@ package org.jclouds.rest.internal; import static com.google.common.base.Preconditions.checkNotNull; -import java.lang.reflect.Method; import java.net.URI; import java.util.Arrays; import java.util.Collections; @@ -54,7 +53,6 @@ public class GeneratedHttpRequest extends HttpRequest { public static class Builder extends HttpRequest.Builder { protected Class declaring; - protected Method javaMethod; protected Invokable invoker; // args can be null, so cannot use immutable list protected List args = Lists.newArrayList(); @@ -68,16 +66,6 @@ public class GeneratedHttpRequest extends HttpRequest { return this; } - /** - * @see GeneratedHttpRequest#getJavaMethod() - */ - @Deprecated - public Builder javaMethod(Method javaMethod) { - this.javaMethod = checkNotNull(javaMethod, "javaMethod"); - this.invoker(Invokable.from(javaMethod)); - return this; - } - /** * @see GeneratedHttpRequest#getInvoker() */ @@ -116,16 +104,15 @@ public class GeneratedHttpRequest extends HttpRequest { this.caller = Optional.fromNullable(caller); return this; } - + public GeneratedHttpRequest build() { - return new GeneratedHttpRequest(method, endpoint, headers.build(), payload, declaring, javaMethod, invoker, - args, filters.build(), caller); + return new GeneratedHttpRequest(method, endpoint, headers.build(), payload, declaring, invoker, args, + filters.build(), caller); } public Builder fromGeneratedHttpRequest(GeneratedHttpRequest in) { return super.fromHttpRequest(in) .declaring(in.getDeclaring()) - .javaMethod(in.getJavaMethod()) .invoker(in.invoker) .args(in.getArgs()) .caller(in.getCaller().orNull()); @@ -138,20 +125,18 @@ public class GeneratedHttpRequest extends HttpRequest { } private final Class declaring; - private final Method javaMethod; private final Invokable invoker; private final List args; private final Optional caller; protected GeneratedHttpRequest(String method, URI endpoint, Multimap headers, - @Nullable Payload payload, Class declaring, Method javaMethod, Invokable invoker, - Iterable args, Iterable filters, Optional caller) { + @Nullable Payload payload, Class declaring, Invokable invoker, + List args, Iterable filters, Optional caller) { super(method, endpoint, headers, payload, filters); this.declaring = checkNotNull(declaring, "declaring"); - this.javaMethod = checkNotNull(javaMethod, "javaMethod"); this.invoker = checkNotNull(invoker, "invoker"); // TODO make immutable. ImmutableList.of() doesn't accept nulls - this.args = Lists.newArrayList(checkNotNull(args, "args")); + this.args = Collections.unmodifiableList(checkNotNull(args, "args")); this.caller = checkNotNull(caller, "caller"); } @@ -159,20 +144,12 @@ public class GeneratedHttpRequest extends HttpRequest { return declaring; } - /** - * @deprecated see {@link #getInvoker()} - */ - @Deprecated - public Method getJavaMethod() { - return javaMethod; - } - public Invokable getInvoker() { return invoker; } public List getArgs() { - return Collections.unmodifiableList(args); + return args; } public Optional getCaller() { diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 5eb6738a3f..b610605719 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -18,7 +18,6 @@ */ package org.jclouds.rest.internal; import static com.google.common.base.Functions.toStringFunction; -import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; @@ -44,7 +43,6 @@ import static org.jclouds.util.Strings2.replaceTokens; import java.lang.annotation.Annotation; import java.lang.reflect.Array; -import java.lang.reflect.Method; import java.net.URI; import java.util.Collection; import java.util.LinkedHashMap; @@ -104,7 +102,6 @@ import org.jclouds.rest.binders.BindToJsonPayloadWrappedWith; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; -import com.google.common.base.Objects; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Supplier; @@ -118,7 +115,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedListMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.primitives.Chars; @@ -194,15 +190,6 @@ public abstract class RestAnnotationProcessor { @Resource protected Logger logger = Logger.NULL; - static final LoadingCache> methods = CacheBuilder.newBuilder().build( - new CacheLoader>() { - @Override - public Invokable load(Method method) { - return Invokable.from(method); - } - }); - - private static final Function, ? extends Part> ENTRY_TO_PART = new Function, Part>() { @Override public Part apply(Entry from) { @@ -229,45 +216,8 @@ public abstract class RestAnnotationProcessor { this.inputParamValidator = inputParamValidator; this.declaring = declaring; } - - public static class InvokerKey { - private final String name; - private final int parametersTypeHashCode; - private final Class declaringClass; - public InvokerKey(Invokable invoker) { - this.name = invoker.getName(); - this.declaringClass = invoker.getDeclaringClass(); - int parametersTypeHashCode = 0; - for (Parameter param : invoker.getParameters()) - parametersTypeHashCode += param.getType().hashCode(); - this.parametersTypeHashCode = parametersTypeHashCode; - } - - @Override - public int hashCode() { - return Objects.hashCode(declaringClass, name, parametersTypeHashCode); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - InvokerKey that = InvokerKey.class.cast(obj); - return equal(this.declaringClass, that.declaringClass) - && equal(this.name, that.name) - && equal(this.parametersTypeHashCode, that.parametersTypeHashCode); - } - } - - @Deprecated - public GeneratedHttpRequest createRequest(Method method, @Nullable Object... args) { - List list = args == null ? Lists.newArrayList(new Object[] { null }) : Lists.newArrayList(args); - return createRequest(method, methods.getUnchecked(method), list); - } - - public GeneratedHttpRequest createRequest(Method method, Invokable invoker, List args) { - checkNotNull(method, "method"); + public GeneratedHttpRequest createRequest(Invokable invoker, List args) { checkNotNull(invoker, "invoker"); checkNotNull(args, "args"); inputParamValidator.validateMethodParametersOrThrow(invoker, args); @@ -293,7 +243,6 @@ public abstract class RestAnnotationProcessor { } requestBuilder.declaring(declaring) - .javaMethod(method) .invoker(invoker) .args(args) .filters(getFiltersIfAnnotated(invoker)); @@ -549,14 +498,9 @@ public abstract class RestAnnotationProcessor { } return filters; } - - @Deprecated - public static URI getEndpointInParametersOrNull(Method method, @Deprecated Object[] args, Injector injector) { - return getEndpointInParametersOrNull(methods.getUnchecked(method), args != null ? Lists.newArrayList(args) - : ImmutableList.of(), injector); - } - private static URI getEndpointInParametersOrNull(Invokable method, List args, Injector injector) { + @VisibleForTesting + static URI getEndpointInParametersOrNull(Invokable method, List args, Injector injector) { Collection endpointParams = parametersWithAnnotation(method, EndpointParam.class); if (endpointParams.isEmpty()) return null; @@ -603,7 +547,6 @@ public abstract class RestAnnotationProcessor { } @VisibleForTesting - @Deprecated static URI addHostIfMissing(URI original, URI withHost) { checkNotNull(withHost, "URI withHost cannot be null"); checkArgument(withHost.getHost() != null, "URI withHost must have host:" + withHost); @@ -740,12 +683,6 @@ public abstract class RestAnnotationProcessor { return result.build(); } - @Deprecated - public Multimap buildHeaders(Multimap tokenValues, Method method, Object... args) { - return buildHeaders(tokenValues, methods.getUnchecked(method), args != null ? Lists.newArrayList(args) - : ImmutableList.of()); - } - private Multimap buildHeaders(Multimap tokenValues, Invokable method, List args) { Multimap headers = LinkedHashMultimap.create(); @@ -762,24 +699,16 @@ public abstract class RestAnnotationProcessor { } private void addConsumesIfPresentOnTypeOrMethod(Multimap headers, Invokable method) { - List accept = getAcceptHeadersOrNull(method); - if (accept.size() > 0) + Set accept = getAcceptHeaders(method); + if (!accept.isEmpty()) headers.replaceValues(ACCEPT, accept); } // TODO: refactor this out - @VisibleForTesting - static List getAcceptHeadersOrNull(Invokable method) { - List accept = ImmutableList.of(); - if (method.getDeclaringClass().isAnnotationPresent(Consumes.class)) { - Consumes header = method.getDeclaringClass().getAnnotation(Consumes.class); - accept = asList(header.value()); - } - if (method.isAnnotationPresent(Consumes.class)) { - Consumes header = method.getAnnotation(Consumes.class); - accept = asList(header.value()); - } - return accept; + static Set getAcceptHeaders(Invokable method) { + Optional accept = Optional.fromNullable(method.getAnnotation(Consumes.class)).or( + Optional.fromNullable(method.getDeclaringClass().getAnnotation(Consumes.class))); + return (accept.isPresent()) ? ImmutableSet.copyOf(accept.get().value()) : ImmutableSet. of(); } private void addProducesIfPresentOnTypeOrMethod(Multimap headers, Invokable method) { diff --git a/core/src/main/java/org/jclouds/util/Optionals2.java b/core/src/main/java/org/jclouds/util/Optionals2.java index c3d6d24e24..3488aa9923 100644 --- a/core/src/main/java/org/jclouds/util/Optionals2.java +++ b/core/src/main/java/org/jclouds/util/Optionals2.java @@ -18,7 +18,6 @@ */ package org.jclouds.util; -import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; @@ -37,12 +36,6 @@ public class Optionals2 { return returnTypeOrTypeOfOptional(type.getRawType(), type.getType()); } - public static Class returnTypeOrTypeOfOptional(Method method) { - Class syncClass = method.getReturnType(); - Type genericType = method.getGenericReturnType(); - return returnTypeOrTypeOfOptional(syncClass, genericType); - } - private static Class returnTypeOrTypeOfOptional(Class syncClass, Type genericType) { if (syncClass.isAssignableFrom(Optional.class)) { ParameterizedType futureType = ParameterizedType.class.cast(genericType); @@ -57,8 +50,7 @@ public class Optionals2 { return syncClass; } - public static boolean isReturnTypeOptional(Method method) { - return method.getReturnType().isAssignableFrom(Optional.class); + public static boolean isReturnTypeOptional(Invokable method) { + return method.getReturnType().getRawType().isAssignableFrom(Optional.class); } - } diff --git a/core/src/main/java/org/jclouds/util/Throwables2.java b/core/src/main/java/org/jclouds/util/Throwables2.java index 4e14ea0081..aa78fdcf93 100644 --- a/core/src/main/java/org/jclouds/util/Throwables2.java +++ b/core/src/main/java/org/jclouds/util/Throwables2.java @@ -34,6 +34,7 @@ import org.jclouds.rest.ResourceNotFoundException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; import com.google.common.base.Throwables; +import com.google.common.reflect.TypeToken; import com.google.inject.CreationException; import com.google.inject.ProvisionException; import com.google.inject.spi.Message; @@ -120,10 +121,10 @@ public class Throwables2 { // Note this needs to be kept up-to-date with all top-level exceptions jclouds works against @SuppressWarnings( { "unchecked", "rawtypes" }) - public static Exception returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(Class[] exceptionTypes, + public static Exception returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(Iterable> throwables, Exception exception) throws Exception { - for (Class type : exceptionTypes) { - Throwable throwable = getFirstThrowableOfType(exception, type); + for (TypeToken type : throwables) { + Throwable throwable = getFirstThrowableOfType(exception, (Class) type.getRawType()); if (throwable != null) { return (Exception) throwable; } diff --git a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java index 8407f984b5..820d078cb7 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -23,7 +23,6 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Method; import java.util.Properties; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -50,6 +49,8 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; @Test(groups = "unit", testName = "BackoffLimitedRetryHandlerTest") public class BackoffLimitedRetryHandlerTest { @@ -169,9 +170,9 @@ public class BackoffLimitedRetryHandlerTest { .getInstance(RestAnnotationProcessor.Factory.class).declaring(IntegrationTestAsyncClient.class); private HttpCommand createCommand() throws SecurityException, NoSuchMethodException { - Method method = IntegrationTestAsyncClient.class.getMethod("download", String.class); + Invokable method = Invokable.from(IntegrationTestAsyncClient.class.getMethod("download", String.class)); - return new HttpCommand(processor.createRequest(method, "1")); + return new HttpCommand(processor.createRequest(method, ImmutableList. of("1"))); } @Test diff --git a/core/src/test/java/org/jclouds/http/internal/TrackingJavaUrlHttpCommandExecutorService.java b/core/src/test/java/org/jclouds/http/internal/TrackingJavaUrlHttpCommandExecutorService.java index 0a44f93562..eaaaa76bd4 100644 --- a/core/src/test/java/org/jclouds/http/internal/TrackingJavaUrlHttpCommandExecutorService.java +++ b/core/src/test/java/org/jclouds/http/internal/TrackingJavaUrlHttpCommandExecutorService.java @@ -18,7 +18,6 @@ */ package org.jclouds.http.internal; -import java.lang.reflect.Method; import java.util.Collection; import java.util.List; import java.util.concurrent.ExecutorService; @@ -42,6 +41,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; +import com.google.common.reflect.Invokable; import com.google.inject.AbstractModule; import com.google.inject.Module; import com.google.inject.TypeLiteral; @@ -73,16 +73,15 @@ public class TrackingJavaUrlHttpCommandExecutorService extends JavaUrlHttpComman }; } - public static Method getJavaMethodForRequestAtIndex(final Collection commandsInvoked, int index) { - return getJavaMethodForRequest(Iterables.get(commandsInvoked, index)); + public static Invokable getInvokerOfRequestAtIndex(final Collection commandsInvoked, int index) { + return getInvokerOfRequest(Iterables.get(commandsInvoked, index)); } - public static Method getJavaMethodForRequest(HttpCommand commandInvoked) { - return GeneratedHttpRequest.class.cast(commandInvoked.getCurrentRequest()).getJavaMethod(); + public static Invokable getInvokerOfRequest(HttpCommand commandInvoked) { + return GeneratedHttpRequest.class.cast(commandInvoked.getCurrentRequest()).getInvoker(); } - @SuppressWarnings("unchecked") - public static List getJavaArgsForRequestAtIndex(final Collection commandsInvoked, int index) { + public static List getArgsForRequestAtIndex(final Collection commandsInvoked, int index) { return GeneratedHttpRequest.class.cast(Iterables.get(commandsInvoked, index).getCurrentRequest()).getArgs(); } diff --git a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java index d032510bd7..d7c2afcb4b 100644 --- a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java +++ b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java @@ -18,8 +18,6 @@ */ package org.jclouds.rest; -import java.lang.reflect.Method; - import javax.ws.rs.POST; import javax.ws.rs.PathParam; @@ -34,6 +32,8 @@ import org.testng.TestException; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; import com.google.inject.Injector; @Test(groups = "unit") @@ -58,26 +58,26 @@ public class InputParamValidatorTest { */ @Test public void testInputParamsValidation() throws Exception { - Method allParamsValidatedMethod = InputParamValidatorForm.class.getMethod("allParamsValidated", String.class, - String.class); - Method oneParamValidatedMethod = InputParamValidatorForm.class.getMethod("oneParamValidated", String.class, - String.class); + Invokable allParamsValidatedMethod = Invokable.from(InputParamValidatorForm.class.getMethod( + "allParamsValidated", String.class, String.class)); + Invokable oneParamValidatedMethod = Invokable.from(InputParamValidatorForm.class.getMethod( + "oneParamValidated", String.class, String.class)); RestAnnotationProcessor restAnnotationProcessor = factory(InputParamValidatorForm.class); - restAnnotationProcessor.createRequest(allParamsValidatedMethod, "blah", "blah"); - restAnnotationProcessor.createRequest(oneParamValidatedMethod, "blah", "blah"); + restAnnotationProcessor.createRequest(allParamsValidatedMethod, ImmutableList. of("blah", "blah")); + restAnnotationProcessor.createRequest(oneParamValidatedMethod, ImmutableList. of("blah", "blah")); try { - restAnnotationProcessor.createRequest(allParamsValidatedMethod, "BLAH", "blah"); + restAnnotationProcessor.createRequest(allParamsValidatedMethod, ImmutableList. of("BLAH", "blah")); throw new TestException( "AllLowerCaseValidator shouldn't have passed 'BLAH' as a parameter because it's uppercase."); } catch (IllegalArgumentException e) { // supposed to happen - continue } - restAnnotationProcessor.createRequest(oneParamValidatedMethod, "BLAH", "blah"); + restAnnotationProcessor.createRequest(oneParamValidatedMethod, ImmutableList. of("BLAH", "blah")); try { - restAnnotationProcessor.createRequest(oneParamValidatedMethod, "blah", "BLAH"); + restAnnotationProcessor.createRequest(oneParamValidatedMethod, ImmutableList. of("blah", "BLAH")); throw new TestException( "AllLowerCaseValidator shouldn't have passed 'BLAH' as the second parameter because it's uppercase."); } catch (IllegalArgumentException e) { @@ -98,8 +98,8 @@ public class InputParamValidatorTest { @Test(expectedExceptions = ClassCastException.class) public void testWrongPredicateTypeLiteral() throws Exception { - Method method = WrongValidator.class.getMethod("method", Integer.class); - new InputParamValidator(injector).validateMethodParametersOrThrow(method, 55); + Invokable method = Invokable.from(WrongValidator.class.getMethod("method", Integer.class)); + new InputParamValidator(injector).validateMethodParametersOrThrow(method, ImmutableList. of(55)); } private RestAnnotationProcessor factory(Class clazz) { diff --git a/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java b/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java index 9aa1035203..8e48bc5c40 100644 --- a/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java +++ b/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java @@ -21,7 +21,6 @@ package org.jclouds.rest.binders; import static org.testng.Assert.assertEquals; import java.io.File; -import java.lang.reflect.Method; import javax.ws.rs.PathParam; @@ -33,6 +32,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.reflect.Invokable; /** * Tests behavior of {@code BindMapToStringPayload} @@ -53,9 +53,9 @@ public class BindMapToStringPayloadTest { @Test public void testCorrect() throws SecurityException, NoSuchMethodException { - Method testPayload = TestPayload.class.getMethod("testPayload", String.class); + Invokable testPayload = Invokable.from(TestPayload.class.getMethod("testPayload", String.class)); GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .declaring(TestPayload.class).javaMethod(testPayload).args(ImmutableList. of("robot")) + .declaring(TestPayload.class).invoker(testPayload).args(ImmutableList. of("robot")) .method("POST").endpoint("http://localhost").build(); GeneratedHttpRequest newRequest = binder() @@ -67,9 +67,9 @@ public class BindMapToStringPayloadTest { @Test public void testDecodes() throws SecurityException, NoSuchMethodException { - Method testPayload = TestPayload.class.getMethod("changeAdminPass", String.class); + Invokable testPayload = Invokable.from(TestPayload.class.getMethod("changeAdminPass", String.class)); GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .declaring(TestPayload.class).javaMethod(testPayload).args(ImmutableList. of("foo")) + .declaring(TestPayload.class).invoker(testPayload).args(ImmutableList. of("foo")) .method("POST").endpoint("http://localhost").build(); GeneratedHttpRequest newRequest = binder() @@ -81,9 +81,9 @@ public class BindMapToStringPayloadTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testMustHavePayloadAnnotation() throws SecurityException, NoSuchMethodException { - Method noPayload = TestPayload.class.getMethod("noPayload", String.class); + Invokable noPayload = Invokable.from(TestPayload.class.getMethod("noPayload", String.class)); GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .declaring(TestPayload.class).javaMethod(noPayload).args(ImmutableList. of("robot")) + .declaring(TestPayload.class).invoker(noPayload).args(ImmutableList. of("robot")) .method("POST").endpoint("http://localhost").build(); binder().bindToRequest(request, ImmutableMap.of("fooble", "robot")); } diff --git a/core/src/test/java/org/jclouds/rest/functions/PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest.java b/core/src/test/java/org/jclouds/rest/functions/PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest.java index a16f078c7c..6e39c6c157 100644 --- a/core/src/test/java/org/jclouds/rest/functions/PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest.java +++ b/core/src/test/java/org/jclouds/rest/functions/PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest.java @@ -33,6 +33,8 @@ import org.testng.annotations.Test; import com.google.common.base.Optional; import com.google.common.base.Stopwatch; +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; /** * Allows you to use simple api version comparison to determine if a feature is @@ -163,8 +165,8 @@ public class PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest ClassInvokerArgsAndReturnVal getApi(String name, Class type) { try { return ClassInvokerArgsAndReturnVal.builder().clazz(type) - .invoker(EC2AsyncApi.class.getDeclaredMethod("get" + name + "ApiForRegion", String.class)) - .args(new Object[] { "region" }).returnVal("present").build(); + .invoker(Invokable.from(EC2AsyncApi.class.getDeclaredMethod("get" + name + "ApiForRegion", String.class))) + .args(ImmutableList. of("region")).returnVal("present").build(); } catch (Exception e) { throw propagate(e); } diff --git a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java index 60be8f1827..e085b3179f 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java @@ -26,7 +26,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import java.io.IOException; -import java.lang.reflect.Method; import java.util.Date; import java.util.Map.Entry; import java.util.concurrent.ExecutorService; @@ -49,6 +48,7 @@ import org.testng.annotations.Test; import com.google.common.collect.Multimap; import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.TreeMultimap; +import com.google.common.reflect.Invokable; import com.google.inject.AbstractModule; import com.google.inject.Injector; import com.google.inject.name.Names; @@ -160,7 +160,7 @@ public abstract class BaseRestApiTest { assertEquals(request.getRequestLine(), toMatch); } - protected void assertFallbackClassEquals(Method method, @Nullable Class expected) { + protected void assertFallbackClassEquals(Invokable method, @Nullable Class expected) { Fallback fallbackAnnotation = method.getAnnotation(Fallback.class); Class assigned = fallbackAnnotation != null ? fallbackAnnotation.value() : MapHttp4xxCodesToExceptions.class; if (expected == null) @@ -169,13 +169,13 @@ public abstract class BaseRestApiTest { assertEquals(assigned, expected); } - protected void assertSaxResponseParserClassEquals(Method method, @Nullable Class parserClass) { + protected void assertSaxResponseParserClassEquals(Invokable method, @Nullable Class parserClass) { XMLResponseParser annotation = method.getAnnotation(XMLResponseParser.class); Class expected = (annotation != null) ? annotation.value() :null; assertEquals(expected, parserClass); } - protected void assertResponseParserClassEquals(Method method, HttpRequest request, @Nullable Class parserClass) { + protected void assertResponseParserClassEquals(Invokable method, HttpRequest request, @Nullable Class parserClass) { assertEquals(AsyncRestClientProxy.createResponseParser(parserFactory, injector, method, request).getClass(), parserClass); } 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 cf8e4e8a04..3b13893d14 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -35,8 +35,6 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.lang.reflect.Array; -import java.lang.reflect.Method; import java.net.URI; import java.net.URLEncoder; import java.security.NoSuchAlgorithmException; @@ -141,8 +139,10 @@ 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.Lists; import com.google.common.collect.Multimap; import com.google.common.io.Files; +import com.google.common.reflect.Invokable; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.AbstractModule; @@ -467,19 +467,19 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @FOO @Path("/") - @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) + @QueryParams(keys = { "foo", "fooble"}, values = { "bar", "baz"}) public void foo2() { } @FOO @Path("/") - @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) + @QueryParams(keys = { "foo", "fooble"}, values = { "bar", "baz"}) public void foo3(@QueryParam("robbie") String robbie) { } @FOO @Path("/") - @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) + @QueryParams(keys = { "foo", "fooble"}, values = { "bar", "baz"}) public void foo3Nullable(@Nullable @QueryParam("robbie") String robbie) { } @@ -490,8 +490,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQuery() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("foo"); - HttpRequest request = factory(TestQuery.class).createRequest(method, new Object[] {}); + Invokable method = Invokable.from(TestQuery.class.getMethod("foo")); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&x-ms-rubbish=bin"); @@ -499,8 +499,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQuery2() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("foo2"); - HttpRequest request = factory(TestQuery.class).createRequest(method, new Object[] {}); + Invokable method = Invokable.from(TestQuery.class.getMethod("foo2")); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=bar&fooble=baz"); @@ -508,27 +508,23 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQuery3() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("foo3", String.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, new Object[] { "wonder" }); + Invokable method = Invokable.from(TestQuery.class.getMethod("foo3", String.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of("wonder")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=bar&fooble=baz&robbie=wonder"); assertEquals(request.getMethod(), "FOO"); } - @Test + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{robbie\\} for method TestQuery.foo3") public void testNiceNPEQueryParam() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestQuery.class.getMethod("foo3", String.class); - try { - factory(TestPath.class).createRequest(method, (String) null); - } catch (NullPointerException e) { - assertEquals(e.getMessage(), "param{robbie} for method TestQuery.foo3"); - } + Invokable method = Invokable.from(TestQuery.class.getMethod("foo3", String.class)); + factory(TestPath.class).createRequest(method, Lists. newArrayList((String) null)); } public void testNoNPEOnQueryParamWithNullable() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("foo3Nullable", String.class); - HttpRequest request = factory(TestPath.class).createRequest(method, (String) null); + Invokable method = Invokable.from(TestQuery.class.getMethod("foo3Nullable", String.class)); + HttpRequest request = factory(TestPath.class).createRequest(method, Lists. newArrayList((String) null)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "foo=bar&fooble=baz"); @@ -536,9 +532,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableOneString() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); Set bars = ImmutableSortedSet. of("1"); - HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + HttpRequest request = factory(TestPath.class).createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "foo=1"); @@ -546,9 +542,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableString() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); Set bars = ImmutableSortedSet. of("1", "2", "3"); - HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + HttpRequest request = factory(TestPath.class).createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "foo=1&foo=2&foo=3"); @@ -556,9 +552,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableInteger() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); Set bars = ImmutableSortedSet. of(1, 2, 3); - HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + HttpRequest request = factory(TestPath.class).createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), "foo=1&foo=2&foo=3"); @@ -566,9 +562,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableEmpty() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); + Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); Set bars = Collections.emptySet(); - HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { bars }); + HttpRequest request = factory(TestPath.class).createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), null); @@ -576,8 +572,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableNull() throws SecurityException, NoSuchMethodException { - Method method = TestQuery.class.getMethod("queryParamIterable", Iterable.class); - HttpRequest request = factory(TestPath.class).createRequest(method, (Iterable) null); + Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); + HttpRequest request = factory(TestPath.class).createRequest(method, Lists. newArrayList((String) null)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); assertEquals(request.getEndpoint().getQuery(), null); @@ -604,8 +600,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testHttpRequestOptionsNoPayloadParam() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPayloadParamVarargs.class.getMethod("post"); - HttpRequest request = factory(TestQuery.class).createRequest(method); + Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("post")); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList.of()); assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "", "application/octet-stream", false); @@ -618,55 +614,52 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPayloadParamVarargs.class.getMethod("post", Payload.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, Payloads.newStringPayload("foo")); + Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("post", Payload.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(Payloads.newStringPayload("foo"))); assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "foo", "application/octet-stream", false); } public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class); - HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, new TestHttpRequestOptions().payload("fooya")); + Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class)); + HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, ImmutableList. of(new TestHttpRequestOptions().payload("fooya"))); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "fooya", "application/unknown", false); } public void testHeaderAndQueryVarargs() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPayloadParamVarargs.class.getMethod("varargs", Array.newInstance(HttpRequestOptions.class, 0) - .getClass()); - HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, + Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargs", HttpRequestOptions[].class)); + HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, ImmutableList. of( new TestHttpRequestOptions().payload("fooya"), new TestHttpRequestOptions().headerParams(ImmutableMultimap.of("X-header-1", "fooya")), - new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "value"))); + new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "value")))); assertRequestLineEquals(request, "POST http://localhost:9999?key=value HTTP/1.1"); assertNonPayloadHeadersEqual(request, "X-header-1: fooya\n"); assertPayloadEquals(request, "fooya", "application/unknown", false); } public void testHeaderAndQueryVarargsPlusReq() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPayloadParamVarargs.class.getMethod("varargsWithReq", String.class, Array.newInstance(HttpRequestOptions.class, 0) - .getClass()); - HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, "required param", - new Object[]{ new TestHttpRequestOptions().payload("fooya"), + Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargsWithReq", String.class, HttpRequestOptions[].class)); + HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, ImmutableList. of("required param", + new TestHttpRequestOptions().payload("fooya"), new TestHttpRequestOptions().headerParams(ImmutableMultimap.of("X-header-1", "fooya")), - new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "value"))}); + new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "value")))); assertRequestLineEquals(request, "POST http://localhost:9999?key=value HTTP/1.1"); assertNonPayloadHeadersEqual(request, "X-header-1: fooya\n"); assertPayloadEquals(request, "fooya", "application/unknown", false); } public void testDuplicateHeaderAndQueryVarargs() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPayloadParamVarargs.class.getMethod("varargs", Array.newInstance(HttpRequestOptions.class, 0) - .getClass()); - HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, + Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargs", HttpRequestOptions[].class)); + HttpRequest request = factory(TestPayloadParamVarargs.class).createRequest(method, ImmutableList. of( new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "value")), new TestHttpRequestOptions().payload("fooya"), new TestHttpRequestOptions().headerParams(ImmutableMultimap.of("X-header-1", "fooya")), new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "anothervalue")), new TestHttpRequestOptions().headerParams(ImmutableMultimap.of("X-header-1", "fooya again!")), - new TestHttpRequestOptions().payload("last_payload_wins!")); + new TestHttpRequestOptions().payload("last_payload_wins!"))); assertRequestLineEquals(request, "POST http://localhost:9999?key=value&key=anothervalue HTTP/1.1"); assertNonPayloadHeadersEqual(request, "X-header-1: fooya\nX-header-1: fooya again!\n"); assertPayloadEquals(request, "last_payload_wins!", "application/unknown", false); @@ -679,8 +672,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCustomMethod() throws SecurityException, NoSuchMethodException { - Method method = TestCustomMethod.class.getMethod("foo"); - HttpRequest request = factory(TestCustomMethod.class).createRequest(method, new Object[] {}); + Invokable method = Invokable.from(TestCustomMethod.class.getMethod("foo")); + HttpRequest request = factory(TestCustomMethod.class).createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), ""); assertEquals(request.getMethod(), "FOO"); @@ -697,8 +690,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testOverriddenMethod() throws SecurityException, NoSuchMethodException { - Method method = TestOverridden.class.getMethod("foo"); - HttpRequest request = factory(TestOverridden.class).createRequest(method, new Object[] {}); + Invokable method = Invokable.from(TestOverridden.class.getMethod("foo")); + HttpRequest request = factory(TestOverridden.class).createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), ""); assertEquals(request.getMethod(), "POST"); @@ -717,8 +710,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException { - Method method = TestOverriddenEndpoint.class.getMethod("foo"); - HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(method, new Object[] {}); + Invokable method = Invokable.from(TestOverriddenEndpoint.class.getMethod("foo")); + HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPort(), 1111); assertEquals(request.getEndpoint().getPath(), ""); @@ -726,9 +719,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException { - Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class); + Invokable method = Invokable.from(TestOverriddenEndpoint.class.getMethod("foo", URI.class)); HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(method, - new Object[] { URI.create("http://wowsa:8001") }); + ImmutableList. of(URI.create("http://wowsa:8001"))); assertEquals(request.getEndpoint().getHost(), "wowsa"); assertEquals(request.getEndpoint().getPort(), 8001); assertEquals(request.getEndpoint().getPath(), ""); @@ -769,8 +762,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequest() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("post", String.class); - HttpRequest request = factory(TestPost.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPost.class.getMethod("post", String.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -778,8 +771,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequestNullOk1() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("post", String.class); - HttpRequest request = factory(TestPost.class).createRequest(method); + Invokable method = Invokable.from(TestPost.class.getMethod("post", String.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList.of()); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -787,8 +780,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequestNullOk2() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("post", String.class); - HttpRequest request = factory(TestPost.class).createRequest(method, (String) null); + Invokable method = Invokable.from(TestPost.class.getMethod("post", String.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, Lists. newArrayList((String) null)); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -796,9 +789,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequestNullNotOk1() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("postNonnull", String.class); + Invokable method = Invokable.from(TestPost.class.getMethod("postNonnull", String.class)); try { - HttpRequest request = factory(TestPost.class).createRequest(method); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList.of()); Assert.fail("call should have failed with illegal null parameter, not permitted " + request + " to be created"); } catch (NullPointerException e) { Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1") >= 0, @@ -806,20 +799,15 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } } + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "postNonnull parameter 1") public void testCreatePostRequestNullNotOk2() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("postNonnull", String.class); - try { - HttpRequest request = factory(TestPost.class).createRequest(method, (String) null); - Assert.fail("call should have failed with illegal null parameter, not permitted " + request + " to be created"); - } catch (NullPointerException e) { - Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1") >= 0, - "Error message should have referred to parameter 'parameter 1': " + e); - } + Invokable method = Invokable.from(TestPost.class.getMethod("postNonnull", String.class)); + factory(TestPost.class).createRequest(method, Lists. newArrayList((String) null)); } public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("postAsJson", String.class); - HttpRequest request = factory(TestPost.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPost.class.getMethod("postAsJson", String.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -827,8 +815,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("postWithPath", String.class, MapBinder.class); - HttpRequest request = factory(TestPost.class).createRequest(method, "data", new org.jclouds.rest.MapBinder() { + Invokable method = Invokable.from(TestPost.class.getMethod("postWithPath", String.class, MapBinder.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList. of("data", new org.jclouds.rest.MapBinder() { @Override public R bindToRequest(R request, Map postParams) { request.setPayload((String) postParams.get("fooble")); @@ -839,14 +827,14 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public R bindToRequest(R request, Object toBind) { throw new RuntimeException("this shouldn't be used in POST"); } - }); + })); assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1"); assertPayloadEquals(request, "data", "application/unknown", false); } public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("postWithMethodBinder", String.class); - HttpRequest request = factory(TestPost.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPost.class.getMethod("postWithMethodBinder", String.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -854,8 +842,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostWithMethodBinderAndDefaults() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("postWithMethodBinderAndDefaults", String.class); - HttpRequest request = factory(TestPost.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPost.class.getMethod("postWithMethodBinderAndDefaults", String.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -863,8 +851,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostWithPayload() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPost.class.getMethod("testPayload", String.class); - HttpRequest request = factory(TestPost.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPost.class.getMethod("testPayload", String.class)); + HttpRequest request = factory(TestPost.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -892,9 +880,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestMultipartForm.class.getMethod("withStringPart", String.class); - GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method, - "foobledata"); + Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withStringPart", String.class)); + GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method,ImmutableList. of( + "foobledata")); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest,// @@ -905,23 +893,16 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { "----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false); } + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "fooble") public void testMultipartWithStringPartNullNotOkay() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestMultipartForm.class.getMethod("withStringPart", String.class); - try { - GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method, - (String) null); - Assert.fail("call should have failed with illegal null parameter, not permitted " + httpRequest - + " to be created"); - } catch (NullPointerException e) { - Assert.assertTrue(e.toString().indexOf("fooble") >= 0, - "Error message should have referred to parameter 'fooble': " + e); - } + Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withStringPart", String.class)); + factory(TestMultipartForm.class).createRequest(method, Lists. newArrayList((String) null)); } public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class); + Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class)); GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method, - "name", "foobledata"); + ImmutableList. of("name", "foobledata")); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest,// @@ -936,27 +917,20 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { "----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false); } + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{name\\} for method TestMultipartForm.withParamStringPart") public void testMultipartWithParamStringPartNullNotOk() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class); - try { - GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method, - null, "foobledata"); - Assert.fail("call should have failed with illegal null parameter, not permitted " + httpRequest - + " to be created"); - } catch (NullPointerException e) { - Assert.assertTrue(e.toString().indexOf("name") >= 0, - "Error message should have referred to parameter 'name': " + e); - } + Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class)); + factory(TestMultipartForm.class).createRequest(method, Lists. newArrayList(null, "foobledata")); } public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestMultipartForm.class.getMethod("withParamFilePart", String.class, File.class); + Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamFilePart", String.class, File.class)); File file = File.createTempFile("foo", "bar"); Files.append("foobledata", file, UTF_8); file.deleteOnExit(); GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method, - "name", file); + ImmutableList. of("name", file)); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest,// @@ -972,9 +946,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", String.class, byte[].class); + Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", String.class, byte[].class)); GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method, - "name", "goo".getBytes()); + ImmutableList. of("name", "goo".getBytes())); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest,// @@ -991,13 +965,13 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { }; public void testMultipartWithParamFileBinaryPart() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestMultipartForm.class.getMethod("withParamFileBinaryPart", String.class, File.class); + Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamFileBinaryPart", String.class, File.class)); File file = File.createTempFile("foo", "bar"); Files.write(new byte[] { 17, 26, 39, 40, 50 }, file); file.deleteOnExit(); GeneratedHttpRequest httpRequest = factory(TestMultipartForm.class).createRequest(method, - "name", file); + ImmutableList. of("name", file)); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest,// @@ -1125,8 +1099,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testAlternateHttpMethod() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("rowdy", String.class); - HttpRequest request = factory(TestPut.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPut.class.getMethod("rowdy", String.class)); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "ROWDY http://localhost:9999/strings/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -1134,8 +1108,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testAlternateHttpMethodSameArity() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("rowdy", int.class); - HttpRequest request = factory(TestPut.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPut.class.getMethod("rowdy", int.class)); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "ROWDY http://localhost:9999/ints/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -1143,8 +1117,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("putWithMethodBinder", String.class); - HttpRequest request = factory(TestPut.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPut.class.getMethod("putWithMethodBinder", String.class)); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -1152,8 +1126,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutWithMethodProduces() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("putWithMethodBinderProduces", String.class); - HttpRequest request = factory(TestPut.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPut.class.getMethod("putWithMethodBinderProduces", String.class)); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -1162,8 +1136,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testCreatePutWithMethodConsumes() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("putWithMethodBinderConsumes", String.class); - HttpRequest request = factory(TestPut.class).createRequest(method, "data"); + Invokable method = Invokable.from(TestPut.class.getMethod("putWithMethodBinderConsumes", String.class)); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/json\n"); @@ -1181,8 +1155,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testGeneric1() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testGeneric"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testGeneric")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseJson.class); // now test that it works! @@ -1197,8 +1171,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testGeneric2() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testGeneric2"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testGeneric2")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseJson.class); // now test that it works! @@ -1213,8 +1187,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testGeneric3() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testGeneric3"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testGeneric3")); + HttpRequest request = factory(TestPut.class).createRequest(method ,ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseJson.class); // now test that it works! @@ -1229,8 +1203,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrap1() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrap"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); // now test that it works! @@ -1244,8 +1218,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrapValueNamed() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrapValueNamed"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrapValueNamed")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseFirstJsonValueNamed.class); // now test that it works! @@ -1258,15 +1232,15 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testWrapWith() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testWrapWith", String.class); - HttpRequest request = factory(TestPut.class).createRequest(method, "bar"); + Invokable method = Invokable.from(TestPut.class.getMethod("testWrapWith", String.class)); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList. of("bar")); assertPayloadEquals(request, "{\"foo\":\"bar\"}", "application/json", false); } @SuppressWarnings("unchecked") public void testUnwrap2() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrap2"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap2")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); // now test that it works! @@ -1280,8 +1254,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrap3() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrap3"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap3")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); // now test that it works! @@ -1295,8 +1269,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrap4() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrap4"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap4")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); // now test that it works! @@ -1310,8 +1284,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void selectLong() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("selectLong"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("selectLong")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseFirstJsonValueNamed.class); // now test that it works! @@ -1325,8 +1299,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void selectLongAddOne() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("selectLongAddOne"); - HttpRequest request = factory(TestPut.class).createRequest(method); + Invokable method = Invokable.from(TestPut.class.getMethod("selectLongAddOne")); + HttpRequest request = factory(TestPut.class).createRequest(method, ImmutableList.of()); Function> parser = (Function>) AsyncRestClientProxy .createResponseParser(parserFactory, injector, method, request); @@ -1365,26 +1339,26 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testRequestFilter() throws SecurityException, NoSuchMethodException { - Method method = TestRequestFilter.class.getMethod("get"); - HttpRequest request = factory(TestRequestFilter.class).createRequest(method, new Object[] {}); + Invokable method = Invokable.from(TestRequestFilter.class.getMethod("get")); + HttpRequest request = factory(TestRequestFilter.class).createRequest(method, ImmutableList.of()); assertEquals(request.getFilters().size(), 2); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class); assertEquals(request.getFilters().get(1).getClass(), TestRequestFilter2.class); } public void testRequestFilterOverride() throws SecurityException, NoSuchMethodException { - Method method = TestRequestFilter.class.getMethod("getOverride"); - HttpRequest request = factory(TestRequestFilter.class).createRequest(method, new Object[] {}); + Invokable method = Invokable.from(TestRequestFilter.class.getMethod("getOverride")); + HttpRequest request = factory(TestRequestFilter.class).createRequest(method, ImmutableList.of()); assertEquals(request.getFilters().size(), 1); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class); } public void testRequestFilterOverrideOnRequest() throws SecurityException, NoSuchMethodException { - Method method = TestRequestFilter.class.getMethod("getOverride", HttpRequest.class); + Invokable method = Invokable.from(TestRequestFilter.class.getMethod("getOverride", HttpRequest.class)); HttpRequest request = factory(TestRequestFilter.class).createRequest( - method, + method, ImmutableList. of( HttpRequest.builder().method("GET").endpoint("http://localhost") - .addHeader("foo", "bar").build()); + .addHeader("foo", "bar").build())); assertEquals(request.getFilters().size(), 1); assertEquals(request.getHeaders().size(), 1); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class); @@ -1399,8 +1373,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testSkipEncoding() throws SecurityException, NoSuchMethodException { - Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class); - HttpRequest request = factory(TestEncoding.class).createRequest(method, new Object[] { "1", "localhost" }); + Invokable method = Invokable.from(TestEncoding.class.getMethod("twoPaths", String.class, String.class)); + HttpRequest request = factory(TestEncoding.class).createRequest(method, ImmutableList. of("1", "localhost")); assertEquals(request.getEndpoint().getPath(), "/1/localhost"); assertEquals(request.getMethod(), HttpMethod.GET); assertEquals(request.getHeaders().size(), 0); @@ -1408,8 +1382,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testEncodingPath() throws SecurityException, NoSuchMethodException { - Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class); - HttpRequest request = factory(TestEncoding.class).createRequest(method, "/", "localhost" ); + Invokable method = Invokable.from(TestEncoding.class.getMethod("twoPaths", String.class, String.class)); + HttpRequest request = factory(TestEncoding.class).createRequest(method, ImmutableList. of("/", "localhost" )); assertEquals(request.getEndpoint().getPath(), "///localhost"); assertEquals(request.getMethod(), HttpMethod.GET); assertEquals(request.getHeaders().size(), 0); @@ -1428,9 +1402,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(enabled = false) public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class); + Invokable method = Invokable.from(TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class)); HttpRequest request = factory(TestConstantPathParam.class).createRequest(method, - new Object[] { "1", "localhost" }); + ImmutableList. of("1", "localhost")); assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -1473,20 +1447,16 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } } - @Test + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{path\\} for method TestPath.onePath") public void testNiceNPEPathParam() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPath.class.getMethod("onePath", String.class); - try { - factory(TestPath.class).createRequest(method, (String) null); - } catch (NullPointerException e) { - assertEquals(e.getMessage(), "param{path} for method TestPath.onePath"); - } + Invokable method = Invokable.from(TestPath.class.getMethod("onePath", String.class)); + factory(TestPath.class).createRequest(method, Lists. newArrayList((String) null)); } @Test public void testPathParamExtractor() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPath.class.getMethod("onePathParamExtractor", String.class); - HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { "localhost" }); + Invokable method = Invokable.from(TestPath.class.getMethod("onePathParamExtractor", String.class)); + HttpRequest request = factory(TestPath.class).createRequest(method, ImmutableList. of("localhost")); assertRequestLineEquals(request, "GET http://localhost:9999/l HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -1494,8 +1464,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testQueryParamExtractor() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPath.class.getMethod("oneQueryParamExtractor", String.class); - HttpRequest request = factory(TestPath.class).createRequest(method, "localhost"); + Invokable method = Invokable.from(TestPath.class.getMethod("oneQueryParamExtractor", String.class)); + HttpRequest request = factory(TestPath.class).createRequest(method, ImmutableList. of("localhost")); assertRequestLineEquals(request, "GET http://localhost:9999/?one=l HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -1503,21 +1473,17 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testFormParamExtractor() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPath.class.getMethod("oneFormParamExtractor", String.class); - HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { "localhost" }); + Invokable method = Invokable.from(TestPath.class.getMethod("oneFormParamExtractor", String.class)); + HttpRequest request = factory(TestPath.class).createRequest(method, ImmutableList. of("localhost")); assertRequestLineEquals(request, "POST http://localhost:9999/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "one=l", "application/x-www-form-urlencoded", false); } - @Test + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{one\\} for method TestPath.oneFormParamExtractor") public void testNiceNPEFormParam() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPath.class.getMethod("oneFormParamExtractor", String.class); - try { - factory(TestPath.class).createRequest(method, (String) null); - } catch (NullPointerException e) { - assertEquals(e.getMessage(), "param{one} for method TestPath.oneFormParamExtractor"); - } + Invokable method = Invokable.from(TestPath.class.getMethod("oneFormParamExtractor", String.class)); + factory(TestPath.class).createRequest(method, Lists. newArrayList((String) null)); } static class FirstCharacter implements Function { @@ -1541,7 +1507,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @GET @Path("/") - @Headers(keys = { "slash", "hyphen" }, values = { "/{bucket}", "-{bucket}" }) + @Headers(keys = { "slash", "hyphen"}, values = { "/{bucket}", "-{bucket}"}) public void twoHeader(@PathParam("bucket") String path) { } @@ -1560,8 +1526,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException { - Method oneHeader = TestHeader.class.getMethod("twoHeader", String.class); - Multimap headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" }) + Invokable method = Invokable.from(TestHeader.class.getMethod("twoHeader", String.class)); + Multimap headers = factory(TestHeader.class).createRequest(method, ImmutableList. of("robot")) .getHeaders(); assertEquals(headers.size(), 2); assertEquals(headers.get("slash"), ImmutableList.of("/robot")); @@ -1578,17 +1544,17 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException { - Method oneHeader = TestClassHeader.class.getMethod("oneHeader", String.class); - Multimap headers = factory(TestClassHeader.class).createRequest(oneHeader, - new Object[] { "robot" }).getHeaders(); + Invokable method = Invokable.from(TestClassHeader.class.getMethod("oneHeader", String.class)); + Multimap headers = factory(TestClassHeader.class).createRequest(method, + ImmutableList. of("robot")).getHeaders(); assertEquals(headers.size(), 1); assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/robot")); } @Test public void testBuildOneHeader() throws SecurityException, NoSuchMethodException { - Method oneHeader = TestHeader.class.getMethod("oneHeader", String.class); - Multimap headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" }) + Invokable method = Invokable.from(TestHeader.class.getMethod("oneHeader", String.class)); + Multimap headers = factory(TestHeader.class).createRequest(method, ImmutableList. of("robot")) .getHeaders(); assertEquals(headers.size(), 1); assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/robot")); @@ -1596,18 +1562,18 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException { - Method twoHeaders = TestHeader.class.getMethod("twoHeaders", String.class, String.class); - Multimap headers = factory(TestHeader.class).createRequest(twoHeaders, - new Object[] { "robot", "eggs" }).getHeaders(); + Invokable method = Invokable.from(TestHeader.class.getMethod("twoHeaders", String.class, String.class)); + Multimap headers = factory(TestHeader.class).createRequest(method, + ImmutableList. of("robot", "eggs")).getHeaders(); assertEquals(headers.size(), 1); assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/robot/eggs")); } @Test public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException { - Method twoHeadersOutOfOrder = TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class); - Multimap headers = factory(TestHeader.class).createRequest(twoHeadersOutOfOrder, - new Object[] { "robot", "eggs" }).getHeaders(); + Invokable method = Invokable.from(TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class)); + Multimap headers = factory(TestHeader.class).createRequest(method, + ImmutableList. of("robot", "eggs")).getHeaders(); assertEquals(headers.size(), 1); assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/eggs/robot")); } @@ -1620,9 +1586,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testQueryInOptions() throws SecurityException, NoSuchMethodException { - Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class); + Invokable method = Invokable.from(TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class)); String query = factory(TestQueryReplace.class) - .createRequest(oneQuery, new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery(); + .createRequest(method, ImmutableList. of("robot", new TestReplaceQueryOptions())).getEndpoint().getQuery(); assertEquals(query, "x-amz-copy-source=/robot"); } @@ -1641,7 +1607,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @GET @Path("/") - @QueryParams(keys = { "slash", "hyphen" }, values = { "/{bucket}", "-{bucket}" }) + @QueryParams(keys = { "slash", "hyphen"}, values = { "/{bucket}", "-{bucket}"}) public void twoQuery(@PathParam("bucket") String path) { } @@ -1660,8 +1626,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException { - Method oneQuery = TestQueryReplace.class.getMethod("twoQuery", String.class); - String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint() + Invokable method = Invokable.from(TestQueryReplace.class.getMethod("twoQuery", String.class)); + String query = factory(TestQueryReplace.class).createRequest(method, ImmutableList. of("robot")).getEndpoint() .getQuery(); assertEquals(query, "slash=/robot&hyphen=-robot"); } @@ -1676,33 +1642,33 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException { - Method oneQuery = TestClassQuery.class.getMethod("oneQuery", String.class); - String query = factory(TestClassQuery.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint() + Invokable method = Invokable.from(TestClassQuery.class.getMethod("oneQuery", String.class)); + String query = factory(TestClassQuery.class).createRequest(method, ImmutableList. of("robot")).getEndpoint() .getQuery(); assertEquals(query, "x-amz-copy-source=/robot"); } @Test public void testBuildOneQuery() throws SecurityException, NoSuchMethodException { - Method oneQuery = TestQueryReplace.class.getMethod("oneQuery", String.class); - String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint() + Invokable method = Invokable.from(TestQueryReplace.class.getMethod("oneQuery", String.class)); + String query = factory(TestQueryReplace.class).createRequest(method, ImmutableList. of("robot")).getEndpoint() .getQuery(); assertEquals(query, "x-amz-copy-source=/robot"); } @Test public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException { - Method twoQuerys = TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class); - String query = factory(TestQueryReplace.class).createRequest(twoQuerys, new Object[] { "robot", "eggs" }) + Invokable method = Invokable.from(TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class)); + String query = factory(TestQueryReplace.class).createRequest(method, ImmutableList. of("robot", "eggs")) .getEndpoint().getQuery(); assertEquals(query, "x-amz-copy-source=/robot/eggs"); } @Test public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException { - Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class); + Invokable method = Invokable.from(TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class)); String query = factory(TestQueryReplace.class) - .createRequest(twoQuerysOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getQuery(); + .createRequest(method, ImmutableList. of("robot", "eggs")).getEndpoint().getQuery(); assertEquals(query, "x-amz-copy-source=/eggs/robot"); } @@ -1736,19 +1702,19 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, - new PayloadEnclosingImpl(newStringPayload("whoops"))); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of( + new PayloadEnclosingImpl(newStringPayload("whoops")))); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", false); } public void testPutPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class)); PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newStringPayload("whoops")); calculateMD5(payloadEnclosing); - HttpRequest request = factory(TestQuery.class).createRequest(method, payloadEnclosing); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payloadEnclosing)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -1757,12 +1723,12 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class)); PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl( newInputStreamPayload(Strings2.toInputStream("whoops"))); calculateMD5(payloadEnclosing); - HttpRequest request = factory(TestQuery.class).createRequest(method, payloadEnclosing); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payloadEnclosing)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -1770,46 +1736,46 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadChunkedNoContentLength() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("putXfer", Payload.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, newStringPayload("whoops")); + Invokable method = Invokable.from(TestTransformers.class.getMethod("putXfer", Payload.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(newStringPayload("whoops"))); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Transfer-Encoding: chunked\n"); assertPayloadEquals(request, "whoops", "application/unknown", false); } public void testPutPayload() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("put", Payload.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, newStringPayload("whoops")); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(newStringPayload("whoops"))); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", false); } public void testPutPayloadContentDisposition() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("put", Payload.class); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); Payload payload = newStringPayload("whoops"); payload.getContentMetadata().setContentDisposition("attachment; filename=photo.jpg"); - HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", "attachment; filename=photo.jpg", null, null, false); } public void testPutPayloadContentEncoding() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("put", Payload.class); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); Payload payload = newStringPayload("whoops"); payload.getContentMetadata().setContentEncoding("gzip"); - HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", null, "gzip", null, false); } public void testPutPayloadContentLanguage() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestTransformers.class.getMethod("put", Payload.class); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); Payload payload = newStringPayload("whoops"); payload.getContentMetadata().setContentLanguage("en"); - HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", null, null, "en", false); @@ -1819,8 +1785,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { IOException { Payload payload = newStringPayload("whoops"); calculateMD5(payload); - Method method = TestTransformers.class.getMethod("put", Payload.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", true); @@ -1829,8 +1795,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testPutInputStreamPayload() throws SecurityException, NoSuchMethodException, IOException { Payload payload = newInputStreamPayload(Strings2.toInputStream("whoops")); payload.getContentMetadata().setContentLength((long) "whoops".length()); - Method method = TestTransformers.class.getMethod("put", Payload.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", false); @@ -1840,28 +1806,27 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { NoSuchMethodException { Payload payload = newStringPayload("whoops"); calculateMD5(payload); - Method method = TestTransformers.class.getMethod("put", Payload.class); - HttpRequest request = factory(TestQuery.class).createRequest(method, payload); + Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + HttpRequest request = factory(TestQuery.class).createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", true); } public void testInputStreamListenableFuture() throws SecurityException, NoSuchMethodException { - Method method = TestTransformers.class.getMethod("futureInputStream"); + Invokable method = Invokable.from(TestTransformers.class.getMethod("futureInputStream")); Class> transformer = unwrap(factory(TestTransformers.class), method); assertEquals(transformer, ReturnInputStream.class); } @SuppressWarnings("unchecked") - public static Class> unwrap(RestAnnotationProcessor processor, - Method method) { - return (Class>) AsyncRestClientProxy.getParserOrThrowException(method) - .getTypeLiteral().getRawType(); + public static Class> unwrap(RestAnnotationProcessor processor, Invokable method) { + return (Class>) AsyncRestClientProxy + .getParserOrThrowException(method).getTypeLiteral().getRawType(); } public void testURIListenableFuture() throws SecurityException, NoSuchMethodException { - Method method = TestTransformers.class.getMethod("futureUri"); + Invokable method = Invokable.from(TestTransformers.class.getMethod("futureUri")); Class> transformer = unwrap(factory(TestTransformers.class), method); assertEquals(transformer, ParseURIFromListOrLocationHeaderIf20x.class); } @@ -1878,26 +1843,23 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } - @SuppressWarnings("static-access") @Test(expectedExceptions = { RuntimeException.class }) public void testNoTransformer() throws SecurityException, NoSuchMethodException { - Method method = TestTransformers.class.getMethod("noTransformer"); + Invokable method = Invokable.from(TestTransformers.class.getMethod("noTransformer")); AsyncRestClientProxy.getParserOrThrowException(method); } public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException { - RestAnnotationProcessor processor = factory(TestTransformers.class); - Method method = TestTransformers.class.getMethod("oneTransformerWithContext"); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .method("GET").endpoint("http://localhost").declaring(TestTransformers.class) - .javaMethod(method).args(new Object[] {}).build(); - Function transformer = AsyncRestClientProxy.createResponseParser(parserFactory, injector, method, request); + .invoker(Invokable.from(TestTransformers.class.getMethod("oneTransformerWithContext"))).build(); + Function transformer = AsyncRestClientProxy.createResponseParser(parserFactory, injector, request.getInvoker(), request); assertEquals(transformer.getClass(), ReturnStringIf200Context.class); assertEquals(((ReturnStringIf200Context) transformer).request, request); } public void testOneTransformer() throws SecurityException, NoSuchMethodException { - Method method = TestTransformers.class.getMethod("oneTransformer"); + Invokable method = Invokable.from(TestTransformers.class.getMethod("oneTransformer")); Class> transformer = unwrap(factory(TestTransformers.class), method); assertEquals(transformer, ReturnStringIf2xx.class); } @@ -1954,8 +1916,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException { Date date = new Date(); GetOptions options = GetOptions.Builder.ifModifiedSince(date); - Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions[].class); - HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1", options }); + Invokable method = Invokable.from(TestRequest.class.getMethod("get", String.class, HttpRequestOptions[].class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1", options)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getMethod(), HttpMethod.GET); @@ -1968,8 +1930,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException { Date date = new Date(); GetOptions options = GetOptions.Builder.ifModifiedSince(date); - Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1", options }); + Invokable method = Invokable.from(TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1", options)); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getMethod(), HttpMethod.GET); @@ -1988,16 +1950,16 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetOptionsThatProducesQuery() throws SecurityException, NoSuchMethodException, IOException { PrefixOptions options = new PrefixOptions().withPrefix("1"); - Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1", options }); + Invokable method = Invokable.from(TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1", options)); assertRequestLineEquals(request, "GET http://localhost:9999/1?prefix=1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: localhost:9999\n"); assertPayloadEquals(request, null, null, false); } public void testCreateGetQuery() throws SecurityException, NoSuchMethodException { - Method method = TestRequest.class.getMethod("getQuery", String.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1" }); + Invokable method = Invokable.from(TestRequest.class.getMethod("getQuery", String.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getQuery(), "max-keys=0"); @@ -2006,8 +1968,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException { - Method method = TestRequest.class.getMethod("getQueryNull", String.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1" }); + Invokable method = Invokable.from(TestRequest.class.getMethod("getQueryNull", String.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getQuery(), "acl"); @@ -2016,8 +1978,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreateGetQueryEmpty() throws SecurityException, NoSuchMethodException { - Method method = TestRequest.class.getMethod("getQueryEmpty", String.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1" }); + Invokable method = Invokable.from(TestRequest.class.getMethod("getQueryEmpty", String.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getEndpoint().getQuery(), "acl="); @@ -2034,8 +1996,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetOptionsThatProducesPayload() throws SecurityException, NoSuchMethodException, IOException { PayloadOptions options = new PayloadOptions(); - Method method = TestRequest.class.getMethod("putOptions", String.class, HttpRequestOptions.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, "1", options); + Invokable method = Invokable.from(TestRequest.class.getMethod("putOptions", String.class, HttpRequestOptions.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1", options)); assertRequestLineEquals(request, "PUT http://localhost:9999/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: localhost:9999\n"); @@ -2050,8 +2012,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(dataProvider = "strings") public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException, UnsupportedEncodingException { - Method method = TestRequest.class.getMethod("get", String.class, String.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, key, "localhost"); + Invokable method = Invokable.from(TestRequest.class.getMethod("get", String.class, String.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of(key, "localhost")); assertEquals(request.getEndpoint().getHost(), "localhost"); String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20"); assertEquals(request.getEndpoint().getRawPath(), expectedPath); @@ -2062,8 +2024,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutRequest() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestRequest.class.getMethod("put", String.class, String.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, "111", "data"); + Invokable method = Invokable.from(TestRequest.class.getMethod("put", String.class, String.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("111", "data")); assertRequestLineEquals(request, "PUT http://localhost:9999/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -2071,8 +2033,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutHeader() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestRequest.class.getMethod("putHeader", String.class, String.class); - HttpRequest request = factory(TestRequest.class).createRequest(method, "1", "data"); + Invokable method = Invokable.from(TestRequest.class.getMethod("putHeader", String.class, String.class)); + HttpRequest request = factory(TestRequest.class).createRequest(method, ImmutableList. of("1", "data")); assertRequestLineEquals(request, "PUT http://localhost:9999/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "foo: --1--\n"); @@ -2090,9 +2052,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException { - Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class); + Invokable method = Invokable.from(TestVirtualHostMethod.class.getMethod("get", String.class, String.class)); HttpRequest request = factory(TestVirtualHostMethod.class).createRequest(method, - new Object[] { "1", "localhost" }); + ImmutableList. of("1", "localhost")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getMethod(), HttpMethod.GET); @@ -2114,8 +2076,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testVirtualHost() throws SecurityException, NoSuchMethodException { - Method method = TestVirtualHost.class.getMethod("get", String.class, String.class); - HttpRequest request = factory(TestVirtualHost.class).createRequest(method, new Object[] { "1", "localhost" }); + Invokable method = Invokable.from(TestVirtualHost.class.getMethod("get", String.class, String.class)); + HttpRequest request = factory(TestVirtualHost.class).createRequest(method, ImmutableList. of("1", "localhost")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getMethod(), HttpMethod.GET); @@ -2125,8 +2087,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testHostPrefix() throws SecurityException, NoSuchMethodException { - Method method = TestVirtualHost.class.getMethod("getPrefix", String.class, String.class); - HttpRequest request = factory(TestVirtualHost.class).createRequest(method, new Object[] { "1", "holy" }); + Invokable method = Invokable.from(TestVirtualHost.class.getMethod("getPrefix", String.class, String.class)); + HttpRequest request = factory(TestVirtualHost.class).createRequest(method, ImmutableList. of("1", "holy")); assertEquals(request.getEndpoint().getHost(), "holy.localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); assertEquals(request.getMethod(), HttpMethod.GET); @@ -2135,8 +2097,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testHostPrefixEmpty() throws SecurityException, NoSuchMethodException { - Method method = TestVirtualHost.class.getMethod("getPrefix", String.class, String.class); - factory(TestVirtualHost.class).createRequest(method, "1", ""); + Invokable method = Invokable.from(TestVirtualHost.class.getMethod("getPrefix", String.class, String.class)); + factory(TestVirtualHost.class).createRequest(method, ImmutableList. of("1", "")); } public interface TestHeaders { @@ -2155,27 +2117,27 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testOneHeader() throws SecurityException, NoSuchMethodException, ExecutionException { - Method method = TestHeaders.class.getMethod("oneHeader", String.class); - Multimap headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of(), method, "robot"); + Invokable method = Invokable.from(TestHeaders.class.getMethod("oneHeader", String.class)); + Multimap headers = factory(TestHeaders.class).createRequest(method, + ImmutableList. of("robot")).getHeaders(); assertEquals(headers.size(), 1); assertEquals(headers.get("header"), ImmutableList.of("robot")); } @Test public void testOneIntHeader() throws SecurityException, NoSuchMethodException, ExecutionException { - Method method = TestHeaders.class.getMethod("oneIntHeader", int.class); - Multimap headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of(), method, 1); + Invokable method = Invokable.from(TestHeaders.class.getMethod("oneIntHeader", int.class)); + Multimap headers = factory(TestHeaders.class).createRequest(method, + ImmutableList. of(1)).getHeaders(); assertEquals(headers.size(), 1); assertEquals(headers.get("header"), ImmutableList.of("1")); } @Test public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException, ExecutionException { - Method method = TestHeaders.class.getMethod("twoDifferentHeaders", String.class, String.class); - Multimap headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of(), method, "robot", "egg"); + Invokable method = Invokable.from(TestHeaders.class.getMethod("twoDifferentHeaders", String.class, String.class)); + Multimap headers = factory(TestHeaders.class).createRequest(method, + ImmutableList. of("robot", "egg")).getHeaders(); assertEquals(headers.size(), 2); assertEquals(headers.get("header1"), ImmutableList.of("robot")); assertEquals(headers.get("header2"), ImmutableList.of("egg")); @@ -2183,9 +2145,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException, ExecutionException { - Method method = TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class); - Multimap headers = factory(TestHeaders.class).buildHeaders( - ImmutableMultimap. of(), method, "robot", "egg"); + Invokable method = Invokable.from(TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class)); + Multimap headers = factory(TestHeaders.class).createRequest(method, + ImmutableList. of("robot", "egg")).getHeaders(); assertEquals(headers.size(), 2); Collection values = headers.get("header"); assert values.contains("robot"); @@ -2223,11 +2185,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } - @SuppressWarnings("static-access") @Test public void testOneEndpointParam() throws SecurityException, NoSuchMethodException, ExecutionException { - Method method = TestEndpointParams.class.getMethod("oneEndpointParam", String.class); - URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method, new Object[] { "robot" }, + Invokable method = Invokable.from(TestEndpointParams.class.getMethod("oneEndpointParam", String.class)); + URI uri = RestAnnotationProcessor.getEndpointInParametersOrNull(method, ImmutableList. of("robot"), injector); assertEquals(uri, URI.create("robot")); @@ -2235,9 +2196,9 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = IllegalStateException.class) public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException, ExecutionException { - Method method = TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class); - factory(TestEndpointParams.class).getEndpointInParametersOrNull(method, - new Object[] { "robot", "egg" }, injector); + Invokable method = Invokable.from(TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class)); + RestAnnotationProcessor.getEndpointInParametersOrNull(method, + ImmutableList. of("robot", "egg"), injector); } public interface TestPayload { @@ -2257,8 +2218,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testPut() throws SecurityException, NoSuchMethodException, IOException { RestAnnotationProcessor processor = factory(TestPayload.class); - Method method = TestPayload.class.getMethod("put", String.class); - GeneratedHttpRequest request = processor.createRequest(method, "test"); + Invokable method = Invokable.from(TestPayload.class.getMethod("put", String.class)); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("test")); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -2268,8 +2229,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void putWithPath() throws SecurityException, NoSuchMethodException, IOException { RestAnnotationProcessor processor = factory(TestPayload.class); - Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class); - GeneratedHttpRequest request = processor.createRequest(method, "rabble", "test"); + Invokable method = Invokable.from(TestPayload.class.getMethod("putWithPath", String.class, String.class)); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("rabble", "test")); assertRequestLineEquals(request, "PUT http://localhost:9999/rabble HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -2297,7 +2258,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @POST @Path("/") - @FormParams(keys = { "slash", "hyphen" }, values = { "/{bucket}", "-{bucket}" }) + @FormParams(keys = { "slash", "hyphen"}, values = { "/{bucket}", "-{bucket}"}) public void twoForm(@PathParam("bucket") String path) { } @@ -2316,8 +2277,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoForm() throws SecurityException, NoSuchMethodException { - Method oneForm = TestFormReplace.class.getMethod("twoForm", String.class); - Object form = factory(TestFormReplace.class).createRequest(oneForm, "robot").getPayload().getRawContent(); + Invokable method = Invokable.from(TestFormReplace.class.getMethod("twoForm", String.class)); + Object form = factory(TestFormReplace.class).createRequest(method, ImmutableList. of("robot")).getPayload().getRawContent(); assertEquals(form, "slash=/robot&hyphen=-robot"); } @@ -2368,30 +2329,30 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneClassForm() throws SecurityException, NoSuchMethodException { - Method oneForm = TestClassForm.class.getMethod("oneForm", String.class); - Object form = factory(TestClassForm.class).createRequest(oneForm, "robot").getPayload().getRawContent(); + Invokable method = Invokable.from(TestClassForm.class.getMethod("oneForm", String.class)); + Object form = factory(TestClassForm.class).createRequest(method, ImmutableList. of("robot")).getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot"); } @Test public void testBuildOneForm() throws SecurityException, NoSuchMethodException { - Method oneForm = TestFormReplace.class.getMethod("oneForm", String.class); - Object form = factory(TestFormReplace.class).createRequest(oneForm, "robot").getPayload().getRawContent(); + Invokable method = Invokable.from(TestFormReplace.class.getMethod("oneForm", String.class)); + Object form = factory(TestFormReplace.class).createRequest(method, ImmutableList. of("robot")).getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot"); } @Test public void testBuildTwoForms() throws SecurityException, NoSuchMethodException { - Method twoForms = TestFormReplace.class.getMethod("twoForms", String.class, String.class); - Object form = factory(TestFormReplace.class).createRequest(twoForms, "robot", "eggs").getPayload() + Invokable method = Invokable.from(TestFormReplace.class.getMethod("twoForms", String.class, String.class)); + Object form = factory(TestFormReplace.class).createRequest(method, ImmutableList. of("robot", "eggs")).getPayload() .getRawContent(); assertEquals(form, "x-amz-copy-source=/robot/eggs"); } @Test public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException { - Method twoFormsOutOfOrder = TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class); - Object form = factory(TestFormReplace.class).createRequest(twoFormsOutOfOrder, "robot", "eggs").getPayload() + Invokable method = Invokable.from(TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class)); + Object form = factory(TestFormReplace.class).createRequest(method, ImmutableList. of("robot", "eggs")).getPayload() .getRawContent(); assertEquals(form, "x-amz-copy-source=/eggs/robot"); } diff --git a/core/src/test/java/org/jclouds/util/Optionals2Test.java b/core/src/test/java/org/jclouds/util/Optionals2Test.java index 9a2ffbddc6..233ee03618 100644 --- a/core/src/test/java/org/jclouds/util/Optionals2Test.java +++ b/core/src/test/java/org/jclouds/util/Optionals2Test.java @@ -22,11 +22,10 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import java.lang.reflect.Method; - import org.testng.annotations.Test; import com.google.common.base.Optional; +import com.google.common.reflect.Invokable; /** * @author Adrian Cole @@ -41,25 +40,25 @@ public class Optionals2Test { } public void testReturnTypeOrTypeOfOptionalWhenOptional() throws SecurityException, NoSuchMethodException { - Method method = Test.class.getMethod("getOptional"); + Invokable method = Invokable.from(Test.class.getMethod("getOptional")); assertEquals(Optionals2.returnTypeOrTypeOfOptional(method), String.class); } public void testReturnTypeOrTypeOfOptionalWhenNotOptional() throws SecurityException, NoSuchMethodException { - Method method = Test.class.getMethod("getNotOptional"); + Invokable method = Invokable.from(Test.class.getMethod("getNotOptional")); assertEquals(Optionals2.returnTypeOrTypeOfOptional(method), String.class); } public void testIsReturnTypeOptionalWhenOptional() throws SecurityException, NoSuchMethodException { - Method method = Test.class.getMethod("getOptional"); + Invokable method = Invokable.from(Test.class.getMethod("getOptional")); assertTrue(Optionals2.isReturnTypeOptional(method)); } public void testIsReturnTypeOptionalWhenNotOptional() throws SecurityException, NoSuchMethodException { - Method method = Test.class.getMethod("getNotOptional"); + Invokable method = Invokable.from(Test.class.getMethod("getNotOptional")); assertFalse(Optionals2.isReturnTypeOptional(method)); } diff --git a/core/src/test/java/org/jclouds/util/Throwables2Test.java b/core/src/test/java/org/jclouds/util/Throwables2Test.java index 278fe874c1..425a200d4d 100644 --- a/core/src/test/java/org/jclouds/util/Throwables2Test.java +++ b/core/src/test/java/org/jclouds/util/Throwables2Test.java @@ -26,8 +26,8 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.net.SocketException; -import java.util.Map; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; import org.jclouds.concurrent.TransformParallelException; @@ -41,6 +41,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; import com.google.inject.CreationException; import com.google.inject.ProvisionException; import com.google.inject.spi.Message; @@ -117,153 +118,160 @@ public class Throwables2Test { assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); } - @SuppressWarnings("unchecked") public void testGetCauseTransformParallel() { Exception aex = createMock(AuthorizationException.class); - TransformParallelException pex = new TransformParallelException((Map) ImmutableMap.of(), ImmutableMap.of("bad", - aex), "test"); + TransformParallelException pex = new TransformParallelException(ImmutableMap.> of(), + ImmutableMap.of("bad", aex), "test"); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), aex); } - @SuppressWarnings("unchecked") public void testGetFirstThrowableOfTypeInnerTransformParallel() { Exception aex = createMock(AuthorizationException.class); - TransformParallelException pex = new TransformParallelException((Map) ImmutableMap.of(), ImmutableMap.of("bad", - (Exception) new ExecutionException(aex)), "test"); + TransformParallelException pex = new TransformParallelException(ImmutableMap.> of(), + ImmutableMap.of("bad", (Exception) new ExecutionException(aex)), "test"); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), aex); } - @SuppressWarnings("unchecked") public void testGetFirstThrowableOfTypeOuterTransformParallel() { Exception aex = createMock(AuthorizationException.class); - TransformParallelException pex = new TransformParallelException((Map) ImmutableMap.of(), ImmutableMap.of("bad", - (Exception) aex), "test"); + TransformParallelException pex = new TransformParallelException(ImmutableMap.> of(), + ImmutableMap.of("bad", (Exception) aex), "test"); assertEquals(getFirstThrowableOfType(new ExecutionException(pex), AuthorizationException.class), aex); } - @SuppressWarnings("unchecked") public void testGetFirstThrowableOfTypeFailTransformParallel() { Exception aex = createMock(TimeoutException.class); - TransformParallelException pex = new TransformParallelException((Map) ImmutableMap.of(), ImmutableMap.of("bad", - aex), "test"); + TransformParallelException pex = new TransformParallelException(ImmutableMap.> of(), + ImmutableMap.of("bad", aex), "test"); assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null); } @Test public void testReturnExceptionThatsInList() throws Exception { Exception e = new TestException(); - assertEquals(returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] { TestException.class }, e), - e); - assertEquals(returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] { TestException.class }, - new RuntimeException(e)), e); + assertEquals( + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause( + ImmutableSet.> of(TypeToken.of(TestException.class)), e), e); + assertEquals( + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause( + ImmutableSet.> of(TypeToken.of(TestException.class)), + new RuntimeException(e)), e); } @Test(expectedExceptions = TestException.class) public void testThrowExceptionNotInList() throws Exception { Exception e = new TestException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, e); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), e); } @Test(expectedExceptions = IllegalStateException.class) public void testPropagateStandardExceptionIllegalStateException() throws Exception { Exception e = new IllegalStateException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } @Test(expectedExceptions = IllegalArgumentException.class) public void testPropagateStandardExceptionIllegalArgumentException() throws Exception { Exception e = new IllegalArgumentException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } @Test(expectedExceptions = UnsupportedOperationException.class) public void testPropagateStandardExceptionUnsupportedOperationException() throws Exception { Exception e = new UnsupportedOperationException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } @Test(expectedExceptions = AssertionError.class) public void testPropagateStandardExceptionAssertionError() throws Exception { AssertionError e = new AssertionError(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } @Test(expectedExceptions = AuthorizationException.class) public void testPropagateStandardExceptionAuthorizationException() throws Exception { Exception e = new AuthorizationException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } @Test(expectedExceptions = AuthorizationException.class) public void testPropagateProvisionExceptionAuthorizationException() throws Exception { Exception e = new AuthorizationException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new ProvisionException(ImmutableSet.of(new Message( - ImmutableList.of(), "Error in custom provider",e)))); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new ProvisionException(ImmutableSet.of(new Message(ImmutableList.of(), "Error in custom provider", e)))); } @Test(expectedExceptions = AuthorizationException.class) public void testPropagateCreationExceptionAuthorizationException() throws Exception { Exception e = new AuthorizationException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new CreationException(ImmutableSet.of(new Message( - ImmutableList.of(), "Error in custom provider",e)))); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new CreationException(ImmutableSet.of(new Message(ImmutableList.of(), "Error in custom provider", e)))); } @Test(expectedExceptions = InsufficientResourcesException.class) public void testPropagateStandardExceptionInsufficientResourcesException() throws Exception { Exception e = new InsufficientResourcesException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } @Test(expectedExceptions = ResourceNotFoundException.class) public void testPropagateStandardExceptionResourceNotFoundException() throws Exception { Exception e = new ResourceNotFoundException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } @Test(expectedExceptions = IllegalStateException.class) public void testPropagateStandardExceptionIllegalStateExceptionNestedInHttpResponseException() throws Exception { Exception e = new IllegalStateException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException("goo", - createNiceMock(HttpCommand.class), null, e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e)); } @Test(expectedExceptions = IllegalArgumentException.class) public void testPropagateStandardExceptionIllegalArgumentExceptionNestedInHttpResponseException() throws Exception { Exception e = new IllegalArgumentException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException("goo", - createNiceMock(HttpCommand.class), null, e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e)); } @Test(expectedExceptions = UnsupportedOperationException.class) public void testPropagateStandardExceptionUnsupportedOperationExceptionNestedInHttpResponseException() - throws Exception { + throws Exception { Exception e = new UnsupportedOperationException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException("goo", - createNiceMock(HttpCommand.class), null, e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e)); } @Test(expectedExceptions = AuthorizationException.class) public void testPropagateStandardExceptionAuthorizationExceptionNestedInHttpResponseException() throws Exception { Exception e = new AuthorizationException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException("goo", - createNiceMock(HttpCommand.class), null, e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e)); } @Test(expectedExceptions = ResourceNotFoundException.class) public void testPropagateStandardExceptionResourceNotFoundExceptionNestedInHttpResponseException() throws Exception { Exception e = new ResourceNotFoundException(); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new HttpResponseException("goo", - createNiceMock(HttpCommand.class), null, e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new HttpResponseException("goo", createNiceMock(HttpCommand.class), null, e)); } @Test(expectedExceptions = HttpResponseException.class) public void testPropagateStandardExceptionHttpResponseException() throws Exception { Exception e = new HttpResponseException("goo", createNiceMock(HttpCommand.class), null); - returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(new Class[] {}, new RuntimeException(e)); + returnFirstExceptionIfInListOrThrowStandardExceptionOrCause(ImmutableSet.> of(), + new RuntimeException(e)); } static class TestException extends Exception { - + private static final long serialVersionUID = 1L; } }