mirror of https://github.com/apache/jclouds.git
Merge pull request #548 from aplowe/master
RestAnnotationProcessor.MethodKey change
This commit is contained in:
commit
b2d4a158a6
|
@ -348,7 +348,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
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 + ((name == null) ? 0 : name.hashCode());
|
||||||
result = prime * result + parametersTypeHashCode;
|
result = prime * result + parametersTypeHashCode;
|
||||||
return result;
|
return result;
|
||||||
|
@ -363,10 +363,10 @@ public class RestAnnotationProcessor<T> {
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
MethodKey other = (MethodKey) obj;
|
MethodKey other = (MethodKey) obj;
|
||||||
if (declaringPackage == null) {
|
if (declaringClass == null) {
|
||||||
if (other.declaringPackage != null)
|
if (other.declaringClass != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!declaringPackage.equals(other.declaringPackage))
|
} else if (!declaringClass.equals(other.declaringClass))
|
||||||
return false;
|
return false;
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
if (other.name != null)
|
if (other.name != null)
|
||||||
|
@ -380,11 +380,11 @@ public class RestAnnotationProcessor<T> {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int parametersTypeHashCode;
|
private final int parametersTypeHashCode;
|
||||||
private final Package declaringPackage;
|
private final Class declaringClass;
|
||||||
|
|
||||||
public MethodKey(Method method) {
|
public MethodKey(Method method) {
|
||||||
this.name = method.getName();
|
this.name = method.getName();
|
||||||
this.declaringPackage = method.getDeclaringClass().getPackage();
|
this.declaringClass = method.getDeclaringClass();
|
||||||
int parametersTypeHashCode = 0;
|
int parametersTypeHashCode = 0;
|
||||||
for (Class<?> param : method.getParameterTypes())
|
for (Class<?> param : method.getParameterTypes())
|
||||||
parametersTypeHashCode += param.hashCode();
|
parametersTypeHashCode += param.hashCode();
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
protected static class CallerModule extends RestClientModule<Caller, AsyncCaller> {
|
protected static class CallerModule extends RestClientModule<Caller, AsyncCaller> {
|
||||||
CallerModule() {
|
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
|
@Override
|
||||||
|
@ -199,7 +199,14 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Path("/{path}")
|
@Path("/{path}")
|
||||||
ListenableFuture<Void> onePath(@PathParam("path") String 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)
|
@Endpoint(Localhost2.class)
|
||||||
@Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS)
|
@Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS)
|
||||||
public static interface Caller {
|
public static interface Caller {
|
||||||
|
@ -212,6 +219,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Delegate
|
@Delegate
|
||||||
public Callee getCallee();
|
public Callee getCallee();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
public Callee2 getCallee2();
|
||||||
|
|
||||||
@Delegate
|
@Delegate
|
||||||
public Callee getCallee(@EndpointParam URI endpoint);
|
public Callee getCallee(@EndpointParam URI endpoint);
|
||||||
|
|
||||||
|
@ -224,6 +234,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
void onePath(String path);
|
void onePath(String path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Timeout(duration = 10, timeUnit = TimeUnit.NANOSECONDS)
|
||||||
|
public static interface Callee2 {
|
||||||
|
|
||||||
|
void onePath(String path);
|
||||||
|
}
|
||||||
|
|
||||||
public static interface AsyncCaller {
|
public static interface AsyncCaller {
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -233,6 +249,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Delegate
|
@Delegate
|
||||||
public AsyncCallee getCallee();
|
public AsyncCallee getCallee();
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
public AsyncCallee2 getCallee2();
|
||||||
|
|
||||||
@Delegate
|
@Delegate
|
||||||
public AsyncCallee getCallee(@EndpointParam URI endpoint);
|
public AsyncCallee getCallee(@EndpointParam URI endpoint);
|
||||||
|
|
||||||
|
@ -267,14 +286,14 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testDelegateIsLazyLoadedAndRequestIncludesVersionAndPath() throws InterruptedException,
|
public void testDelegateIsLazyLoadedAndRequestIncludesVersionAndPath() throws InterruptedException,
|
||||||
ExecutionException {
|
ExecutionException {
|
||||||
Injector child = injectorForCaller(new HttpCommandExecutorService() {
|
Injector child = injectorForCaller(new HttpCommandExecutorService() {
|
||||||
|
int callCounter=0;
|
||||||
@Override
|
@Override
|
||||||
public Future<HttpResponse> submit(HttpCommand command) {
|
public Future<HttpResponse> submit(HttpCommand command) {
|
||||||
assertEquals(command.getCurrentRequest().getRequestLine(),
|
if (callCounter == 1) assertEquals(command.getCurrentRequest().getRequestLine(), "GET http://localhost:1111/client/1/bar/2 HTTP/1.1");
|
||||||
"GET http://localhost:1111/client/1/foo 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());
|
return Futures.immediateFuture(HttpResponse.builder().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -285,8 +304,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
child.getInstance(Caller.class).getCallee().onePath("foo");
|
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");
|
child.getInstance(Caller.class).getCallee().onePath("foo");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAsyncDelegateIsLazyLoadedAndRequestIncludesEndpointVersionAndPath() throws InterruptedException,
|
public void testAsyncDelegateIsLazyLoadedAndRequestIncludesEndpointVersionAndPath() throws InterruptedException,
|
||||||
|
|
Loading…
Reference in New Issue