From bac869dce58532cb562c5ec098c6f0f531c769d0 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 12 Nov 2012 09:55:43 -0800 Subject: [PATCH] carve out EC2Api/EC2AsyncApi for new features --- .../src/main/java/org/jclouds/ec2/EC2Api.java | 77 +++++++++++++++++++ .../java/org/jclouds/ec2/EC2AsyncApi.java | 57 ++++++++++++++ .../java/org/jclouds/ec2/EC2AsyncClient.java | 31 +------- .../main/java/org/jclouds/ec2/EC2Client.java | 30 +------- ...asswordCredentialsFromWindowsInstance.java | 8 +- .../ec2/config/EC2RestClientModule.java | 30 +++++++- .../org/jclouds/ec2/features/WindowsApi.java | 2 + .../jclouds/ec2/features/WindowsAsyncApi.java | 2 + ...aseEC2ComputeServiceContextExpectTest.java | 4 +- .../config/EC2RestClientModuleExpectTest.java | 4 +- .../ec2/features/WindowsApiExpectTest.java | 16 ++-- .../ec2/features/WindowsApiLiveTest.java | 16 ++-- .../ec2/internal/BaseEC2ApiExpectTest.java | 66 ++++++++++++++++ .../ec2/internal/BaseEC2ApiLiveTest.java | 27 +++++++ .../ec2/internal/BaseEC2ClientExpectTest.java | 66 ++++++++++++++++ .../ec2/internal/BaseEC2ExpectTest.java | 39 ---------- .../EC2ElasticBlockStoreClientExpectTest.java | 4 +- 17 files changed, 358 insertions(+), 121 deletions(-) create mode 100644 apis/ec2/src/main/java/org/jclouds/ec2/EC2Api.java create mode 100644 apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncApi.java create mode 100644 apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiExpectTest.java create mode 100644 apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiLiveTest.java create mode 100644 apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ClientExpectTest.java diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2Api.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2Api.java new file mode 100644 index 0000000000..bb8dcf7527 --- /dev/null +++ b/apis/ec2/src/main/java/org/jclouds/ec2/EC2Api.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ec2; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.ec2.features.WindowsApi; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.location.Region; +import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.EndpointParam; + +import com.google.common.annotations.Beta; +import com.google.common.base.Optional; +import com.google.inject.Provides; + +/** + * Provides access to EC2 features, broken up by feature group. Use of the + * {@link Optional} type allows you to check to see if the underlying + * implementation supports a particular feature before attempting to use it. + * This is useful in clones like OpenStack, CloudStack, or Eucalyptus, which + * track the api, but are always behind Amazon's service. In the case of Amazon + * ({@code aws-ec2}), you can expect all features to be present. + * + * + * Example + * + *
+ * Optional<? extends WindowsApi> windowsOption = ec2Client.getWindowsApi();
+ * checkState(windowsOption.isPresent(), "windows feature required, but not present");
+ * 
+ * + * @author Adrian Cole + * @see EC2AsyncApi + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface EC2Api { + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); + + /** + * Provides synchronous access to Windows features. + */ + @Delegate + @Beta + Optional getWindowsApi(); + + @Delegate + @Beta + Optional getWindowsApiForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + +} diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncApi.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncApi.java new file mode 100644 index 0000000000..a4305113c7 --- /dev/null +++ b/apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncApi.java @@ -0,0 +1,57 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ec2; + +import java.util.Set; + +import org.jclouds.ec2.features.WindowsAsyncApi; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.location.Region; +import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.EndpointParam; + +import com.google.common.base.Optional; +import com.google.inject.Provides; + +/** + * Refer to javadoc for {@link EC2Api}, as this interface is the same, except + * features provide asynchronous return values. + * + * @author Adrian Cole + */ +public interface EC2AsyncApi { + /** + * + * @return the Region codes configured + */ + @Provides + @Region + Set getConfiguredRegions(); + + /** + * Provides asynchronous access to Windows features. + */ + @Delegate + Optional getWindowsApi(); + + @Delegate + Optional getWindowsApiForRegion( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); +} diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncClient.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncClient.java index aa9efa770a..270557a2ca 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncClient.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/EC2AsyncClient.java @@ -18,9 +18,6 @@ */ package org.jclouds.ec2; -import java.util.Set; - -import org.jclouds.ec2.features.WindowsAsyncApi; import org.jclouds.ec2.services.AMIAsyncClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; import org.jclouds.ec2.services.ElasticBlockStoreAsyncClient; @@ -29,29 +26,15 @@ import org.jclouds.ec2.services.InstanceAsyncClient; import org.jclouds.ec2.services.KeyPairAsyncClient; import org.jclouds.ec2.services.SecurityGroupAsyncClient; import org.jclouds.ec2.services.WindowsAsyncClient; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.Delegate; -import org.jclouds.rest.annotations.EndpointParam; - -import com.google.common.annotations.Beta; -import com.google.inject.Provides; /** * Provides asynchronous access to EC2 services. * * @author Adrian Cole */ -public interface EC2AsyncClient { +public interface EC2AsyncClient extends EC2AsyncApi { public static final String VERSION = "2010-06-15"; - /** - * - * @return the Region codes configured - */ - @Provides - @Region - Set getConfiguredRegions(); /** * Provides asynchronous access to AMI services. @@ -100,16 +83,4 @@ public interface EC2AsyncClient { */ @Delegate ElasticBlockStoreAsyncClient getElasticBlockStoreServices(); - - /** - * Provides asynchronous access to Windows features. - */ - @Delegate - @Beta - WindowsAsyncApi getWindowsApi(); - - @Delegate - @Beta - WindowsAsyncApi getWindowsApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/EC2Client.java b/apis/ec2/src/main/java/org/jclouds/ec2/EC2Client.java index ffc8218e41..5d410c2c79 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/EC2Client.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/EC2Client.java @@ -18,11 +18,9 @@ */ package org.jclouds.ec2; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.ec2.features.WindowsApi; import org.jclouds.ec2.services.AMIClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient; import org.jclouds.ec2.services.ElasticBlockStoreClient; @@ -31,14 +29,7 @@ import org.jclouds.ec2.services.InstanceClient; import org.jclouds.ec2.services.KeyPairClient; import org.jclouds.ec2.services.SecurityGroupClient; import org.jclouds.ec2.services.WindowsClient; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.location.Region; -import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.Delegate; -import org.jclouds.rest.annotations.EndpointParam; - -import com.google.common.annotations.Beta; -import com.google.inject.Provides; /** * Provides synchronous access to EC2 services. @@ -46,14 +37,7 @@ import com.google.inject.Provides; * @author Adrian Cole */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -public interface EC2Client { - /** - * - * @return the Region codes configured - */ - @Provides - @Region - Set getConfiguredRegions(); +public interface EC2Client extends EC2Api { /** * Provides synchronous access to AMI services. @@ -102,17 +86,5 @@ public interface EC2Client { */ @Delegate ElasticBlockStoreClient getElasticBlockStoreServices(); - - /** - * Provides synchronous access to Windows features. - */ - @Delegate - @Beta - WindowsApi getWindowsApi(); - - @Delegate - @Beta - WindowsApi getWindowsApiForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java index c618708742..be340665a4 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java @@ -19,6 +19,7 @@ package org.jclouds.ec2.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -44,6 +45,7 @@ import org.jclouds.predicates.RetryablePredicate; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; +import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Strings; import com.google.common.util.concurrent.Atomics; @@ -72,12 +74,16 @@ public class PasswordCredentialsFromWindowsInstance implements Function windowsOption = ec2Client.getWindowsApiForRegion(instance.getRegion()); + checkState(windowsOption.isPresent(), "windows feature not present in region %s", instance.getRegion()); + + final WindowsApi windowsApi = windowsOption.get(); + LoginCredentials credentials = LoginCredentials.builder().user("Administrator").noPrivateKey().build(); String privateKey = getPrivateKeyOrNull(instance); if (privateKey == null) { return credentials; } - final WindowsApi windowsApi = ec2Client.getWindowsApiForRegion(instance.getRegion()); // The Administrator password will take some time before it is ready - Amazon says // sometimes // 15 minutes. diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java index b427cd974a..ab1af745d6 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/config/EC2RestClientModule.java @@ -20,7 +20,11 @@ package org.jclouds.ec2.config; import java.util.Map; +import javax.inject.Singleton; + import org.jclouds.aws.config.WithZonesFormSigningRestClientModule; +import org.jclouds.ec2.EC2Api; +import org.jclouds.ec2.EC2AsyncApi; import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.features.WindowsApi; @@ -56,6 +60,7 @@ import org.jclouds.rest.ConfiguresRestClient; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; +import com.google.inject.Provides; import com.google.inject.Scopes; /** @@ -64,7 +69,8 @@ import com.google.inject.Scopes; * @author Adrian Cole (EDIT: Nick Terry nterry@familysearch.org) */ @ConfiguresRestClient -public class EC2RestClientModule extends +// EC2Api not EC2Client so that this can be used for new apps that only depend on EC2Api +public class EC2RestClientModule extends WithZonesFormSigningRestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// .put(AMIClient.class, AMIAsyncClient.class)// @@ -80,6 +86,7 @@ public class EC2RestClientModule @SuppressWarnings("unchecked") public EC2RestClientModule() { + // retaining top-level type of EC2Client vs EC2Api until we migrate all functionality up super(TypeToken.class.cast(TypeToken.of(EC2Client.class)), TypeToken.class.cast(TypeToken.of(EC2AsyncClient.class)), DELEGATE_MAP); } @@ -88,6 +95,27 @@ public class EC2RestClientModule super(syncClientType, asyncClientType, sync2Async); } + + /** + * so that we can make bindings to {@link EC2Api directly} until we switch + * off {@link @EC2Client} + */ + @Singleton + @Provides + EC2Api provideEC2Api(EC2Client in) { + return in; + } + + /** + * so that we can make bindings to {@link EC2AsyncApi directly} until we switch + * off {@link @EC2AsyncClient} + */ + @Singleton + @Provides + EC2AsyncApi provideEC2Api(EC2AsyncClient in) { + return in; + } + @Override protected void installLocations() { install(new LocationModule()); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsApi.java b/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsApi.java index 844bf9f41f..f34a6ce4e2 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsApi.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsApi.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.ec2.domain.PasswordData; +import org.jclouds.rest.annotations.SinceApiVersion; import com.google.common.annotations.Beta; @@ -35,6 +36,7 @@ import com.google.common.annotations.Beta; */ @Timeout(duration = 45, timeUnit = TimeUnit.SECONDS) @Beta +@SinceApiVersion("2008-08-08") public interface WindowsApi { /** diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsAsyncApi.java b/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsAsyncApi.java index 5e3322aaf4..679bf4e046 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsAsyncApi.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/features/WindowsAsyncApi.java @@ -30,6 +30,7 @@ import org.jclouds.ec2.xml.GetPasswordDataResponseHandler; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SinceApiVersion; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -48,6 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture; @RequestFilters(FormSigner.class) @VirtualHost @Beta +@SinceApiVersion("2008-08-08") public interface WindowsAsyncApi { /** diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/BaseEC2ComputeServiceContextExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/BaseEC2ComputeServiceContextExpectTest.java index 86cbeaf8e2..fc1cb1419d 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/BaseEC2ComputeServiceContextExpectTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/internal/BaseEC2ComputeServiceContextExpectTest.java @@ -22,14 +22,14 @@ package org.jclouds.ec2.compute.internal; import java.util.Properties; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.ec2.internal.BaseEC2ExpectTest; +import org.jclouds.ec2.internal.BaseEC2ClientExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import com.google.common.base.Function; import com.google.inject.Module; -public abstract class BaseEC2ComputeServiceContextExpectTest extends BaseEC2ExpectTest implements +public abstract class BaseEC2ComputeServiceContextExpectTest extends BaseEC2ClientExpectTest implements Function { @Override diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/config/EC2RestClientModuleExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/config/EC2RestClientModuleExpectTest.java index cee0074d32..2d8630d03b 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/config/EC2RestClientModuleExpectTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/config/EC2RestClientModuleExpectTest.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import org.jclouds.ec2.internal.BaseEC2ExpectTest; +import org.jclouds.ec2.internal.BaseEC2ClientExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.location.Region; @@ -48,7 +48,7 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ @Test(groups = "unit", testName = "EC2RestClientModuleExpectTest") -public class EC2RestClientModuleExpectTest extends BaseEC2ExpectTest { +public class EC2RestClientModuleExpectTest extends BaseEC2ClientExpectTest { private Injector injector; public EC2RestClientModuleExpectTest() { diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiExpectTest.java index ab058b9649..f34a0b5fe1 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiExpectTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiExpectTest.java @@ -23,8 +23,8 @@ import static org.testng.Assert.assertNull; import java.util.TimeZone; -import org.jclouds.ec2.EC2Client; -import org.jclouds.ec2.internal.BaseEC2ExpectTest; +import org.jclouds.ec2.EC2Api; +import org.jclouds.ec2.internal.BaseEC2ApiExpectTest; import org.jclouds.ec2.parse.GetPasswordDataResponseTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; @@ -34,7 +34,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "unit", testName = "WindowsApiExpectTest") -public class WindowsApiExpectTest extends BaseEC2ExpectTest { +public class WindowsApiExpectTest extends BaseEC2ApiExpectTest { public WindowsApiExpectTest() { TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); @@ -63,19 +63,17 @@ public class WindowsApiExpectTest extends BaseEC2ExpectTest { HttpResponse getResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResourceWithContentType("/get_passworddata.xml", "text/xml")).build(); - EC2Client apiWhenExist = requestSendsResponse( - get, getResponse); + EC2Api apiWhenExist = requestSendsResponse(get, getResponse); - assertEquals(apiWhenExist.getWindowsApi().getPasswordDataForInstance("i-2574e22a").toString(), new GetPasswordDataResponseTest().expected().toString()); + assertEquals(apiWhenExist.getWindowsApi().get().getPasswordDataForInstance("i-2574e22a").toString(), new GetPasswordDataResponseTest().expected().toString()); } public void testGetPasswordDataWhenResponseIs404() throws Exception { HttpResponse getResponse = HttpResponse.builder().statusCode(404).build(); - EC2Client apiWhenDontExist = requestSendsResponse( - get, getResponse); + EC2Api apiWhenDontExist = requestSendsResponse(get, getResponse); - assertNull(apiWhenDontExist.getWindowsApi().getPasswordDataForInstance("i-2574e22a")); + assertNull(apiWhenDontExist.getWindowsApi().get().getPasswordDataForInstance("i-2574e22a")); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiLiveTest.java index 97d6691b35..02bf23eb69 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/features/WindowsApiLiveTest.java @@ -18,18 +18,22 @@ */ package org.jclouds.ec2.features; -import org.jclouds.ec2.internal.BaseEC2ClientLiveTest; +import org.jclouds.ec2.internal.BaseEC2ApiLiveTest; +import org.testng.SkipException; import org.testng.annotations.Test; +import com.google.common.base.Optional; + /** * @author Adrian Cole */ -@Test(groups = "live", testName = "WindowsApiLiveTest") -public class WindowsApiLiveTest extends BaseEC2ClientLiveTest { - - +@Test(groups = "live") +public class WindowsApiLiveTest extends BaseEC2ApiLiveTest { protected WindowsApi api() { - return context.getApi().getWindowsApi(); + Optional windowsOption = context.getApi().getWindowsApi(); + if (!windowsOption.isPresent()) + throw new SkipException("windows api not present"); + return windowsOption.get(); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiExpectTest.java new file mode 100644 index 0000000000..b90ac2c8d0 --- /dev/null +++ b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiExpectTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ec2.internal; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.jclouds.date.DateService; +import org.jclouds.ec2.EC2Api; +import org.jclouds.ec2.EC2AsyncApi; +import org.jclouds.ec2.config.EC2RestClientModule; +import org.jclouds.rest.ConfiguresRestClient; + +import com.google.common.base.Supplier; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +public abstract class BaseEC2ApiExpectTest extends BaseEC2ExpectTest { + + @ConfiguresRestClient + protected static class TestEC2RestClientModule extends EC2RestClientModule { + + @Override + protected void configure() { + super.configure(); + // predicatable node names + final AtomicInteger suffix = new AtomicInteger(); + bind(new TypeLiteral>() { + }).toInstance(new Supplier() { + + @Override + public String get() { + return suffix.getAndIncrement() + ""; + } + + }); + } + + @Override + @Provides + protected String provideTimeStamp(DateService dateService) { + return CONSTANT_DATE; + } + } + + @Override + protected Module createModule() { + return new TestEC2RestClientModule(); + } +} diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiLiveTest.java new file mode 100644 index 0000000000..14920e6137 --- /dev/null +++ b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiLiveTest.java @@ -0,0 +1,27 @@ +package org.jclouds.ec2.internal; + +import org.jclouds.apis.BaseContextLiveTest; +import org.jclouds.ec2.EC2Api; +import org.jclouds.ec2.EC2AsyncApi; +import org.jclouds.rest.RestContext; + +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +public class BaseEC2ApiLiveTest extends BaseContextLiveTest> { + + public BaseEC2ApiLiveTest() { + provider = "ec2"; + } + + @Override + protected TypeToken> contextType() { + return new TypeToken>() { + private static final long serialVersionUID = -5070937833892503232L; + }; + } + +} diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ClientExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ClientExpectTest.java new file mode 100644 index 0000000000..d0c5d8fe37 --- /dev/null +++ b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ClientExpectTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ec2.internal; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.jclouds.date.DateService; +import org.jclouds.ec2.EC2AsyncClient; +import org.jclouds.ec2.EC2Client; +import org.jclouds.ec2.config.EC2RestClientModule; +import org.jclouds.rest.ConfiguresRestClient; + +import com.google.common.base.Supplier; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +public abstract class BaseEC2ClientExpectTest extends BaseEC2ExpectTest { + + @ConfiguresRestClient + protected static class TestEC2RestClientModule extends EC2RestClientModule { + + @Override + protected void configure() { + super.configure(); + // predicatable node names + final AtomicInteger suffix = new AtomicInteger(); + bind(new TypeLiteral>() { + }).toInstance(new Supplier() { + + @Override + public String get() { + return suffix.getAndIncrement() + ""; + } + + }); + } + + @Override + @Provides + protected String provideTimeStamp(DateService dateService) { + return CONSTANT_DATE; + } + } + + @Override + protected Module createModule() { + return new TestEC2RestClientModule(); + } +} diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ExpectTest.java index 2034a7b2d8..9f447eed38 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ExpectTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ExpectTest.java @@ -19,29 +19,20 @@ package org.jclouds.ec2.internal; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; import javax.ws.rs.core.MediaType; import org.jclouds.aws.filters.FormSigner; import org.jclouds.date.DateService; import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.ec2.EC2AsyncClient; -import org.jclouds.ec2.EC2Client; -import org.jclouds.ec2.config.EC2RestClientModule; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.internal.BaseRestClientExpectTest; import com.google.common.base.Functions; -import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; public abstract class BaseEC2ExpectTest extends BaseRestClientExpectTest { protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z"; @@ -87,34 +78,4 @@ public abstract class BaseEC2ExpectTest extends BaseRestClientExpectTest { describeAvailabilityZonesRequestResponse = builder.build(); } - @ConfiguresRestClient - protected static class TestEC2RestClientModule extends EC2RestClientModule { - - @Override - protected void configure() { - super.configure(); - // predicatable node names - final AtomicInteger suffix = new AtomicInteger(); - bind(new TypeLiteral>() { - }).toInstance(new Supplier() { - - @Override - public String get() { - return suffix.getAndIncrement() + ""; - } - - }); - } - - @Override - @Provides - protected String provideTimeStamp(DateService dateService) { - return CONSTANT_DATE; - } - } - - @Override - protected Module createModule() { - return new TestEC2RestClientModule(); - } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java index 4ef1fd8c0c..f181ad0025 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/services/EC2ElasticBlockStoreClientExpectTest.java @@ -22,7 +22,7 @@ import static org.testng.Assert.assertEquals; import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.domain.Volume; -import org.jclouds.ec2.internal.BaseEC2ExpectTest; +import org.jclouds.ec2.internal.BaseEC2ClientExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableMap.Builder; * @author Adrian Cole */ @Test(groups = "unit", testName = "EC2ElasticBlockStoreClientExpectTest") -public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ExpectTest { +public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ClientExpectTest { Volume creating = Volume.builder() .id("vol-2a21e543") .status(Volume.Status.CREATING)