diff --git a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java index cffed5400d..45868b9d4b 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java @@ -23,12 +23,9 @@ */ package org.jclouds.gogrid; -import static com.google.common.base.Preconditions.checkNotNull; - import java.util.List; import java.util.Properties; -import com.google.inject.Key; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; @@ -36,42 +33,44 @@ import org.jclouds.gogrid.config.GoGridComputeServiceContextModule; import org.jclouds.gogrid.config.GoGridRestClientModule; import org.jclouds.gogrid.config.internal.GoGridResolveImagesModule; +import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.TypeLiteral; /** - * + * * @author Adrian Cole */ -public class GoGridContextBuilder extends ComputeServiceContextBuilder { +public class GoGridContextBuilder extends + ComputeServiceContextBuilder { - public GoGridContextBuilder(Properties props) { - super(new TypeLiteral() { - }, new TypeLiteral() { - }, props); - } + public GoGridContextBuilder(Properties props) { + super(new TypeLiteral() { + }, new TypeLiteral() { + }, props); + } - protected void addClientModule(List modules) { - modules.add(new GoGridRestClientModule()); - } + protected void addClientModule(List modules) { + modules.add(new GoGridRestClientModule()); + } - @Override - protected void addContextModule(List modules) { - modules.add(new GoGridComputeServiceContextModule()); - } + @Override + protected void addContextModule(List modules) { + modules.add(new GoGridComputeServiceContextModule()); + } - @Override - protected void addImageResolutionModule() { - modules.add(new GoGridResolveImagesModule()); - } + @Override + protected void addImageResolutionModule() { + modules.add(new GoGridResolveImagesModule()); + } - @Override - public ComputeServiceContext buildComputeServiceContext() { - return this - .buildInjector() - .getInstance( + @Override + public ComputeServiceContext buildComputeServiceContext() { + return this + .buildInjector() + .getInstance( Key - .get(new TypeLiteral>() { - })); - } + .get(new TypeLiteral>() { + })); + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java index 40a7f8c317..d2390dcc46 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindIdsToQueryParams.java @@ -23,49 +23,46 @@ */ package org.jclouds.gogrid.binders; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY; + import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; import org.jclouds.rest.internal.GeneratedHttpRequest; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY; - /** * Binds IDs to corresponding query parameters - * + * * @author Oleksiy Yarmula */ public class BindIdsToQueryParams implements Binder { - /** - * Binds the ids to query parameters. The pattern, as - * specified by GoGrid's specification, is: - * - * https://api.gogrid.com/api/grid/server/get - * ?id=5153 - * &id=3232 - * - * @param request - * request where the query params will be set - * @param input array of String params - */ - @Override - public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - checkArgument(checkNotNull(input, "input is null") instanceof Long[], - "this binder is only valid for Long[] arguments"); + /** + * Binds the ids to query parameters. The pattern, as specified by GoGrid's specification, is: + * + * https://api.gogrid.com/api/grid/server/get ?id=5153 &id=3232 + * + * @param request + * request where the query params will be set + * @param input + * array of String params + */ + @Override + public void bindToRequest(HttpRequest request, Object input) { + checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests!"); + checkArgument(checkNotNull(input, "input is null") instanceof Long[], + "this binder is only valid for Long[] arguments"); - Long[] names = (Long[]) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; + Long[] names = (Long[]) input; + GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - for(Long id : names) { - generatedRequest.addQueryParam(ID_KEY, checkNotNull(id.toString(), - /*or throw*/ "id must have a non-null value")); - } + for (Long id : names) { + generatedRequest.addQueryParam(ID_KEY, checkNotNull(id.toString(), + /* or throw */"id must have a non-null value")); + } - } + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java index d93ae42bfd..c68183d07b 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindNamesToQueryParams.java @@ -23,48 +23,45 @@ */ package org.jclouds.gogrid.binders; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY; + import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; import org.jclouds.rest.internal.GeneratedHttpRequest; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY; - /** * Binds names to corresponding query parameters - + * * @author Oleksiy Yarmula */ public class BindNamesToQueryParams implements Binder { - /** - * Binds the names to query parameters. The pattern, as - * specified by GoGrid's specification, is: - * - * https://api.gogrid.com/api/grid/server/get - * ?name=My+Server - * &name=My+Server+2 - * &name=My+Server+3 - * &name=My+Server+4 - * @param request - * request where the query params will be set - * @param input array of String params - */ - @Override - public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - checkArgument(checkNotNull(input, "input is null") instanceof String[], - "this binder is only valid for String[] arguments"); + /** + * Binds the names to query parameters. The pattern, as specified by GoGrid's specification, is: + * + * https://api.gogrid.com/api/grid/server/get ?name=My+Server &name=My+Server+2 &name=My+Server+3 + * &name=My+Server+4 + * + * @param request + * request where the query params will be set + * @param input + * array of String params + */ + @Override + public void bindToRequest(HttpRequest request, Object input) { + checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests!"); + checkArgument(checkNotNull(input, "input is null") instanceof String[], + "this binder is only valid for String[] arguments"); - String[] names = (String[]) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; + String[] names = (String[]) input; + GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - for(String name : names) { - generatedRequest.addQueryParam(NAME_KEY, name); - } + for (String name : names) { + generatedRequest.addQueryParam(NAME_KEY, name); + } - } + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java index ae85baf9dc..54a7bd91f0 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindObjectNameToGetJobsRequestQueryParams.java @@ -18,37 +18,37 @@ */ package org.jclouds.gogrid.binders; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.gogrid.reference.GoGridQueryParams.OBJECT_KEY; + import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; import org.jclouds.rest.internal.GeneratedHttpRequest; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.gogrid.reference.GoGridQueryParams.*; - /** - * + * * @see org.jclouds.gogrid.services.GridJobClient#getJobsForObjectName(String) - * + * * @author Oleksiy Yarmula */ public class BindObjectNameToGetJobsRequestQueryParams implements Binder { - /** - * Maps the object's name to the - * input of , + "this binder is only valid for GeneratedHttpRequests!"); + checkArgument(checkNotNull(input, "input is null") instanceof String, + "this binder is only valid for String arguments"); - String serverName = (String) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; + String serverName = (String) input; + GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - generatedRequest.addQueryParam(OBJECT_KEY, serverName); - } + generatedRequest.addQueryParam(OBJECT_KEY, serverName); + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java index 7f8802c968..c3a0e86fde 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/binders/BindVirtualIpPortPairToQueryParams.java @@ -18,41 +18,40 @@ */ package org.jclouds.gogrid.binders; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static org.jclouds.gogrid.reference.GoGridQueryParams.VIRTUAL_IP_KEY; + import org.jclouds.gogrid.domain.IpPortPair; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; import org.jclouds.rest.internal.GeneratedHttpRequest; -import static org.jclouds.gogrid.reference.GoGridQueryParams.VIRTUAL_IP_KEY; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; /** * Binds a virtual IP to the request. - * - * The {@link IpPortPair} must have a {@link IpPortPair#ip} set with a valid - * IP address. - * + * + * The {@link IpPortPair} must have a {@link IpPortPair#ip} set with a valid IP address. + * * @author Oleksiy Yarmula */ public class BindVirtualIpPortPairToQueryParams implements Binder { - @Override - public void bindToRequest(HttpRequest request, Object input) { - checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, - "this binder is only valid for GeneratedHttpRequests!"); - checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair, - "this binder is only valid for a IpPortPair argument"); + @Override + public void bindToRequest(HttpRequest request, Object input) { + checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest, + "this binder is only valid for GeneratedHttpRequests!"); + checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair, + "this binder is only valid for a IpPortPair argument"); - IpPortPair ipPortPair = (IpPortPair) input; - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; + IpPortPair ipPortPair = (IpPortPair) input; + GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - checkNotNull(ipPortPair.getIp(), "There must be an IP address defined"); - checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object"); - checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); + checkNotNull(ipPortPair.getIp(), "There must be an IP address defined"); + checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object"); + checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer"); - generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp()); - generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort())); - } + generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp()); + generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort())); + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java index e845814d07..7137399755 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java @@ -26,56 +26,59 @@ package org.jclouds.gogrid.config; import java.lang.reflect.Type; import java.net.URI; import java.util.Date; -import java.util.Map; import javax.inject.Named; import javax.inject.Singleton; -import com.google.common.collect.Maps; -import com.google.gson.*; -import org.jclouds.Constants; +import org.jclouds.gogrid.GoGrid; import org.jclouds.gogrid.GoGridAsyncClient; import org.jclouds.gogrid.GoGridClient; +import org.jclouds.gogrid.reference.GoGridConstants; import org.jclouds.http.functions.config.ParserModule.DateAdapter; import org.jclouds.lifecycle.Closer; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.gogrid.GoGrid; -import org.jclouds.gogrid.reference.GoGridConstants; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; import com.google.inject.AbstractModule; import com.google.inject.Provides; /** * Configures the GoGrid connection, including logging and http transport. - * + * * @author Adrian Cole * @author Oleksiy Yarmula */ public class GoGridContextModule extends AbstractModule { - @Override - protected void configure() { - bind(DateAdapter.class).to(DateSecondsAdapter.class); - } + @Override + protected void configure() { + bind(DateAdapter.class).to(DateSecondsAdapter.class); + } - @Provides - @Singleton - RestContext provideContext(Closer closer, GoGridAsyncClient asyncApi, - GoGridClient syncApi, @GoGrid URI endPoint, @Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) { - return new RestContextImpl(closer, asyncApi, syncApi, endPoint, account); - } + @Provides + @Singleton + RestContext provideContext(Closer closer, + GoGridAsyncClient asyncApi, GoGridClient syncApi, @GoGrid URI endPoint, + @Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) { + return new RestContextImpl(closer, asyncApi, syncApi, + endPoint, account); + } - @Singleton - public static class DateSecondsAdapter implements DateAdapter { + @Singleton + public static class DateSecondsAdapter implements DateAdapter { - public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.getTime()); - } + public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getTime()); + } - public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - String toParse = json.getAsJsonPrimitive().getAsString(); - return new Date(Long.valueOf(toParse)); - } - } + public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + String toParse = json.getAsJsonPrimitive().getAsString(); + return new Date(Long.valueOf(toParse)); + } + } } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java index 26795aaa47..4eab7d199d 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java @@ -41,6 +41,8 @@ */ package org.jclouds.gogrid.config; +import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_SESSIONINTERVAL; + import java.net.InetSocketAddress; import java.net.URI; import java.util.Map; @@ -49,17 +51,33 @@ import java.util.concurrent.TimeUnit; import javax.inject.Named; import javax.inject.Singleton; -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.common.collect.Maps; import org.jclouds.Constants; import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.date.TimeStamp; -import org.jclouds.gogrid.domain.*; +import org.jclouds.gogrid.GoGrid; +import org.jclouds.gogrid.domain.IpState; +import org.jclouds.gogrid.domain.JobState; +import org.jclouds.gogrid.domain.LoadBalancerOs; +import org.jclouds.gogrid.domain.LoadBalancerPersistenceType; +import org.jclouds.gogrid.domain.LoadBalancerState; +import org.jclouds.gogrid.domain.LoadBalancerType; +import org.jclouds.gogrid.domain.ObjectType; +import org.jclouds.gogrid.domain.ServerImageState; +import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.gogrid.handlers.GoGridErrorHandler; -import org.jclouds.gogrid.services.*; +import org.jclouds.gogrid.reference.GoGridConstants; +import org.jclouds.gogrid.services.GridImageAsyncClient; +import org.jclouds.gogrid.services.GridImageClient; +import org.jclouds.gogrid.services.GridIpAsyncClient; +import org.jclouds.gogrid.services.GridIpClient; +import org.jclouds.gogrid.services.GridJobAsyncClient; +import org.jclouds.gogrid.services.GridJobClient; +import org.jclouds.gogrid.services.GridLoadBalancerAsyncClient; +import org.jclouds.gogrid.services.GridLoadBalancerClient; +import org.jclouds.gogrid.services.GridServerAsyncClient; +import org.jclouds.gogrid.services.GridServerClient; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.RequiresHttp; import org.jclouds.http.annotation.ClientError; @@ -70,17 +88,15 @@ import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; -import org.jclouds.gogrid.GoGrid; -import org.jclouds.gogrid.reference.GoGridConstants; - +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.common.collect.Maps; import com.google.inject.AbstractModule; import com.google.inject.Provides; -import static org.jclouds.gogrid.reference.GoGridConstants.*; - /** * Configures the GoGrid connection. - * + * * @author Adrian Cole * @author Oleksiy Yarmula */ @@ -88,139 +104,136 @@ import static org.jclouds.gogrid.reference.GoGridConstants.*; @ConfiguresRestClient public class GoGridRestClientModule extends AbstractModule { - @Override - protected void configure() { - bindErrorHandlers(); - bindRetryHandlers(); - } + @Override + protected void configure() { + bindErrorHandlers(); + bindRetryHandlers(); + } - @Provides - @Singleton - protected GridServerAsyncClient provideServerClient(RestClientFactory factory) { - return factory.create(GridServerAsyncClient.class); - } + @Provides + @Singleton + protected GridServerAsyncClient provideServerClient(RestClientFactory factory) { + return factory.create(GridServerAsyncClient.class); + } - @Provides - @Singleton - public GridServerClient provideServerClient(GridServerAsyncClient client) throws IllegalArgumentException, + @Provides + @Singleton + public GridServerClient provideServerClient(GridServerAsyncClient client) + throws IllegalArgumentException, SecurityException, NoSuchMethodException { + return SyncProxy.create(GridServerClient.class, client); + } + + @Provides + @Singleton + protected GridJobAsyncClient provideJobClient(RestClientFactory factory) { + return factory.create(GridJobAsyncClient.class); + } + + @Provides + @Singleton + public GridJobClient provideJobClient(GridJobAsyncClient client) + throws IllegalArgumentException, SecurityException, NoSuchMethodException { + return SyncProxy.create(GridJobClient.class, client); + } + + @Provides + @Singleton + protected GridIpAsyncClient provideIpClient(RestClientFactory factory) { + return factory.create(GridIpAsyncClient.class); + } + + @Provides + @Singleton + public GridIpClient provideIpClient(GridIpAsyncClient client) throws IllegalArgumentException, SecurityException, NoSuchMethodException { - return SyncProxy.create(GridServerClient.class, client); - } + return SyncProxy.create(GridIpClient.class, client); + } - @Provides - @Singleton - protected GridJobAsyncClient provideJobClient(RestClientFactory factory) { - return factory.create(GridJobAsyncClient.class); - } + @Provides + @Singleton + protected GridLoadBalancerAsyncClient provideLoadBalancerClient(RestClientFactory factory) { + return factory.create(GridLoadBalancerAsyncClient.class); + } - @Provides - @Singleton - public GridJobClient provideJobClient(GridJobAsyncClient client) throws IllegalArgumentException, - SecurityException, NoSuchMethodException { - return SyncProxy.create(GridJobClient.class, client); - } + @Provides + @Singleton + public GridLoadBalancerClient provideLoadBalancerClient(GridLoadBalancerAsyncClient client) + throws IllegalArgumentException, SecurityException, NoSuchMethodException { + return SyncProxy.create(GridLoadBalancerClient.class, client); + } - @Provides - @Singleton - protected GridIpAsyncClient provideIpClient(RestClientFactory factory) { - return factory.create(GridIpAsyncClient.class); - } + @Provides + @Singleton + protected GridImageAsyncClient provideImageClient(RestClientFactory factory) { + return factory.create(GridImageAsyncClient.class); + } - @Provides - @Singleton - public GridIpClient provideIpClient(GridIpAsyncClient client) throws IllegalArgumentException, - SecurityException, NoSuchMethodException { - return SyncProxy.create(GridIpClient.class, client); - } + @Provides + @Singleton + public GridImageClient provideImageClient(GridImageAsyncClient client) + throws IllegalArgumentException, SecurityException, NoSuchMethodException { + return SyncProxy.create(GridImageClient.class, client); + } - @Provides - @Singleton - protected GridLoadBalancerAsyncClient provideLoadBalancerClient(RestClientFactory factory) { - return factory.create(GridLoadBalancerAsyncClient.class); - } + @Provides + @Singleton + @GoGrid + protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) { + return URI.create(endpoint); + } - @Provides - @Singleton - public GridLoadBalancerClient provideLoadBalancerClient(GridLoadBalancerAsyncClient client) throws IllegalArgumentException, - SecurityException, NoSuchMethodException { - return SyncProxy.create(GridLoadBalancerClient.class, client); - } + @Provides + @TimeStamp + protected Long provideTimeStamp(@TimeStamp Supplier cache) { + return cache.get(); + } - @Provides - @Singleton - protected GridImageAsyncClient provideImageClient(RestClientFactory factory) { - return factory.create(GridImageAsyncClient.class); - } + @Provides + @Singleton + protected Predicate socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 1, TimeUnit.SECONDS); + } - @Provides - @Singleton - public GridImageClient provideImageClient(GridImageAsyncClient client) throws IllegalArgumentException, - SecurityException, NoSuchMethodException { - return SyncProxy.create(GridImageClient.class, client); - } + @SuppressWarnings("unchecked") + @Provides + @Singleton + @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) + public Map provideCustomAdapterBindings() { + Map bindings = Maps.newHashMap(); + bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter()); + bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter()); + bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter()); + bindings.put(LoadBalancerPersistenceType.class, + new CustomDeserializers.LoadBalancerPersistenceTypeAdapter()); + bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter()); + bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); + bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter()); + bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); + bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); + return bindings; + } - @Provides - @Singleton - @GoGrid - protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) { - return URI.create(endpoint); - } + /** + * borrowing concurrency code to ensure that caching takes place properly + */ + @Provides + @TimeStamp + Supplier provideTimeStampCache(@Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds) { + return new ExpirableSupplier(new Supplier() { + public Long get() { + return System.currentTimeMillis() / 1000; + } + }, seconds, TimeUnit.SECONDS); + } - @Provides - @TimeStamp - protected Long provideTimeStamp(@TimeStamp Supplier cache) { - return cache.get(); - } + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GoGridErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(GoGridErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(GoGridErrorHandler.class); + } - @Provides - @Singleton - protected Predicate socketTester(SocketOpen open) { - return new RetryablePredicate(open, 130, 1, TimeUnit.SECONDS); - } - - @Provides - @Singleton - @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) - public Map provideCustomAdapterBindings() { - Map bindings = Maps.newHashMap(); - bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter()); - bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter()); - bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter()); - bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter()); - bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter()); - bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); - bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter()); - bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); - bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); - return bindings; - } - - - /** - * borrowing concurrency code to ensure that caching takes place properly - */ - @Provides - @TimeStamp - Supplier provideTimeStampCache( - @Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds) { - return new ExpirableSupplier(new Supplier() { - public Long get() { - return System.currentTimeMillis() / 1000; - } - }, seconds, TimeUnit.SECONDS); - } - - protected void bindErrorHandlers() { - bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to( - GoGridErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to( - GoGridErrorHandler.class); - bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to( - GoGridErrorHandler.class); - } - - protected void bindRetryHandlers() { - // TODO - } + protected void bindRetryHandlers() { + // TODO + } } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/JobState.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/JobState.java index d255979301..3764ed143a 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/domain/JobState.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/JobState.java @@ -18,8 +18,6 @@ */ package org.jclouds.gogrid.domain; -import org.omg.CORBA.UNKNOWN; - import static com.google.common.base.Preconditions.checkNotNull; /** @@ -27,32 +25,33 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public enum JobState { - QUEUED("Queued", "Change request is new to the system."), - PROCESSING("Processing", "Change request is is transient state...Processing."), - SUCCEEDED("Succeeded", "Change request has succeeded."), - FAILED("Failed", "Change request has failed."), - CANCELED("Canceled", "Change request has been canceled."), - FATAL("Fatal", "Change request had Fatal or Unrecoverable Failure"), - CREATED("Created", "Change request is created but not queued yet"), - UNKNOWN("Unknown", "The state is unknown to JClouds"); + QUEUED("Queued", "Change request is new to the system."), PROCESSING("Processing", + "Change request is is transient state...Processing."), SUCCEEDED("Succeeded", + "Change request has succeeded."), FAILED("Failed", "Change request has failed."), CANCELED( + "Canceled", "Change request has been canceled."), FATAL("Fatal", + "Change request had Fatal or Unrecoverable Failure"), CREATED("Created", + "Change request is created but not queued yet"), UNKNOWN("Unknown", + "The state is unknown to JClouds"); - String name; - String description; - JobState(String name, String description) { - this.name = name; - this.description = description; - } + String name; + String description; - @Override - public String toString() { - return name; - } + JobState(String name, String description) { + this.name = name; + this.description = description; + } - public static JobState fromValue(String state) { - for(JobState jobState : values()) { - if(jobState.name.equals(checkNotNull(state))) return jobState; - } - return UNKNOWN; - } + @Override + public String toString() { + return name; + } + + public static JobState fromValue(String state) { + for (JobState jobState : values()) { + if (jobState.name.equals(checkNotNull(state))) + return jobState; + } + return UNKNOWN; + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/LoadBalancerPersistenceType.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/LoadBalancerPersistenceType.java index 3b956570f5..4ccbbda042 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/domain/LoadBalancerPersistenceType.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/LoadBalancerPersistenceType.java @@ -18,8 +18,6 @@ */ package org.jclouds.gogrid.domain; -import com.google.common.base.CaseFormat; - import static com.google.common.base.Preconditions.checkNotNull; /** @@ -27,25 +25,24 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public enum LoadBalancerPersistenceType { - NONE("None"), - SSL_STICKY("SSL Sticky"), - SOURCE_ADDRESS("Source Address"), - UNKNOWN("Unknown"); + NONE("None"), SSL_STICKY("SSL Sticky"), SOURCE_ADDRESS("Source Address"), UNKNOWN("Unknown"); - String type; - LoadBalancerPersistenceType(String type) { - this.type = type; - } + String type; - @Override - public String toString() { - return type; - } + LoadBalancerPersistenceType(String type) { + this.type = type; + } - public static LoadBalancerPersistenceType fromValue(String type) { - for(LoadBalancerPersistenceType persistenceType : values()) { - if(persistenceType.type.equals(checkNotNull(type))) return persistenceType; - } - return UNKNOWN; - } + @Override + public String toString() { + return type; + } + + public static LoadBalancerPersistenceType fromValue(String type) { + for (LoadBalancerPersistenceType persistenceType : values()) { + if (persistenceType.type.equals(checkNotNull(type))) + return persistenceType; + } + return UNKNOWN; + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/PowerCommand.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/PowerCommand.java index a1389253bb..ac6e072d43 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/domain/PowerCommand.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/PowerCommand.java @@ -23,32 +23,27 @@ */ package org.jclouds.gogrid.domain; -import com.google.common.base.CaseFormat; /** * Server's state transition. - * - * Using this value, server's state will be changed - * to one of the following: + * + * Using this value, server's state will be changed to one of the following: *
    *
  • Start
  • *
  • Stop
  • *
  • Restart
  • *
- * + * * @see org.jclouds.gogrid.services.GridServerClient#power(String, PowerCommand) * @see
- * + * * @author Oleksiy Yarmula */ public enum PowerCommand { - START, - STOP /*NOTE: This is a hard shutdown, equivalent to powering off a server.*/, - RESTART; + START, STOP /* NOTE: This is a hard shutdown, equivalent to powering off a server. */, RESTART; - - @Override - public String toString() { - return name().toLowerCase(); - } + @Override + public String toString() { + return name().toLowerCase(); + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java b/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java index 24e646f2a6..0eae549ffa 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java @@ -23,8 +23,16 @@ */ package org.jclouds.gogrid.filters; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.String.format; + +import java.net.URI; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; + import org.jclouds.Constants; import org.jclouds.date.TimeStamp; import org.jclouds.encryption.EncryptionService; @@ -36,73 +44,64 @@ import org.jclouds.logging.Logger; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; - -import java.net.URI; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; /** * @author Oleksiy Yarmula */ -public class SharedKeyLiteAuthentication implements HttpRequestFilter { +public class SharedKeyLiteAuthentication implements HttpRequestFilter { - private final String apiKey; - private final String secret; - private final Long timeStamp; - private final EncryptionService encryptionService; - @Resource - @Named(Constants.LOGGER_SIGNATURE) - Logger signatureLog = Logger.NULL; + private final String apiKey; + private final String secret; + private final Long timeStamp; + private final EncryptionService encryptionService; + @Resource + @Named(Constants.LOGGER_SIGNATURE) + Logger signatureLog = Logger.NULL; - @Inject - public SharedKeyLiteAuthentication(@Named(GoGridConstants.PROPERTY_GOGRID_USER) String apiKey, - @Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String secret, - @TimeStamp Long timeStamp, - EncryptionService encryptionService) { - this.encryptionService = encryptionService; - this.apiKey = apiKey; - this.secret = secret; - this.timeStamp = timeStamp; - } + @Inject + public SharedKeyLiteAuthentication(@Named(GoGridConstants.PROPERTY_GOGRID_USER) String apiKey, + @Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String secret, + @TimeStamp Long timeStamp, EncryptionService encryptionService) { + this.encryptionService = encryptionService; + this.apiKey = apiKey; + this.secret = secret; + this.timeStamp = timeStamp; + } - public void filter(HttpRequest request) { - checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, + public void filter(HttpRequest request) { + checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, "this decorator is only valid for GeneratedHttpRequests!"); - GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; - String toSign = createStringToSign(); - String signatureMd5 = getMd5For(toSign); + String toSign = createStringToSign(); + String signatureMd5 = getMd5For(toSign); - String query = request.getEndpoint().getQuery(); - Multimap decodedParams = - RestAnnotationProcessor.parseQueryToMap(query); + String query = request.getEndpoint().getQuery(); + Multimap decodedParams = RestAnnotationProcessor.parseQueryToMap(query); - decodedParams.replaceValues("sig", ImmutableSet.of(signatureMd5)); - decodedParams.replaceValues("api_key", ImmutableSet.of(apiKey)); + decodedParams.replaceValues("sig", ImmutableSet.of(signatureMd5)); + decodedParams.replaceValues("api_key", ImmutableSet.of(apiKey)); - String updatedQuery = RestAnnotationProcessor.makeQueryLine(decodedParams, null); - String requestBasePart = request.getEndpoint().toASCIIString(); - String updatedEndpoint = requestBasePart.substring(0, requestBasePart.indexOf("?") + 1) + updatedQuery; - request.setEndpoint(URI.create(updatedEndpoint )); - - HttpUtils.logRequest(signatureLog, request, "<<"); - } + String updatedQuery = RestAnnotationProcessor.makeQueryLine(decodedParams, null); + String requestBasePart = request.getEndpoint().toASCIIString(); + String updatedEndpoint = requestBasePart.substring(0, requestBasePart.indexOf("?") + 1) + + updatedQuery; + request.setEndpoint(URI.create(updatedEndpoint)); - private String createStringToSign() { - return format("%s%s%s", apiKey, secret, timeStamp); - } + HttpUtils.logRequest(signatureLog, request, "<<"); + } - private String getMd5For(String stringToHash) { - try { - return encryptionService.md5Hex(stringToHash.getBytes()); - } catch(Exception e) { - throw new RuntimeException(e); - } - } + private String createStringToSign() { + return format("%s%s%s", apiKey, secret, timeStamp); + } + + private String getMd5For(String stringToHash) { + try { + return encryptionService.md5Hex(stringToHash.getBytes()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponse.java b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponse.java index 73c2f9ffaf..83ff2ae135 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponse.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseErrorFromJsonResponse.java @@ -23,48 +23,47 @@ */ package org.jclouds.gogrid.functions; -import com.google.common.collect.Iterables; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.google.inject.Singleton; -import org.jclouds.gogrid.domain.internal.ErrorResponse; -import org.jclouds.gogrid.domain.internal.GenericResponseContainer; -import org.jclouds.http.functions.ParseJson; - -import javax.inject.Inject; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.util.SortedSet; -import static com.google.common.base.Preconditions.checkState; +import javax.inject.Inject; + +import org.jclouds.gogrid.domain.internal.ErrorResponse; +import org.jclouds.gogrid.domain.internal.GenericResponseContainer; +import org.jclouds.http.functions.ParseJson; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.google.inject.Singleton; /** - * Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse - * error response} from a json string. + * Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse error response} from a json + * string. * * GoGrid may return multiple error objects, if multiple errors were found. - * + * * @author Oleksiy Yarmula */ @Singleton public class ParseErrorFromJsonResponse extends ParseJson> { - @Inject - public ParseErrorFromJsonResponse(Gson gson) { - super(gson); - } + @Inject + public ParseErrorFromJsonResponse(Gson gson) { + super(gson); + } - public SortedSet apply(InputStream stream) { - Type setType = new TypeToken>() { - }.getType(); - GenericResponseContainer response; - try { - response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("jclouds requires UTF-8 encoding", e); - } - return response.getList(); - } + public SortedSet apply(InputStream stream) { + Type setType = new TypeToken>() { + }.getType(); + GenericResponseContainer response; + try { + response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("jclouds requires UTF-8 encoding", e); + } + return response.getList(); + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseLoadBalancerListFromJsonResponse.java b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseLoadBalancerListFromJsonResponse.java index 7291682dce..b591a9f367 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseLoadBalancerListFromJsonResponse.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseLoadBalancerListFromJsonResponse.java @@ -18,41 +18,42 @@ */ package org.jclouds.gogrid.functions; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import org.jclouds.gogrid.domain.Job; -import org.jclouds.gogrid.domain.LoadBalancer; -import org.jclouds.gogrid.domain.internal.GenericResponseContainer; -import org.jclouds.http.functions.ParseJson; - -import javax.inject.Inject; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.util.SortedSet; +import javax.inject.Inject; + +import org.jclouds.gogrid.domain.LoadBalancer; +import org.jclouds.gogrid.domain.internal.GenericResponseContainer; +import org.jclouds.http.functions.ParseJson; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + /** * Parses {@link org.jclouds.gogrid.domain.LoadBalancer jobs} from a json string. - * + * * @author Oleksiy Yarmula */ public class ParseLoadBalancerListFromJsonResponse extends ParseJson> { - @Inject - public ParseLoadBalancerListFromJsonResponse(Gson gson) { - super(gson); - } + @Inject + public ParseLoadBalancerListFromJsonResponse(Gson gson) { + super(gson); + } - public SortedSet apply(InputStream stream) { - Type setType = new TypeToken>() { - }.getType(); - GenericResponseContainer response; - try { - response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("jclouds requires UTF-8 encoding", e); - } - return response.getList(); - } + public SortedSet apply(InputStream stream) { + Type setType = new TypeToken>() { + }.getType(); + GenericResponseContainer response; + try { + response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("jclouds requires UTF-8 encoding", e); + } + return response.getList(); + } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseOptionsFromJsonResponse.java b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseOptionsFromJsonResponse.java index 6f83e9a915..481a0aaae7 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseOptionsFromJsonResponse.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseOptionsFromJsonResponse.java @@ -18,44 +18,44 @@ */ package org.jclouds.gogrid.functions; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import org.jclouds.gogrid.domain.LoadBalancer; -import org.jclouds.gogrid.domain.Option; -import org.jclouds.gogrid.domain.internal.GenericResponseContainer; -import org.jclouds.http.functions.ParseJson; - -import javax.inject.Inject; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.util.SortedSet; +import javax.inject.Inject; + +import org.jclouds.gogrid.domain.Option; +import org.jclouds.gogrid.domain.internal.GenericResponseContainer; +import org.jclouds.http.functions.ParseJson; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + /** * Parses the list of generic options. - * - * GoGrid uses options as containers for - * id/name/description objects. - * + * + * GoGrid uses options as containers for id/name/description objects. + * * @author Oleksiy Yarmula */ public class ParseOptionsFromJsonResponse extends ParseJson> { - @Inject - public ParseOptionsFromJsonResponse(Gson gson) { - super(gson); - } + @Inject + public ParseOptionsFromJsonResponse(Gson gson) { + super(gson); + } - public SortedSet * @author Oleksiy Yarmula */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) public interface GridImageClient { - /** - * Returns all server images. - * - * @param options options to narrow the search down - * @return server images found - */ - Set getImageList(GetImageListOptions... options); + /** + * Returns all server images. + * + * @param options + * options to narrow the search down + * @return server images found + */ + Set getImageList(GetImageListOptions... options); - /** - * Returns images, found by specified ids - * @param ids the ids that match existing images - * @return images found - */ - Set getImagesById(Long... ids); + /** + * Returns images, found by specified ids + * + * @param ids + * the ids that match existing images + * @return images found + */ + Set getImagesById(Long... ids); - /** - * Returns images, found by specified names - * @param names the names that march existing images - * @return images found - */ - Set getImagesByName(String... names); + /** + * Returns images, found by specified names + * + * @param names + * the names that march existing images + * @return images found + */ + Set getImagesByName(String... names); - /** - * Edits an existing image - * - * @param idOrName id or name of the existing image - * @param newDescription description to replace the current one - * @return edited server image - */ - ServerImage editImageDescription(String idOrName, String newDescription); + /** + * Edits an existing image + * + * @param idOrName + * id or name of the existing image + * @param newDescription + * description to replace the current one + * @return edited server image + */ + ServerImage editImageDescription(String idOrName, String newDescription); - /** - * Edits an existing image - * - * @param idOrName id or name of the existing image - * @param newFriendlyName friendly name to replace the current one - * @return edited server image - */ - ServerImage editImageFriendlyName(String idOrName, String newFriendlyName); + /** + * Edits an existing image + * + * @param idOrName + * id or name of the existing image + * @param newFriendlyName + * friendly name to replace the current one + * @return edited server image + */ + ServerImage editImageFriendlyName(String idOrName, String newFriendlyName); } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/services/GridIpAsyncClient.java b/gogrid/src/main/java/org/jclouds/gogrid/services/GridIpAsyncClient.java index 7b738ba8bb..c0d9f509c8 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/services/GridIpAsyncClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/services/GridIpAsyncClient.java @@ -18,11 +18,17 @@ */ package org.jclouds.gogrid.services; -import com.google.common.util.concurrent.ListenableFuture; +import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION; +import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_STATE_KEY; +import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_TYPE_KEY; + +import java.util.Set; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + import org.jclouds.gogrid.GoGrid; import org.jclouds.gogrid.domain.Ip; -import org.jclouds.gogrid.domain.IpState; -import org.jclouds.gogrid.domain.IpType; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse; import org.jclouds.gogrid.options.GetIpListOptions; @@ -31,17 +37,11 @@ import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import java.util.Set; - -import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION; -import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_STATE_KEY; -import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_TYPE_KEY; +import com.google.common.util.concurrent.ListenableFuture; /** * @see org.jclouds.gogrid.services.GridImageClient - * + * * @author Oleksiy Yarmula */ @Endpoint(GoGrid.class) @@ -49,41 +49,39 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_TYPE_KEY; @QueryParams(keys = VERSION, values = "1.3") public interface GridIpAsyncClient { - /** + /** * @see GridIpClient#getIpList(org.jclouds.gogrid.options.GetIpListOptions...) */ - @GET - @ResponseParser(ParseIpListFromJsonResponse.class) - @Path("/grid/ip/list") - ListenableFuture> getIpList(GetIpListOptions... options); + @GET + @ResponseParser(ParseIpListFromJsonResponse.class) + @Path("/grid/ip/list") + ListenableFuture> getIpList(GetIpListOptions... options); - /** + /** * @see org.jclouds.gogrid.services.GridIpClient#getUnassignedIpList() */ - @GET - @ResponseParser(ParseIpListFromJsonResponse.class) - @Path("/grid/ip/list") - @QueryParams(keys = IP_STATE_KEY, values = "Unassigned") - ListenableFuture> getUnassignedIpList(); + @GET + @ResponseParser(ParseIpListFromJsonResponse.class) + @Path("/grid/ip/list") + @QueryParams(keys = IP_STATE_KEY, values = "Unassigned") + ListenableFuture> getUnassignedIpList(); - - /** + /** * @see org.jclouds.gogrid.services.GridIpClient#getUnassignedPublicIpList() */ - @GET - @ResponseParser(ParseIpListFromJsonResponse.class) - @Path("/grid/ip/list") - @QueryParams(keys = {IP_STATE_KEY, IP_TYPE_KEY}, values = {"Unassigned", "Public"}) - ListenableFuture> getUnassignedPublicIpList(); + @GET + @ResponseParser(ParseIpListFromJsonResponse.class) + @Path("/grid/ip/list") + @QueryParams(keys = { IP_STATE_KEY, IP_TYPE_KEY }, values = { "Unassigned", "Public" }) + ListenableFuture> getUnassignedPublicIpList(); - /** + /** * @see org.jclouds.gogrid.services.GridIpClient#getAssignedIpList() */ - @GET - @ResponseParser(ParseIpListFromJsonResponse.class) - @Path("/grid/ip/list") - @QueryParams(keys = IP_STATE_KEY, values = "Assigned") - ListenableFuture> getAssignedIpList(); - + @GET + @ResponseParser(ParseIpListFromJsonResponse.class) + @Path("/grid/ip/list") + @QueryParams(keys = IP_STATE_KEY, values = "Assigned") + ListenableFuture> getAssignedIpList(); } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java index 08ce864d85..9483d1f09c 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseJobsFromJsonResponseTest.java @@ -18,6 +18,27 @@ */ package org.jclouds.gogrid.functions; +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.UnknownHostException; +import java.util.Date; +import java.util.Map; +import java.util.SortedSet; + +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.gogrid.config.GoGridContextModule; +import org.jclouds.gogrid.domain.Job; +import org.jclouds.gogrid.domain.JobProperties; +import org.jclouds.gogrid.domain.JobState; +import org.jclouds.gogrid.domain.ObjectType; +import org.jclouds.gogrid.domain.Option; +import org.jclouds.gogrid.functions.internal.CustomDeserializers; +import org.jclouds.http.functions.config.ParserModule; +import org.testng.annotations.Test; + import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; @@ -25,21 +46,6 @@ import com.google.gson.Gson; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Provides; -import org.jclouds.Constants; -import org.jclouds.gogrid.config.GoGridContextModule; -import org.jclouds.gogrid.domain.*; -import org.jclouds.gogrid.functions.internal.CustomDeserializers; -import org.jclouds.http.functions.config.ParserModule; -import org.testng.annotations.Test; - -import javax.inject.Singleton; -import java.io.InputStream; -import java.net.UnknownHostException; -import java.util.Date; -import java.util.Map; -import java.util.SortedSet; - -import static org.testng.Assert.assertEquals; /** * @author Oleksiy Yarmula @@ -47,57 +53,47 @@ import static org.testng.Assert.assertEquals; @Test(groups = "unit", testName = "gogrid.ParseJobsFromJsonResponseTest") public class ParseJobsFromJsonResponseTest { - @Test - public void testApplyInputStreamDetails() throws UnknownHostException { - InputStream is = getClass().getResourceAsStream("/test_get_job_list.json"); + @Test + public void testApplyInputStreamDetails() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/test_get_job_list.json"); - ParseJobListFromJsonResponse parser = new ParseJobListFromJsonResponse(i - .getInstance(Gson.class)); - SortedSet response = parser.apply(is); + ParseJobListFromJsonResponse parser = new ParseJobListFromJsonResponse(i + .getInstance(Gson.class)); + SortedSet response = parser.apply(is); - Map details = Maps.newTreeMap(); - details.put("description", null); - details.put("image", "GSI-f8979644-e646-4711-ad58-d98a5fa3612c"); - details.put("ip", "204.51.240.189"); - details.put("name", "ServerCreated40562"); - details.put("type", "virtual_server"); + Map details = Maps.newTreeMap(); + details.put("description", null); + details.put("image", "GSI-f8979644-e646-4711-ad58-d98a5fa3612c"); + details.put("ip", "204.51.240.189"); + details.put("name", "ServerCreated40562"); + details.put("type", "virtual_server"); - Job job = new Job(250628L, - new Option(7L, "DeleteVirtualServer", "Delete Virtual Server"), - ObjectType.VIRTUAL_SERVER, - new Date(1267404528895L), - new Date(1267404538592L), - JobState.SUCCEEDED, - 1, - "3116784158f0af2d-24076@api.gogrid.com", - ImmutableSortedSet.of( - new JobProperties(940263L, new Date(1267404528897L), - JobState.CREATED, null), - new JobProperties(940264L, new Date(1267404528967L), - JobState.QUEUED, null) - ), - details); - assertEquals(job, Iterables.getOnlyElement(response)); - } + Job job = new Job(250628L, new Option(7L, "DeleteVirtualServer", "Delete Virtual Server"), + ObjectType.VIRTUAL_SERVER, new Date(1267404528895L), new Date(1267404538592L), + JobState.SUCCEEDED, 1, "3116784158f0af2d-24076@api.gogrid.com", ImmutableSortedSet + .of(new JobProperties(940263L, new Date(1267404528897L), JobState.CREATED, + null), new JobProperties(940264L, new Date(1267404528967L), + JobState.QUEUED, null)), details); + assertEquals(job, Iterables.getOnlyElement(response)); + } + Injector i = Guice.createInjector(new ParserModule() { + @Override + protected void configure() { + bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); + super.configure(); + } - Injector i = Guice.createInjector(new ParserModule() { - @Override - protected void configure() { - bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); - super.configure(); - } - - @Provides - @Singleton - @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) - public Map provideCustomAdapterBindings() { - Map bindings = Maps.newHashMap(); - bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter()); - bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter()); - return bindings; - } - }); - + @SuppressWarnings( { "unused", "unchecked" }) + @Provides + @Singleton + @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) + public Map provideCustomAdapterBindings() { + Map bindings = Maps.newHashMap(); + bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter()); + bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter()); + return bindings; + } + }); } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java index 3762dce122..aa041cad6d 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseLoadBalancersFromJsonResponseTest.java @@ -18,6 +18,29 @@ */ package org.jclouds.gogrid.functions; +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.UnknownHostException; +import java.util.Map; +import java.util.SortedSet; + +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.gogrid.config.GoGridContextModule; +import org.jclouds.gogrid.domain.Ip; +import org.jclouds.gogrid.domain.IpPortPair; +import org.jclouds.gogrid.domain.IpState; +import org.jclouds.gogrid.domain.LoadBalancer; +import org.jclouds.gogrid.domain.LoadBalancerOs; +import org.jclouds.gogrid.domain.LoadBalancerPersistenceType; +import org.jclouds.gogrid.domain.LoadBalancerState; +import org.jclouds.gogrid.domain.LoadBalancerType; +import org.jclouds.gogrid.functions.internal.CustomDeserializers; +import org.jclouds.http.functions.config.ParserModule; +import org.testng.annotations.Test; + import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; @@ -25,21 +48,6 @@ import com.google.gson.Gson; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Provides; -import org.jclouds.Constants; -import org.jclouds.gogrid.config.GoGridContextModule; -import org.jclouds.gogrid.domain.*; -import org.jclouds.gogrid.functions.internal.CustomDeserializers; -import org.jclouds.http.functions.config.ParserModule; -import org.testng.annotations.Test; - -import javax.inject.Singleton; -import java.io.InputStream; -import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.Map; -import java.util.SortedSet; - -import static org.testng.Assert.assertEquals; /** * @author Oleksiy Yarmula @@ -47,60 +55,45 @@ import static org.testng.Assert.assertEquals; @Test(groups = "unit", testName = "gogrid.ParseLoadBalancersFromJsonResponseTest") public class ParseLoadBalancersFromJsonResponseTest { - @Test - public void testApplyInputStreamDetails() throws UnknownHostException { - InputStream is = getClass().getResourceAsStream("/test_get_load_balancer_list.json"); + @Test + public void testApplyInputStreamDetails() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/test_get_load_balancer_list.json"); - ParseLoadBalancerListFromJsonResponse parser = new ParseLoadBalancerListFromJsonResponse(i - .getInstance(Gson.class)); - SortedSet response = parser.apply(is); + ParseLoadBalancerListFromJsonResponse parser = new ParseLoadBalancerListFromJsonResponse(i + .getInstance(Gson.class)); + SortedSet response = parser.apply(is); - LoadBalancer loadBalancer = new LoadBalancer(6372L, - "Balancer", null, new IpPortPair(new Ip(1313082L, - "204.51.240.181", - "204.51.240.176/255.255.255.240", - true, - IpState.ASSIGNED), - 80), - ImmutableSortedSet.of( - new IpPortPair(new Ip(1313086L, - "204.51.240.185", - "204.51.240.176/255.255.255.240", - true, - IpState.ASSIGNED), - 80), - new IpPortPair(new Ip(1313089L, - "204.51.240.188", - "204.51.240.176/255.255.255.240", - true, - IpState.ASSIGNED), - 80) - ), - LoadBalancerType.ROUND_ROBIN, - LoadBalancerPersistenceType.NONE, - LoadBalancerOs.F5, - LoadBalancerState.ON); - assertEquals(Iterables.getOnlyElement(response), loadBalancer); - } + LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair( + new Ip(1313082L, "204.51.240.181", "204.51.240.176/255.255.255.240", true, + IpState.ASSIGNED), 80), ImmutableSortedSet.of(new IpPortPair( + new Ip(1313086L, "204.51.240.185", "204.51.240.176/255.255.255.240", true, + IpState.ASSIGNED), 80), new IpPortPair(new Ip(1313089L, "204.51.240.188", + "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), 80)), + LoadBalancerType.ROUND_ROBIN, LoadBalancerPersistenceType.NONE, LoadBalancerOs.F5, + LoadBalancerState.ON); + assertEquals(Iterables.getOnlyElement(response), loadBalancer); + } - Injector i = Guice.createInjector(new ParserModule() { - @Override - protected void configure() { - bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); - super.configure(); - } + Injector i = Guice.createInjector(new ParserModule() { + @Override + protected void configure() { + bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); + super.configure(); + } - @Provides - @Singleton - @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) - public Map provideCustomAdapterBindings() { - Map bindings = Maps.newHashMap(); - bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter()); - bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter()); - bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter()); - bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter()); - bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); - return bindings; - } - }); + @Provides + @Singleton + @SuppressWarnings( { "unused", "unchecked" }) + @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) + public Map provideCustomAdapterBindings() { + Map bindings = Maps.newHashMap(); + bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter()); + bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter()); + bindings.put(LoadBalancerPersistenceType.class, + new CustomDeserializers.LoadBalancerPersistenceTypeAdapter()); + bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter()); + bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); + return bindings; + } + }); } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java index 1c206c28fc..1b01a89b3f 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java @@ -18,11 +18,14 @@ */ package org.jclouds.gogrid.functions; -import com.google.common.collect.Maps; -import com.google.gson.Gson; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Provides; +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.UnknownHostException; +import java.util.Map; + +import javax.inject.Singleton; + import org.jclouds.Constants; import org.jclouds.domain.Credentials; import org.jclouds.gogrid.config.GoGridContextModule; @@ -32,12 +35,12 @@ import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.functions.config.ParserModule; import org.testng.annotations.Test; -import static org.testng.Assert.*; -import javax.inject.Singleton; -import java.io.InputStream; -import java.net.UnknownHostException; -import java.util.Map; +import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Provides; /** * @author Oleksiy Yarmula @@ -45,36 +48,35 @@ import java.util.Map; @Test(groups = "unit", testName = "gogrid.ParseServerNameToCredentialsMapFromJsonResponseTest") public class ParseServerNameToCredentialsMapFromJsonResponseTest { - @Test - public void testApplyInputStreamDetails() throws UnknownHostException { - InputStream is = getClass().getResourceAsStream("/test_credentials_list.json"); + @Test + public void testApplyInputStreamDetails() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/test_credentials_list.json"); - ParseServerNameToCredentialsMapFromJsonResponse parser = new ParseServerNameToCredentialsMapFromJsonResponse(i - .getInstance(Gson.class)); - Map response = parser.apply(is); - assertEquals(response.size(), 6); - } + ParseServerNameToCredentialsMapFromJsonResponse parser = new ParseServerNameToCredentialsMapFromJsonResponse( + i.getInstance(Gson.class)); + Map response = parser.apply(is); + assertEquals(response.size(), 6); + } + Injector i = Guice.createInjector(new ParserModule() { + @Override + protected void configure() { + bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); + super.configure(); + } - Injector i = Guice.createInjector(new ParserModule() { - @Override - protected void configure() { - bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); - super.configure(); - } - - - @Provides - @Singleton - @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) - public Map provideCustomAdapterBindings() { - Map bindings = Maps.newHashMap(); - bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); - bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); - bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); - bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); - return bindings; - } - }); + @Provides + @Singleton + @SuppressWarnings( { "unused", "unchecked" }) + @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) + public Map provideCustomAdapterBindings() { + Map bindings = Maps.newHashMap(); + bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); + bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); + bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); + bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); + return bindings; + } + }); } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java index 0da461e935..e0b3587e36 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java @@ -27,87 +27,86 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.UnknownHostException; -import java.util.Arrays; import java.util.Date; import java.util.Map; import java.util.SortedSet; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.inject.Provides; +import javax.inject.Singleton; + import org.jclouds.Constants; import org.jclouds.gogrid.config.GoGridContextModule; -import org.jclouds.gogrid.domain.*; +import org.jclouds.gogrid.domain.BillingToken; +import org.jclouds.gogrid.domain.Customer; +import org.jclouds.gogrid.domain.Ip; +import org.jclouds.gogrid.domain.IpState; +import org.jclouds.gogrid.domain.Option; +import org.jclouds.gogrid.domain.Server; +import org.jclouds.gogrid.domain.ServerImage; +import org.jclouds.gogrid.domain.ServerImageState; +import org.jclouds.gogrid.domain.ServerImageType; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.functions.config.ParserModule; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.inject.Guice; import com.google.inject.Injector; - -import javax.inject.Singleton; +import com.google.inject.Provides; /** * Tests behavior of {@code ParseStatusesFromJsonResponse} - * + * * @author Adrian Cole */ @Test(groups = "unit", testName = "gogrid.ParseServersFromJsonResponseTest") public class ParseServersFromJsonResponseTest { - @Test - public void testApplyInputStreamDetails() throws UnknownHostException { - InputStream is = getClass().getResourceAsStream("/test_get_server_list.json"); + @Test + public void testApplyInputStreamDetails() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/test_get_server_list.json"); - ParseServerListFromJsonResponse parser = new ParseServerListFromJsonResponse(i - .getInstance(Gson.class)); - SortedSet response = parser.apply(is); + ParseServerListFromJsonResponse parser = new ParseServerListFromJsonResponse(i + .getInstance(Gson.class)); + SortedSet response = parser.apply(is); - Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)"); - Option webServer = new Option(1L, "Web Server", "Web or Application Server"); - Server server = new Server(75245L, false, "PowerServer", "server to test the api. created by Alex", - new Option(1L, "On", "Server is in active state."), - webServer, - new Option(1L, "512MB", "Server with 512MB RAM"), - centOs, - new Ip(1313079L, "204.51.240.178", "204.51.240.176/255.255.255.240", true, - IpState.ASSIGNED), - new ServerImage(1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", - "BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", - centOs, null, ServerImageType.WEB_APPLICATION_SERVER, - ServerImageState.AVAILABLE, - 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", - true, true, - new Date(1261504577971L), - new Date(1262649582180L), - ImmutableSortedSet.of( - new BillingToken(38L, "CentOS 5.2 32bit", 0.0), - new BillingToken(56L, "BitNami: Gallery", 0.0) - ), - new Customer(24732L, "BitRock"))); - assertEquals(Iterables.getOnlyElement(response), server); - } + Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)"); + Option webServer = new Option(1L, "Web Server", "Web or Application Server"); + Server server = new Server(75245L, false, "PowerServer", + "server to test the api. created by Alex", new Option(1L, "On", + "Server is in active state."), webServer, new Option(1L, "512MB", + "Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178", + "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), new ServerImage( + 1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", + "BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", centOs, + null, ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE, + 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true, + new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of( + new BillingToken(38L, "CentOS 5.2 32bit", 0.0), new BillingToken( + 56L, "BitNami: Gallery", 0.0)), new Customer(24732L, + "BitRock"))); + assertEquals(Iterables.getOnlyElement(response), server); + } + Injector i = Guice.createInjector(new ParserModule() { + @Override + protected void configure() { + bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); + super.configure(); + } - Injector i = Guice.createInjector(new ParserModule() { - @Override - protected void configure() { - bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); - super.configure(); - } - - - @Provides - @Singleton - @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) - public Map provideCustomAdapterBindings() { - Map bindings = Maps.newHashMap(); - bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); - bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); - bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); - return bindings; - } - }); + @Provides + @Singleton + @SuppressWarnings( { "unused", "unchecked" }) + @com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS) + public Map provideCustomAdapterBindings() { + Map bindings = Maps.newHashMap(); + bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); + bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); + bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); + return bindings; + } + }); } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java index befa678ec4..5a41b0cb75 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageAsyncClientTest.java @@ -18,11 +18,15 @@ */ package org.jclouds.gogrid.services; -import com.google.common.collect.Iterables; -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.inject.Singleton; + import org.jclouds.encryption.EncryptionService; import org.jclouds.gogrid.GoGrid; import org.jclouds.gogrid.domain.ServerImageState; @@ -37,166 +41,154 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import javax.inject.Singleton; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URI; - -import static org.testng.Assert.assertEquals; +import com.google.common.collect.Iterables; +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; /** * @author Oleksiy Yarmula */ public class GridImageAsyncClientTest extends RestClientTest { - @Test - public void testGetImageListWithOptions() throws NoSuchMethodException, IOException { - Method method = GridImageAsyncClient.class.getMethod("getImageList", GetImageListOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - new GetImageListOptions().onlyPublic().setState(ServerImageState.AVAILABLE). - setType(ServerImageType.WEB_APPLICATION_SERVER)); + @Test + public void testGetImageListWithOptions() throws NoSuchMethodException, IOException { + Method method = GridImageAsyncClient.class.getMethod("getImageList", + GetImageListOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + new GetImageListOptions().onlyPublic().setState(ServerImageState.AVAILABLE).setType( + ServerImageType.WEB_APPLICATION_SERVER)); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/list?v=1.4&" + - "isPublic=true&image.state=Available&" + - "image.type=Web%20Server HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/list?v=1.4&" + + "isPublic=true&image.state=Available&" + "image.type=Web%20Server HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/list?" + - "v=1.4&isPublic=true&image.state=Available&" + - "image.type=Web%20Server&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/list?" + + "v=1.4&isPublic=true&image.state=Available&" + "image.type=Web%20Server&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testGetImagesByName() throws NoSuchMethodException, IOException { - Method method = GridImageAsyncClient.class.getMethod("getImagesByName", String[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "name1", "name2"); + @Test + public void testGetImagesByName() throws NoSuchMethodException, IOException { + Method method = GridImageAsyncClient.class.getMethod("getImagesByName", String[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + "name1", "name2"); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/get?v=1.4&" + - "name=name1&name=name2 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.4&" + + "name=name1&name=name2 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/get?v=1.4&" + - "name=name1&name=name2&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.4&" + + "name=name1&name=name2&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testEditImageDescription() throws NoSuchMethodException, IOException { - Method method = GridImageAsyncClient.class.getMethod("editImageDescription", String.class, String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "imageName", "newDesc"); + @Test + public void testEditImageDescription() throws NoSuchMethodException, IOException { + Method method = GridImageAsyncClient.class.getMethod("editImageDescription", String.class, + String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + "imageName", "newDesc"); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + - "image=imageName&description=newDesc HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + + "image=imageName&description=newDesc HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + - "image=imageName&description=newDesc&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + + "image=imageName&description=newDesc&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testEditImageFriendlyName() throws NoSuchMethodException, IOException { - Method method = GridImageAsyncClient.class.getMethod("editImageFriendlyName", String.class, String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "imageName", "newFriendlyName"); + @Test + public void testEditImageFriendlyName() throws NoSuchMethodException, IOException { + Method method = GridImageAsyncClient.class.getMethod("editImageFriendlyName", String.class, + String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + "imageName", "newFriendlyName"); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + - "image=imageName&friendlyName=newFriendlyName HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + + "image=imageName&friendlyName=newFriendlyName HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + - "image=imageName&friendlyName=newFriendlyName&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" + + "image=imageName&friendlyName=newFriendlyName&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); - } + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + } - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(URI.class).annotatedWith(GoGrid.class).toInstance( - URI.create("https://api.gogrid.com/api")); - bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - } + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(GoGrid.class).toInstance( + URI.create("https://api.gogrid.com/api")); + bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } - @Provides - @Singleton - public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService) - throws UnsupportedEncodingException { - return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); - } - }; - } + @SuppressWarnings("unused") + @Provides + @Singleton + public SharedKeyLiteAuthentication provideAuthentication( + EncryptionService encryptionService) throws UnsupportedEncodingException { + return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); + } + }; + } } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridIpAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridIpAsyncClientTest.java index fe0947700f..ac2fac0086 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridIpAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridIpAsyncClientTest.java @@ -18,125 +18,122 @@ */ package org.jclouds.gogrid.services; -import com.google.common.collect.Iterables; -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.inject.Singleton; + import org.jclouds.encryption.EncryptionService; import org.jclouds.gogrid.GoGrid; import org.jclouds.gogrid.domain.IpType; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse; -import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse; import org.jclouds.gogrid.options.GetIpListOptions; -import org.jclouds.gogrid.options.GetJobListOptions; import org.jclouds.logging.Logger; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import javax.inject.Singleton; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URI; -import java.util.Date; - -import static org.testng.Assert.assertEquals; +import com.google.common.collect.Iterables; +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; /** * @author Oleksiy Yarmula */ public class GridIpAsyncClientTest extends RestClientTest { - @Test - public void testGetIpListWithOptions() throws NoSuchMethodException, IOException { - Method method = GridIpAsyncClient.class.getMethod("getIpList", GetIpListOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC)); + @Test + public void testGetIpListWithOptions() throws NoSuchMethodException, IOException { + Method method = GridIpAsyncClient.class.getMethod("getIpList", GetIpListOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC)); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" + - "ip.type=Public HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" + + "ip.type=Public HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" + - "ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" + + "ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } + @Test + public void testGetAssignedIpList() throws NoSuchMethodException, IOException { + Method method = GridIpAsyncClient.class.getMethod("getAssignedIpList"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); - @Test - public void testGetAssignedIpList() throws NoSuchMethodException, IOException { - Method method = GridIpAsyncClient.class.getMethod("getAssignedIpList"); - GeneratedHttpRequest httpRequest = processor.createRequest(method); + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + } + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } - @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); - } + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(GoGrid.class).toInstance( + URI.create("https://api.gogrid.com/api")); + bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } - - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(URI.class).annotatedWith(GoGrid.class).toInstance( - URI.create("https://api.gogrid.com/api")); - bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - } - - @Provides - @Singleton - public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService) - throws UnsupportedEncodingException { - return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); - } - }; - } + @Provides + @Singleton + @SuppressWarnings("unused") + public SharedKeyLiteAuthentication provideAuthentication( + EncryptionService encryptionService) throws UnsupportedEncodingException { + return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); + } + }; + } } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java index d4f1b0729d..e5fdf5deea 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java @@ -18,11 +18,16 @@ */ package org.jclouds.gogrid.services; -import com.google.common.collect.Iterables; -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Date; + +import javax.inject.Singleton; + import org.jclouds.encryption.EncryptionService; import org.jclouds.gogrid.GoGrid; import org.jclouds.gogrid.domain.JobState; @@ -36,154 +41,141 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import javax.inject.Singleton; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URI; -import java.util.Date; - -import static org.testng.Assert.assertEquals; +import com.google.common.collect.Iterables; +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; /** * @author Oleksiy Yarmula */ public class GridJobAsyncClientTest extends RestClientTest { - @Test - public void testGetJobListWithOptions() throws NoSuchMethodException, IOException { - Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - new GetJobListOptions.Builder(). - create(). - withStartDate(new Date(1267385381770L)). - withEndDate(new Date(1267385382770L)). - onlyForObjectType(ObjectType.VIRTUAL_SERVER). - onlyForState(JobState.PROCESSING)); + @Test + public void testGetJobListWithOptions() throws NoSuchMethodException, IOException { + Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + new GetJobListOptions.Builder().create().withStartDate(new Date(1267385381770L)) + .withEndDate(new Date(1267385382770L)).onlyForObjectType( + ObjectType.VIRTUAL_SERVER).onlyForState(JobState.PROCESSING)); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" + - "enddate=1267385382770&job.objecttype=VirtualServer&" + - "job.state=Processing HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" + + "enddate=1267385382770&job.objecttype=VirtualServer&" + + "job.state=Processing HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" + - "enddate=1267385382770&job.objecttype=VirtualServer&" + - "job.state=Processing&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" + + "enddate=1267385382770&job.objecttype=VirtualServer&" + + "job.state=Processing&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testGetJobListNoOptions() throws NoSuchMethodException, IOException { - Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method); + @Test + public void testGetJobListNoOptions() throws NoSuchMethodException, IOException { + Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/job/list?v=1.3 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/job/list?v=1.3 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testGetJobsForServerName() throws NoSuchMethodException, IOException { - Method method = GridJobAsyncClient.class.getMethod("getJobsForObjectName", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "MyServer"); + @Test + public void testGetJobsForServerName() throws NoSuchMethodException, IOException { + Method method = GridJobAsyncClient.class.getMethod("getJobsForObjectName", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, + "MyServer"); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/job/list?v=1.3&" + - "object=MyServer HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.3&" + + "object=MyServer HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/job/list?v=1.3&" + - "object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.3&" + + "object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } + @Test + public void testGetJobsById() throws NoSuchMethodException, IOException { + Method method = GridJobAsyncClient.class.getMethod("getJobsById", Long[].class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, 123L, + 456L); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.3&" + + "id=123&id=456 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - @Test - public void testGetJobsById() throws NoSuchMethodException, IOException { - Method method = GridJobAsyncClient.class.getMethod("getJobsById", Long[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - 123L, 456L); + assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/job/get?v=1.3&" + - "id=123&id=456 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.3&" + + "id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + } - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/job/get?v=1.3&" + - "id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } - @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); - } + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(GoGrid.class).toInstance( + URI.create("https://api.gogrid.com/api")); + bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } - - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(URI.class).annotatedWith(GoGrid.class).toInstance( - URI.create("https://api.gogrid.com/api")); - bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - } - - @Provides - @Singleton - public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService) - throws UnsupportedEncodingException { - return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); - } - }; - } + @Provides + @Singleton + @SuppressWarnings("unused") + public SharedKeyLiteAuthentication provideAuthentication( + EncryptionService encryptionService) throws UnsupportedEncodingException { + return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); + } + }; + } } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java index 7d79a1e587..2d8fe134b8 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java @@ -18,11 +18,17 @@ */ package org.jclouds.gogrid.services; -import com.google.common.collect.Iterables; -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Arrays; +import java.util.List; + +import javax.inject.Singleton; + import org.jclouds.encryption.EncryptionService; import org.jclouds.gogrid.GoGrid; import org.jclouds.gogrid.domain.Ip; @@ -39,206 +45,192 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; -import javax.inject.Singleton; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URI; -import java.util.Arrays; -import java.util.List; - -import static org.testng.Assert.assertEquals; +import com.google.common.collect.Iterables; +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; /** * @author Oleksiy Yarmula */ public class GridLoadBalancerAsyncClientTest extends RestClientTest { - @Test - public void testGetLoadBalancerList() throws NoSuchMethodException, IOException { - Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancerList"); - GeneratedHttpRequest httpRequest = processor.createRequest(method); + @Test + public void testGetLoadBalancerList() throws NoSuchMethodException, IOException { + Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancerList"); + GeneratedHttpRequest httpRequest = processor + .createRequest(method); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, + ParseLoadBalancerListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testAddLoadBalancer() throws NoSuchMethodException, IOException { - Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer", - String.class, IpPortPair.class, List.class, AddLoadBalancerOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80), - Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), - new IpPortPair(new Ip("127.0.0.1"), 9090)), - new AddLoadBalancerOptions.Builder().create(LoadBalancerType.LEAST_CONNECTED, - LoadBalancerPersistenceType.SSL_STICKY)); + @Test + public void testAddLoadBalancer() throws NoSuchMethodException, IOException { + Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer", String.class, + IpPortPair.class, List.class, AddLoadBalancerOptions[].class); + GeneratedHttpRequest httpRequest = processor.createRequest( + method, "BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80), Arrays.asList( + new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip( + "127.0.0.1"), 9090)), new AddLoadBalancerOptions.Builder().create( + LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SSL_STICKY)); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" + - "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" + - "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" + - "virtualip.ip=127.0.0.1&virtualip.port=80 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" + + "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" + + "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" + + "virtualip.ip=127.0.0.1&virtualip.port=80 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" + - "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" + - "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" + - "virtualip.ip=127.0.0.1&virtualip.port=80&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" + + "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" + + "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" + + "virtualip.ip=127.0.0.1&virtualip.port=80&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testEditLoadBalancer() throws NoSuchMethodException, IOException { - Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", - String.class, List.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), + @Test + public void testEditLoadBalancer() throws NoSuchMethodException, IOException { + Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", String.class, + List.class); + GeneratedHttpRequest httpRequest = processor.createRequest( + method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip("127.0.0.1"), 9090))); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" + - "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" + + "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" + - "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" + + "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testGetLoadBalancersByName() throws NoSuchMethodException, IOException { - Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName", String[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - "My Load Balancer", "My Load Balancer 2"); + @Test + public void testGetLoadBalancersByName() throws NoSuchMethodException, IOException { + Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName", + String[].class); + GeneratedHttpRequest httpRequest = processor.createRequest( + method, "My Load Balancer", "My Load Balancer 2"); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerListFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, + ParseLoadBalancerListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } - @Test - public void testDeleteLoadBalancerById() throws NoSuchMethodException, IOException { - Method method = GridLoadBalancerAsyncClient.class.getMethod("deleteById", Long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, - 55L); + @Test + public void testDeleteLoadBalancerById() throws NoSuchMethodException, IOException { + Method method = GridLoadBalancerAsyncClient.class.getMethod("deleteById", Long.class); + GeneratedHttpRequest httpRequest = processor.createRequest( + method, 55L); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "delete?v=1.4&id=55 HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "delete?v=1.4&id=55 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); - assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpRequest); - Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - assertRequestLineEquals(httpRequest, - "GET https://api.gogrid.com/api/grid/loadbalancer/" + - "delete?v=1.4&id=55&" + - "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + - "HTTP/1.1"); - assertHeadersEqual(httpRequest, ""); - assertPayloadEquals(httpRequest, null); - } + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "delete?v=1.4&id=55&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + } - @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); - } + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(GoGrid.class).toInstance( + URI.create("https://api.gogrid.com/api")); + bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(URI.class).annotatedWith(GoGrid.class).toInstance( - URI.create("https://api.gogrid.com/api")); - bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - } - - @Provides - @Singleton - public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService) - throws UnsupportedEncodingException { - return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); - } - }; - } + @Provides + @Singleton + @SuppressWarnings("unused") + public SharedKeyLiteAuthentication provideAuthentication( + EncryptionService encryptionService) throws UnsupportedEncodingException { + return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); + } + }; + } }