Merge pull request #548 from aplowe/master

RestAnnotationProcessor.MethodKey change
This commit is contained in:
Adrian Cole 2012-04-10 06:44:21 -07:00
commit b2d4a158a6
2 changed files with 33 additions and 13 deletions

View File

@ -348,7 +348,7 @@ public class RestAnnotationProcessor<T> {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((declaringPackage == null) ? 0 : declaringPackage.hashCode());
result = prime * result + ((declaringClass == null) ? 0 : declaringClass.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + parametersTypeHashCode;
return result;
@ -363,10 +363,10 @@ public class RestAnnotationProcessor<T> {
if (getClass() != obj.getClass())
return false;
MethodKey other = (MethodKey) obj;
if (declaringPackage == null) {
if (other.declaringPackage != null)
if (declaringClass == null) {
if (other.declaringClass != null)
return false;
} else if (!declaringPackage.equals(other.declaringPackage))
} else if (!declaringClass.equals(other.declaringClass))
return false;
if (name == null) {
if (other.name != null)
@ -380,11 +380,11 @@ public class RestAnnotationProcessor<T> {
private final String name;
private final int parametersTypeHashCode;
private final Package declaringPackage;
private final Class declaringClass;
public MethodKey(Method method) {
this.name = method.getName();
this.declaringPackage = method.getDeclaringClass().getPackage();
this.declaringClass = method.getDeclaringClass();
int parametersTypeHashCode = 0;
for (Class<?> param : method.getParameterTypes())
parametersTypeHashCode += param.hashCode();

View File

@ -180,7 +180,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@ConfiguresRestClient
protected static class CallerModule extends RestClientModule<Caller, AsyncCaller> {
CallerModule() {
super(Caller.class, AsyncCaller.class, ImmutableMap.<Class<?>, Class<?>> of(Callee.class, AsyncCallee.class));
super(Caller.class, AsyncCaller.class, ImmutableMap.<Class<?>, Class<?>> of(Callee.class, AsyncCallee.class, Callee2.class, AsyncCallee2.class));
}
@Override
@ -199,7 +199,14 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@Path("/{path}")
ListenableFuture<Void> onePath(@PathParam("path") String path);
}
@Path("/client/{jclouds.api-version}")
public static interface AsyncCallee2 {
@GET
@Path("/{path}/2")
ListenableFuture<Void> onePath(@PathParam("path") String path);
}
@Endpoint(Localhost2.class)
@Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS)
public static interface Caller {
@ -212,6 +219,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@Delegate
public Callee getCallee();
@Delegate
public Callee2 getCallee2();
@Delegate
public Callee getCallee(@EndpointParam URI endpoint);
@ -224,6 +234,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
void onePath(String path);
}
@Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS)
public static interface Callee2 {
void onePath(String path);
}
public static interface AsyncCaller {
@Provides
@ -233,6 +249,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@Delegate
public AsyncCallee getCallee();
@Delegate
public AsyncCallee2 getCallee2();
@Delegate
public AsyncCallee getCallee(@EndpointParam URI endpoint);
@ -267,14 +286,14 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
public void testDelegateIsLazyLoadedAndRequestIncludesVersionAndPath() throws InterruptedException,
ExecutionException {
Injector child = injectorForCaller(new HttpCommandExecutorService() {
int callCounter=0;
@Override
public Future<HttpResponse> submit(HttpCommand command) {
assertEquals(command.getCurrentRequest().getRequestLine(),
"GET http://localhost:1111/client/1/foo HTTP/1.1");
if (callCounter == 1) assertEquals(command.getCurrentRequest().getRequestLine(), "GET http://localhost:1111/client/1/bar/2 HTTP/1.1");
else assertEquals(command.getCurrentRequest().getRequestLine(), "GET http://localhost:1111/client/1/foo HTTP/1.1");
callCounter++;
return Futures.immediateFuture(HttpResponse.builder().build());
}
});
try {
@ -285,8 +304,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
}
child.getInstance(Caller.class).getCallee().onePath("foo");
child.getInstance(Caller.class).getCallee2().onePath("bar");
// Note if wrong method is picked up, we'll see "http://localhost:1111/client/1/foo/2"!
child.getInstance(Caller.class).getCallee().onePath("foo");
}
public void testAsyncDelegateIsLazyLoadedAndRequestIncludesEndpointVersionAndPath() throws InterruptedException,