From 58f0f577d0863f5eb0cc9e0a0b3f099b6b2666f9 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 19 Jan 2013 17:17:06 -0800 Subject: [PATCH] centralize construction of invokables --- .../main/java/org/jclouds/ContextBuilder.java | 6 +- core/src/main/java/org/jclouds/apis/Apis.java | 4 +- .../apis/internal/BaseApiMetadata.java | 6 +- ...WithWildcardExtendsExplicitAndRawType.java | 7 +- .../java/org/jclouds/providers/Providers.java | 9 +- .../jclouds/reflect/FunctionalReflection.java | 8 +- .../java/org/jclouds/reflect/Reflection2.java | 195 ++++++++-- .../rest/config/CallGetOnFuturesProvider.java | 3 +- .../jclouds/rest/config/HttpApiProvider.java | 3 +- .../org/jclouds/rest/config/RestModule.java | 38 +- .../rest/internal/BaseRestApiMetadata.java | 4 +- .../DelegatesToInvocationFunction.java | 27 +- .../org/jclouds/apis/BaseViewLiveTest.java | 4 +- .../http/functions/BaseHandlerTest.java | 6 +- .../BackoffLimitedRetryHandlerTest.java | 4 +- .../org/jclouds/internal/BaseViewTest.java | 12 +- .../java/org/jclouds/json/BaseParserTest.java | 5 +- .../internal/BaseProviderMetadataTest.java | 4 +- .../org/jclouds/reflect/Reflection2Test.java | 79 ++++ .../jclouds/rest/InputParamValidatorTest.java | 13 +- .../ProvidesAnnotationExpectTest.java | 148 ++++++++ .../binders/BindMapToStringPayloadTest.java | 10 +- ...aphicallyAtOrAfterSinceApiVersionTest.java | 8 +- .../internal/BaseRestApiMetadataTest.java | 5 +- .../rest/internal/BlockOnFutureTest.java | 10 +- .../internal/RestAnnotationProcessorTest.java | 343 +++++++----------- .../java/org/jclouds/util/Optionals2Test.java | 10 +- .../org/jclouds/util/Throwables2Test.java | 6 +- 28 files changed, 631 insertions(+), 346 deletions(-) create mode 100644 core/src/test/java/org/jclouds/reflect/Reflection2Test.java create mode 100644 core/src/test/java/org/jclouds/rest/annotationparsing/ProvidesAnnotationExpectTest.java diff --git a/core/src/main/java/org/jclouds/ContextBuilder.java b/core/src/main/java/org/jclouds/ContextBuilder.java index 254de0a220..106c28f0e7 100644 --- a/core/src/main/java/org/jclouds/ContextBuilder.java +++ b/core/src/main/java/org/jclouds/ContextBuilder.java @@ -42,7 +42,7 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; import static org.jclouds.Constants.PROPERTY_PROVIDER; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException; import java.util.List; @@ -491,7 +491,7 @@ public class ContextBuilder { // TODO: move this up if (apiMetadata instanceof RestApiMetadata) { RestApiMetadata rest = RestApiMetadata.class.cast(apiMetadata); - modules.add(new RestClientModule(typeTokenOf(rest.getApi()), typeTokenOf(rest.getAsyncApi()))); + modules.add(new RestClientModule(typeToken(rest.getApi()), typeToken(rest.getAsyncApi()))); } else { modules.add(new RestModule()); } @@ -568,7 +568,7 @@ public class ContextBuilder { * @see #buildView(TypeToken) */ public V buildView(Class viewType) { - return buildView(typeTokenOf(viewType)); + return buildView(typeToken(viewType)); } /** diff --git a/core/src/main/java/org/jclouds/apis/Apis.java b/core/src/main/java/org/jclouds/apis/Apis.java index 58b722095c..29ae0a2926 100644 --- a/core/src/main/java/org/jclouds/apis/Apis.java +++ b/core/src/main/java/org/jclouds/apis/Apis.java @@ -21,7 +21,7 @@ package org.jclouds.apis; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.find; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import java.util.NoSuchElementException; import java.util.ServiceLoader; @@ -116,7 +116,7 @@ public class Apis { } public static Iterable viewableAs(Class type) { - return filter(all(), ApiPredicates.viewableAs(typeTokenOf(type))); + return filter(all(), ApiPredicates.viewableAs(typeToken(type))); } /** diff --git a/core/src/main/java/org/jclouds/apis/internal/BaseApiMetadata.java b/core/src/main/java/org/jclouds/apis/internal/BaseApiMetadata.java index 761023998e..a86b0189ce 100644 --- a/core/src/main/java/org/jclouds/apis/internal/BaseApiMetadata.java +++ b/core/src/main/java/org/jclouds/apis/internal/BaseApiMetadata.java @@ -32,7 +32,7 @@ import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT; import static org.jclouds.Constants.PROPERTY_USER_THREADS; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import java.net.URI; import java.util.Properties; @@ -93,7 +93,7 @@ public abstract class BaseApiMetadata implements ApiMetadata { private Optional defaultCredential = Optional.absent(); private Properties defaultProperties = BaseApiMetadata.defaultProperties(); private URI documentation; - private TypeToken context = typeTokenOf(Context.class); + private TypeToken context = typeToken(Context.class); private Set> defaultModules = ImmutableSet.of(); /** @@ -119,7 +119,7 @@ public abstract class BaseApiMetadata implements ApiMetadata { */ @Override public T view(Class view) { - return view(typeTokenOf(checkNotNull(view, "view"))); + return view(typeToken(checkNotNull(view, "view"))); } /** diff --git a/core/src/main/java/org/jclouds/config/BindRestContextWithWildcardExtendsExplicitAndRawType.java b/core/src/main/java/org/jclouds/config/BindRestContextWithWildcardExtendsExplicitAndRawType.java index 780b22ed23..d14c554b74 100644 --- a/core/src/main/java/org/jclouds/config/BindRestContextWithWildcardExtendsExplicitAndRawType.java +++ b/core/src/main/java/org/jclouds/config/BindRestContextWithWildcardExtendsExplicitAndRawType.java @@ -17,10 +17,9 @@ * under the License. */ package org.jclouds.config; - import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import org.jclouds.rest.RestApiMetadata; import org.jclouds.rest.RestContext; @@ -50,8 +49,8 @@ public class BindRestContextWithWildcardExtendsExplicitAndRawType extends Abstra @SuppressWarnings("unchecked") @Override protected void configure() { - TypeToken concreteType = BaseRestApiMetadata.contextToken(typeTokenOf(restApiMetadata.getApi()), TypeToken - .of(restApiMetadata.getAsyncApi())); + TypeToken concreteType = BaseRestApiMetadata.contextToken(typeToken(restApiMetadata.getApi()), + typeToken(restApiMetadata.getAsyncApi())); // bind explicit type bind(TypeLiteral.get(concreteType.getType())).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, diff --git a/core/src/main/java/org/jclouds/providers/Providers.java b/core/src/main/java/org/jclouds/providers/Providers.java index 8500ba6977..36b55e2efa 100644 --- a/core/src/main/java/org/jclouds/providers/Providers.java +++ b/core/src/main/java/org/jclouds/providers/Providers.java @@ -17,10 +17,9 @@ * under the License. */ package org.jclouds.providers; - import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.find; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import java.util.NoSuchElementException; import java.util.ServiceLoader; @@ -117,7 +116,7 @@ public class Providers { } public static Iterable viewableAs(Class viewableAs) { - return filter(all(), ProviderPredicates.viewableAs(typeTokenOf(viewableAs))); + return filter(all(), ProviderPredicates.viewableAs(typeToken(viewableAs))); } /** @@ -179,7 +178,7 @@ public class Providers { public static Iterable boundedByIso3166Code(String iso3166Code, Class viewableAs) { - return boundedByIso3166Code(iso3166Code, typeTokenOf(viewableAs)); + return boundedByIso3166Code(iso3166Code, typeToken(viewableAs)); } /** @@ -215,6 +214,6 @@ public class Providers { public static Iterable collocatedWith(ProviderMetadata providerMetadata, Class viewableAs) { - return collocatedWith(providerMetadata, typeTokenOf(viewableAs)); + return collocatedWith(providerMetadata, typeToken(viewableAs)); } } diff --git a/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java b/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java index fe659fad4b..4e96983ba2 100644 --- a/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java +++ b/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java @@ -24,7 +24,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.notNull; import static com.google.common.base.Throwables.propagate; import static com.google.common.collect.Iterables.all; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.method; +import static org.jclouds.reflect.Reflection2.typeToken; import static org.jclouds.util.Throwables2.propagateIfPossible; import java.lang.reflect.Method; @@ -84,8 +85,7 @@ public final class FunctionalReflection { public static T newProxy(Class enclosingType, Function invocationFunction) { checkNotNull(invocationFunction, "invocationFunction"); - return newProxy(enclosingType, - new FunctionalInvocationHandler(typeTokenOf(enclosingType), invocationFunction)); + return newProxy(enclosingType, new FunctionalInvocationHandler(typeToken(enclosingType), invocationFunction)); } @SuppressWarnings("unchecked") @@ -113,7 +113,7 @@ public final class FunctionalReflection { args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); - Invokable invokable = enclosingType.method(invoked); + Invokable invokable = method(enclosingType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); diff --git a/core/src/main/java/org/jclouds/reflect/Reflection2.java b/core/src/main/java/org/jclouds/reflect/Reflection2.java index b3c9eeb1b7..7c603abe60 100644 --- a/core/src/main/java/org/jclouds/reflect/Reflection2.java +++ b/core/src/main/java/org/jclouds/reflect/Reflection2.java @@ -19,65 +19,196 @@ package org.jclouds.reflect; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.toArray; -import java.lang.reflect.Type; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; import com.google.common.annotations.Beta; -import com.google.common.base.Function; +import com.google.common.base.Objects; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.reflect.Invokable; import com.google.common.reflect.TypeToken; /** - * Invokable utilities + * Utilities that allow access to {@link Invokable}s with {@link Invokable#getOwnerType() owner types}. * * @since 1.6 */ @Beta public final class Reflection2 { - private static final LoadingCache, TypeToken> typeTokenForClass = CacheBuilder.newBuilder().build( - new CacheLoader, TypeToken>() { - public TypeToken load(final Class key) throws Exception { - return TypeToken.of(key); - } - }); /** - * Cache of type tokens for the supplied class. - */ - public static Function, TypeToken> typeTokenForClass() { - return typeTokenForClass; - } - - /** - * Cache of type tokens for the supplied class. + * gets a {@link TypeToken} for the given class. */ @SuppressWarnings("unchecked") - public static TypeToken typeTokenOf(Class in) { + public static TypeToken typeToken(Class in) { return (TypeToken) typeTokenForClass.apply(checkNotNull(in, "class")); } - private static final LoadingCache> typeTokenForType = CacheBuilder.newBuilder().build( - new CacheLoader>() { - public TypeToken load(final Type key) throws Exception { + /** + * returns an {@link Invokable} object that links the {@code method} to its owner. + * + * @param ownerType + * corresponds to {@link Invokable#getOwnerType()} + * @param method + * present in {@code ownerType} + */ + @SuppressWarnings("unchecked") + public static Invokable method(TypeToken ownerType, Method method) { + return (Invokable) methods.apply(new TypeTokenAndMethod(ownerType, method)); + } + + /** + * returns an {@link Invokable} object that reflects a method present in the {@link TypeToken} type. + * + * @param ownerType + * corresponds to {@link Invokable#getOwnerType()} + * @param parameterTypes + * corresponds to {@link Method#getParameterTypes()} + * + * @throws IllegalArgumentException + * if the method doesn't exist or a security exception occurred + */ + @SuppressWarnings("unchecked") + public static Invokable method(Class ownerType, String name, Class... parameterTypes) { + return (Invokable) methodForArgs.apply(new TypeTokenNameAndParameterTypes(typeToken(ownerType), name, + parameterTypes)); + } + + /** + * return all methods present in the class as {@link Invokable}s. + * + * @param ownerType + * corresponds to {@link Invokable#getOwnerType()} + */ + @SuppressWarnings("unchecked") + public static Collection> methods(Class ownerType) { + return Collection.class.cast(methodsForTypeToken.apply(typeToken(ownerType)).values()); + } + + private static final LoadingCache> methods = CacheBuilder.newBuilder().build( + new CacheLoader>() { + public Invokable load(TypeTokenAndMethod key) { + return key.type.method(key.method); + } + }); + + private static class TypeTokenAndMethod { + + protected final TypeToken type; + protected final Method method; + + public TypeTokenAndMethod(TypeToken type, Method method) { + this.type = checkNotNull(type, "type"); + this.method = checkNotNull(method, "method"); + } + + public int hashCode() { + return Objects.hashCode(type, method); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + TypeTokenAndMethod that = TypeTokenAndMethod.class.cast(obj); + return Objects.equal(this.type, that.type) && Objects.equal(this.method, that.method); + } + } + + private static final LoadingCache, TypeToken> typeTokenForClass = CacheBuilder.newBuilder().build( + new CacheLoader, TypeToken>() { + public TypeToken load(final Class key) { return TypeToken.of(key); } }); - /** - * Cache of type tokens for the supplied class. - */ - public static Function> typeTokenForType() { - return typeTokenForType; + private static class TypeTokenAndParameterTypes { + + protected final TypeToken type; + protected final List> parameterTypes; + + public TypeTokenAndParameterTypes(TypeToken type, Class... parameterTypes) { + this.type = checkNotNull(type, "type"); + this.parameterTypes = Arrays.asList(checkNotNull(parameterTypes, "parameterTypes")); + } + + public int hashCode() { + return Objects.hashCode(type, parameterTypes); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + TypeTokenAndParameterTypes that = TypeTokenAndParameterTypes.class.cast(obj); + return Objects.equal(this.type, that.type) && Objects.equal(this.parameterTypes, that.parameterTypes); + } + + public String toString() { + return Objects.toStringHelper("").add("type", type).add("parameterTypes", parameterTypes).toString(); + } } - /** - * Cache of type tokens for the supplied type. - */ - @SuppressWarnings("unchecked") - public static TypeToken typeTokenOf(Type in) { - return (TypeToken) typeTokenForType.apply(checkNotNull(in, "class")); + private static final LoadingCache> methodForArgs = CacheBuilder + .newBuilder().build(new CacheLoader>() { + public Invokable load(final TypeTokenNameAndParameterTypes key) { + try { + Method method = key.type.getRawType().getMethod(key.name, toArray(key.parameterTypes, Class.class)); + return methods.apply(new TypeTokenAndMethod(key.type, method)); + } catch (SecurityException e) { + throw new IllegalArgumentException(e.getMessage() + " getting method " + key.toString(), e); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("no such method " + key.toString(), e); + } + } + }); + + private static class TypeTokenNameAndParameterTypes extends TypeTokenAndParameterTypes { + + private final String name; + + public TypeTokenNameAndParameterTypes(TypeToken type, String name, Class... parameterTypes) { + super(type, parameterTypes); + this.name = checkNotNull(name, "name"); + } + + public int hashCode() { + return Objects.hashCode(super.hashCode(), name); + } + + public boolean equals(Object obj) { + if (super.equals(obj)) { + TypeTokenNameAndParameterTypes that = TypeTokenNameAndParameterTypes.class.cast(obj); + return name.equals(that.name); + } + return false; + } + + public String toString() { + return Objects.toStringHelper("").add("type", type).add("name", name).add("parameterTypes", parameterTypes) + .toString(); + } } + private static final LoadingCache, Map>> methodsForTypeToken = CacheBuilder + .newBuilder().build(new CacheLoader, Map>>() { + public Map> load(final TypeToken key) { + Builder> builder = ImmutableMap.> builder(); + for (Method method : key.getRawType().getMethods()) + builder.put(method, method(key, method)); + return builder.build(); + } + }); + } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java b/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java index 58018d61c9..27fb53c93d 100644 --- a/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java +++ b/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java @@ -18,7 +18,6 @@ */ package org.jclouds.rest.config; -import static org.jclouds.reflect.Reflection2.typeTokenOf; import java.lang.reflect.Proxy; @@ -47,7 +46,7 @@ public class CallGetOnFuturesProvider implements Provider { Class asyncApiType) { this.syncInvoker = syncInvoker; this.apiType = apiType; - RestModule.putInvokables(typeTokenOf(apiType), typeTokenOf(asyncApiType), invokables); + RestModule.putInvokables(apiType, asyncApiType, invokables); } @SuppressWarnings("unchecked") diff --git a/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java b/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java index 6c55f065dd..820ebe1f39 100644 --- a/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java +++ b/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java @@ -18,7 +18,6 @@ */ package org.jclouds.rest.config; -import static org.jclouds.reflect.Reflection2.typeTokenOf; import java.lang.reflect.Proxy; @@ -46,7 +45,7 @@ public class HttpApiProvider implements Provider { DelegatesToInvocationFunction httpInvoker, Class apiType, Class asyncApiType) { this.httpInvoker = httpInvoker; this.apiType = apiType; - RestModule.putInvokables(typeTokenOf(apiType), typeTokenOf(asyncApiType), invokables); + RestModule.putInvokables(apiType, asyncApiType, invokables); } @SuppressWarnings("unchecked") diff --git a/core/src/main/java/org/jclouds/rest/config/RestModule.java b/core/src/main/java/org/jclouds/rest/config/RestModule.java index f7c30a7fbc..315f152bde 100644 --- a/core/src/main/java/org/jclouds/rest/config/RestModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestModule.java @@ -19,18 +19,21 @@ package org.jclouds.rest.config; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; +import static com.google.common.collect.Iterables.toArray; +import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Maps.transformValues; import static com.google.common.util.concurrent.Atomics.newReference; import static org.jclouds.Constants.PROPERTY_TIMEOUTS_PREFIX; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.method; +import static org.jclouds.reflect.Reflection2.methods; import static org.jclouds.rest.config.BinderUtils.bindHttpApi; import static org.jclouds.util.Maps2.transformKeys; import static org.jclouds.util.Predicates2.startsWith; import java.lang.reflect.Method; import java.net.URI; -import java.util.Arrays; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; @@ -57,7 +60,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.reflect.Invokable; -import com.google.common.reflect.TypeToken; +import com.google.common.reflect.Parameter; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.TypeLiteral; @@ -80,7 +83,7 @@ public class RestModule extends AbstractModule { public RestModule(Map, Class> sync2Async) { this.sync2Async = sync2Async; } - + /** * seeds well-known invokables. */ @@ -88,33 +91,42 @@ public class RestModule extends AbstractModule { @Singleton protected Cache, Invokable> seedKnownSync2AsyncInvokables() { Cache, Invokable> sync2AsyncBuilder = CacheBuilder.newBuilder().build(); - putInvokables(typeTokenOf(HttpClient.class), typeTokenOf(HttpAsyncClient.class), sync2AsyncBuilder); + putInvokables(HttpClient.class, HttpAsyncClient.class, sync2AsyncBuilder); for (Class s : sync2Async.keySet()) { - putInvokables(typeTokenOf(s), typeTokenOf(sync2Async.get(s)), sync2AsyncBuilder); + putInvokables(s, sync2Async.get(s), sync2AsyncBuilder); } return sync2AsyncBuilder; } // accessible for ClientProvider - public static void putInvokables(TypeToken sync, TypeToken async, Cache, Invokable> cache) { - for (Method invoked : sync.getRawType().getMethods()) { + public static void putInvokables(Class sync, Class async, Cache, Invokable> cache) { + for (Invokable invoked : methods(sync)) { if (!objectMethods.contains(invoked)) { try { - Method delegatedMethod = async.getRawType().getMethod(invoked.getName(), invoked.getParameterTypes()); - checkArgument(Arrays.equals(delegatedMethod.getExceptionTypes(), invoked.getExceptionTypes()), + Invokable delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); + checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()), "invoked %s has different typed exceptions than delegated invoked %s", invoked, delegatedMethod); invoked.setAccessible(true); delegatedMethod.setAccessible(true); - cache.put(sync.method(invoked), async.method(delegatedMethod)); + cache.put(invoked, delegatedMethod); } catch (SecurityException e) { throw propagate(e); - } catch (NoSuchMethodException e) { - throw propagate(e); } } } } + /** + * for portability with {@link Class#getMethod(String, Class...)} + */ + private static Class[] getParameterTypes(Invokable in) { + return toArray(transform(checkNotNull(in, "invokable").getParameters(), new Function>() { + public Class apply(Parameter input) { + return input.getType().getRawType(); + } + }), Class.class); + } + protected void installLocations() { install(new LocationModule()); } diff --git a/core/src/main/java/org/jclouds/rest/internal/BaseRestApiMetadata.java b/core/src/main/java/org/jclouds/rest/internal/BaseRestApiMetadata.java index f48d88f8ad..4c4c8990b0 100644 --- a/core/src/main/java/org/jclouds/rest/internal/BaseRestApiMetadata.java +++ b/core/src/main/java/org/jclouds/rest/internal/BaseRestApiMetadata.java @@ -19,7 +19,7 @@ package org.jclouds.rest.internal; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import java.util.Properties; @@ -72,7 +72,7 @@ public abstract class BaseRestApiMetadata extends BaseApiMetadata implements Res checkNotNull(asyncApi, "asyncApi"); javaApi(api, asyncApi) .name(String.format("%s->%s", api.getSimpleName(), asyncApi.getSimpleName())) - .context(contextToken(typeTokenOf(api), typeTokenOf(asyncApi))) + .context(contextToken(typeToken(api), typeToken(asyncApi))) .defaultProperties(BaseRestApiMetadata.defaultProperties()); } diff --git a/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java b/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java index 9ae84c1f5d..d1ff456cbf 100644 --- a/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java +++ b/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java @@ -23,7 +23,8 @@ import static com.google.common.base.Throwables.propagate; import static com.google.common.collect.Iterables.all; import static com.google.common.collect.Iterables.find; import static com.google.inject.util.Types.newParameterizedType; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.method; +import static org.jclouds.reflect.Reflection2.typeToken; import static org.jclouds.util.Optionals2.isReturnTypeOptional; import static org.jclouds.util.Optionals2.unwrapIfOptional; import static org.jclouds.util.Throwables2.getFirstThrowableOfType; @@ -66,7 +67,6 @@ import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Provides; import com.google.inject.ProvisionException; -import com.google.inject.TypeLiteral; import com.google.inject.util.Types; /** @@ -96,10 +96,11 @@ public final class DelegatesToInvocationFunction *
  • other method calls are dispatched to {@link #handleInvocation}. * - * @throws Throwable + * + * @throws Throwable */ @Override - public final Object invoke(Object proxy, Method invoked, @Nullable Object[] argv) throws Throwable { + public final Object invoke(Object proxy, Method invoked, @Nullable Object[] argv) throws Throwable { if (argv == null) { argv = NO_ARGS; } @@ -118,7 +119,7 @@ public final class DelegatesToInvocationFunction invokable = enclosingType.method(invoked); + Invokable invokable = method(ownerType, invoked); Invocation invocation = Invocation.create(invokable, args); try { return handle(invocation); @@ -135,20 +136,19 @@ public final class DelegatesToInvocationFunction enclosingType; + private final TypeToken ownerType; private final SetCaller setCaller; private final Map, Class> syncToAsync; private final Function> optionalConverter; private final F methodInvoker; - @SuppressWarnings("unchecked") @Inject DelegatesToInvocationFunction(Injector injector, SetCaller setCaller, Map, Class> syncToAsync, - TypeLiteral enclosingType, Function> optionalConverter, F methodInvoker) { + Class ownerType, Function> optionalConverter, F methodInvoker) { this.injector = checkNotNull(injector, "injector"); - this.enclosingType = (TypeToken) typeTokenOf(checkNotNull(enclosingType, "enclosingType").getType()); + this.ownerType = typeToken(checkNotNull(ownerType, "ownerType")); this.setCaller = checkNotNull(setCaller, "setCaller"); this.syncToAsync = checkNotNull(syncToAsync, "syncToAsync"); this.optionalConverter = checkNotNull(optionalConverter, "optionalConverter"); @@ -174,7 +174,7 @@ public final class DelegatesToInvocationFunction methodInvokerFor(Class returnType) { switch (methodInvoker.getClass().getTypeParameters().length) { @@ -256,8 +256,7 @@ public final class DelegatesToInvocationFunction extends BaseContextLiveTe @Override protected TypeToken contextType() { - return typeTokenOf(Context.class); + return typeToken(Context.class); } protected V createView(Properties props, Iterable modules) { diff --git a/core/src/test/java/org/jclouds/http/functions/BaseHandlerTest.java b/core/src/test/java/org/jclouds/http/functions/BaseHandlerTest.java index 612e68b4f5..fc83e258ef 100644 --- a/core/src/test/java/org/jclouds/http/functions/BaseHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/functions/BaseHandlerTest.java @@ -19,6 +19,7 @@ package org.jclouds.http.functions; import static com.google.common.base.Throwables.propagate; +import static org.jclouds.reflect.Reflection2.method; import java.util.List; @@ -29,7 +30,6 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; import com.google.inject.Guice; import com.google.inject.Injector; @@ -54,11 +54,9 @@ public class BaseHandlerTest { @BeforeTest protected void setUpRequest() { try { - toString = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), ImmutableList.of()); + toString = Invocation.create(method(String.class, "toString"), ImmutableList.of()); } catch (SecurityException e) { throw propagate(e); - } catch (NoSuchMethodException e) { - throw propagate(e); } request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key").invocation(toString) .build(); 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 8896a0f7be..909baa41de 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -17,7 +17,7 @@ * under the License. */ package org.jclouds.http.handlers; - +import static org.jclouds.reflect.Reflection2.method; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -125,7 +125,7 @@ public class BackoffLimitedRetryHandlerTest { .getInstance(RestAnnotationProcessor.class); private HttpCommand createCommand() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(IntegrationTestAsyncClient.class.getMethod("download", String.class)); + Invokable method = method(IntegrationTestAsyncClient.class, "download", String.class); return new HttpCommand(processor.createRequest(method, ImmutableList. of("1"))); } diff --git a/core/src/test/java/org/jclouds/internal/BaseViewTest.java b/core/src/test/java/org/jclouds/internal/BaseViewTest.java index c3de223bb6..9b947080a3 100644 --- a/core/src/test/java/org/jclouds/internal/BaseViewTest.java +++ b/core/src/test/java/org/jclouds/internal/BaseViewTest.java @@ -19,7 +19,7 @@ package org.jclouds.internal; import static org.easymock.EasyMock.createMock; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.fail; @@ -64,22 +64,22 @@ public class BaseViewTest { private static class Wine extends BaseView { protected Wine() { - super(new Water(), typeTokenOf(Water.class)); + super(new Water(), typeToken(Water.class)); } } public void testWaterTurnedIntoWine() { Wine wine = new Wine(); - assertEquals(wine.getBackendType(), typeTokenOf(Water.class)); - assertEquals(wine.unwrap(typeTokenOf(Water.class)).getClass(), Water.class); + assertEquals(wine.getBackendType(), typeToken(Water.class)); + assertEquals(wine.unwrap(typeToken(Water.class)).getClass(), Water.class); assertEquals(wine.unwrap().getClass(), Water.class); } public void testPeanutButterDidntTurnIntoWine() { Wine wine = new Wine(); - assertNotEquals(wine.getBackendType(), typeTokenOf(PeanutButter.class)); + assertNotEquals(wine.getBackendType(), typeToken(PeanutButter.class)); try { - wine.unwrap(typeTokenOf(PeanutButter.class)); + wine.unwrap(typeToken(PeanutButter.class)); fail(); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "backend type: org.jclouds.internal.BaseViewTest$Water not assignable from org.jclouds.internal.BaseViewTest$PeanutButter"); diff --git a/core/src/test/java/org/jclouds/json/BaseParserTest.java b/core/src/test/java/org/jclouds/json/BaseParserTest.java index d3143826fd..ae6910ff87 100644 --- a/core/src/test/java/org/jclouds/json/BaseParserTest.java +++ b/core/src/test/java/org/jclouds/json/BaseParserTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.json; +import static org.jclouds.reflect.Reflection2.method; import static org.testng.Assert.assertEquals; import java.lang.annotation.ElementType; @@ -39,7 +40,6 @@ import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; import com.google.inject.Guice; import com.google.inject.Injector; @@ -62,8 +62,7 @@ public abstract class BaseParserTest { return (Function) i .createChildInjector(new SaxParserModule()) .getInstance(TransformerForRequest.class) - .getTransformerForMethod( - Invocation.create(Invokable.from(getClass().getMethod("expected")), ImmutableList.of()), i); + .getTransformerForMethod(Invocation.create(method(getClass(), "expected"), ImmutableList.of()), i); } catch (Exception e) { throw Throwables.propagate(e); } diff --git a/core/src/test/java/org/jclouds/providers/internal/BaseProviderMetadataTest.java b/core/src/test/java/org/jclouds/providers/internal/BaseProviderMetadataTest.java index a915b12e1e..bc66237438 100644 --- a/core/src/test/java/org/jclouds/providers/internal/BaseProviderMetadataTest.java +++ b/core/src/test/java/org/jclouds/providers/internal/BaseProviderMetadataTest.java @@ -19,7 +19,7 @@ package org.jclouds.providers.internal; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import static org.testng.Assert.assertEquals; import java.util.Set; @@ -63,7 +63,7 @@ public abstract class BaseProviderMetadataTest { public void testOfApiContains() { if (expectedApi == null) Logger.getAnonymousLogger().warning("please update your test class"); - ImmutableSet ofApi = ImmutableSet.copyOf(Providers.apiMetadataAssignableFrom(typeTokenOf(expectedApi.getClass()))); + ImmutableSet ofApi = ImmutableSet.copyOf(Providers.apiMetadataAssignableFrom(typeToken(expectedApi.getClass()))); assert ofApi.contains(toTest) : String.format("%s not found in %s", toTest, ofApi); } diff --git a/core/src/test/java/org/jclouds/reflect/Reflection2Test.java b/core/src/test/java/org/jclouds/reflect/Reflection2Test.java new file mode 100644 index 0000000000..4255b5225a --- /dev/null +++ b/core/src/test/java/org/jclouds/reflect/Reflection2Test.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.reflect; + +import static com.google.common.base.Functions.toStringFunction; +import static org.jclouds.reflect.Reflection2.method; +import static org.jclouds.reflect.Reflection2.methods; +import static org.jclouds.reflect.Reflection2.typeToken; +import static org.testng.Assert.assertEquals; + +import java.util.Set; + +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.Invokable; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test +public class Reflection2Test { + + public void testTypeToken() { + assertEquals(typeToken(String.class), TypeToken.of(String.class)); + } + + public void testMethodFromJavaMethod() throws SecurityException, NoSuchMethodException { + assertEquals(method(typeToken(String.class), String.class.getMethod("toString")), TypeToken.of(String.class) + .method(String.class.getMethod("toString")).returning(String.class)); + } + + public void testMethodFromClassAndNoParams() { + @SuppressWarnings("rawtypes") + Invokable methodInSuper = method(Set.class, "iterator"); + + assertEquals(methodInSuper.getOwnerType(), typeToken(Set.class)); + } + + public void testMethodFromClassAndParams() { + @SuppressWarnings("rawtypes") + Invokable methodInSuper = method(Set.class, "equals", Object.class); + + assertEquals(methodInSuper.getOwnerType(), typeToken(Set.class)); + assertEquals(methodInSuper.getParameters().get(0).getType().getRawType(), Object.class); + } + + public void testMethods() { + Set methodNames = FluentIterable.from(methods(Set.class)) + .transform(new Function, String>() { + public String apply(Invokable input) { + return input.getName(); + } + }).transform(toStringFunction()).toSet(); + + assertEquals(methodNames, ImmutableSet.of("add", "equals", "hashCode", "clear", "isEmpty", "contains", "addAll", + "size", "toArray", "iterator", "remove", "removeAll", "containsAll", "retainAll")); + } +} diff --git a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java index f7a1c5c492..0073bb9250 100644 --- a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java +++ b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.rest; +import static org.jclouds.reflect.Reflection2.method; + import javax.ws.rs.POST; import javax.ws.rs.PathParam; @@ -36,7 +38,6 @@ 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") public class InputParamValidatorTest { @@ -59,10 +60,10 @@ public class InputParamValidatorTest { */ @Test public void testInputParamsValidation() throws Exception { - Invokable allParamsValidatedMethod = Invokable.from(InputParamValidatorForm.class.getMethod( - "allParamsValidated", String.class, String.class)); - Invokable oneParamValidatedMethod = Invokable.from(InputParamValidatorForm.class.getMethod( - "oneParamValidated", String.class, String.class)); + Invokable allParamsValidatedMethod = method(InputParamValidatorForm.class, "allParamsValidated", + String.class, String.class); + Invokable oneParamValidatedMethod = method(InputParamValidatorForm.class, "oneParamValidated", + String.class, String.class); restAnnotationProcessor.createRequest(allParamsValidatedMethod, ImmutableList. of("blah", "blah")); restAnnotationProcessor.createRequest(oneParamValidatedMethod, ImmutableList. of("blah", "blah")); @@ -98,7 +99,7 @@ public class InputParamValidatorTest { @Test(expectedExceptions = ClassCastException.class) public void testWrongPredicateTypeLiteral() throws Exception { - Invocation invocation = Invocation.create(Invokable.from(WrongValidator.class.getMethod("method", Integer.class)), + Invocation invocation = Invocation.create(method(WrongValidator.class, "method", Integer.class), ImmutableList. of(55)); new InputParamValidator(injector).validateMethodParametersOrThrow(invocation); } diff --git a/core/src/test/java/org/jclouds/rest/annotationparsing/ProvidesAnnotationExpectTest.java b/core/src/test/java/org/jclouds/rest/annotationparsing/ProvidesAnnotationExpectTest.java new file mode 100644 index 0000000000..88aab9d98b --- /dev/null +++ b/core/src/test/java/org/jclouds/rest/annotationparsing/ProvidesAnnotationExpectTest.java @@ -0,0 +1,148 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.rest.annotationparsing; + +import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint; +import static org.testng.Assert.assertEquals; + +import java.util.NoSuchElementException; +import java.util.Set; + +import javax.inject.Named; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.internal.BaseRestClientExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; + +/** + * Tests that we can add {@link Provides} methods on interfaces + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ProvidesAnnotationExpectTest") +public class ProvidesAnnotationExpectTest extends BaseRestClientExpectTest { + + static interface ProvidingApi { + @Provides + Set set(); + + @Named("bar") + @Provides + Set foo(); + + @Named("exception") + @Provides + Set exception(); + + @Named("NoSuchElementException") + @Provides + Set noSuchElementException(); + } + + static interface ProvidingAsyncApi { + @Provides + Set set(); + + @Named("bar") + @Provides + Set foo(); + + @Named("exception") + @Provides + Set exception(); + + @Named("NoSuchElementException") + @Provides + Set noSuchElementException(); + } + + @Test + public void testProvidesWithGeneric(){ + ProvidingApi client = requestsSendResponses(ImmutableMap. of()); + assertEquals(client.set(), ImmutableSet.of("foo")); + } + + @Test + public void testProvidesWithGenericQualified(){ + ProvidingApi client = requestsSendResponses(ImmutableMap. of()); + assertEquals(client.foo(), ImmutableSet.of("bar")); + } + + @Test(expectedExceptions = AuthorizationException.class) + public void testProvidesWithGenericQualifiedAuthorizationException(){ + ProvidingApi client = requestsSendResponses(ImmutableMap. of()); + client.exception(); + } + + @Test(expectedExceptions = NoSuchElementException.class) + public void testProvidesWithGenericQualifiedNoSuchElementException(){ + ProvidingApi client = requestsSendResponses(ImmutableMap. of()); + client.noSuchElementException(); + } + + // crufty junk until we inspect delegating api classes for all their client + // mappings and make a test helper for random classes. + + @Override + public ProviderMetadata createProviderMetadata() { + return forClientMappedToAsyncClientOnEndpoint(ProvidingApi.class, ProvidingAsyncApi.class, "http://mock"); + } + + @Override + protected Module createModule() { + return new ProvidingRestClientModule(); + } + + @ConfiguresRestClient + static class ProvidingRestClientModule extends RestClientModule { + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).toInstance(ImmutableSet.of("foo")); + bind(new TypeLiteral>() { + }).annotatedWith(Names.named("bar")).toInstance(ImmutableSet.of("bar")); + } + + @Provides + @Named("exception") + Set exception() { + throw new AuthorizationException(); + } + + @Provides + @Named("NoSuchElementException") + Set noSuchElementException() { + throw new NoSuchElementException(); + } + } +} 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 a99a8a3af3..583082d6a6 100644 --- a/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java +++ b/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java @@ -18,6 +18,7 @@ */ package org.jclouds.rest.binders; +import static org.jclouds.reflect.Reflection2.method; import static org.testng.Assert.assertEquals; import java.io.File; @@ -33,10 +34,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.reflect.TypeToken; - import com.google.common.reflect.Invokable; - /** * Tests behavior of {@code BindMapToStringPayload} * @@ -56,7 +54,7 @@ public class BindMapToStringPayloadTest { @Test public void testCorrect() throws SecurityException, NoSuchMethodException { - Invokable testPayload = Invokable.from(TestPayload.class.getMethod("testPayload", String.class)); + Invokable testPayload = method(TestPayload.class, "testPayload", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList. of("robot"))) .method("POST").endpoint("http://localhost").build(); @@ -70,7 +68,7 @@ public class BindMapToStringPayloadTest { @Test public void testDecodes() throws SecurityException, NoSuchMethodException { - Invokable testPayload = Invokable.from(TestPayload.class.getMethod("changeAdminPass", String.class)); + Invokable testPayload = method(TestPayload.class, "changeAdminPass", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList. of("foo"))) .method("POST").endpoint("http://localhost").build(); @@ -84,7 +82,7 @@ public class BindMapToStringPayloadTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testMustHavePayloadAnnotation() throws SecurityException, NoSuchMethodException { - Invokable noPayload = Invokable.from(TestPayload.class.getMethod("noPayload", String.class)); + Invokable noPayload = method(TestPayload.class, "noPayload", String.class); GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(noPayload, ImmutableList. of("robot"))) .method("POST").endpoint("http://localhost").build(); 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 6acd1bc26e..8d7102aaf6 100644 --- a/core/src/test/java/org/jclouds/rest/functions/PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest.java +++ b/core/src/test/java/org/jclouds/rest/functions/PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest.java @@ -19,6 +19,7 @@ package org.jclouds.rest.functions; import static com.google.common.base.Throwables.propagate; +import static org.jclouds.reflect.Reflection2.method; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -35,7 +36,6 @@ 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 @@ -165,9 +165,9 @@ public class PresentWhenApiVersionLexicographicallyAtOrAfterSinceApiVersionTest InvocationSuccess getApi(String name, Class target) { try { - return InvocationSuccess.create(Invocation.create( - Invokable.from(EC2AsyncApi.class.getDeclaredMethod("get" + name + "ApiForRegion", String.class)), - ImmutableList. of("region")), "present"); + return InvocationSuccess.create( + Invocation.create(method(EC2AsyncApi.class, "get" + name + "ApiForRegion", String.class), + ImmutableList. of("region")), "present"); } catch (Exception e) { throw propagate(e); } diff --git a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiMetadataTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiMetadataTest.java index 68448dd562..ec42464cdb 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiMetadataTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiMetadataTest.java @@ -17,8 +17,7 @@ * under the License. */ package org.jclouds.rest.internal; - -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import java.util.Set; @@ -46,7 +45,7 @@ public abstract class BaseRestApiMetadataTest extends BaseApiMetadataTest { @Test public void testContextAssignableFromRestContext() { - Set all = ImmutableSet.copyOf(Apis.contextAssignableFrom(typeTokenOf(RestContext.class))); + Set all = ImmutableSet.copyOf(Apis.contextAssignableFrom(typeToken(RestContext.class))); assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); } diff --git a/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java b/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java index ed4e669578..d9673c9a57 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java @@ -22,7 +22,7 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.method; import static org.testng.Assert.assertEquals; import java.util.concurrent.ExecutionException; @@ -39,7 +39,6 @@ import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.ListenableFuture; /** @@ -62,16 +61,13 @@ public class BlockOnFutureTest { } } - private TypeToken enclosingType; private Invocation get; private Invocation namedGet; @BeforeClass void setupInvocations() throws SecurityException, NoSuchMethodException { - enclosingType = typeTokenOf(ThingAsyncApi.class); - get = Invocation.create(enclosingType.method(ThingAsyncApi.class.getDeclaredMethod("get")), ImmutableList.of()); - namedGet = Invocation.create(enclosingType.method(ThingAsyncApi.class.getDeclaredMethod("namedGet")), - ImmutableList.of()); + get = Invocation.create(method(ThingAsyncApi.class, "get"), ImmutableList.of()); + namedGet = Invocation.create(method(ThingAsyncApi.class, "namedGet"), ImmutableList.of()); } @SuppressWarnings("unchecked") 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 58510157fd..0040ea719e 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.io.Payloads.calculateMD5; import static org.jclouds.io.Payloads.newInputStreamPayload; import static org.jclouds.io.Payloads.newStringPayload; +import static org.jclouds.reflect.Reflection2.method; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.fail; @@ -42,7 +43,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -93,7 +93,6 @@ import org.jclouds.logging.config.NullLoggingModule; import org.jclouds.providers.AnonymousProviderMetadata; import org.jclouds.reflect.Invocation; import org.jclouds.reflect.InvocationSuccess; -import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.InvocationContext; import org.jclouds.rest.annotations.BinderParam; @@ -120,7 +119,6 @@ import org.jclouds.rest.annotations.WrapWith; import org.jclouds.rest.binders.BindAsHostPrefix; import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.binders.BindToStringPayload; -import org.jclouds.rest.config.AsyncHttpApiProvider; import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.functions.ImplicitOptionalConverter; import org.jclouds.util.Strings2; @@ -148,12 +146,9 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.AbstractModule; import com.google.inject.ConfigurationException; import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provides; import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; - /** * Tests behavior of {@code RestAnnotationProcessor} * @@ -497,7 +492,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQuery() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("foo")); + Invokable method = method(TestQuery.class, "foo"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); @@ -506,7 +501,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQuery2() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("foo2")); + Invokable method = method(TestQuery.class, "foo2"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/"); @@ -515,7 +510,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQuery3() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("foo3", String.class)); + Invokable method = method(TestQuery.class, "foo3", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("wonder")); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -526,12 +521,12 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{robbie\\} for invocation TestQuery.foo3") public void testNiceNPEQueryParam() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestQuery.class.getMethod("foo3", String.class)); + Invokable method = method(TestQuery.class, "foo3", String.class); processor.createRequest(method, Lists. newArrayList((String) null)); } public void testNoNPEOnQueryParamWithNullable() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("foo3Nullable", String.class)); + Invokable method = method(TestQuery.class, "foo3Nullable", String.class); GeneratedHttpRequest request = processor.createRequest(method, Lists. newArrayList((String) null)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -541,7 +536,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableOneString() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); + Invokable method = method(TestQuery.class, "queryParamIterable", Iterable.class); Set bars = ImmutableSortedSet. of("1"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -551,7 +546,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableString() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); + Invokable method = method(TestQuery.class, "queryParamIterable", Iterable.class); Set bars = ImmutableSortedSet. of("1", "2", "3"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -561,7 +556,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableInteger() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); + Invokable method = method(TestQuery.class, "queryParamIterable", Iterable.class); Set bars = ImmutableSortedSet. of(1, 2, 3); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -571,7 +566,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableEmpty() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); + Invokable method = method(TestQuery.class, "queryParamIterable", Iterable.class); Set bars = Collections.emptySet(); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(bars)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -581,7 +576,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testQueryParamIterableNull() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class)); + Invokable method = method(TestQuery.class, "queryParamIterable", Iterable.class); GeneratedHttpRequest request = processor.createRequest(method, Lists. newArrayList((String) null)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -610,7 +605,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testHttpRequestOptionsNoPayloadParam() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("post")); + Invokable method = method(TestPayloadParamVarargs.class, "post"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); @@ -635,7 +630,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("post", Payload.class)); + Invokable method = method(TestPayloadParamVarargs.class, "post", Payload.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(Payloads.newStringPayload("foo"))); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); @@ -644,8 +639,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable - .from(TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class)); + Invokable method = method(TestPayloadParamVarargs.class, "post", HttpRequestOptions.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(new TestHttpRequestOptions().payload("fooya"))); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); @@ -654,8 +648,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testHeaderAndQueryVarargs() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargs", - HttpRequestOptions[].class)); + Invokable method = method(TestPayloadParamVarargs.class, "varargs", + HttpRequestOptions[].class); GeneratedHttpRequest request = processor.createRequest( method, ImmutableList. of(new TestHttpRequestOptions().payload("fooya"), @@ -667,8 +661,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testHeaderAndQueryVarargsPlusReq() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargsWithReq", String.class, - HttpRequestOptions[].class)); + Invokable method = method(TestPayloadParamVarargs.class, "varargsWithReq", String.class, + HttpRequestOptions[].class); GeneratedHttpRequest request = processor.createRequest( method, ImmutableList. of("required param", new TestHttpRequestOptions().payload("fooya"), @@ -680,8 +674,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testDuplicateHeaderAndQueryVarargs() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargs", - HttpRequestOptions[].class)); + Invokable method = method(TestPayloadParamVarargs.class, "varargs", + HttpRequestOptions[].class); GeneratedHttpRequest request = processor.createRequest( method, ImmutableList. of(new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "value")), @@ -702,7 +696,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCustomMethod() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestCustomMethod.class.getMethod("foo")); + Invokable method = method(TestCustomMethod.class, "foo"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), ""); @@ -720,7 +714,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testOverriddenMethod() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestOverridden.class.getMethod("foo")); + Invokable method = method(TestOverridden.class, "foo"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), ""); @@ -740,7 +734,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestOverriddenEndpoint.class.getMethod("foo")); + Invokable method = method(TestOverriddenEndpoint.class, "foo"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPort(), 1111); @@ -749,7 +743,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestOverriddenEndpoint.class.getMethod("foo", URI.class)); + Invokable method = method(TestOverriddenEndpoint.class, "foo", URI.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(URI.create("http://wowsa:8001"))); assertEquals(request.getEndpoint().getHost(), "wowsa"); @@ -792,7 +786,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("post", String.class)); + Invokable method = method(TestPost.class, "post", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); @@ -801,7 +795,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequestNullOk1() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("post", String.class)); + Invokable method = method(TestPost.class, "post", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); @@ -810,7 +804,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequestNullOk2() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("post", String.class)); + Invokable method = method(TestPost.class, "post", String.class); GeneratedHttpRequest request = processor.createRequest(method, Lists. newArrayList((String) null)); @@ -820,7 +814,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostRequestNullNotOk1() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("postNonnull", String.class)); + Invokable method = method(TestPost.class, "postNonnull", String.class); try { GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); Assert.fail("call should have failed with illegal null parameter, not permitted " + request + " to be created"); @@ -832,12 +826,12 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "postNonnull parameter 1") public void testCreatePostRequestNullNotOk2() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("postNonnull", String.class)); + Invokable method = method(TestPost.class, "postNonnull", String.class); processor.createRequest(method, Lists. newArrayList((String) null)); } public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("postAsJson", String.class)); + Invokable method = method(TestPost.class, "postAsJson", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); @@ -846,7 +840,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("postWithPath", String.class, MapBinder.class)); + Invokable method = method(TestPost.class, "postWithPath", String.class, MapBinder.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data", new org.jclouds.rest.MapBinder() { @Override @@ -865,7 +859,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("postWithMethodBinder", String.class)); + Invokable method = method(TestPost.class, "postWithMethodBinder", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1"); @@ -874,8 +868,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostWithMethodBinderAndDefaults() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable - .from(TestPost.class.getMethod("postWithMethodBinderAndDefaults", String.class)); + Invokable method = method(TestPost.class, "postWithMethodBinderAndDefaults", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1"); @@ -884,7 +877,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePostWithPayload() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPost.class.getMethod("testPayload", String.class)); + Invokable method = method(TestPost.class, "testPayload", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1"); @@ -913,7 +906,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withStringPart", String.class)); + Invokable method = method(TestMultipartForm.class, "withStringPart", String.class); GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of("foobledata")); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); @@ -928,13 +921,13 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "fooble") public void testMultipartWithStringPartNullNotOkay() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withStringPart", String.class)); + Invokable method = method(TestMultipartForm.class, "withStringPart", String.class); processor.createRequest(method, Lists. newArrayList((String) null)); } public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamStringPart", String.class, - String.class)); + Invokable method = method(TestMultipartForm.class, "withParamStringPart", String.class, + String.class); GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of("name", "foobledata")); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); @@ -953,14 +946,14 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{name\\} for invocation TestMultipartForm.withParamStringPart") public void testMultipartWithParamStringPartNullNotOk() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamStringPart", String.class, - String.class)); + Invokable method = method(TestMultipartForm.class, "withParamStringPart", String.class, + String.class); processor.createRequest(method, Lists. newArrayList(null, "foobledata")); } public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamFilePart", String.class, - File.class)); + Invokable method = method(TestMultipartForm.class, "withParamFilePart", String.class, + File.class); File file = File.createTempFile("foo", "bar"); Files.append("foobledata", file, UTF_8); file.deleteOnExit(); @@ -982,8 +975,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", - String.class, byte[].class)); + Invokable method = method(TestMultipartForm.class, "withParamByteArrayBinaryPart", + String.class, byte[].class); GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList. of("name", "goo".getBytes())); assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1"); @@ -1002,8 +995,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { }; public void testMultipartWithParamFileBinaryPart() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestMultipartForm.class.getMethod("withParamFileBinaryPart", - String.class, File.class)); + Invokable method = method(TestMultipartForm.class, "withParamFileBinaryPart", + String.class, File.class); File file = File.createTempFile("foo", "bar"); Files.write(new byte[] { 17, 26, 39, 40, 50 }, file); file.deleteOnExit(); @@ -1137,7 +1130,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testAlternateHttpMethod() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("rowdy", String.class)); + Invokable method = method(TestPut.class, "rowdy", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "ROWDY http://localhost:9999/strings/data HTTP/1.1"); @@ -1146,7 +1139,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testAlternateHttpMethodSameArity() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("rowdy", int.class)); + Invokable method = method(TestPut.class, "rowdy", int.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "ROWDY http://localhost:9999/ints/data HTTP/1.1"); @@ -1155,7 +1148,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("putWithMethodBinder", String.class)); + Invokable method = method(TestPut.class, "putWithMethodBinder", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1"); @@ -1164,7 +1157,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutWithMethodProduces() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("putWithMethodBinderProduces", String.class)); + Invokable method = method(TestPut.class, "putWithMethodBinderProduces", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1"); @@ -1174,7 +1167,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testCreatePutWithMethodConsumes() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("putWithMethodBinderConsumes", String.class)); + Invokable method = method(TestPut.class, "putWithMethodBinderConsumes", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("data")); assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1"); @@ -1192,7 +1185,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testGeneric1() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testGeneric")); + Invokable method = method(TestPut.class, "testGeneric"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseJson.class); @@ -1206,7 +1199,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testGeneric2() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testGeneric2")); + Invokable method = method(TestPut.class, "testGeneric2"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseJson.class); @@ -1220,7 +1213,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testGeneric3() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testGeneric3")); + Invokable method = method(TestPut.class, "testGeneric3"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseJson.class); @@ -1234,7 +1227,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrap1() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap")); + Invokable method = method(TestPut.class, "testUnwrap"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); @@ -1247,7 +1240,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrapValueNamed() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrapValueNamed")); + Invokable method = method(TestPut.class, "testUnwrapValueNamed"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseFirstJsonValueNamed.class); @@ -1259,14 +1252,14 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testWrapWith() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testWrapWith", String.class)); + Invokable method = method(TestPut.class, "testWrapWith", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("bar")); assertPayloadEquals(request, "{\"foo\":\"bar\"}", "application/json", false); } @SuppressWarnings("unchecked") public void testUnwrap2() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap2")); + Invokable method = method(TestPut.class, "testUnwrap2"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); @@ -1279,7 +1272,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrap3() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap3")); + Invokable method = method(TestPut.class, "testUnwrap3"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); @@ -1292,7 +1285,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void testUnwrap4() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("testUnwrap4")); + Invokable method = method(TestPut.class, "testUnwrap4"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); @@ -1305,7 +1298,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void selectLong() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("selectLong")); + Invokable method = method(TestPut.class, "selectLong"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertResponseParserClassEquals(method, request, ParseFirstJsonValueNamed.class); @@ -1318,7 +1311,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @SuppressWarnings("unchecked") public void selectLongAddOne() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPut.class.getMethod("selectLongAddOne")); + Invokable method = method(TestPut.class, "selectLongAddOne"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); Function parser = transformer.apply(request); @@ -1357,7 +1350,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testRequestFilter() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestRequestFilter.class.getMethod("get")); + Invokable method = method(TestRequestFilter.class, "get"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertEquals(request.getFilters().size(), 2); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class); @@ -1365,14 +1358,14 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testRequestFilterOverride() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestRequestFilter.class.getMethod("getOverride")); + Invokable method = method(TestRequestFilter.class, "getOverride"); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); assertEquals(request.getFilters().size(), 1); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class); } public void testRequestFilterOverrideOnRequest() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestRequestFilter.class.getMethod("getOverride", HttpRequest.class)); + Invokable method = method(TestRequestFilter.class, "getOverride", HttpRequest.class); GeneratedHttpRequest request = processor.createRequest( method, ImmutableList. of(HttpRequest.builder().method("GET").endpoint("http://localhost") @@ -1391,7 +1384,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testSkipEncoding() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestEncoding.class.getMethod("twoPaths", String.class, String.class)); + Invokable method = method(TestEncoding.class, "twoPaths", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", "localhost")); assertEquals(request.getEndpoint().getPath(), "/1/localhost"); @@ -1401,7 +1394,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testEncodingPath() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestEncoding.class.getMethod("twoPaths", String.class, String.class)); + Invokable method = method(TestEncoding.class, "twoPaths", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("/", "localhost")); assertEquals(request.getEndpoint().getPath(), "///localhost"); @@ -1422,8 +1415,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(enabled = false) public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestConstantPathParam.class.getMethod("twoPaths", String.class, - String.class)); + Invokable method = method(TestConstantPathParam.class, "twoPaths", String.class, + String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", "localhost")); assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1"); @@ -1470,13 +1463,13 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{path\\} for invocation TestPath.onePath") public void testNiceNPEPathParam() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPath.class.getMethod("onePath", String.class)); + Invokable method = method(TestPath.class, "onePath", String.class); processor.createRequest(method, Lists. newArrayList((String) null)); } @Test public void testPathParamExtractor() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPath.class.getMethod("onePathParamExtractor", String.class)); + Invokable method = method(TestPath.class, "onePathParamExtractor", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("localhost")); assertRequestLineEquals(request, "GET http://localhost:9999/l HTTP/1.1"); @@ -1486,7 +1479,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testQueryParamExtractor() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPath.class.getMethod("oneQueryParamExtractor", String.class)); + Invokable method = method(TestPath.class, "oneQueryParamExtractor", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("localhost")); assertRequestLineEquals(request, "GET http://localhost:9999/?one=l HTTP/1.1"); @@ -1496,7 +1489,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testFormParamExtractor() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPath.class.getMethod("oneFormParamExtractor", String.class)); + Invokable method = method(TestPath.class, "oneFormParamExtractor", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("localhost")); assertRequestLineEquals(request, "POST http://localhost:9999/ HTTP/1.1"); @@ -1506,7 +1499,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{one\\} for invocation TestPath.oneFormParamExtractor") public void testNiceNPEFormParam() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPath.class.getMethod("oneFormParamExtractor", String.class)); + Invokable method = method(TestPath.class, "oneFormParamExtractor", String.class); processor.createRequest(method, Lists. newArrayList((String) null)); } @@ -1550,7 +1543,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestHeader.class.getMethod("twoHeader", String.class)); + Invokable method = method(TestHeader.class, "twoHeader", String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot")).getHeaders(); assertEquals(headers.size(), 2); @@ -1568,7 +1561,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestClassHeader.class.getMethod("oneHeader", String.class)); + Invokable method = method(TestClassHeader.class, "oneHeader", String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot")).getHeaders(); assertEquals(headers.size(), 1); @@ -1577,7 +1570,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneHeader() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestHeader.class.getMethod("oneHeader", String.class)); + Invokable method = method(TestHeader.class, "oneHeader", String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot")).getHeaders(); assertEquals(headers.size(), 1); @@ -1586,7 +1579,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestHeader.class.getMethod("twoHeaders", String.class, String.class)); + Invokable method = method(TestHeader.class, "twoHeaders", String.class, String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot", "eggs")).getHeaders(); assertEquals(headers.size(), 1); @@ -1595,8 +1588,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, - String.class)); + Invokable method = method(TestHeader.class, "twoHeadersOutOfOrder", String.class, + String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot", "eggs")).getHeaders(); assertEquals(headers.size(), 1); @@ -1611,8 +1604,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testQueryInOptions() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQueryReplace.class.getMethod("queryInOptions", String.class, - TestReplaceQueryOptions.class)); + Invokable method = method(TestQueryReplace.class, "queryInOptions", String.class, + TestReplaceQueryOptions.class); String query = processor .createRequest(method, ImmutableList. of("robot", new TestReplaceQueryOptions())).getEndpoint() .getQuery(); @@ -1653,7 +1646,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQueryReplace.class.getMethod("twoQuery", String.class)); + Invokable method = method(TestQueryReplace.class, "twoQuery", String.class); String query = processor.createRequest(method, ImmutableList. of("robot")) .getEndpoint().getQuery(); assertEquals(query, "slash=/robot&hyphen=-robot"); @@ -1669,7 +1662,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestClassQuery.class.getMethod("oneQuery", String.class)); + Invokable method = method(TestClassQuery.class, "oneQuery", String.class); String query = processor.createRequest(method, ImmutableList. of("robot")) .getEndpoint().getQuery(); assertEquals(query, "x-amz-copy-source=/robot"); @@ -1677,7 +1670,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneQuery() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQueryReplace.class.getMethod("oneQuery", String.class)); + Invokable method = method(TestQueryReplace.class, "oneQuery", String.class); String query = processor.createRequest(method, ImmutableList. of("robot")) .getEndpoint().getQuery(); assertEquals(query, "x-amz-copy-source=/robot"); @@ -1685,8 +1678,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable - .from(TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class)); + Invokable method = method(TestQueryReplace.class, "twoQuerys", String.class, String.class); String query = processor .createRequest(method, ImmutableList. of("robot", "eggs")).getEndpoint().getQuery(); assertEquals(query, "x-amz-copy-source=/robot/eggs"); @@ -1694,8 +1686,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, - String.class)); + Invokable method = method(TestQueryReplace.class, "twoQuerysOutOfOrder", String.class, + String.class); String query = processor .createRequest(method, ImmutableList. of("robot", "eggs")).getEndpoint().getQuery(); assertEquals(query, "x-amz-copy-source=/eggs/robot"); @@ -1731,7 +1723,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class)); + Invokable method = method(TestTransformers.class, "put", PayloadEnclosing.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(new PayloadEnclosingImpl(newStringPayload("whoops")))); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); @@ -1740,7 +1732,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class)); + Invokable method = method(TestTransformers.class, "put", PayloadEnclosing.class); PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newStringPayload("whoops")); calculateMD5(payloadEnclosing); GeneratedHttpRequest request = processor.createRequest(method, @@ -1753,7 +1745,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class)); + Invokable method = method(TestTransformers.class, "put", PayloadEnclosing.class); PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl( newInputStreamPayload(Strings2.toInputStream("whoops"))); @@ -1767,7 +1759,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadChunkedNoContentLength() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("putXfer", Payload.class)); + Invokable method = method(TestTransformers.class, "putXfer", Payload.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(newStringPayload("whoops"))); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); @@ -1776,7 +1768,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayload() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + Invokable method = method(TestTransformers.class, "put", Payload.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(newStringPayload("whoops"))); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); @@ -1785,7 +1777,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadContentDisposition() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + Invokable method = method(TestTransformers.class, "put", Payload.class); Payload payload = newStringPayload("whoops"); payload.getContentMetadata().setContentDisposition("attachment; filename=photo.jpg"); GeneratedHttpRequest request = processor.createRequest(method, @@ -1796,7 +1788,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadContentEncoding() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + Invokable method = method(TestTransformers.class, "put", Payload.class); Payload payload = newStringPayload("whoops"); payload.getContentMetadata().setContentEncoding("gzip"); GeneratedHttpRequest request = processor.createRequest(method, @@ -1807,7 +1799,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testPutPayloadContentLanguage() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + Invokable method = method(TestTransformers.class, "put", Payload.class); Payload payload = newStringPayload("whoops"); payload.getContentMetadata().setContentLanguage("en"); GeneratedHttpRequest request = processor.createRequest(method, @@ -1821,7 +1813,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { IOException { Payload payload = newStringPayload("whoops"); calculateMD5(payload); - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + Invokable method = method(TestTransformers.class, "put", Payload.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); @@ -1832,7 +1824,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testPutInputStreamPayload() throws SecurityException, NoSuchMethodException, IOException { Payload payload = newInputStreamPayload(Strings2.toInputStream("whoops")); payload.getContentMetadata().setContentLength((long) "whoops".length()); - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + Invokable method = method(TestTransformers.class, "put", Payload.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); @@ -1844,7 +1836,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { NoSuchMethodException { Payload payload = newStringPayload("whoops"); calculateMD5(payload); - Invokable method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class)); + Invokable method = method(TestTransformers.class, "put", Payload.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(payload)); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); @@ -1853,7 +1845,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testInputStreamListenableFuture() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("futureInputStream")); + Invokable method = method(TestTransformers.class, "futureInputStream"); Class> transformer = unwrap(TestTransformers.class, method); assertEquals(transformer, ReturnInputStream.class); } @@ -1865,7 +1857,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testURIListenableFuture() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("futureUri")); + Invokable method = method(TestTransformers.class, "futureUri"); Class> transformer = unwrap(TestTransformers.class, method); assertEquals(transformer, ParseURIFromListOrLocationHeaderIf20x.class); } @@ -1884,7 +1876,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = RuntimeException.class) public void testNoTransformer() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("noTransformer")); + Invokable method = method(TestTransformers.class, "noTransformer"); unwrap(TestTransformers.class, method); } @@ -1893,7 +1885,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { .method("GET") .endpoint("http://localhost") .invocation( - Invocation.create(Invokable.from(TestTransformers.class.getMethod("oneTransformerWithContext")), + Invocation.create(method(TestTransformers.class, "oneTransformerWithContext"), ImmutableList.of())).build(); Function transformer = this.transformer.apply(request); assertEquals(transformer.getClass(), ReturnStringIf200Context.class); @@ -1901,7 +1893,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testOneTransformer() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestTransformers.class.getMethod("oneTransformer")); + Invokable method = method(TestTransformers.class, "oneTransformer"); Class> transformer = unwrap(TestTransformers.class, method); assertEquals(transformer, ReturnStringIf2xx.class); } @@ -1958,8 +1950,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException { Date date = new Date(); GetOptions options = GetOptions.Builder.ifModifiedSince(date); - Invokable method = Invokable.from(TestRequest.class.getMethod("get", String.class, - HttpRequestOptions[].class)); + Invokable method = method(TestRequest.class, "get", String.class, + HttpRequestOptions[].class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", options)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -1974,8 +1966,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException { Date date = new Date(); GetOptions options = GetOptions.Builder.ifModifiedSince(date); - Invokable method = Invokable.from(TestRequest.class - .getMethod("get", String.class, HttpRequestOptions.class)); + Invokable method = method(TestRequest.class, "get", String.class, HttpRequestOptions.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", options)); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -1996,8 +1987,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetOptionsThatProducesQuery() throws SecurityException, NoSuchMethodException, IOException { PrefixOptions options = new PrefixOptions().withPrefix("1"); - Invokable method = Invokable.from(TestRequest.class - .getMethod("get", String.class, HttpRequestOptions.class)); + Invokable method = method(TestRequest.class, "get", String.class, HttpRequestOptions.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", options)); assertRequestLineEquals(request, "GET http://localhost:9999/1?prefix=1 HTTP/1.1"); @@ -2006,7 +1996,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreateGetQuery() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestRequest.class.getMethod("getQuery", String.class)); + Invokable method = method(TestRequest.class, "getQuery", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); @@ -2016,7 +2006,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestRequest.class.getMethod("getQueryNull", String.class)); + Invokable method = method(TestRequest.class, "getQueryNull", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); @@ -2026,7 +2016,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreateGetQueryEmpty() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestRequest.class.getMethod("getQueryEmpty", String.class)); + Invokable method = method(TestRequest.class, "getQueryEmpty", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1")); assertEquals(request.getEndpoint().getHost(), "localhost"); assertEquals(request.getEndpoint().getPath(), "/1"); @@ -2044,8 +2034,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { public void testCreateGetOptionsThatProducesPayload() throws SecurityException, NoSuchMethodException, IOException { PayloadOptions options = new PayloadOptions(); - Invokable method = Invokable.from(TestRequest.class.getMethod("putOptions", String.class, - HttpRequestOptions.class)); + Invokable method = method(TestRequest.class, "putOptions", String.class, + HttpRequestOptions.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", options)); @@ -2062,7 +2052,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(dataProvider = "strings") public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException, UnsupportedEncodingException { - Invokable method = Invokable.from(TestRequest.class.getMethod("get", String.class, String.class)); + Invokable method = method(TestRequest.class, "get", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of(key, "localhost")); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -2075,7 +2065,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutRequest() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestRequest.class.getMethod("put", String.class, String.class)); + Invokable method = method(TestRequest.class, "put", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("111", "data")); @@ -2085,7 +2075,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { } public void testCreatePutHeader() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestRequest.class.getMethod("putHeader", String.class, String.class)); + Invokable method = method(TestRequest.class, "putHeader", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", "data")); @@ -2105,7 +2095,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestVirtualHostMethod.class.getMethod("get", String.class, String.class)); + Invokable method = method(TestVirtualHostMethod.class, "get", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", "localhost")); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -2129,7 +2119,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testVirtualHost() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestVirtualHost.class.getMethod("get", String.class, String.class)); + Invokable method = method(TestVirtualHost.class, "get", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", "localhost")); assertEquals(request.getEndpoint().getHost(), "localhost"); @@ -2141,7 +2131,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testHostPrefix() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestVirtualHost.class.getMethod("getPrefix", String.class, String.class)); + Invokable method = method(TestVirtualHost.class, "getPrefix", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("1", "holy")); assertEquals(request.getEndpoint().getHost(), "holy.localhost"); @@ -2152,7 +2142,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testHostPrefixEmpty() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestVirtualHost.class.getMethod("getPrefix", String.class, String.class)); + Invokable method = method(TestVirtualHost.class, "getPrefix", String.class, String.class); processor.createRequest(method, ImmutableList. of("1", "")); } @@ -2172,7 +2162,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testOneHeader() throws SecurityException, NoSuchMethodException, ExecutionException { - Invokable method = Invokable.from(TestHeaders.class.getMethod("oneHeader", String.class)); + Invokable method = method(TestHeaders.class, "oneHeader", String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot")).getHeaders(); assertEquals(headers.size(), 1); @@ -2181,7 +2171,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testOneIntHeader() throws SecurityException, NoSuchMethodException, ExecutionException { - Invokable method = Invokable.from(TestHeaders.class.getMethod("oneIntHeader", int.class)); + Invokable method = method(TestHeaders.class, "oneIntHeader", int.class); Multimap headers = processor.createRequest(method, ImmutableList. of(1)).getHeaders(); assertEquals(headers.size(), 1); @@ -2190,8 +2180,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException, ExecutionException { - Invokable method = Invokable.from(TestHeaders.class.getMethod("twoDifferentHeaders", String.class, - String.class)); + Invokable method = method(TestHeaders.class, "twoDifferentHeaders", String.class, + String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot", "egg")).getHeaders(); assertEquals(headers.size(), 2); @@ -2201,8 +2191,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException, ExecutionException { - Invokable method = Invokable - .from(TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class)); + Invokable method = method(TestHeaders.class, "twoSameHeaders", String.class, String.class); Multimap headers = processor.createRequest(method, ImmutableList. of("robot", "egg")).getHeaders(); assertEquals(headers.size(), 2); @@ -2244,7 +2233,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testOneEndpointParam() throws SecurityException, NoSuchMethodException, ExecutionException { - Invokable method = Invokable.from(TestEndpointParams.class.getMethod("oneEndpointParam", String.class)); + Invokable method = method(TestEndpointParams.class, "oneEndpointParam", String.class); URI uri = RestAnnotationProcessor.getEndpointInParametersOrNull( Invocation.create(method, ImmutableList. of("robot")), injector); assertEquals(uri, URI.create("robot")); @@ -2253,8 +2242,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test(expectedExceptions = IllegalStateException.class) public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException, ExecutionException { - Invokable method = Invokable.from(TestEndpointParams.class.getMethod("twoEndpointParams", String.class, - String.class)); + Invokable method = method(TestEndpointParams.class, "twoEndpointParams", String.class, + String.class); RestAnnotationProcessor.getEndpointInParametersOrNull( Invocation.create(method, ImmutableList. of("robot", "egg")), injector); } @@ -2275,7 +2264,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testPut() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPayload.class.getMethod("put", String.class)); + Invokable method = method(TestPayload.class, "put", String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("test")); @@ -2286,7 +2275,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void putWithPath() throws SecurityException, NoSuchMethodException, IOException { - Invokable method = Invokable.from(TestPayload.class.getMethod("putWithPath", String.class, String.class)); + Invokable method = method(TestPayload.class, "putWithPath", String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. of("rabble", "test")); @@ -2335,7 +2324,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoForm() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestFormReplace.class.getMethod("twoForm", String.class)); + Invokable method = method(TestFormReplace.class, "twoForm", String.class); Object form = processor.createRequest(method, ImmutableList. of("robot")) .getPayload().getRawContent(); assertEquals(form, "slash=/robot&hyphen=-robot"); @@ -2343,55 +2332,14 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @FormParams(keys = "x-amz-copy-source", values = "/{bucket}") public interface TestClassForm { - @Provides - Set set(); - - @Named("bar") - @Provides - Set foo(); - - @Named("exception") - @Provides - Set exception(); - - @Named("NoSuchElementException") - @Provides - Set noSuchElementException(); - @POST @Path("/") void oneForm(@PathParam("bucket") String path); } - static final Key> formKey = Key - .get(new TypeLiteral>() { - }); - - @Test - public void testProvidesWithGeneric() throws SecurityException, NoSuchMethodException { - Set set = injector.getInstance(formKey).get().set(); - assertEquals(set, ImmutableSet.of("foo")); - } - - @Test - public void testProvidesWithGenericQualified() throws SecurityException, NoSuchMethodException { - Set set = injector.getInstance(formKey).get().foo(); - assertEquals(set, ImmutableSet.of("bar")); - } - - @Test(expectedExceptions = AuthorizationException.class) - public void testProvidesWithGenericQualifiedAuthorizationException() throws SecurityException, NoSuchMethodException { - injector.getInstance(formKey).get().exception(); - } - - @Test(expectedExceptions = NoSuchElementException.class) - public void testProvidesWithGenericQualifiedNoSuchElementException() throws SecurityException, NoSuchMethodException { - injector.getInstance(formKey).get().noSuchElementException(); - } - @Test public void testBuildOneClassForm() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestClassForm.class.getMethod("oneForm", String.class)); + Invokable method = method(TestClassForm.class, "oneForm", String.class); Object form = processor.createRequest(method, ImmutableList. of("robot")) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot"); @@ -2399,7 +2347,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildOneForm() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestFormReplace.class.getMethod("oneForm", String.class)); + Invokable method = method(TestFormReplace.class, "oneForm", String.class); Object form = processor.createRequest(method, ImmutableList. of("robot")) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot"); @@ -2407,7 +2355,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoForms() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestFormReplace.class.getMethod("twoForms", String.class, String.class)); + Invokable method = method(TestFormReplace.class, "twoForms", String.class, String.class); Object form = processor.createRequest(method, ImmutableList. of("robot", "eggs")) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/robot/eggs"); @@ -2415,8 +2363,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { @Test public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException { - Invokable method = Invokable.from(TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, - String.class)); + Invokable method = method(TestFormReplace.class, "twoFormsOutOfOrder", String.class, + String.class); Object form = processor.createRequest(method, ImmutableList. of("robot", "eggs")) .getPayload().getRawContent(); assertEquals(form, "x-amz-copy-source=/eggs/robot"); @@ -2462,30 +2410,11 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest { AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(Callee.class, AsyncCallee.class, "http://localhost:9999")) .modules(ImmutableSet. of(new MockModule(), new NullLoggingModule(), new AbstractModule() { - - @Override protected void configure() { - bind(new TypeLiteral>() { - }).toInstance(ImmutableSet.of("foo")); - bind(new TypeLiteral>() { - }).annotatedWith(Names.named("bar")).toInstance(ImmutableSet.of("bar")); bind(new TypeLiteral>() { }).annotatedWith(Localhost2.class).toInstance( Suppliers.ofInstance(URI.create("http://localhost:1111"))); } - - @Provides - @Named("exception") - Set exception() { - throw new AuthorizationException(); - } - - @Provides - @Named("NoSuchElementException") - Set noSuchElementException() { - throw new NoSuchElementException(); - } - })).buildInjector(); parserFactory = injector.getInstance(ParseSax.Factory.class); processor = injector.getInstance(RestAnnotationProcessor.class); diff --git a/core/src/test/java/org/jclouds/util/Optionals2Test.java b/core/src/test/java/org/jclouds/util/Optionals2Test.java index 5f156176f4..8b8791a462 100644 --- a/core/src/test/java/org/jclouds/util/Optionals2Test.java +++ b/core/src/test/java/org/jclouds/util/Optionals2Test.java @@ -17,7 +17,7 @@ * under the License. */ package org.jclouds.util; - +import static org.jclouds.reflect.Reflection2.method; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; @@ -40,25 +40,25 @@ public class Optionals2Test { } public void testReturnTypeOrTypeOfOptionalWhenOptional() throws SecurityException, NoSuchMethodException { - Invokable invoked = Invokable.from(Test.class.getMethod("getOptional")); + Invokable invoked = method(Test.class, "getOptional"); assertEquals(Optionals2.unwrapIfOptional(invoked.getReturnType()), String.class); } public void testReturnTypeOrTypeOfOptionalWhenNotOptional() throws SecurityException, NoSuchMethodException { - Invokable invoked = Invokable.from(Test.class.getMethod("getNotOptional")); + Invokable invoked = method(Test.class, "getNotOptional"); assertEquals(Optionals2.unwrapIfOptional(invoked.getReturnType()), String.class); } public void testIsReturnTypeOptionalWhenOptional() throws SecurityException, NoSuchMethodException { - Invokable invoked = Invokable.from(Test.class.getMethod("getOptional")); + Invokable invoked = method(Test.class, "getOptional"); assertTrue(Optionals2.isReturnTypeOptional(invoked)); } public void testIsReturnTypeOptionalWhenNotOptional() throws SecurityException, NoSuchMethodException { - Invokable invoked = Invokable.from(Test.class.getMethod("getNotOptional")); + Invokable invoked = method(Test.class, "getNotOptional"); assertFalse(Optionals2.isReturnTypeOptional(invoked)); } diff --git a/core/src/test/java/org/jclouds/util/Throwables2Test.java b/core/src/test/java/org/jclouds/util/Throwables2Test.java index 907d739865..15497a7982 100644 --- a/core/src/test/java/org/jclouds/util/Throwables2Test.java +++ b/core/src/test/java/org/jclouds/util/Throwables2Test.java @@ -20,7 +20,7 @@ package org.jclouds.util; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createNiceMock; -import static org.jclouds.reflect.Reflection2.typeTokenOf; +import static org.jclouds.reflect.Reflection2.typeToken; import static org.jclouds.util.Throwables2.getFirstThrowableOfType; import static org.jclouds.util.Throwables2.propagateIfPossible; import static org.testng.Assert.assertEquals; @@ -148,14 +148,14 @@ public class Throwables2Test { @Test(expectedExceptions = TestException.class) public void testPropagateExceptionThatsInList() throws Throwable { Exception e = new TestException(); - propagateIfPossible(e, ImmutableSet.> of(typeTokenOf(TestException.class))); + propagateIfPossible(e, ImmutableSet.> of(typeToken(TestException.class))); } @Test(expectedExceptions = TestException.class) public void testPropagateWrappedExceptionThatsInList() throws Throwable { Exception e = new TestException(); propagateIfPossible(new RuntimeException(e), - ImmutableSet.> of(typeTokenOf(TestException.class))); + ImmutableSet.> of(typeToken(TestException.class))); } public void testPropagateIfPossibleDoesnThrowExceptionNotInList() throws Throwable {