Merge pull request #1334 from jclouds/delegate-with-payloadparam

@Delegate considers @PayloadParam
This commit is contained in:
Adrian Cole 2013-02-21 12:59:23 -08:00
commit 5f8c2c269c
2 changed files with 28 additions and 5 deletions

View File

@ -293,7 +293,13 @@ public class RestAnnotationProcessor implements Function<Invocation, HttpRequest
org.jclouds.rest.MapBinder mapBinder = getMapPayloadBinderOrNull(invocation); org.jclouds.rest.MapBinder mapBinder = getMapPayloadBinderOrNull(invocation);
if (mapBinder != null) { if (mapBinder != null) {
Map<String, Object> mapParams = buildPayloadParams(invocation); Map<String, Object> mapParams;
if (caller != null) {
mapParams = buildPayloadParams(caller);
mapParams.putAll(buildPayloadParams(invocation));
} else {
mapParams = buildPayloadParams(invocation);
}
if (invocation.getInvokable().isAnnotationPresent(PayloadParams.class)) { if (invocation.getInvokable().isAnnotationPresent(PayloadParams.class)) {
PayloadParams params = invocation.getInvokable().getAnnotation(PayloadParams.class); PayloadParams params = invocation.getInvokable().getAnnotation(PayloadParams.class);
addMapPayload(mapParams, params, headers); addMapPayload(mapParams, params, headers);

View File

@ -22,6 +22,7 @@ import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToA
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import javax.ws.rs.HEAD; import javax.ws.rs.HEAD;
import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
@ -32,6 +33,8 @@ import org.jclouds.providers.ProviderMetadata;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.internal.BaseRestClientExpectTest; import org.jclouds.rest.internal.BaseRestClientExpectTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -52,22 +55,26 @@ public class DelegateAnnotationExpectTest extends BaseRestClientExpectTest<Deleg
@Delegate @Delegate
@Path("/projects/{project}") @Path("/projects/{project}")
DiskApi getDiskApiForProject(@PathParam("project") String projectName); DiskApi getDiskApiForProject(@PayloadParam("project") @PathParam("project") String projectName);
} }
static interface DelegatingAsyncApi { static interface DelegatingAsyncApi {
@Delegate @Delegate
@Path("/projects/{project}") @Path("/projects/{project}")
DiskAsyncApi getDiskApiForProject(@PathParam("project") String projectName); DiskAsyncApi getDiskApiForProject(@PayloadParam("project") @PathParam("project") String projectName);
} }
static interface DiskApi { static interface DiskApi {
void syncAll();
boolean exists(@PathParam("disk") String diskName); boolean exists(@PathParam("disk") String diskName);
} }
static interface DiskAsyncApi { static interface DiskAsyncApi {
@POST
@Payload("<Sync>{project}</Sync>")
ListenableFuture<Void> syncAll();
@HEAD @HEAD
@Path("/disks/{disk}") @Path("/disks/{disk}")
@ -75,6 +82,17 @@ public class DelegateAnnotationExpectTest extends BaseRestClientExpectTest<Deleg
public ListenableFuture<Boolean> exists(@PathParam("disk") String diskName); public ListenableFuture<Boolean> exists(@PathParam("disk") String diskName);
} }
public void testDelegatingCallTakesIntoConsiderationAndCalleePayloadParam() {
DelegatingApi client = requestSendsResponse(
HttpRequest.builder().method("POST")
.endpoint("http://mock/projects/prod")
.payload("<Sync>prod</Sync>").build(),
HttpResponse.builder().statusCode(200).build());
client.getDiskApiForProject("prod").syncAll();
}
public void testDelegatingCallTakesIntoConsiderationCallerAndCalleePath() { public void testDelegatingCallTakesIntoConsiderationCallerAndCalleePath() {
DelegatingApi client = requestSendsResponse( DelegatingApi client = requestSendsResponse(
@ -82,7 +100,6 @@ public class DelegateAnnotationExpectTest extends BaseRestClientExpectTest<Deleg
HttpResponse.builder().statusCode(200).build()); HttpResponse.builder().statusCode(200).build());
assertTrue(client.getDiskApiForProject("prod").exists("disk1")); assertTrue(client.getDiskApiForProject("prod").exists("disk1"));
} }
// crufty junk until we inspect delegating api classes for all their client // crufty junk until we inspect delegating api classes for all their client