From 4eb6c081551eea2ec994b69595096a2c191cfb78 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 18 Dec 2011 17:59:13 -0800 Subject: [PATCH] removed deprecated Unwrap fields --- .../jclouds/cloudstack/AsyncJobException.java | 2 + .../org/jclouds/cloudstack/domain/Host.java | 11 +- .../org/jclouds/cloudstack/domain/ISO.java | 3 +- .../cloudstack/domain/ISOExtraction.java | 4 +- .../features/GlobalAccountAsyncClient.java | 12 +- .../features/GlobalOfferingAsyncClient.java | 17 +-- .../features/LoadBalancerAsyncClient.java | 22 +-- .../features/SecurityGroupAsyncClient.java | 11 +- .../features/TemplateAsyncClient.java | 1 - .../features/VirtualMachineAsyncClient.java | 14 +- .../ParseAsyncJobsFromHttpResponse.java | 5 +- .../cloudstack/options/ListHostsOptions.java | 5 +- .../options/UpdateServiceOfferingOptions.java | 4 - .../cloudstack/predicates/JobComplete.java | 4 - .../predicates/VirtualMachineExpunged.java | 14 +- ...oudStackComputeServiceAdapterLiveTest.java | 2 +- .../GlobalCapacityClientLiveTest.java | 8 +- .../features/GlobalHostAsyncClientTest.java | 6 +- .../features/GlobalHostClientLiveTest.java | 8 +- .../GlobalOfferingAsyncClientTest.java | 8 +- .../features/GlobalUsageClientLiveTest.java | 28 +--- .../features/GlobalUserAsyncClientTest.java | 6 +- .../features/LoadBalancerAsyncClientTest.java | 12 +- .../features/LoadBalancerClientLiveTest.java | 22 +-- .../features/OfferingAsyncClientTest.java | 5 +- .../SecurityGroupAsyncClientTest.java | 11 +- .../features/TemplateAsyncClientTest.java | 3 +- .../VirtualMachineAsyncClientTest.java | 15 +- .../UpdateNetworkOfferingOptionsTest.java | 8 +- .../UpdateServiceOfferingOptionsTest.java | 17 +-- .../parse/JobResultResponseTest.java | 1 - .../ListNetworkOfferingsResponseTest.java | 5 +- .../parse/ListStoragePoolsResponseTest.java | 17 +-- .../predicates/JobCompleteTest.java | 30 ++-- .../functions/UnwrapOnlyNestedJsonValue.java | 70 --------- .../UnwrapOnlyNestedJsonValueInSet.java | 51 ------- .../org/jclouds/rest/annotations/Unwrap.java | 43 ------ .../internal/RestAnnotationProcessor.java | 27 +--- .../internal/RestAnnotationProcessorTest.java | 135 ------------------ 39 files changed, 153 insertions(+), 514 deletions(-) delete mode 100644 core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValue.java delete mode 100644 core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValueInSet.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/AsyncJobException.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/AsyncJobException.java index b2fd691ac3..48004f655d 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/AsyncJobException.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/AsyncJobException.java @@ -23,6 +23,8 @@ package org.jclouds.cloudstack; */ public class AsyncJobException extends RuntimeException { + private static final long serialVersionUID = -9174243454135616477L; + public AsyncJobException() { } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java index a4a74d1543..8b59238963 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java @@ -18,16 +18,13 @@ */ package org.jclouds.cloudstack.domain; -import com.google.common.collect.Maps; -import com.google.gson.annotations.SerializedName; -import org.omg.CORBA.UNKNOWN; - -import java.util.Date; -import java.util.Map; - import static com.google.common.base.CaseFormat.UPPER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import java.util.Date; + +import com.google.gson.annotations.SerializedName; + /** * Represents a host issued by Cloudstack * diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java index 7f50c62620..b38b81509d 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISO.java @@ -18,9 +18,10 @@ */ package org.jclouds.cloudstack.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Date; -import static com.google.common.base.Preconditions.checkNotNull; import com.google.gson.annotations.SerializedName; /** diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java index 28f53e09f7..9fb91087c4 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ISOExtraction.java @@ -18,10 +18,10 @@ */ package org.jclouds.cloudstack.domain; -import com.google.gson.annotations.SerializedName; - import java.util.Date; +import com.google.gson.annotations.SerializedName; + /** * @author Richard Downer */ diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java index 88f0746f69..27c9507d44 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalAccountAsyncClient.java @@ -18,7 +18,11 @@ */ package org.jclouds.cloudstack.features; -import com.google.common.util.concurrent.ListenableFuture; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import org.jclouds.cloudstack.domain.Account; import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.options.CreateAccountOptions; @@ -29,11 +33,7 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import java.util.Set; +import com.google.common.util.concurrent.ListenableFuture; /** * Provides asynchronous access to CloudStack Account features available to Global diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java index 00ee41798e..1483459665 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClient.java @@ -18,32 +18,27 @@ */ package org.jclouds.cloudstack.features; -import com.google.common.util.concurrent.ListenableFuture; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import org.jclouds.cloudstack.domain.DiskOffering; import org.jclouds.cloudstack.domain.NetworkOffering; import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.options.CreateDiskOfferingOptions; import org.jclouds.cloudstack.options.CreateServiceOfferingOptions; -import org.jclouds.cloudstack.options.ListDiskOfferingsOptions; -import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions; -import org.jclouds.cloudstack.options.ListServiceOfferingsOptions; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions; import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.OnlyElement; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import java.util.Set; +import com.google.common.util.concurrent.ListenableFuture; /** * Provides asynchronous access to cloudstack via their REST API. diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java index 13a95ac2ae..cc368ecbe2 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java @@ -32,10 +32,11 @@ import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; import org.jclouds.functions.JoinOnComma; import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.OnlyElement; import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.Unwrap; +import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -58,7 +59,7 @@ public interface LoadBalancerAsyncClient { */ @GET @QueryParams(keys = "command", values = "listLoadBalancerRules") - @Unwrap(depth = 2) + @SelectJson("loadbalancerrule") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listLoadBalancerRules(ListLoadBalancerRulesOptions... options); @@ -68,7 +69,8 @@ public interface LoadBalancerAsyncClient { */ @GET @QueryParams(keys = "command", values = "listLoadBalancerRules") - @Unwrap(depth = 3, edgeCollection = Set.class) + @SelectJson("loadbalancerrule") + @OnlyElement @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getLoadBalancerRule(@QueryParam("id") long id); @@ -78,7 +80,7 @@ public interface LoadBalancerAsyncClient { */ @GET @QueryParams(keys = "command", values = "createLoadBalancerRule") - @Unwrap(depth = 2) + @SelectJson("loadbalancerrule") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture createLoadBalancerRuleForPublicIP(@QueryParam("publicipid") long publicIPId, @QueryParam("algorithm") Algorithm algorithm, @QueryParam("name") String name, @@ -89,7 +91,7 @@ public interface LoadBalancerAsyncClient { */ @GET @QueryParams(keys = "command", values = "deleteLoadBalancerRule") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture deleteLoadBalancerRule(@QueryParam("id") long id); @@ -100,7 +102,7 @@ public interface LoadBalancerAsyncClient { @GET @QueryParams(keys = "command", values = "assignToLoadBalancerRule") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture assignVirtualMachinesToLoadBalancerRule(@QueryParam("id") long id, @QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) Iterable virtualMachineIds); @@ -111,7 +113,7 @@ public interface LoadBalancerAsyncClient { @GET @QueryParams(keys = "command", values = "assignToLoadBalancerRule") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture assignVirtualMachinesToLoadBalancerRule(@QueryParam("id") long id, @QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) long... virtualMachineIds); @@ -122,7 +124,7 @@ public interface LoadBalancerAsyncClient { @GET @QueryParams(keys = "command", values = "removeFromLoadBalancerRule") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture removeVirtualMachinesFromLoadBalancerRule(@QueryParam("id") long id, @QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) Iterable virtualMachineIds); @@ -133,7 +135,7 @@ public interface LoadBalancerAsyncClient { @GET @QueryParams(keys = "command", values = "removeFromLoadBalancerRule") @ExceptionParser(ReturnNullOnNotFoundOr404.class) - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture removeVirtualMachinesFromLoadBalancerRule(@QueryParam("id") long id, @QueryParam("virtualmachineids") @ParamParser(JoinOnComma.class) long... virtualMachineIds); @@ -143,7 +145,7 @@ public interface LoadBalancerAsyncClient { */ @GET @QueryParams(keys = "command", values = "listLoadBalancerRuleInstances") - @Unwrap(depth = 2) + @SelectJson("loadbalancerrule") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listVirtualMachinesAssignedToLoadBalancerRule(@QueryParam("id") long id); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java index 1a197fb555..e6312bcd63 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java @@ -37,7 +37,6 @@ import org.jclouds.rest.annotations.OnlyElement; import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.SelectJson; -import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; @@ -92,7 +91,7 @@ public interface SecurityGroupAsyncClient { */ @GET @QueryParams(keys = "command", values = "authorizeSecurityGroupIngress") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture authorizeIngressPortsToCIDRs(@QueryParam("securitygroupid") long securityGroupId, @QueryParam("protocol") String protocol, @QueryParam("startport") int startPort, @@ -105,7 +104,7 @@ public interface SecurityGroupAsyncClient { */ @GET @QueryParams(keys = "command", values = "authorizeSecurityGroupIngress") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture authorizeIngressPortsToSecurityGroups(@QueryParam("securitygroupid") long securityGroupId, @QueryParam("protocol") String protocol, @QueryParam("startport") int startPort, @@ -118,7 +117,7 @@ public interface SecurityGroupAsyncClient { */ @GET @QueryParams(keys = { "command", "protocol" }, values = { "authorizeSecurityGroupIngress", "ICMP" }) - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture authorizeIngressICMPToCIDRs(@QueryParam("securitygroupid") long securityGroupId, @QueryParam("icmpcode") int ICMPCode, @QueryParam("icmptype") int ICMPType, @@ -130,7 +129,7 @@ public interface SecurityGroupAsyncClient { */ @GET @QueryParams(keys = { "command", "protocol" }, values = { "authorizeSecurityGroupIngress", "ICMP" }) - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture authorizeIngressICMPToSecurityGroups(@QueryParam("securitygroupid") long securityGroupId, @QueryParam("icmpcode") int ICMPCode, @QueryParam("icmptype") int ICMPType, @@ -143,7 +142,7 @@ public interface SecurityGroupAsyncClient { @GET @QueryParams(keys = "command", values = "revokeSecurityGroupIngress") @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture revokeIngressRule(@QueryParam("id") long id, AccountInDomainOptions... options); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java index d3186e53fd..c96c871ae6 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/TemplateAsyncClient.java @@ -50,7 +50,6 @@ import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import com.google.common.util.concurrent.ListenableFuture; diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java index 2662526a32..b63d402afc 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java @@ -90,7 +90,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "rebootVirtualMachine") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture rebootVirtualMachine(@QueryParam("id") long id); @@ -99,7 +99,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "startVirtualMachine") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture startVirtualMachine(@QueryParam("id") long id); @@ -108,7 +108,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "stopVirtualMachine") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture stopVirtualMachine(@QueryParam("id") long id); @@ -117,7 +117,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "resetPasswordForVirtualMachine") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture resetPasswordForVirtualMachine(@QueryParam("id") long id); @@ -126,7 +126,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "changeServiceForVirtualMachine") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture changeServiceForVirtualMachine(@QueryParam("id") long id); @@ -135,7 +135,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "updateVirtualMachine") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) ListenableFuture updateVirtualMachine(@QueryParam("id") long id); @@ -144,7 +144,7 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "destroyVirtualMachine") - @Unwrap(depth = 2) + @SelectJson("jobid") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture destroyVirtualMachine(@QueryParam("id") long id); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ParseAsyncJobsFromHttpResponse.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ParseAsyncJobsFromHttpResponse.java index f182804121..0cfeae650f 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ParseAsyncJobsFromHttpResponse.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/ParseAsyncJobsFromHttpResponse.java @@ -25,18 +25,17 @@ import java.util.Set; import javax.inject.Singleton; -import com.google.inject.TypeLiteral; import org.jclouds.cloudstack.domain.AsyncJob; import org.jclouds.domain.JsonBall; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ParseFirstJsonValueNamed; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; +import org.jclouds.json.internal.GsonWrapper; import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Inject; -import org.jclouds.json.internal.GsonWrapper; +import com.google.inject.TypeLiteral; /** * @author Adrian Cole diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java index ca4d3c2731..76ec74e815 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListHostsOptions.java @@ -18,10 +18,9 @@ */ package org.jclouds.cloudstack.options; -import com.google.common.collect.ImmutableSet; import org.jclouds.cloudstack.domain.Host; -import org.jclouds.cloudstack.domain.NetworkType; -import org.jclouds.cloudstack.domain.TrafficType; + +import com.google.common.collect.ImmutableSet; /** * Options used to control what hosts information is returned diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java index fb09236a98..24a6d10b0e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateServiceOfferingOptions.java @@ -19,10 +19,6 @@ package org.jclouds.cloudstack.options; import com.google.common.collect.ImmutableSet; -import org.jclouds.cloudstack.domain.StorageType; -import org.jclouds.cloudstack.domain.SystemVmType; - -import java.util.Set; /** * Options to control how service offerings are created diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/JobComplete.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/JobComplete.java index b288205327..0f6668517e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/JobComplete.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/JobComplete.java @@ -19,10 +19,6 @@ package org.jclouds.cloudstack.predicates; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.cloudstack.domain.AsyncJob.ResultCode.FAIL; -import static org.jclouds.cloudstack.domain.AsyncJob.ResultCode.SUCCESS; -import static org.jclouds.cloudstack.domain.AsyncJob.Status.FAILED; -import static org.jclouds.cloudstack.domain.AsyncJob.Status.SUCCEEDED; import javax.annotation.Resource; import javax.inject.Singleton; diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/VirtualMachineExpunged.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/VirtualMachineExpunged.java index 3873b1e5a2..e1517ae6f3 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/VirtualMachineExpunged.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/predicates/VirtualMachineExpunged.java @@ -18,17 +18,17 @@ */ package org.jclouds.cloudstack.predicates; -import com.google.common.base.Predicate; -import com.google.inject.Inject; -import org.jclouds.cloudstack.CloudStackClient; -import org.jclouds.cloudstack.domain.VirtualMachine; -import org.jclouds.cloudstack.domain.VirtualMachine.State; -import org.jclouds.logging.Logger; +import static com.google.common.base.Preconditions.checkNotNull; import javax.annotation.Resource; import javax.inject.Singleton; -import static com.google.common.base.Preconditions.checkNotNull; +import org.jclouds.cloudstack.CloudStackClient; +import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.logging.Logger; + +import com.google.common.base.Predicate; +import com.google.inject.Inject; /** * diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java index 027be867b3..3f488e0b94 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java @@ -67,8 +67,8 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; +import com.google.common.cache.LoadingCache; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.net.InetAddresses; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java index b16fb4e3dc..8882360e7f 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalCapacityClientLiveTest.java @@ -18,13 +18,13 @@ */ package org.jclouds.cloudstack.features; -import org.jclouds.cloudstack.domain.Capacity; -import org.jclouds.cloudstack.options.ListCapacityOptions; -import org.testng.annotations.Test; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.util.Set; -import static org.testng.Assert.*; +import org.jclouds.cloudstack.domain.Capacity; +import org.testng.annotations.Test; /** * Tests behavior of {@code GlobalCapacityClient} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java index d986814aa7..38c7c3d23d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java @@ -18,7 +18,8 @@ */ package org.jclouds.cloudstack.features; -import com.google.inject.TypeLiteral; +import java.lang.reflect.Method; + import org.jclouds.cloudstack.options.ListHostsOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseFirstJsonValueNamed; @@ -26,8 +27,7 @@ import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import java.io.IOException; -import java.lang.reflect.Method; +import com.google.inject.TypeLiteral; /** * Tests behavior of {@code GlobalHostAsyncClient} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java index 85c1199e9e..7764ca8a5f 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientLiveTest.java @@ -18,14 +18,12 @@ */ package org.jclouds.cloudstack.features; -import org.jclouds.cloudstack.domain.Host; -import org.jclouds.logging.Logger; -import org.testng.annotations.Test; +import static org.testng.Assert.assertTrue; import java.util.Set; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import org.jclouds.cloudstack.domain.Host; +import org.testng.annotations.Test; /** * Tests behavior of {@code GlobalHostClient} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java index 214210e123..926aeb2fdf 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalOfferingAsyncClientTest.java @@ -18,7 +18,8 @@ */ package org.jclouds.cloudstack.features; -import com.google.inject.TypeLiteral; +import java.lang.reflect.Method; + import org.jclouds.cloudstack.options.CreateDiskOfferingOptions; import org.jclouds.cloudstack.options.CreateServiceOfferingOptions; import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; @@ -31,10 +32,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import java.io.IOException; -import java.lang.reflect.Method; - -import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.DEFAULT; +import com.google.inject.TypeLiteral; /** * Tests behavior of {@code GlobalOfferingAsyncClient} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java index e696588dcf..1557fa95f9 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUsageClientLiveTest.java @@ -18,33 +18,19 @@ */ package org.jclouds.cloudstack.features; -import com.google.common.collect.ImmutableSet; -import org.jclouds.cloudstack.domain.DiskOffering; -import org.jclouds.cloudstack.domain.JobResult; -import org.jclouds.cloudstack.domain.NetworkOffering; -import org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType; -import org.jclouds.cloudstack.domain.ServiceOffering; -import org.jclouds.cloudstack.domain.StorageType; -import org.jclouds.cloudstack.domain.UsageRecord; -import org.jclouds.cloudstack.options.GenerateUsageRecordsOptions; -import org.jclouds.cloudstack.options.ListUsageRecordsOptions; -import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions; -import org.jclouds.cloudstack.options.UpdateNetworkOfferingOptions; -import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions; -import org.jclouds.logging.Logger; -import org.testng.annotations.Test; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.util.Calendar; import java.util.Date; import java.util.Set; import java.util.TimeZone; -import static com.google.common.collect.Iterables.getFirst; -import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.OPTIONAL; -import static org.jclouds.cloudstack.domain.NetworkOfferingAvailabilityType.REQUIRED; -import static org.jclouds.cloudstack.options.CreateDiskOfferingOptions.Builder.diskSizeInGB; -import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable; -import static org.testng.Assert.*; +import org.jclouds.cloudstack.domain.JobResult; +import org.jclouds.cloudstack.domain.UsageRecord; +import org.jclouds.cloudstack.options.GenerateUsageRecordsOptions; +import org.jclouds.cloudstack.options.ListUsageRecordsOptions; +import org.testng.annotations.Test; /** * Tests behavior of {@code GlobalUsageClient} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserAsyncClientTest.java index 400fc9f96d..6a73a72477 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalUserAsyncClientTest.java @@ -18,9 +18,9 @@ */ package org.jclouds.cloudstack.features; -import com.google.inject.TypeLiteral; +import java.lang.reflect.Method; + import org.jclouds.cloudstack.options.CreateUserOptions; -import org.jclouds.cloudstack.options.UpdateAccountOptions; import org.jclouds.cloudstack.options.UpdateUserOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseFirstJsonValueNamed; @@ -29,7 +29,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import java.lang.reflect.Method; +import com.google.inject.TypeLiteral; /** * Tests behavior of {@code GlobalUserAsyncClient} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java index f077c153ee..48b9278fe8 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java @@ -24,7 +24,7 @@ import java.lang.reflect.Method; import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; import org.jclouds.http.HttpRequest; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -52,7 +52,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest job = AsyncJob.builder().id(100L) .status(Status.SUCCEEDED).resultCode(ResultCode.SUCCESS).build(); - expect(asyncJobClient.getAsyncJob(job.getId())).andReturn(job); + expect((Object) asyncJobClient.getAsyncJob(job.getId())).andReturn(job); replay(client, asyncJobClient); assertTrue(new JobComplete(client).apply(job.getId())); @@ -66,10 +66,10 @@ public class JobCompleteTest { @Test public void testFailedJobComplete() { - AsyncJob job = AsyncJob.builder().id(100L) + AsyncJob job = AsyncJob.builder().id(100L) .status(Status.FAILED).resultCode(ResultCode.FAIL) .error(new AsyncJobError(ErrorCode.INTERNAL_ERROR, "Dummy test error")).build(); - expect(asyncJobClient.getAsyncJob(job.getId())).andReturn(job); + expect((Object) asyncJobClient.getAsyncJob(job.getId())).andReturn(job); replay(client, asyncJobClient); try { diff --git a/core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValue.java b/core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValue.java deleted file mode 100644 index 6a264cb2d3..0000000000 --- a/core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValue.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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.http.functions; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.http.HttpResponse; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.inject.TypeLiteral; - -/** - * @author Adrian Cole - */ -@Singleton -public class UnwrapOnlyNestedJsonValue implements Function { - - private final ParseJson>> json; - private final TypeLiteral type; - - @Inject - UnwrapOnlyNestedJsonValue(ParseJson>> json, TypeLiteral type) { - this.json = json; - this.type = type; - } - - @SuppressWarnings("unchecked") - @Override - public T apply(HttpResponse arg0) { - Map> map = json.apply(arg0); - if (map == null || map.size() == 0) - return null; - Map map1 = Iterables.getOnlyElement(map.values()); - if (map1 == null || map1.size() == 0) { - if (type.getRawType().isAssignableFrom(Set.class)) - return (T) ImmutableSet.of(); - else if (type.getRawType().isAssignableFrom(List.class)) - return (T) ImmutableList.of(); - else if (type.getRawType().isAssignableFrom(Map.class)) - return (T) ImmutableMap.of(); - return null; - } - return Iterables.getOnlyElement(map1.values()); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValueInSet.java b/core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValueInSet.java deleted file mode 100644 index f65138c01d..0000000000 --- a/core/src/main/java/org/jclouds/http/functions/UnwrapOnlyNestedJsonValueInSet.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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.http.functions; - -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.http.HttpResponse; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -/** - * @author Adrian Cole - */ -@Singleton -public class UnwrapOnlyNestedJsonValueInSet implements Function { - - private final UnwrapOnlyNestedJsonValue> json; - - @Inject - UnwrapOnlyNestedJsonValueInSet(UnwrapOnlyNestedJsonValue> json) { - this.json = json; - } - - @Override - public T apply(HttpResponse arg0) { - Set set = json.apply(arg0); - if (set == null || set.size() == 0) - return null; - return Iterables.getOnlyElement(set); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/annotations/Unwrap.java b/core/src/main/java/org/jclouds/rest/annotations/Unwrap.java index fa39a4db3e..cd1848d1dd 100644 --- a/core/src/main/java/org/jclouds/rest/annotations/Unwrap.java +++ b/core/src/main/java/org/jclouds/rest/annotations/Unwrap.java @@ -23,7 +23,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import java.util.Map; /** * Unwraps the only value in a nested json reponse @@ -35,48 +34,6 @@ import java.util.Map; @Target(METHOD) @Retention(RUNTIME) public @interface Unwrap { - /** - * level to unwrap. - * - * ex. if default (1) - * - * { "foo" :"bar" } becomes "bar" - * - * ex. if (2) - * - * { "foo" : {"bar" : ["baz"]} } becomes ["baz"] - * - *

Deprecation

- *

- * Note that using @SelectJson("bar") is more effective than guessing the - * depth - * - * @see SelectJson - */ - @Deprecated - int depth() default 1; - /** - * final collection type - * - * ex. if depth(2), edgeCollection(Map.class) - * - * { "foo" : {"bar" : ["baz"]} } becomes ["baz"] - * - * ex. if depth(3), edgeCollection(Set.class) - * - * { "foo" : {"bar" : ["baz"]} } becomes "baz" - * - *

Note

only Map and Set are valid - *

- *

Deprecation

- *

- * Note that using @SelectJson("bar") @OnlyElement will have the same effect - * - * @see SelectJson - * @see OnlyElement - */ - @Deprecated - Class edgeCollection() default Map.class; } diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 40346b5ce6..63baf2dea7 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -47,9 +47,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; -import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import javax.annotation.Resource; @@ -78,6 +78,7 @@ import org.jclouds.http.HttpUtils; import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseXMLWithJAXB; import org.jclouds.http.functions.ReleasePayloadAndReturn; @@ -85,10 +86,6 @@ import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.UnwrapOnlyJsonValue; -import org.jclouds.http.functions.UnwrapOnlyJsonValueInSet; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet; -import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.utils.ModifyRequest; import org.jclouds.internal.ClassMethodArgs; @@ -142,18 +139,18 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Throwables; -import com.google.common.cache.LoadingCache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Iterables; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; -import com.google.common.collect.ImmutableSet.Builder; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; import com.google.inject.Injector; @@ -844,23 +841,11 @@ public class RestAnnotationProcessor { return returnVal; } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "unchecked" }) public static Key> getJsonParserKeyForMethodAnType(Method method, Type returnVal) { ParameterizedType parserType; if (method.isAnnotationPresent(Unwrap.class)) { - int depth = method.getAnnotation(Unwrap.class).depth(); - Class edgeCollection = method.getAnnotation(Unwrap.class).edgeCollection(); - if (depth == 1 && edgeCollection == Map.class) - parserType = Types.newParameterizedType(UnwrapOnlyJsonValue.class, returnVal); - else if (depth == 2 && edgeCollection == Map.class) - parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, returnVal); - else if (depth == 2 && edgeCollection == Set.class) - parserType = Types.newParameterizedType(UnwrapOnlyJsonValueInSet.class, returnVal); - else if (depth == 3 && edgeCollection == Set.class) - parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValueInSet.class, returnVal); - else - throw new IllegalStateException(String.format("depth(%d) edgeCollection(%s) not yet supported for @Unwrap", - depth, edgeCollection)); + parserType = Types.newParameterizedType(UnwrapOnlyJsonValue.class, returnVal); } else { parserType = Types.newParameterizedType(ParseJson.class, returnVal); } 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 3fef693a26..0728545c11 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -99,9 +99,6 @@ import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnStringIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.UnwrapOnlyJsonValue; -import org.jclouds.http.functions.UnwrapOnlyJsonValueInSet; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet; import org.jclouds.http.internal.PayloadEnclosingImpl; import org.jclouds.http.options.BaseHttpRequestOptions; import org.jclouds.http.options.GetOptions; @@ -897,29 +894,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @Consumes(MediaType.APPLICATION_JSON) ListenableFuture> testUnwrap4(); - @GET - @Path("/") - @Unwrap(depth = 2) - @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture> testUnwrapDepth2(); - - @GET - @Path("/") - @Unwrap(depth = 2) - @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture testUnwrapDepth2Long(); - @GET @Path("/") @SelectJson("jobid") ListenableFuture selectLong(); - @GET - @Path("/") - @Unwrap(depth = 2, edgeCollection = Set.class) - @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture testUnwrapDepth2Set(); - @GET @Path("/") @SelectJson("runit") @@ -927,12 +906,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @Consumes(MediaType.APPLICATION_JSON) ListenableFuture selectOnlyElement(); - @GET - @Path("/") - @Unwrap(depth = 3, edgeCollection = Set.class) - @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture testUnwrapDepth3(); - @Target({ ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @HttpMethod("ROWDY") @@ -1136,68 +1109,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { ImmutableSet.of("0.7.0", "0.7.1")); } - @SuppressWarnings("unchecked") - public void testUnwrapDepth2() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrapDepth2"); - HttpRequest request = factory(TestPut.class).createRequest(method); - - assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValue.class); - // now test that it works! - - Function> parser = (Function>) RestAnnotationProcessor - .createResponseParser(parserFactory, injector, method, request); - - assertEquals(parser.apply(new HttpResponse(200, "ok", - newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}"))), ImmutableSet.of("0.7.0", "0.7.1")); - - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))), - ImmutableSet. of()); - } - - @SuppressWarnings("unchecked") - public void testUnwrapDepth2Set() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrapDepth2Set"); - HttpRequest request = factory(TestPut.class).createRequest(method); - - assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValueInSet.class); - // now test that it works! - - Function> parser = (Function>) RestAnnotationProcessor - .createResponseParser(parserFactory, injector, method, request); - - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\"]}"))), "0.7.0"); - - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[]}"))), null); - } - - @SuppressWarnings("unchecked") - public void testSelectOnlyElement() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("selectOnlyElement"); - HttpRequest request = factory(TestPut.class).createRequest(method); - - Function> parser = (Function>) RestAnnotationProcessor - .createResponseParser(parserFactory, injector, method, request); - - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\"]}"))), "0.7.0"); - - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[]}"))), null); - } - - @SuppressWarnings("unchecked") - public void testUnwrapDepth2Long() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrapDepth2Long"); - HttpRequest request = factory(TestPut.class).createRequest(method); - - assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValue.class); - // now test that it works! - - Function> parser = (Function>) RestAnnotationProcessor - .createResponseParser(parserFactory, injector, method, request); - - assertEquals(parser.apply(new HttpResponse(200, "ok", - newStringPayload("{ \"destroyvirtualmachineresponse\" : {\"jobid\":4} }"))), new Long(4)); - } - @SuppressWarnings("unchecked") public void selectLong() throws SecurityException, NoSuchMethodException, IOException { Method method = TestPut.class.getMethod("selectLong"); @@ -1213,52 +1124,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { newStringPayload("{ \"destroyvirtualmachineresponse\" : {\"jobid\":4} }"))), new Long(4)); } - @SuppressWarnings("unchecked") - public void testUnwrapDepth3() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrapDepth3"); - HttpRequest request = factory(TestPut.class).createRequest(method); - - assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValueInSet.class); - // now test that it works! - - Function> parser = (Function>) RestAnnotationProcessor - .createResponseParser(parserFactory, injector, method, request); - - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\"]}}"))), - "0.7.0"); - } - - @SuppressWarnings("unchecked") - public void testUnwrapDepth3None() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrapDepth3"); - HttpRequest request = factory(TestPut.class).createRequest(method); - - assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValueInSet.class); - // now test that it works! - - Function> parser = (Function>) RestAnnotationProcessor - .createResponseParser(parserFactory, injector, method, request); - - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[]}}"))), null); - assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))), null); - - } - - @SuppressWarnings("unchecked") - @Test(expectedExceptions = IllegalArgumentException.class) - public void testUnwrapDepth3TooMany() throws SecurityException, NoSuchMethodException, IOException { - Method method = TestPut.class.getMethod("testUnwrapDepth3"); - HttpRequest request = factory(TestPut.class).createRequest(method); - - assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValueInSet.class); - // now test that it works! - - Function> parser = (Function>) RestAnnotationProcessor - .createResponseParser(parserFactory, injector, method, request); - - parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}"))); - } - static class TestRequestFilter1 implements HttpRequestFilter { public HttpRequest filter(HttpRequest request) throws HttpException { return request;